aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go22
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
}