From 2e71e50b6bc6072ee72f13cc57443da935964f5c Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Mon, 31 Mar 2025 12:02:19 +0530 Subject: [PATCH] core: emit sidechain event during reorg --- core/blockchain.go | 6 +++++- core/blockchain_test.go | 7 +++---- core/events.go | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 06a84f4264..f124caee91 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1993,7 +1993,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types // BOR } } else { - bc.chainSideFeed.Send(ChainSideEvent{Block: block}) + bc.chainSideFeed.Send(ChainSideEvent{Header: block.Header()}) bc.chain2HeadFeed.Send(Chain2HeadEvent{ Type: Chain2HeadForkEvent, @@ -2994,6 +2994,10 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Header) error // TODO(karalabe): This should be nuked out, no idea how, deprecate some APIs? { for i := len(oldChain) - 1; i >= 0; i-- { + // Also send event for blocks removed from the canon chain. Note: Geth has removed + // the concept of side chains but we need them in bor. + bc.chainSideFeed.Send(ChainSideEvent{Header: oldChain[i]}) + block := bc.GetBlock(oldChain[i].Hash(), oldChain[i].Number.Uint64()) if block == nil { return errInvalidOldChain // Corrupt database, mostly here to avoid weird panics diff --git a/core/blockchain_test.go b/core/blockchain_test.go index d14e050baa..19a9975e5d 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -1513,7 +1513,6 @@ func checkLogEvents(t *testing.T, logsCh <-chan []*types.Log, rmLogsCh <-chan Re } func TestReorgSideEvent(t *testing.T) { - t.Skip("needs discussion") testReorgSideEvent(t, rawdb.HashScheme) testReorgSideEvent(t, rawdb.PathScheme) } @@ -1575,9 +1574,9 @@ done: for { select { case ev := <-chainSideCh: - block := ev.Block - if _, ok := expectedSideHashes[block.Hash()]; !ok { - t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) + header := ev.Header + if _, ok := expectedSideHashes[header.Hash()]; !ok { + t.Errorf("%d: didn't expect %x to be in side chain", i, header.Hash()) } i++ diff --git a/core/events.go b/core/events.go index 62fb2d3cf5..ab8b2b5f84 100644 --- a/core/events.go +++ b/core/events.go @@ -34,7 +34,7 @@ type ChainEvent struct { } type ChainSideEvent struct { - Block *types.Block + Header *types.Header } type ChainHeadEvent struct {