diff --git a/core/blockchain.go b/core/blockchain.go index d6880d2d4fe9..1c764d500cee 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2121,15 +2121,16 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { log.Crit("Failed to delete useless indexes", "err", err) } - // Send out events for deleted logs. The number of - // restored logs can be very high, so the events are sent in batches of - // size < 512. + // Send out events for deleted and new logs. The number of logs can be very + // high, so the events are sent in batches of size around 512. + + // Deleted logs + blocks var deletedLogs []*types.Log for i := len(oldChain) - 1; i >= 0; i-- { - oldBlock := oldChain[i] + // Also send event for blocks removed from the canon chain. + bc.chainSideFeed.Send(ChainSideEvent{Block: oldChain[i]}) // Collect deleted logs for notification - if logs := bc.collectLogs(oldBlock.Hash(), true); len(logs) > 0 { - //deletedLogs = append(deletedLogs, logs) + if logs := bc.collectLogs(oldChain[i].Hash(), true); len(logs) > 0 { deletedLogs = append(deletedLogs, logs...) } if len(deletedLogs) > 512 { @@ -2140,11 +2141,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { if len(deletedLogs) > 0 { bc.rmLogsFeed.Send(RemovedLogsEvent{deletedLogs}) } - - // Send events for 'reborn' logs, i.e. logs that were previously - // removed but now got restored in the new chain branch. The number of - // restored logs can be very high, so the events are sent in batches of - // size < 512. + // New logs var rebirthLogs []*types.Log for i := len(newChain) - 1; i >= 1; i-- { // Collect reborn logs due to chain reorg @@ -2159,13 +2156,6 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { if len(rebirthLogs) > 0 { bc.logsFeed.Send(rebirthLogs) } - - // Send notifications for blocks removed from the canon chain. - if len(oldChain) > 0 { - for i := len(oldChain) - 1; i >= 0; i-- { - bc.chainSideFeed.Send(ChainSideEvent{Block: oldChain[i]}) - } - } return nil } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index b7fc26ae2086..06c43658ed9b 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -1158,7 +1158,7 @@ func TestLogRebirth(t *testing.T) { blockchain.SubscribeLogsEvent(newLogCh) blockchain.SubscribeRemovedLogsEvent(rmLogsCh) - // This chain contains a single log. + // This chain contains 10 logs. genDb, chain, _ := GenerateChainWithGenesis(gspec, engine, 3, func(i int, gen *BlockGen) { if i < 2 { for ii := 0; ii < 5; ii++ {