core: emit sidechain event during reorg

This commit is contained in:
Manav Darji 2025-03-31 12:02:19 +05:30
parent 0c0b9bc025
commit 2e71e50b6b
No known key found for this signature in database
GPG key ID: A426F0124435F36E
3 changed files with 9 additions and 6 deletions

View file

@ -1993,7 +1993,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
// BOR // BOR
} }
} else { } else {
bc.chainSideFeed.Send(ChainSideEvent{Block: block}) bc.chainSideFeed.Send(ChainSideEvent{Header: block.Header()})
bc.chain2HeadFeed.Send(Chain2HeadEvent{ bc.chain2HeadFeed.Send(Chain2HeadEvent{
Type: Chain2HeadForkEvent, 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? // TODO(karalabe): This should be nuked out, no idea how, deprecate some APIs?
{ {
for i := len(oldChain) - 1; i >= 0; i-- { 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()) block := bc.GetBlock(oldChain[i].Hash(), oldChain[i].Number.Uint64())
if block == nil { if block == nil {
return errInvalidOldChain // Corrupt database, mostly here to avoid weird panics return errInvalidOldChain // Corrupt database, mostly here to avoid weird panics

View file

@ -1513,7 +1513,6 @@ func checkLogEvents(t *testing.T, logsCh <-chan []*types.Log, rmLogsCh <-chan Re
} }
func TestReorgSideEvent(t *testing.T) { func TestReorgSideEvent(t *testing.T) {
t.Skip("needs discussion")
testReorgSideEvent(t, rawdb.HashScheme) testReorgSideEvent(t, rawdb.HashScheme)
testReorgSideEvent(t, rawdb.PathScheme) testReorgSideEvent(t, rawdb.PathScheme)
} }
@ -1575,9 +1574,9 @@ done:
for { for {
select { select {
case ev := <-chainSideCh: case ev := <-chainSideCh:
block := ev.Block header := ev.Header
if _, ok := expectedSideHashes[block.Hash()]; !ok { if _, ok := expectedSideHashes[header.Hash()]; !ok {
t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) t.Errorf("%d: didn't expect %x to be in side chain", i, header.Hash())
} }
i++ i++

View file

@ -34,7 +34,7 @@ type ChainEvent struct {
} }
type ChainSideEvent struct { type ChainSideEvent struct {
Block *types.Block Header *types.Header
} }
type ChainHeadEvent struct { type ChainHeadEvent struct {