|
|
|
@ -149,6 +149,10 @@ func pricedSetCodeTx(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, ke |
|
|
|
|
}) |
|
|
|
|
authList = append(authList, auth) |
|
|
|
|
} |
|
|
|
|
return pricedSetCodeTxWithAuth(nonce, gaslimit, gasFee, tip, key, authList) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func pricedSetCodeTxWithAuth(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, key *ecdsa.PrivateKey, authList []types.SetCodeAuthorization) *types.Transaction { |
|
|
|
|
return types.MustSignNewTx(key, types.LatestSignerForChainID(params.TestChainConfig.ChainID), &types.SetCodeTx{ |
|
|
|
|
ChainID: uint256.MustFromBig(params.TestChainConfig.ChainID), |
|
|
|
|
Nonce: nonce, |
|
|
|
@ -2393,6 +2397,65 @@ func TestSetCodeTransactions(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestSetCodeTransactionsReorg(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
|
|
|
|
|
// Create the pool to test the status retrievals with
|
|
|
|
|
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) |
|
|
|
|
blockchain := newTestBlockChain(params.MergedTestChainConfig, 1000000, statedb, new(event.Feed)) |
|
|
|
|
|
|
|
|
|
pool := New(testTxPoolConfig, blockchain) |
|
|
|
|
pool.Init(testTxPoolConfig.PriceLimit, blockchain.CurrentBlock(), makeAddressReserver()) |
|
|
|
|
defer pool.Close() |
|
|
|
|
|
|
|
|
|
// Create the test accounts
|
|
|
|
|
var ( |
|
|
|
|
keyA, _ = crypto.GenerateKey() |
|
|
|
|
addrA = crypto.PubkeyToAddress(keyA.PublicKey) |
|
|
|
|
) |
|
|
|
|
testAddBalance(pool, addrA, big.NewInt(params.Ether)) |
|
|
|
|
// Send an authorization for 0x42
|
|
|
|
|
var authList []types.SetCodeAuthorization |
|
|
|
|
auth, _ := types.SignSetCode(keyA, types.SetCodeAuthorization{ |
|
|
|
|
ChainID: *uint256.MustFromBig(params.TestChainConfig.ChainID), |
|
|
|
|
Address: common.Address{0x42}, |
|
|
|
|
Nonce: 0, |
|
|
|
|
}) |
|
|
|
|
authList = append(authList, auth) |
|
|
|
|
if err := pool.addRemoteSync(pricedSetCodeTxWithAuth(0, 250000, uint256.NewInt(10), uint256.NewInt(3), keyA, authList)); err != nil { |
|
|
|
|
t.Fatalf("failed to add with remote setcode transaction: %v", err) |
|
|
|
|
} |
|
|
|
|
// Simulate the chain moving
|
|
|
|
|
blockchain.statedb.SetNonce(addrA, 1, tracing.NonceChangeAuthorization) |
|
|
|
|
blockchain.statedb.SetCode(addrA, types.AddressToDelegation(auth.Address)) |
|
|
|
|
<-pool.requestReset(nil, nil) |
|
|
|
|
// Set an authorization for 0x00
|
|
|
|
|
auth, _ = types.SignSetCode(keyA, types.SetCodeAuthorization{ |
|
|
|
|
ChainID: *uint256.MustFromBig(params.TestChainConfig.ChainID), |
|
|
|
|
Address: common.Address{}, |
|
|
|
|
Nonce: 0, |
|
|
|
|
}) |
|
|
|
|
authList = append(authList, auth) |
|
|
|
|
if err := pool.addRemoteSync(pricedSetCodeTxWithAuth(1, 250000, uint256.NewInt(10), uint256.NewInt(3), keyA, authList)); err != nil { |
|
|
|
|
t.Fatalf("failed to add with remote setcode transaction: %v", err) |
|
|
|
|
} |
|
|
|
|
// Try to add a transactions in
|
|
|
|
|
if err := pool.addRemoteSync(pricedTransaction(2, 100000, big.NewInt(1000), keyA)); !errors.Is(err, txpool.ErrAccountLimitExceeded) { |
|
|
|
|
t.Fatalf("unexpected error %v, expecting %v", err, txpool.ErrAccountLimitExceeded) |
|
|
|
|
} |
|
|
|
|
// Simulate the chain moving
|
|
|
|
|
blockchain.statedb.SetNonce(addrA, 2, tracing.NonceChangeAuthorization) |
|
|
|
|
blockchain.statedb.SetCode(addrA, nil) |
|
|
|
|
<-pool.requestReset(nil, nil) |
|
|
|
|
// Now send two transactions from addrA
|
|
|
|
|
if err := pool.addRemoteSync(pricedTransaction(2, 100000, big.NewInt(1000), keyA)); err != nil { |
|
|
|
|
t.Fatalf("failed to added single transaction: %v", err) |
|
|
|
|
} |
|
|
|
|
if err := pool.addRemoteSync(pricedTransaction(3, 100000, big.NewInt(1000), keyA)); err != nil { |
|
|
|
|
t.Fatalf("failed to added single transaction: %v", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Benchmarks the speed of validating the contents of the pending queue of the
|
|
|
|
|
// transaction pool.
|
|
|
|
|
func BenchmarkPendingDemotion100(b *testing.B) { benchmarkPendingDemotion(b, 100) } |
|
|
|
|