File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
crates/anvil/src/eth/backend/mem Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -337,11 +337,15 @@ impl BlockchainStorage {
337337 let mut removed = vec ! [ ] ;
338338 let best_num: u64 = self . best_number ;
339339 for i in ( block_number + 1 ) ..=best_num {
340- if let Some ( hash) = self . hashes . remove ( & i)
341- && let Some ( block) = self . blocks . remove ( & hash)
342- {
343- self . remove_block_transactions_by_number ( block. header . number ) ;
344- removed. push ( block) ;
340+ if let Some ( hash) = self . hashes . get ( & i) . copied ( ) {
341+ // First remove the block's transactions while the mappings still exist
342+ self . remove_block_transactions_by_number ( i) ;
343+
344+ // Now remove the block from storage (may already be empty of txs) and drop mapping
345+ if let Some ( block) = self . blocks . remove ( & hash) {
346+ removed. push ( block) ;
347+ }
348+ self . hashes . remove ( & i) ;
345349 }
346350 }
347351 self . best_hash = block_hash;
You can’t perform that action at this time.
0 commit comments