@@ -228,6 +228,10 @@ func pricedSetCodeTx(nonce uint64, gaslimit uint64, gasFee, tip *uint256.Int, ke
228
228
}, u .key )
229
229
authList = append (authList , auth )
230
230
}
231
+ return pricedSetCodeTxWithAuth (nonce , gaslimit , gasFee , tip , key , authList )
232
+ }
233
+
234
+ func pricedSetCodeTxWithAuth (nonce uint64 , gaslimit uint64 , gasFee , tip * uint256.Int , key * ecdsa.PrivateKey , authList []types.Authorization ) * types.Transaction {
231
235
return types .MustSignNewTx (key , types .LatestSignerForChainID (params .TestChainConfig .ChainID ), & types.SetCodeTx {
232
236
ChainID : params .TestChainConfig .ChainID .Uint64 (),
233
237
Nonce : nonce ,
@@ -2791,6 +2795,75 @@ func TestSetCodeTransactions(t *testing.T) {
2791
2795
}
2792
2796
}
2793
2797
2798
+ func TestSetCodeTransactionsReorg (t * testing.T ) {
2799
+ t .Parallel ()
2800
+
2801
+ // Create the pool to test the status retrievals with
2802
+ // statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
2803
+ statedb , _ := state .New (common.Hash {}, state .NewDatabase (rawdb .NewMemoryDatabase ()), nil )
2804
+ // blockchain := newTestBlockChain(params.MergedTestChainConfig, 1000000, statedb, new(event.Feed))
2805
+ blockchain := & testBlockChain {1000000 , statedb , new (event.Feed ), 0 }
2806
+
2807
+ pool := New (testTxPoolConfig , params .TestChainConfig , blockchain )
2808
+ pool .Init (
2809
+ testTxPoolConfig .PriceLimit ,
2810
+ blockchain .CurrentBlock ().Header (),
2811
+ makeAddressReserver (),
2812
+ )
2813
+
2814
+ // wait for the pool to initialize
2815
+ <- pool .initDoneCh
2816
+
2817
+ defer pool .Close ()
2818
+
2819
+ // Create the test accounts
2820
+ var (
2821
+ keyA , _ = crypto .GenerateKey ()
2822
+ addrA = crypto .PubkeyToAddress (keyA .PublicKey )
2823
+ )
2824
+ testAddBalance (pool , addrA , big .NewInt (params .Ether ))
2825
+ // Send an authorization for 0x42
2826
+ var authList []types.Authorization
2827
+ auth , _ := types .SignAuth (types.Authorization {
2828
+ ChainID : params .TestChainConfig .ChainID .Uint64 (),
2829
+ Address : common.Address {0x42 },
2830
+ Nonce : 0 ,
2831
+ }, keyA )
2832
+ authList = append (authList , auth )
2833
+ if err := pool .addRemoteSync (pricedSetCodeTxWithAuth (0 , 250000 , uint256 .NewInt (10 ), uint256 .NewInt (3 ), keyA , authList )); err != nil {
2834
+ t .Fatalf ("failed to add with remote setcode transaction: %v" , err )
2835
+ }
2836
+ // Simulate the chain moving
2837
+ blockchain .statedb .SetNonce (addrA , 1 )
2838
+ blockchain .statedb .SetCode (addrA , types .AddressToDelegation (auth .Address ))
2839
+ <- pool .requestReset (nil , nil )
2840
+ // Set an authorization for 0x00
2841
+ auth , _ = types .SignAuth (types.Authorization {
2842
+ ChainID : params .TestChainConfig .ChainID .Uint64 (),
2843
+ Address : common.Address {},
2844
+ Nonce : 0 ,
2845
+ }, keyA )
2846
+ authList = append (authList , auth )
2847
+ if err := pool .addRemoteSync (pricedSetCodeTxWithAuth (1 , 250000 , uint256 .NewInt (10 ), uint256 .NewInt (3 ), keyA , authList )); err != nil {
2848
+ t .Fatalf ("failed to add with remote setcode transaction: %v" , err )
2849
+ }
2850
+ // Try to add a transactions in
2851
+ if err := pool .addRemoteSync (pricedTransaction (2 , 100000 , big .NewInt (1000 ), keyA )); ! errors .Is (err , ErrInflightTxLimitReached ) {
2852
+ t .Fatalf ("unexpected error %v, expecting %v" , err , ErrInflightTxLimitReached )
2853
+ }
2854
+ // Simulate the chain moving
2855
+ blockchain .statedb .SetNonce (addrA , 2 )
2856
+ blockchain .statedb .SetCode (addrA , nil )
2857
+ <- pool .requestReset (nil , nil )
2858
+ // Now send two transactions from addrA
2859
+ if err := pool .addRemoteSync (pricedTransaction (2 , 100000 , big .NewInt (1000 ), keyA )); err != nil {
2860
+ t .Fatalf ("failed to added single transaction: %v" , err )
2861
+ }
2862
+ if err := pool .addRemoteSync (pricedTransaction (3 , 100000 , big .NewInt (1000 ), keyA )); err != nil {
2863
+ t .Fatalf ("failed to added single transaction: %v" , err )
2864
+ }
2865
+ }
2866
+
2794
2867
// Benchmarks the speed of validating the contents of the pending queue of the
2795
2868
// transaction pool.
2796
2869
func BenchmarkPendingDemotion100 (b * testing.B ) { benchmarkPendingDemotion (b , 100 ) }
0 commit comments