Skip to content

Commit

Permalink
core: 64bit alignment of testBlockChain.gasLimit (ethereum#23543)
Browse files Browse the repository at this point in the history
This fixes crashes in txpool tests on 32bit platforms.
  • Loading branch information
fjl authored and zzyalbert committed Nov 26, 2021
1 parent e587cee commit 4aeace1
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func init() {
}

type testBlockChain struct {
gasLimit uint64 // must be first field for 64 bit alignment (atomic access)
statedb *state.StateDB
gasLimit uint64
chainHeadFeed *event.Feed
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func setupTxPool() (*TxPool, *ecdsa.PrivateKey) {

func setupTxPoolWithConfig(config *params.ChainConfig) (*TxPool, *ecdsa.PrivateKey) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 10000000, new(event.Feed)}
blockchain := &testBlockChain{10000000, statedb, new(event.Feed)}

key, _ := crypto.GenerateKey()
pool := NewTxPool(testTxPoolConfig, config, blockchain)
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {

// setup pool with 2 transaction in it
statedb.SetBalance(address, new(big.Int).SetUint64(params.Ether))
blockchain := &testChain{&testBlockChain{statedb, 1000000000, new(event.Feed)}, address, &trigger}
blockchain := &testChain{&testBlockChain{1000000000, statedb, new(event.Feed)}, address, &trigger}

tx0 := transaction(0, 100000, key)
tx1 := transaction(1, 100000, key)
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestTransactionChainFork(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
statedb.AddBalance(addr, big.NewInt(100000000000000))

pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
pool.chain = &testBlockChain{1000000, statedb, new(event.Feed)}
<-pool.requestReset(nil, nil)
}
resetState()
Expand Down Expand Up @@ -458,7 +458,7 @@ func TestTransactionDoubleNonce(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
statedb.AddBalance(addr, big.NewInt(100000000000000))

pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
pool.chain = &testBlockChain{1000000, statedb, new(event.Feed)}
<-pool.requestReset(nil, nil)
}
resetState()
Expand Down Expand Up @@ -656,7 +656,7 @@ func TestTransactionPostponing(t *testing.T) {

// Create the pool to test the postponing with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
Expand Down Expand Up @@ -869,7 +869,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {

// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.NoLocals = nolocals
Expand Down Expand Up @@ -961,7 +961,7 @@ func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {

// Create the pool to test the non-expiration enforcement
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.Lifetime = time.Second
Expand Down Expand Up @@ -1146,7 +1146,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {

// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.GlobalSlots = config.AccountSlots * 10
Expand Down Expand Up @@ -1248,7 +1248,7 @@ func TestTransactionCapClearsFromAll(t *testing.T) {

// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.AccountSlots = 2
Expand Down Expand Up @@ -1282,7 +1282,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {

// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.GlobalSlots = 1
Expand Down Expand Up @@ -1330,7 +1330,7 @@ func TestTransactionPoolRepricing(t *testing.T) {

// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
Expand Down Expand Up @@ -1578,7 +1578,7 @@ func TestTransactionPoolRepricingKeepsLocals(t *testing.T) {

// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, eip1559Config, blockchain)
defer pool.Stop()
Expand Down Expand Up @@ -1651,7 +1651,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {

// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.GlobalSlots = 2
Expand Down Expand Up @@ -1757,7 +1757,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {

// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.GlobalSlots = 128
Expand Down Expand Up @@ -1989,7 +1989,7 @@ func TestTransactionDeduplication(t *testing.T) {

// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
Expand Down Expand Up @@ -2055,7 +2055,7 @@ func TestTransactionReplacement(t *testing.T) {

// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
Expand Down Expand Up @@ -2260,7 +2260,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {

// Create the original pool to inject transaction into the journal
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

config := testTxPoolConfig
config.NoLocals = nolocals
Expand Down Expand Up @@ -2302,7 +2302,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
// Terminate the old pool, bump the local nonce, create a new pool and ensure relevant transaction survive
pool.Stop()
statedb.SetNonce(crypto.PubkeyToAddress(local.PublicKey), 1)
blockchain = &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain = &testBlockChain{1000000, statedb, new(event.Feed)}

pool = NewTxPool(config, params.TestChainConfig, blockchain)

Expand All @@ -2329,7 +2329,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
pool.Stop()

statedb.SetNonce(crypto.PubkeyToAddress(local.PublicKey), 1)
blockchain = &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain = &testBlockChain{1000000, statedb, new(event.Feed)}
pool = NewTxPool(config, params.TestChainConfig, blockchain)

pending, queued = pool.Stats()
Expand Down Expand Up @@ -2358,7 +2358,7 @@ func TestTransactionStatusCheck(t *testing.T) {

// Create the pool to test the status retrievals with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{1000000, statedb, new(event.Feed)}

pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
Expand Down

0 comments on commit 4aeace1

Please sign in to comment.