@ -1268,12 +1268,14 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
// event about them
// event about them
func ( self * BlockChain ) reorg ( oldBlock , newBlock * types . Block ) error {
func ( self * BlockChain ) reorg ( oldBlock , newBlock * types . Block ) error {
var (
var (
newChain types . Blocks
newChain types . Blocks
commonBlock * types . Block
oldChain types . Blocks
oldStart = oldBlock
commonBlock * types . Block
newStart = newBlock
oldStart = oldBlock
deletedTxs types . Transactions
newStart = newBlock
deletedLogs vm . Logs
deletedTxs types . Transactions
deletedLogs vm . Logs
deletedLogsByHash = make ( map [ common . Hash ] vm . Logs )
// collectLogs collects the logs that were generated during the
// collectLogs collects the logs that were generated during the
// processing of the block that corresponds with the given hash.
// processing of the block that corresponds with the given hash.
// These logs are later announced as deleted.
// 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 )
receipts := GetBlockReceipts ( self . chainDb , h )
for _ , receipt := range receipts {
for _ , receipt := range receipts {
deletedLogs = append ( deletedLogs , receipt . Logs ... )
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 ( ) {
if oldBlock . NumberU64 ( ) > newBlock . NumberU64 ( ) {
// 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 ( ) ) {
oldChain = append ( oldChain , oldBlock )
deletedTxs = append ( deletedTxs , oldBlock . Transactions ( ) ... )
deletedTxs = append ( deletedTxs , oldBlock . Transactions ( ) ... )
collectLogs ( oldBlock . Hash ( ) )
collectLogs ( oldBlock . Hash ( ) )
@ -1313,6 +1318,8 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
commonBlock = oldBlock
commonBlock = oldBlock
break
break
}
}
oldChain = append ( oldChain , oldBlock )
newChain = append ( newChain , newBlock )
newChain = append ( newChain , newBlock )
deletedTxs = append ( deletedTxs , oldBlock . Transactions ( ) ... )
deletedTxs = append ( deletedTxs , oldBlock . Transactions ( ) ... )
collectLogs ( oldBlock . Hash ( ) )
collectLogs ( oldBlock . Hash ( ) )
@ -1369,6 +1376,14 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
go self . eventMux . Post ( RemovedLogsEvent { deletedLogs } )
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
return nil
}
}