diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-12-01 07:11:24 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-12-01 19:12:30 +0800 |
commit | 9901a40f047f55d1a756805bdeed3997d071c3d1 (patch) | |
tree | 07f07607ab2647f200b2ac17d0cbc3136e68a03f /core/blockchain.go | |
parent | 7dde2b902cf81e90b484b1a48f6d45e0abd10e0f (diff) | |
download | dexon-9901a40f047f55d1a756805bdeed3997d071c3d1.tar dexon-9901a40f047f55d1a756805bdeed3997d071c3d1.tar.gz dexon-9901a40f047f55d1a756805bdeed3997d071c3d1.tar.bz2 dexon-9901a40f047f55d1a756805bdeed3997d071c3d1.tar.lz dexon-9901a40f047f55d1a756805bdeed3997d071c3d1.tar.xz dexon-9901a40f047f55d1a756805bdeed3997d071c3d1.tar.zst dexon-9901a40f047f55d1a756805bdeed3997d071c3d1.zip |
core: added a new RemovedLogEvent
When a chain reorganisation occurs we collect the logs that were deleted
during the chain reorganisation. The removed logs are posted to the
event mux indicating that those were deleted during the reorg.
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 5a6795b3e..dc6e0835c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1240,6 +1240,17 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { oldStart = oldBlock newStart = newBlock deletedTxs types.Transactions + deletedLogs vm.Logs + // collectLogs collects the logs that were generated during the + // processing of the block that corresponds with the given hash. + // These logs are later announced as deleted. + collectLogs = func(h common.Hash) { + // Coalesce logs + receipts := GetBlockReceipts(self.chainDb, h) + for _, receipt := range receipts { + deletedLogs = append(deletedLogs, receipt.Logs...) + } + } ) // first reduce whoever is higher bound @@ -1247,6 +1258,8 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { // reduce old chain for oldBlock = oldBlock; oldBlock != nil && oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) { deletedTxs = append(deletedTxs, oldBlock.Transactions()...) + + collectLogs(oldBlock.Hash()) } } else { // reduce new chain and append new chain blocks for inserting later on @@ -1269,6 +1282,7 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { } newChain = append(newChain, newBlock) deletedTxs = append(deletedTxs, oldBlock.Transactions()...) + collectLogs(oldBlock.Hash()) oldBlock, newBlock = self.GetBlock(oldBlock.ParentHash()), self.GetBlock(newBlock.ParentHash()) if oldBlock == nil { @@ -1302,7 +1316,6 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { if err := WriteMipmapBloom(self.chainDb, block.NumberU64(), receipts); err != nil { return err } - addedTxs = append(addedTxs, block.Transactions()...) } @@ -1316,7 +1329,12 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { } // Must be posted in a goroutine because of the transaction pool trying // to acquire the chain manager lock - go self.eventMux.Post(RemovedTransactionEvent{diff}) + if len(diff) > 0 { + go self.eventMux.Post(RemovedTransactionEvent{diff}) + } + if len(deletedLogs) > 0 { + go self.eventMux.Post(RemovedLogEvent{deletedLogs}) + } return nil } |