From 9fdf04221cc852dfb8de2cdbd1642da2a9dace73 Mon Sep 17 00:00:00 2001 From: Shanin Roman Date: Thu, 21 Dec 2023 13:53:48 +0300 Subject: [PATCH] [BACKPORT] #4164: Fix topology update on restart Signed-off-by: Shanin Roman --- client/tests/integration/offline_peers.rs | 3 +-- core/src/sumeragi/mod.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/tests/integration/offline_peers.rs b/client/tests/integration/offline_peers.rs index 7c44f32cef1..a6d82bcb971 100644 --- a/client/tests/integration/offline_peers.rs +++ b/client/tests/integration/offline_peers.rs @@ -4,11 +4,10 @@ use iroha_client::{ crypto::KeyPair, data_model::{peer::Peer as DataModelPeer, prelude::*}, }; +use iroha_config::iroha::Configuration; use test_network::*; use tokio::runtime::Runtime; -use iroha_config::iroha::Configuration; - #[test] fn genesis_block_is_committed_with_some_offline_peers() -> Result<()> { // Given 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");