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.
This commit is contained in:
Csaba Kiraly 2026-06-23 00:26:22 +02:00
parent 09bd6fc0ec
commit ffb92fef99
2 changed files with 4 additions and 16 deletions

View file

@ -58,7 +58,6 @@ type PeerStats struct {
// Chain is the blockchain interface needed by the tracker. // Chain is the blockchain interface needed by the tracker.
type Chain interface { type Chain interface {
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
GetBlockByNumber(number uint64) *types.Block
GetBlock(hash common.Hash, number uint64) *types.Block GetBlock(hash common.Hash, number uint64) *types.Block
GetCanonicalHash(number uint64) common.Hash GetCanonicalHash(number uint64) common.Hash
CurrentFinalBlock() *types.Header CurrentFinalBlock() *types.Header

View file

@ -34,7 +34,7 @@ import (
// Blocks are stored by hash to exercise the reorg-safe lookup path in // Blocks are stored by hash to exercise the reorg-safe lookup path in
// tracker.handleChainHead (which calls GetBlock(hash, number)). A separate // tracker.handleChainHead (which calls GetBlock(hash, number)). A separate
// canonicalByNum index maps each height to its canonical block hash, used // 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 { type mockChain struct {
mu sync.Mutex mu sync.Mutex
headFeed event.Feed headFeed event.Feed
@ -54,16 +54,6 @@ func (c *mockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event
return c.headFeed.Subscribe(ch) 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 { func (c *mockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() 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 // addBlockAtHeight adds a block at the given height. The salt parameter
// ensures distinct block hashes for two blocks at the same height (used // ensures distinct block hashes for two blocks at the same height (used
// for reorg tests). If canonical is true, the block becomes the canonical // 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 { 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)) 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 // 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. // the same height does not credit transactions from the canonical block.
// //
// Regression check: if the tracker were changed to use GetBlockByNumber, // Regression check: handleChainHead uses GetBlock(hash, number) so a head
// it would always fetch the canonical block A and credit peerA even when // event announcing sibling B fetches B, not the canonical block A.
// the head points to sibling B.
func TestReorgSafety(t *testing.T) { func TestReorgSafety(t *testing.T) {
tr := New() tr := New()
chain := newMockChain() chain := newMockChain()