mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
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:
parent
09bd6fc0ec
commit
ffb92fef99
2 changed files with 4 additions and 16 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue