Skip to content

Commit 7000aa1

Browse files
MariusVanDerWijdenbuddh0
authored andcommitted
core/txpool/legacypool: add setCodeTx reorg test (ethereum#31206)
This PR adds a test that makes sure that a node can send multiple transactions again once a authorization is removed
1 parent c266001 commit 7000aa1

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

core/txpool/legacypool/legacypool_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func pricedSetCodeTx(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, ke
150150
})
151151
authList = append(authList, auth)
152152
}
153+
return pricedSetCodeTxWithAuth(nonce, gaslimit, gasFee, tip, key, authList)
154+
}
155+
156+
func pricedSetCodeTxWithAuth(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, key *ecdsa.PrivateKey, authList []types.SetCodeAuthorization) *types.Transaction {
153157
return types.MustSignNewTx(key, types.LatestSignerForChainID(params.TestChainConfig.ChainID), &types.SetCodeTx{
154158
ChainID: uint256.MustFromBig(params.TestChainConfig.ChainID),
155159
Nonce: nonce,
@@ -2494,6 +2498,65 @@ func TestSetCodeTransactions(t *testing.T) {
24942498
}
24952499
}
24962500

2501+
func TestSetCodeTransactionsReorg(t *testing.T) {
2502+
t.Parallel()
2503+
2504+
// Create the pool to test the status retrievals with
2505+
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
2506+
blockchain := newTestBlockChain(params.MergedTestChainConfig, 1000000, statedb, new(event.Feed))
2507+
2508+
pool := New(testTxPoolConfig, blockchain)
2509+
pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), makeAddressReserver())
2510+
defer pool.Close()
2511+
2512+
// Create the test accounts
2513+
var (
2514+
keyA, _ = crypto.GenerateKey()
2515+
addrA = crypto.PubkeyToAddress(keyA.PublicKey)
2516+
)
2517+
testAddBalance(pool, addrA, big.NewInt(params.Ether))
2518+
// Send an authorization for 0x42
2519+
var authList []types.SetCodeAuthorization
2520+
auth, _ := types.SignSetCode(keyA, types.SetCodeAuthorization{
2521+
ChainID: *uint256.MustFromBig(params.TestChainConfig.ChainID),
2522+
Address: common.Address{0x42},
2523+
Nonce: 0,
2524+
})
2525+
authList = append(authList, auth)
2526+
if err := pool.addRemoteSync(pricedSetCodeTxWithAuth(0, 250000, uint256.NewInt(10), uint256.NewInt(3), keyA, authList)); err != nil {
2527+
t.Fatalf("failed to add with remote setcode transaction: %v", err)
2528+
}
2529+
// Simulate the chain moving
2530+
blockchain.statedb.SetNonce(addrA, 1, tracing.NonceChangeAuthorization)
2531+
blockchain.statedb.SetCode(addrA, types.AddressToDelegation(auth.Address))
2532+
<-pool.requestReset(nil, nil)
2533+
// Set an authorization for 0x00
2534+
auth, _ = types.SignSetCode(keyA, types.SetCodeAuthorization{
2535+
ChainID: *uint256.MustFromBig(params.TestChainConfig.ChainID),
2536+
Address: common.Address{},
2537+
Nonce: 0,
2538+
})
2539+
authList = append(authList, auth)
2540+
if err := pool.addRemoteSync(pricedSetCodeTxWithAuth(1, 250000, uint256.NewInt(10), uint256.NewInt(3), keyA, authList)); err != nil {
2541+
t.Fatalf("failed to add with remote setcode transaction: %v", err)
2542+
}
2543+
// Try to add a transactions in
2544+
if err := pool.addRemoteSync(pricedTransaction(2, 100000, big.NewInt(1000), keyA)); !errors.Is(err, txpool.ErrAccountLimitExceeded) {
2545+
t.Fatalf("unexpected error %v, expecting %v", err, txpool.ErrAccountLimitExceeded)
2546+
}
2547+
// Simulate the chain moving
2548+
blockchain.statedb.SetNonce(addrA, 2, tracing.NonceChangeAuthorization)
2549+
blockchain.statedb.SetCode(addrA, nil)
2550+
<-pool.requestReset(nil, nil)
2551+
// Now send two transactions from addrA
2552+
if err := pool.addRemoteSync(pricedTransaction(2, 100000, big.NewInt(1000), keyA)); err != nil {
2553+
t.Fatalf("failed to added single transaction: %v", err)
2554+
}
2555+
if err := pool.addRemoteSync(pricedTransaction(3, 100000, big.NewInt(1000), keyA)); err != nil {
2556+
t.Fatalf("failed to added single transaction: %v", err)
2557+
}
2558+
}
2559+
24972560
// Benchmarks the speed of validating the contents of the pending queue of the
24982561
// transaction pool.
24992562
func BenchmarkPendingDemotion100(b *testing.B) { benchmarkPendingDemotion(b, 100) }

0 commit comments

Comments
 (0)