aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2016-03-08 01:11:52 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-03-08 23:12:48 +0800
commitba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c (patch)
tree33f5381f85d0ae776bf14dd25141021598df3d6b /core/blockchain.go
parentd45f01d5f782857c6a65f65fdc67b630a8f028bd (diff)
downloaddexon-ba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c.tar
dexon-ba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c.tar.gz
dexon-ba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c.tar.bz2
dexon-ba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c.tar.lz
dexon-ba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c.tar.xz
dexon-ba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c.tar.zst
dexon-ba3fb9e6f4c47edbb0ff99285a0b48dc4bd3f37c.zip
core: announce ChainSideEvent during reorg
Previously all blocks that were already in our chain were never re announced as potential uncle block (e.g. ChainSideEvent). This is problematic during mining where you want to gather as much possible uncles as possible increasing the profit. This is now addressed in this PR where during reorganisations of chains the old chain is regarded as uncles. Fixed #2298
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go27
1 files changed, 21 insertions, 6 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 2c6ff24f9..79648869c 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1268,12 +1268,14 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
// event about them
func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
var (
- newChain types.Blocks
- commonBlock *types.Block
- oldStart = oldBlock
- newStart = newBlock
- deletedTxs types.Transactions
- deletedLogs vm.Logs
+ newChain types.Blocks
+ oldChain types.Blocks
+ commonBlock *types.Block
+ oldStart = oldBlock
+ newStart = newBlock
+ deletedTxs types.Transactions
+ deletedLogs vm.Logs
+ deletedLogsByHash = make(map[common.Hash]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.
@@ -1282,6 +1284,8 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
receipts := GetBlockReceipts(self.chainDb, h)
for _, receipt := range receipts {
deletedLogs = append(deletedLogs, receipt.Logs...)
+
+ deletedLogsByHash[h] = receipt.Logs
}
}
)
@@ -1290,6 +1294,7 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
if oldBlock.NumberU64() > newBlock.NumberU64() {
// reduce old chain
for oldBlock = oldBlock; oldBlock != nil && oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) {
+ oldChain = append(oldChain, oldBlock)
deletedTxs = append(deletedTxs, oldBlock.Transactions()...)
collectLogs(oldBlock.Hash())
@@ -1313,6 +1318,8 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
commonBlock = oldBlock
break
}
+
+ oldChain = append(oldChain, oldBlock)
newChain = append(newChain, newBlock)
deletedTxs = append(deletedTxs, oldBlock.Transactions()...)
collectLogs(oldBlock.Hash())
@@ -1369,6 +1376,14 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
go self.eventMux.Post(RemovedLogsEvent{deletedLogs})
}
+ if len(oldChain) > 0 {
+ go func() {
+ for _, block := range oldChain {
+ self.eventMux.Post(ChainSideEvent{Block: block, Logs: deletedLogsByHash[block.Hash()]})
+ }
+ }()
+ }
+
return nil
}