From 173fbc7985c7eca7e88f5e6b836e8fd87b5e1af5 Mon Sep 17 00:00:00 2001 From: "Sam H. Smith" Date: Thu, 17 Oct 2024 23:58:55 +0200 Subject: [PATCH] fix: Add range check to signature index Signed-off-by: Sam H. Smith --- crates/iroha_core/src/sumeragi/main_loop.rs | 14 +++++++++++++- crates/iroha_p2p/src/network.rs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/iroha_core/src/sumeragi/main_loop.rs b/crates/iroha_core/src/sumeragi/main_loop.rs index f89203ada14..095437fd025 100644 --- a/crates/iroha_core/src/sumeragi/main_loop.rs +++ b/crates/iroha_core/src/sumeragi/main_loop.rs @@ -622,7 +622,19 @@ impl Sumeragi { ); if let Ok(signatory_idx) = usize::try_from(signature.0) { - let signatory = &self.topology.as_ref()[signatory_idx]; + let signatory = if let Some(s) = self.topology.as_ref().get(signatory_idx) { + s + } else { + error!( + peer_id=%self.peer_id, + role=%self.role(), + ?signatory_idx, + topology_size=%self.topology.as_ref().len(), + "Unknown signatory" + ); + + return; + }; match self.topology.role(signatory) { Role::Leader => error!( diff --git a/crates/iroha_p2p/src/network.rs b/crates/iroha_p2p/src/network.rs index 666e35d7226..cf29f4e1c1c 100644 --- a/crates/iroha_p2p/src/network.rs +++ b/crates/iroha_p2p/src/network.rs @@ -223,7 +223,7 @@ impl NetworkBase { #[log(skip(self, shutdown_signal), fields(listen_addr=%self.listen_addr, public_key=%self.key_pair.public_key()))] async fn run(mut self, shutdown_signal: ShutdownSignal) { // 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.