@@ -59,15 +59,21 @@ func init() {
59
59
}
60
60
61
61
type testBlockChain struct {
62
- gasLimit uint64 // must be first field for 64 bit alignment ( atomic access)
62
+ gasLimit atomic. Uint64
63
63
statedb * state.StateDB
64
64
chainHeadFeed * event.Feed
65
65
}
66
66
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
+
67
73
func (bc * testBlockChain ) CurrentBlock () * types.Header {
68
74
return & types.Header {
69
75
Number : new (big.Int ),
70
- GasLimit : atomic . LoadUint64 ( & bc .gasLimit ),
76
+ GasLimit : bc .gasLimit . Load ( ),
71
77
}
72
78
}
73
79
@@ -121,7 +127,7 @@ func setupPool() (*TxPool, *ecdsa.PrivateKey) {
121
127
122
128
func setupPoolWithConfig (config * params.ChainConfig ) (* TxPool , * ecdsa.PrivateKey ) {
123
129
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 ))
125
131
126
132
key , _ := crypto .GenerateKey ()
127
133
pool := NewTxPool (testTxPoolConfig , config , blockchain )
@@ -236,7 +242,7 @@ func TestStateChangeDuringReset(t *testing.T) {
236
242
237
243
// setup pool with 2 transaction in it
238
244
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 }
240
246
241
247
tx0 := transaction (0 , 100000 , key )
242
248
tx1 := transaction (1 , 100000 , key )
@@ -430,7 +436,7 @@ func TestChainFork(t *testing.T) {
430
436
statedb , _ := state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
431
437
statedb .AddBalance (addr , big .NewInt (100000000000000 ))
432
438
433
- pool .chain = & testBlockChain { 1000000 , statedb , new (event.Feed )}
439
+ pool .chain = newTestBlockChain ( 1000000 , statedb , new (event.Feed ))
434
440
<- pool .requestReset (nil , nil )
435
441
}
436
442
resetState ()
@@ -459,7 +465,7 @@ func TestDoubleNonce(t *testing.T) {
459
465
statedb , _ := state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
460
466
statedb .AddBalance (addr , big .NewInt (100000000000000 ))
461
467
462
- pool .chain = & testBlockChain { 1000000 , statedb , new (event.Feed )}
468
+ pool .chain = newTestBlockChain ( 1000000 , statedb , new (event.Feed ))
463
469
<- pool .requestReset (nil , nil )
464
470
}
465
471
resetState ()
@@ -629,7 +635,7 @@ func TestDropping(t *testing.T) {
629
635
t .Errorf ("total transaction mismatch: have %d, want %d" , pool .all .Count (), 4 )
630
636
}
631
637
// 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 )
633
639
<- pool .requestReset (nil , nil )
634
640
635
641
if _ , ok := pool .pending [account ].txs .items [tx0 .Nonce ()]; ! ok {
@@ -657,7 +663,7 @@ func TestPostponing(t *testing.T) {
657
663
658
664
// Create the pool to test the postponing with
659
665
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 ))
661
667
662
668
pool := NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
663
669
defer pool .Stop ()
@@ -869,7 +875,7 @@ func testQueueGlobalLimiting(t *testing.T, nolocals bool) {
869
875
870
876
// Create the pool to test the limit enforcement with
871
877
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 ))
873
879
874
880
config := testTxPoolConfig
875
881
config .NoLocals = nolocals
@@ -961,7 +967,7 @@ func testQueueTimeLimiting(t *testing.T, nolocals bool) {
961
967
962
968
// Create the pool to test the non-expiration enforcement
963
969
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 ))
965
971
966
972
config := testTxPoolConfig
967
973
config .Lifetime = time .Second
@@ -1146,7 +1152,7 @@ func TestPendingGlobalLimiting(t *testing.T) {
1146
1152
1147
1153
// Create the pool to test the limit enforcement with
1148
1154
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 ))
1150
1156
1151
1157
config := testTxPoolConfig
1152
1158
config .GlobalSlots = config .AccountSlots * 10
@@ -1248,7 +1254,7 @@ func TestCapClearsFromAll(t *testing.T) {
1248
1254
1249
1255
// Create the pool to test the limit enforcement with
1250
1256
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 ))
1252
1258
1253
1259
config := testTxPoolConfig
1254
1260
config .AccountSlots = 2
@@ -1282,7 +1288,7 @@ func TestPendingMinimumAllowance(t *testing.T) {
1282
1288
1283
1289
// Create the pool to test the limit enforcement with
1284
1290
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 ))
1286
1292
1287
1293
config := testTxPoolConfig
1288
1294
config .GlobalSlots = 1
@@ -1330,7 +1336,7 @@ func TestRepricing(t *testing.T) {
1330
1336
1331
1337
// Create the pool to test the pricing enforcement with
1332
1338
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 ))
1334
1340
1335
1341
pool := NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
1336
1342
defer pool .Stop ()
@@ -1578,7 +1584,7 @@ func TestRepricingKeepsLocals(t *testing.T) {
1578
1584
1579
1585
// Create the pool to test the pricing enforcement with
1580
1586
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 ))
1582
1588
1583
1589
pool := NewTxPool (testTxPoolConfig , eip1559Config , blockchain )
1584
1590
defer pool .Stop ()
@@ -1651,7 +1657,7 @@ func TestUnderpricing(t *testing.T) {
1651
1657
1652
1658
// Create the pool to test the pricing enforcement with
1653
1659
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 ))
1655
1661
1656
1662
config := testTxPoolConfig
1657
1663
config .GlobalSlots = 2
@@ -1765,7 +1771,7 @@ func TestStableUnderpricing(t *testing.T) {
1765
1771
1766
1772
// Create the pool to test the pricing enforcement with
1767
1773
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 ))
1769
1775
1770
1776
config := testTxPoolConfig
1771
1777
config .GlobalSlots = 128
@@ -1997,7 +2003,7 @@ func TestDeduplication(t *testing.T) {
1997
2003
1998
2004
// Create the pool to test the pricing enforcement with
1999
2005
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 ))
2001
2007
2002
2008
pool := NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
2003
2009
defer pool .Stop ()
@@ -2063,7 +2069,7 @@ func TestReplacement(t *testing.T) {
2063
2069
2064
2070
// Create the pool to test the pricing enforcement with
2065
2071
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 ))
2067
2073
2068
2074
pool := NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
2069
2075
defer pool .Stop ()
@@ -2268,7 +2274,7 @@ func testJournaling(t *testing.T, nolocals bool) {
2268
2274
2269
2275
// Create the original pool to inject transaction into the journal
2270
2276
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 ))
2272
2278
2273
2279
config := testTxPoolConfig
2274
2280
config .NoLocals = nolocals
@@ -2310,7 +2316,7 @@ func testJournaling(t *testing.T, nolocals bool) {
2310
2316
// Terminate the old pool, bump the local nonce, create a new pool and ensure relevant transaction survive
2311
2317
pool .Stop ()
2312
2318
statedb .SetNonce (crypto .PubkeyToAddress (local .PublicKey ), 1 )
2313
- blockchain = & testBlockChain { 1000000 , statedb , new (event.Feed )}
2319
+ blockchain = newTestBlockChain ( 1000000 , statedb , new (event.Feed ))
2314
2320
2315
2321
pool = NewTxPool (config , params .TestChainConfig , blockchain )
2316
2322
@@ -2337,7 +2343,7 @@ func testJournaling(t *testing.T, nolocals bool) {
2337
2343
pool .Stop ()
2338
2344
2339
2345
statedb .SetNonce (crypto .PubkeyToAddress (local .PublicKey ), 1 )
2340
- blockchain = & testBlockChain { 1000000 , statedb , new (event.Feed )}
2346
+ blockchain = newTestBlockChain ( 1000000 , statedb , new (event.Feed ))
2341
2347
pool = NewTxPool (config , params .TestChainConfig , blockchain )
2342
2348
2343
2349
pending , queued = pool .Stats ()
@@ -2366,7 +2372,7 @@ func TestStatusCheck(t *testing.T) {
2366
2372
2367
2373
// Create the pool to test the status retrievals with
2368
2374
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 ))
2370
2376
2371
2377
pool := NewTxPool (testTxPoolConfig , params .TestChainConfig , blockchain )
2372
2378
defer pool .Stop ()
0 commit comments