From 83de555f97d895805107dec695101ebfee49257f Mon Sep 17 00:00:00 2001 From: Shanin Roman Date: Thu, 21 Dec 2023 17:26:27 +0300 Subject: [PATCH] [fix] #4164: Fix topology update on restart Signed-off-by: Shanin Roman --- core/src/sumeragi/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/sumeragi/mod.rs b/core/src/sumeragi/mod.rs index 8c82663ee6c..2bafc67e9f2 100644 --- a/core/src/sumeragi/mod.rs +++ b/core/src/sumeragi/mod.rs @@ -229,11 +229,14 @@ impl SumeragiHandle { fn replay_block( block: &SignedBlock, wsv: &mut WorldStateView, - current_topology: &Topology, + mut current_topology: Topology, ) -> Topology { - let block = ValidBlock::validate(block.clone(), current_topology, wsv) + // NOTE: topology need to be updated up to block's view_change_index + current_topology.rotate_all_n(block.payload().header.view_change_index); + + let block = ValidBlock::validate(block.clone(), ¤t_topology, wsv) .expect("Kura blocks should be valid") - .commit(current_topology) + .commit(¤t_topology) .expect("Kura blocks should be valid"); if block.payload().header.is_genesis() { @@ -293,14 +296,14 @@ impl SumeragiHandle { let block_iter_except_last = (&mut blocks_iter).take(block_count.saturating_sub(skip_block_count + 1)); for block in block_iter_except_last { - current_topology = Self::replay_block(&block, &mut wsv, ¤t_topology); + current_topology = Self::replay_block(&block, &mut wsv, current_topology); } // finalized_wsv is one block behind let finalized_wsv = wsv.clone(); if let Some(block) = blocks_iter.next() { - current_topology = Self::replay_block(&block, &mut wsv, ¤t_topology); + current_topology = Self::replay_block(&block, &mut wsv, current_topology); } info!("Sumeragi has finished loading blocks and setting up the WSV");