|
|
@ -1240,6 +1240,17 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { |
|
|
|
oldStart = oldBlock |
|
|
|
oldStart = oldBlock |
|
|
|
newStart = newBlock |
|
|
|
newStart = newBlock |
|
|
|
deletedTxs types.Transactions |
|
|
|
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
|
|
|
|
// first reduce whoever is higher bound
|
|
|
@ -1247,6 +1258,8 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error { |
|
|
|
// reduce old chain
|
|
|
|
// reduce old chain
|
|
|
|
for oldBlock = oldBlock; oldBlock != nil && oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) { |
|
|
|
for oldBlock = oldBlock; oldBlock != nil && oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) { |
|
|
|
deletedTxs = append(deletedTxs, oldBlock.Transactions()...) |
|
|
|
deletedTxs = append(deletedTxs, oldBlock.Transactions()...) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collectLogs(oldBlock.Hash()) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// reduce new chain and append new chain blocks for inserting later on
|
|
|
|
// 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) |
|
|
|
newChain = append(newChain, newBlock) |
|
|
|
deletedTxs = append(deletedTxs, oldBlock.Transactions()...) |
|
|
|
deletedTxs = append(deletedTxs, oldBlock.Transactions()...) |
|
|
|
|
|
|
|
collectLogs(oldBlock.Hash()) |
|
|
|
|
|
|
|
|
|
|
|
oldBlock, newBlock = self.GetBlock(oldBlock.ParentHash()), self.GetBlock(newBlock.ParentHash()) |
|
|
|
oldBlock, newBlock = self.GetBlock(oldBlock.ParentHash()), self.GetBlock(newBlock.ParentHash()) |
|
|
|
if oldBlock == nil { |
|
|
|
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 { |
|
|
|
if err := WriteMipmapBloom(self.chainDb, block.NumberU64(), receipts); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addedTxs = append(addedTxs, block.Transactions()...) |
|
|
|
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
|
|
|
|
// Must be posted in a goroutine because of the transaction pool trying
|
|
|
|
// to acquire the chain manager lock
|
|
|
|
// 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 |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|