diff --git a/eth/sync_test.go b/eth/sync_test.go index a111f65ddf..828286561c 100644 --- a/eth/sync_test.go +++ b/eth/sync_test.go @@ -158,7 +158,21 @@ func testSnapSyncDisabling(t *testing.T, ethVer uint, snapVer uint) { } } -func TestArtificialFinalityFeatureEnablingDisabling(t *testing.T) { +func TestArtificialFinalityFeatureEnablingDisabling_AbleDisable(t *testing.T) { + // Tweak the hardcoded minArtificialFinalityPeers value + // before anything else (and establish its reassignment to original value). + // Lowering the value from the default is only done to save the boilerplate of + // setting up 5 peers instead of 1. + // Its important to do this before starting the syncer because + // of a potential data race with the minArtificialFinalityPeers value. + // This value does not (should not) change during geth runtime. + oMinAFPeers := minArtificialFinalityPeers + defer func() { + // Clean up after, resetting global default to original value. + minArtificialFinalityPeers = oMinAFPeers + }() + minArtificialFinalityPeers = 1 + maxBlocksCreated := 1024 genFunc := blockGenContemporaryTime(int64(maxBlocksCreated)) @@ -172,13 +186,6 @@ func TestArtificialFinalityFeatureEnablingDisabling(t *testing.T) { one := uint64(1) a.chain.Config().SetECBP1100Transition(&one) - oMinAFPeers := minArtificialFinalityPeers - defer func() { - // Clean up after, resetting global default to original value. - minArtificialFinalityPeers = oMinAFPeers - }() - minArtificialFinalityPeers = 1 - // Create a full protocol manager, check that fast sync gets disabled b := newTestHandlerWithBlocksWithOpts(0, downloader.FullSync, genFunc) if atomic.LoadUint32(&b.handler.snapSync) == 1 { @@ -241,6 +248,20 @@ func TestArtificialFinalityFeatureEnablingDisabling(t *testing.T) { // TestArtificialFinalityFeatureEnablingDisabling_NoDisable tests that when the nodisable override // is in place (see NOTE1 below), AF is not disabled at the min peer floor. func TestArtificialFinalityFeatureEnablingDisabling_NoDisable(t *testing.T) { + // Tweak the hardcoded minArtificialFinalityPeers value + // before anything else (and establish its reassignment to original value). + // Lowering the value from the default is only done to save the boilerplate of + // setting up 5 peers instead of 1. + // Its important to do this before starting the syncer because + // of a potential data race with the minArtificialFinalityPeers value. + // This value does not (should not) change during geth runtime. + oMinAFPeers := minArtificialFinalityPeers + defer func() { + // Clean up after, resetting global default to original value. + minArtificialFinalityPeers = oMinAFPeers + }() + minArtificialFinalityPeers = 1 + maxBlocksCreated := 1024 genFunc := blockGenContemporaryTime(int64(maxBlocksCreated)) @@ -251,13 +272,6 @@ func TestArtificialFinalityFeatureEnablingDisabling_NoDisable(t *testing.T) { one := uint64(1) a.chain.Config().SetECBP1100Transition(&one) - oMinAFPeers := minArtificialFinalityPeers - defer func() { - // Clean up after, resetting global default to original value. - minArtificialFinalityPeers = oMinAFPeers - }() - minArtificialFinalityPeers = 1 - // Create a full protocol manager, check that fast sync gets disabled b := newTestHandlerWithBlocksWithOpts(0, downloader.FullSync, genFunc) defer b.close() @@ -328,6 +342,20 @@ and the number of peers 'a' is connected with being only 1.)`) // be very old (far exceeding the auto-disable stale limit). // In this case, AF features should NOT be enabled. func TestArtificialFinalityFeatureEnablingDisabling_StaleHead(t *testing.T) { + // Tweak the hardcoded minArtificialFinalityPeers value + // before anything else (and establish its reassignment to original value). + // Lowering the value from the default is only done to save the boilerplate of + // setting up 5 peers instead of 1. + // Its important to do this before starting the syncer because + // of a potential data race with the minArtificialFinalityPeers value. + // This value does not (should not) change during geth runtime. + oMinAFPeers := minArtificialFinalityPeers + defer func() { + // Clean up after, resetting global default to original value. + minArtificialFinalityPeers = oMinAFPeers + }() + minArtificialFinalityPeers = 1 + maxBlocksCreated := 1024 // Create a full protocol manager, check that fast sync gets disabled @@ -336,13 +364,6 @@ func TestArtificialFinalityFeatureEnablingDisabling_StaleHead(t *testing.T) { one := uint64(1) a.chain.Config().SetECBP1100Transition(&one) - oMinAFPeers := minArtificialFinalityPeers - defer func() { - // Clean up after, resetting global default to original value. - minArtificialFinalityPeers = oMinAFPeers - }() - minArtificialFinalityPeers = 1 - // Create a full protocol manager, check that fast sync gets disabled b := newTestHandlerWithBlocksWithOpts(0, downloader.FullSync, nil) defer b.close()