mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
core: emit sidechain event during reorg
This commit is contained in:
parent
0c0b9bc025
commit
2e71e50b6b
3 changed files with 9 additions and 6 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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++
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue