diff --git a/crates/iroha/tests/integration/extra_functional/connected_peers.rs b/crates/iroha/tests/integration/extra_functional/connected_peers.rs index 4bc748200d3..3c6f63c6b39 100644 --- a/crates/iroha/tests/integration/extra_functional/connected_peers.rs +++ b/crates/iroha/tests/integration/extra_functional/connected_peers.rs @@ -118,6 +118,31 @@ fn connected_peers_with_f(faults: u64, start_port: Option) -> Result<()> { Ok(()) } +#[test] +fn unregister_single_peer() -> Result<()> { + let (_rt, network, _) = Network::start_test_with_runtime(7, None); + wait_for_genesis_committed(&network.clients(), 0); + + let peer_clients: Vec<_> = Network::peers(&network) + .zip(Network::clients(&network)) + .collect(); + + // Unregister a peer + let removed_peer_idx = rand::thread_rng().gen_range(0..peer_clients.len()); + let (removed_peer, _) = &peer_clients[removed_peer_idx]; + let unregister_peer = Unregister::peer(removed_peer.id.clone()); + peer_clients + .choose(&mut thread_rng()) + .unwrap() + .1 + .submit_blocking(unregister_peer)?; + + let pipeline_time = Config::pipeline_time(); + + thread::sleep(pipeline_time * 2); + Ok(()) +} + fn check_status(peer_clients: &[(&Peer, Client)], expected_blocks: u64) { let n_peers = peer_clients.len() as u64; diff --git a/crates/iroha_core/src/sumeragi/main_loop.rs b/crates/iroha_core/src/sumeragi/main_loop.rs index 2cdf071d362..5802cafe188 100644 --- a/crates/iroha_core/src/sumeragi/main_loop.rs +++ b/crates/iroha_core/src/sumeragi/main_loop.rs @@ -628,6 +628,16 @@ impl Sumeragi { ); if let Ok(signatory_idx) = usize::try_from(signature.0) { + if signatory_idx >= self.topology.as_ref().len() { + error!( + peer_id=%self.peer_id, + role=%self.role(), + ?signatory_idx, + topology_size=%self.topology.as_ref().len(), + "Signature index is out of range." + ); + return; + } let signatory = &self.topology.as_ref()[signatory_idx]; match self.topology.role(signatory) { diff --git a/crates/iroha_p2p/src/network.rs b/crates/iroha_p2p/src/network.rs index fedded056b9..2716f862f15 100644 --- a/crates/iroha_p2p/src/network.rs +++ b/crates/iroha_p2p/src/network.rs @@ -219,7 +219,7 @@ impl NetworkBase { #[log(skip(self), fields(listen_addr=%self.listen_addr, public_key=%self.key_pair.public_key()))] async fn run(mut self) { // TODO: probably should be configuration parameter - let mut update_topology_interval = tokio::time::interval(Duration::from_millis(100)); + let mut update_topology_interval = tokio::time::interval(Duration::from_millis(1000)); loop { tokio::select! { // Select is biased because we want to service messages to take priority over data messages.