From ffb92fef9939edfcf3c0abc94b659ceb18e642b5 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 23 Jun 2026 00:26:22 +0200 Subject: [PATCH] eth/txtracker: drop GetBlockByNumber from the Chain interface The finalization-credit pivot replaced the per-block walk with an iterate-t.txs scan, eliminating the only caller of GetBlockByNumber in this package. Drop it from the Chain interface and from mockChain. *core.BlockChain still satisfies the slimmed interface (it has all the remaining methods); production wiring is unchanged. Updates two stale test comments that referenced the removed call. --- eth/txtracker/tracker.go | 1 - eth/txtracker/tracker_test.go | 19 ++++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/eth/txtracker/tracker.go b/eth/txtracker/tracker.go index e586f9a907..2e219ed1e7 100644 --- a/eth/txtracker/tracker.go +++ b/eth/txtracker/tracker.go @@ -58,7 +58,6 @@ type PeerStats struct { // Chain is the blockchain interface needed by the tracker. type Chain interface { SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription - GetBlockByNumber(number uint64) *types.Block GetBlock(hash common.Hash, number uint64) *types.Block GetCanonicalHash(number uint64) common.Hash CurrentFinalBlock() *types.Header diff --git a/eth/txtracker/tracker_test.go b/eth/txtracker/tracker_test.go index b6d966f576..a660c37274 100644 --- a/eth/txtracker/tracker_test.go +++ b/eth/txtracker/tracker_test.go @@ -34,7 +34,7 @@ import ( // Blocks are stored by hash to exercise the reorg-safe lookup path in // tracker.handleChainHead (which calls GetBlock(hash, number)). A separate // canonicalByNum index maps each height to its canonical block hash, used -// by GetBlockByNumber (the finalization path). +// by GetCanonicalHash in the finalization-credit path. type mockChain struct { mu sync.Mutex headFeed event.Feed @@ -54,16 +54,6 @@ func (c *mockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event return c.headFeed.Subscribe(ch) } -func (c *mockChain) GetBlockByNumber(number uint64) *types.Block { - c.mu.Lock() - defer c.mu.Unlock() - hash, ok := c.canonicalByNum[number] - if !ok { - return nil - } - return c.blocksByHash[hash] -} - func (c *mockChain) GetBlock(hash common.Hash, number uint64) *types.Block { c.mu.Lock() defer c.mu.Unlock() @@ -94,7 +84,7 @@ func (c *mockChain) addBlock(num uint64, txs []*types.Transaction) *types.Block // addBlockAtHeight adds a block at the given height. The salt parameter // ensures distinct block hashes for two blocks at the same height (used // for reorg tests). If canonical is true, the block becomes the canonical -// block for that height (looked up by GetBlockByNumber). +// block for that height (looked up by GetCanonicalHash). func (c *mockChain) addBlockAtHeight(num, salt uint64, txs []*types.Transaction, canonical bool) *types.Block { return c.addBlockAtHeightWithTime(num, salt, txs, canonical, uint64(time.Now().Unix()+3600)) } @@ -390,9 +380,8 @@ func TestEMADecay(t *testing.T) { // HASH (not just by number), so a head event announcing a sibling block at // the same height does not credit transactions from the canonical block. // -// Regression check: if the tracker were changed to use GetBlockByNumber, -// it would always fetch the canonical block A and credit peerA even when -// the head points to sibling B. +// Regression check: handleChainHead uses GetBlock(hash, number) so a head +// event announcing sibling B fetches B, not the canonical block A. func TestReorgSafety(t *testing.T) { tr := New() chain := newMockChain()