aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-12-04 05:27:44 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-12-04 05:27:44 +0800
commitfece1fa9be769f7b5ef7b1b327e4f6ca0dd80227 (patch)
treef644f668ca1819f48726f8c98c864bf4f2b9b52c /core/blockchain.go
parent6d3a92428323bd482bc657228b71cf600b0757ed (diff)
parent9901a40f047f55d1a756805bdeed3997d071c3d1 (diff)
downloadgo-tangerine-fece1fa9be769f7b5ef7b1b327e4f6ca0dd80227.tar.gz
go-tangerine-fece1fa9be769f7b5ef7b1b327e4f6ca0dd80227.tar.zst
go-tangerine-fece1fa9be769f7b5ef7b1b327e4f6ca0dd80227.zip
Merge pull request #2024 from obscuren/exp-logs
core: added a new RemovedLogEvent
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
}