@@ -23,6 +23,7 @@ import (
23
23
"fmt"
24
24
"math/big"
25
25
"math/rand"
26
+ "slices"
26
27
"sync"
27
28
"sync/atomic"
28
29
"testing"
@@ -238,6 +239,23 @@ func validatePoolInternals(pool *LegacyPool) error {
238
239
return fmt .Errorf ("pending nonce mismatch: have %v, want %v" , nonce , last + 1 )
239
240
}
240
241
}
242
+ // Ensure all auths in pool are tracked
243
+ for _ , tx := range pool .all .txs {
244
+ for _ , addr := range tx .SetCodeAuthorities () {
245
+ list := pool .all .auths [addr ]
246
+ if i := slices .Index (list , tx .Hash ()); i < 0 {
247
+ return fmt .Errorf ("authority not tracked: addr %s, tx %s" , addr , tx .Hash ())
248
+ }
249
+ }
250
+ }
251
+ // Ensure all auths in pool have an associated tx.
252
+ for addr , hashes := range pool .all .auths {
253
+ for _ , hash := range hashes {
254
+ if _ , ok := pool .all .txs [hash ]; ! ok {
255
+ return fmt .Errorf ("dangling authority, missing originating tx: addr %s, hash %s" , addr , hash .Hex ())
256
+ }
257
+ }
258
+ }
241
259
return nil
242
260
}
243
261
@@ -2381,6 +2399,32 @@ func TestSetCodeTransactions(t *testing.T) {
2381
2399
}
2382
2400
},
2383
2401
},
2402
+ {
2403
+ name : "remove-hash-from-authority-tracker" ,
2404
+ pending : 10 ,
2405
+ run : func (name string ) {
2406
+ var keys []* ecdsa.PrivateKey
2407
+ for i := 0 ; i < 30 ; i ++ {
2408
+ key , _ := crypto .GenerateKey ()
2409
+ keys = append (keys , key )
2410
+ addr := crypto .PubkeyToAddress (key .PublicKey )
2411
+ testAddBalance (pool , addr , big .NewInt (params .Ether ))
2412
+ }
2413
+ // Create a transactions with 3 unique auths so the lookup's auth map is
2414
+ // filled with addresses.
2415
+ for i := 0 ; i < 30 ; i += 3 {
2416
+ if err := pool .addRemoteSync (pricedSetCodeTx (0 , 250000 , uint256 .NewInt (10 ), uint256 .NewInt (3 ), keys [i ], []unsignedAuth {{0 , keys [i ]}, {0 , keys [i + 1 ]}, {0 , keys [i + 2 ]}})); err != nil {
2417
+ t .Fatalf ("%s: failed to add with remote setcode transaction: %v" , name , err )
2418
+ }
2419
+ }
2420
+ // Replace one of the transactions with a normal transaction so that the
2421
+ // original hash is removed from the tracker. The hash should be
2422
+ // associated with 3 different authorities.
2423
+ if err := pool .addRemoteSync (pricedTransaction (0 , 100000 , big .NewInt (1000 ), keys [0 ])); err != nil {
2424
+ t .Fatalf ("%s: failed to replace with remote transaction: %v" , name , err )
2425
+ }
2426
+ },
2427
+ },
2384
2428
} {
2385
2429
tt .run (tt .name )
2386
2430
pending , queued := pool .Stats ()
0 commit comments