Skip to content

Commit 1212781

Browse files
committed
core/txpool/legacypool: add integrity checks to avoid dangling auths in tracker
1 parent bcb9836 commit 1212781

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

core/txpool/legacypool/legacypool_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"math/big"
2525
"math/rand"
26+
"slices"
2627
"sync"
2728
"sync/atomic"
2829
"testing"
@@ -238,6 +239,23 @@ func validatePoolInternals(pool *LegacyPool) error {
238239
return fmt.Errorf("pending nonce mismatch: have %v, want %v", nonce, last+1)
239240
}
240241
}
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+
}
241259
return nil
242260
}
243261

@@ -2381,6 +2399,32 @@ func TestSetCodeTransactions(t *testing.T) {
23812399
}
23822400
},
23832401
},
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+
},
23842428
} {
23852429
tt.run(tt.name)
23862430
pending, queued := pool.Stats()

0 commit comments

Comments
 (0)