@@ -59,15 +59,21 @@ func init() {
5959}
6060
6161type  testBlockChain  struct  {
62- 	gasLimit       uint64   // must be first field for 64 bit alignment ( atomic access) 
62+ 	gasLimit       atomic. Uint64 
6363	statedb        * state.StateDB 
6464	chainHeadFeed  * event.Feed 
6565}
6666
67+ func  newTestBlockChain (gasLimit  uint64 , statedb  * state.StateDB , chainHeadFeed  * event.Feed ) * testBlockChain  {
68+ 	bc  :=  testBlockChain {statedb : statedb , chainHeadFeed : new (event.Feed )}
69+ 	bc .gasLimit .Store (gasLimit )
70+ 	return  & bc 
71+ }
72+ 
6773func  (bc  * testBlockChain ) CurrentBlock () * types.Header  {
6874	return  & types.Header {
6975		Number :   new (big.Int ),
70- 		GasLimit : atomic . LoadUint64 ( & bc .gasLimit ),
76+ 		GasLimit : bc .gasLimit . Load ( ),
7177	}
7278}
7379
@@ -121,7 +127,7 @@ func setupPool() (*TxPool, *ecdsa.PrivateKey) {
121127
122128func  setupPoolWithConfig (config  * params.ChainConfig ) (* TxPool , * ecdsa.PrivateKey ) {
123129	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
124- 	blockchain  :=  & testBlockChain { 10000000 , statedb , new (event.Feed )} 
130+ 	blockchain  :=  newTestBlockChain ( 10000000 , statedb , new (event.Feed )) 
125131
126132	key , _  :=  crypto .GenerateKey ()
127133	pool  :=  NewTxPool (testTxPoolConfig , config , blockchain )
@@ -236,7 +242,7 @@ func TestStateChangeDuringReset(t *testing.T) {
236242
237243	// setup pool with 2 transaction in it 
238244	statedb .SetBalance (address , new (big.Int ).SetUint64 (params .Ether ))
239- 	blockchain  :=  & testChain {& testBlockChain { 1000000000 , statedb , new (event.Feed )} , address , & trigger }
245+ 	blockchain  :=  & testChain {newTestBlockChain ( 1000000000 , statedb , new (event.Feed )) , address , & trigger }
240246
241247	tx0  :=  transaction (0 , 100000 , key )
242248	tx1  :=  transaction (1 , 100000 , key )
@@ -430,7 +436,7 @@ func TestChainFork(t *testing.T) {
430436		statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
431437		statedb .AddBalance (addr , big .NewInt (100000000000000 ))
432438
433- 		pool .chain  =  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
439+ 		pool .chain  =  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
434440		<- pool .requestReset (nil , nil )
435441	}
436442	resetState ()
@@ -459,7 +465,7 @@ func TestDoubleNonce(t *testing.T) {
459465		statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
460466		statedb .AddBalance (addr , big .NewInt (100000000000000 ))
461467
462- 		pool .chain  =  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
468+ 		pool .chain  =  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
463469		<- pool .requestReset (nil , nil )
464470	}
465471	resetState ()
@@ -629,7 +635,7 @@ func TestDropping(t *testing.T) {
629635		t .Errorf ("total transaction mismatch: have %d, want %d" , pool .all .Count (), 4 )
630636	}
631637	// Reduce the block gas limit, check that invalidated transactions are dropped 
632- 	atomic . StoreUint64 ( & pool .chain .(* testBlockChain ).gasLimit ,  100 )
638+ 	pool .chain .(* testBlockChain ).gasLimit . Store ( 100 )
633639	<- pool .requestReset (nil , nil )
634640
635641	if  _ , ok  :=  pool .pending [account ].txs .items [tx0 .Nonce ()]; ! ok  {
@@ -657,7 +663,7 @@ func TestPostponing(t *testing.T) {
657663
658664	// Create the pool to test the postponing with 
659665	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
660- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
666+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
661667
662668	pool  :=  NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
663669	defer  pool .Stop ()
@@ -869,7 +875,7 @@ func testQueueGlobalLimiting(t *testing.T, nolocals bool) {
869875
870876	// Create the pool to test the limit enforcement with 
871877	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
872- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
878+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
873879
874880	config  :=  testTxPoolConfig 
875881	config .NoLocals  =  nolocals 
@@ -961,7 +967,7 @@ func testQueueTimeLimiting(t *testing.T, nolocals bool) {
961967
962968	// Create the pool to test the non-expiration enforcement 
963969	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
964- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
970+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
965971
966972	config  :=  testTxPoolConfig 
967973	config .Lifetime  =  time .Second 
@@ -1146,7 +1152,7 @@ func TestPendingGlobalLimiting(t *testing.T) {
11461152
11471153	// Create the pool to test the limit enforcement with 
11481154	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
1149- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
1155+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
11501156
11511157	config  :=  testTxPoolConfig 
11521158	config .GlobalSlots  =  config .AccountSlots  *  10 
@@ -1248,7 +1254,7 @@ func TestCapClearsFromAll(t *testing.T) {
12481254
12491255	// Create the pool to test the limit enforcement with 
12501256	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
1251- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
1257+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
12521258
12531259	config  :=  testTxPoolConfig 
12541260	config .AccountSlots  =  2 
@@ -1282,7 +1288,7 @@ func TestPendingMinimumAllowance(t *testing.T) {
12821288
12831289	// Create the pool to test the limit enforcement with 
12841290	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
1285- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
1291+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
12861292
12871293	config  :=  testTxPoolConfig 
12881294	config .GlobalSlots  =  1 
@@ -1330,7 +1336,7 @@ func TestRepricing(t *testing.T) {
13301336
13311337	// Create the pool to test the pricing enforcement with 
13321338	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
1333- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
1339+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
13341340
13351341	pool  :=  NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
13361342	defer  pool .Stop ()
@@ -1578,7 +1584,7 @@ func TestRepricingKeepsLocals(t *testing.T) {
15781584
15791585	// Create the pool to test the pricing enforcement with 
15801586	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
1581- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
1587+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
15821588
15831589	pool  :=  NewTxPool (testTxPoolConfig , eip1559Config , blockchain )
15841590	defer  pool .Stop ()
@@ -1651,7 +1657,7 @@ func TestUnderpricing(t *testing.T) {
16511657
16521658	// Create the pool to test the pricing enforcement with 
16531659	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
1654- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
1660+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
16551661
16561662	config  :=  testTxPoolConfig 
16571663	config .GlobalSlots  =  2 
@@ -1765,7 +1771,7 @@ func TestStableUnderpricing(t *testing.T) {
17651771
17661772	// Create the pool to test the pricing enforcement with 
17671773	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
1768- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
1774+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
17691775
17701776	config  :=  testTxPoolConfig 
17711777	config .GlobalSlots  =  128 
@@ -1997,7 +2003,7 @@ func TestDeduplication(t *testing.T) {
19972003
19982004	// Create the pool to test the pricing enforcement with 
19992005	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
2000- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
2006+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
20012007
20022008	pool  :=  NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
20032009	defer  pool .Stop ()
@@ -2063,7 +2069,7 @@ func TestReplacement(t *testing.T) {
20632069
20642070	// Create the pool to test the pricing enforcement with 
20652071	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
2066- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
2072+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
20672073
20682074	pool  :=  NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
20692075	defer  pool .Stop ()
@@ -2268,7 +2274,7 @@ func testJournaling(t *testing.T, nolocals bool) {
22682274
22692275	// Create the original pool to inject transaction into the journal 
22702276	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
2271- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
2277+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
22722278
22732279	config  :=  testTxPoolConfig 
22742280	config .NoLocals  =  nolocals 
@@ -2310,7 +2316,7 @@ func testJournaling(t *testing.T, nolocals bool) {
23102316	// Terminate the old pool, bump the local nonce, create a new pool and ensure relevant transaction survive 
23112317	pool .Stop ()
23122318	statedb .SetNonce (crypto .PubkeyToAddress (local .PublicKey ), 1 )
2313- 	blockchain  =  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
2319+ 	blockchain  =  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
23142320
23152321	pool  =  NewTxPool (config , params .TestChainConfig , blockchain )
23162322
@@ -2337,7 +2343,7 @@ func testJournaling(t *testing.T, nolocals bool) {
23372343	pool .Stop ()
23382344
23392345	statedb .SetNonce (crypto .PubkeyToAddress (local .PublicKey ), 1 )
2340- 	blockchain  =  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
2346+ 	blockchain  =  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
23412347	pool  =  NewTxPool (config , params .TestChainConfig , blockchain )
23422348
23432349	pending , queued  =  pool .Stats ()
@@ -2366,7 +2372,7 @@ func TestStatusCheck(t *testing.T) {
23662372
23672373	// Create the pool to test the status retrievals with 
23682374	statedb , _  :=  state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
2369- 	blockchain  :=  & testBlockChain { 1000000 , statedb , new (event.Feed )} 
2375+ 	blockchain  :=  newTestBlockChain ( 1000000 , statedb , new (event.Feed )) 
23702376
23712377	pool  :=  NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
23722378	defer  pool .Stop ()
0 commit comments