@@ -349,12 +349,30 @@ impl NonFinalizedState {
349
349
. ok_or ( ReconsiderError :: InvalidatedBlocksEmpty ) ?;
350
350
351
351
let root_parent_hash = invalidated_root. block . header . previous_block_hash ;
352
- let parent_chain = self
353
- . parent_chain ( root_parent_hash)
354
- . map_err ( |_| ReconsiderError :: ParentChainNotFound ( block_hash) ) ?;
355
352
356
- let mut modified_chain = Arc :: unwrap_or_clone ( parent_chain) ;
353
+ // If the parent is the tip of the finalized_state we create a new chain and insert it
354
+ // into the non finalized state
355
+ let chain_result = if root_parent_hash == finalized_state. finalized_tip_hash ( ) {
356
+ let chain = Chain :: new (
357
+ & self . network ,
358
+ finalized_state
359
+ . finalized_tip_height ( )
360
+ . ok_or ( ReconsiderError :: ParentChainNotFound ( block_hash) ) ?,
361
+ finalized_state. sprout_tree_for_tip ( ) ,
362
+ finalized_state. sapling_tree_for_tip ( ) ,
363
+ finalized_state. orchard_tree_for_tip ( ) ,
364
+ finalized_state. history_tree ( ) ,
365
+ finalized_state. finalized_value_pool ( ) ,
366
+ ) ;
367
+ Arc :: new ( chain)
368
+ } else {
369
+ // The parent is not the finalized_tip and still exist in the NonFinalizedState
370
+ // or else we return an error due to the parent not existing in the NonFinalizedState
371
+ self . parent_chain ( root_parent_hash)
372
+ . map_err ( |_| ReconsiderError :: ParentChainNotFound ( block_hash) ) ?
373
+ } ;
357
374
375
+ let mut modified_chain = Arc :: unwrap_or_clone ( chain_result) ;
358
376
for block in Arc :: unwrap_or_clone ( invalidated_blocks) {
359
377
modified_chain = modified_chain. push ( block) ?;
360
378
}
0 commit comments