@@ -1965,8 +1965,8 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
1965
1965
oldChain types.Blocks
1966
1966
commonBlock * types.Block
1967
1967
1968
- deletedTxs types. Transactions
1969
- addedTxs types. Transactions
1968
+ deletedTxs []common. Hash
1969
+ addedTxs []common. Hash
1970
1970
1971
1971
deletedLogs [][]* types.Log
1972
1972
rebirthLogs [][]* types.Log
@@ -1976,7 +1976,9 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
1976
1976
// Old chain is longer, gather all transactions and logs as deleted ones
1977
1977
for ; oldBlock != nil && oldBlock .NumberU64 () != newBlock .NumberU64 (); oldBlock = bc .GetBlock (oldBlock .ParentHash (), oldBlock .NumberU64 ()- 1 ) {
1978
1978
oldChain = append (oldChain , oldBlock )
1979
- deletedTxs = append (deletedTxs , oldBlock .Transactions ()... )
1979
+ for _ , tx := range oldBlock .Transactions () {
1980
+ deletedTxs = append (deletedTxs , tx .Hash ())
1981
+ }
1980
1982
1981
1983
// Collect deleted logs for notification
1982
1984
logs := bc .collectLogs (oldBlock .Hash (), true )
@@ -2006,7 +2008,9 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
2006
2008
}
2007
2009
// Remove an old block as well as stash away a new block
2008
2010
oldChain = append (oldChain , oldBlock )
2009
- deletedTxs = append (deletedTxs , oldBlock .Transactions ()... )
2011
+ for _ , tx := range oldBlock .Transactions () {
2012
+ deletedTxs = append (deletedTxs , tx .Hash ())
2013
+ }
2010
2014
2011
2015
// Collect deleted logs for notification
2012
2016
logs := bc .collectLogs (oldBlock .Hash (), true )
@@ -2025,6 +2029,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
2025
2029
return fmt .Errorf ("invalid new chain" )
2026
2030
}
2027
2031
}
2032
+
2028
2033
// Ensure the user sees large reorgs
2029
2034
if len (oldChain ) > 0 && len (newChain ) > 0 {
2030
2035
logFn := log .Info
@@ -2041,7 +2046,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
2041
2046
} else if len (newChain ) > 0 {
2042
2047
// Special case happens in the post merge stage that current head is
2043
2048
// the ancestor of new head while these two blocks are not consecutive
2044
- log .Info ("Extend chain" , "add" , len (newChain ), "number" , newChain [0 ].NumberU64 (), "hash" , newChain [0 ].Hash ())
2049
+ log .Info ("Extend chain" , "add" , len (newChain ), "number" , newChain [0 ].Number (), "hash" , newChain [0 ].Hash ())
2045
2050
blockReorgAddMeter .Mark (int64 (len (newChain )))
2046
2051
} else {
2047
2052
// len(newChain) == 0 && len(oldChain) > 0
@@ -2054,19 +2059,17 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
2054
2059
// Insert the block in the canonical way, re-writing history
2055
2060
bc .writeHeadBlock (newChain [i ])
2056
2061
2057
- // Collect reborn logs due to chain reorg
2058
- logs := bc .collectLogs (newChain [i ].Hash (), false )
2059
- if len (logs ) > 0 {
2060
- rebirthLogs = append (rebirthLogs , logs )
2061
- }
2062
2062
// Collect the new added transactions.
2063
- addedTxs = append (addedTxs , newChain [i ].Transactions ()... )
2063
+ for _ , tx := range newChain [i ].Transactions () {
2064
+ addedTxs = append (addedTxs , tx .Hash ())
2065
+ }
2064
2066
}
2067
+
2065
2068
// Delete useless indexes right now which includes the non-canonical
2066
2069
// transaction indexes, canonical chain indexes which above the head.
2067
2070
indexesBatch := bc .db .NewBatch ()
2068
- for _ , tx := range types .TxDifference (deletedTxs , addedTxs ) {
2069
- rawdb .DeleteTxLookupEntry (indexesBatch , tx . Hash () )
2071
+ for _ , tx := range types .HashDifference (deletedTxs , addedTxs ) {
2072
+ rawdb .DeleteTxLookupEntry (indexesBatch , tx )
2070
2073
}
2071
2074
// Delete any canonical number assignments above the new head
2072
2075
number := bc .CurrentBlock ().NumberU64 ()
@@ -2080,6 +2083,15 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
2080
2083
if err := indexesBatch .Write (); err != nil {
2081
2084
log .Crit ("Failed to delete useless indexes" , "err" , err )
2082
2085
}
2086
+
2087
+ // Collect the logs
2088
+ for i := len (newChain ) - 1 ; i >= 1 ; i -- {
2089
+ // Collect reborn logs due to chain reorg
2090
+ logs := bc .collectLogs (newChain [i ].Hash (), false )
2091
+ if len (logs ) > 0 {
2092
+ rebirthLogs = append (rebirthLogs , logs )
2093
+ }
2094
+ }
2083
2095
// If any logs need to be fired, do it now. In theory we could avoid creating
2084
2096
// this goroutine if there are no events to fire, but realistcally that only
2085
2097
// ever happens if we're reorging empty blocks, which will only happen on idle
0 commit comments