Skip to content

Commit

Permalink
fix: Add range check to signature index
Browse files Browse the repository at this point in the history
  • Loading branch information
SamHSmith committed Oct 17, 2024
1 parent f36f81d commit 09066b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
25 changes: 25 additions & 0 deletions crates/iroha/tests/integration/extra_functional/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ fn connected_peers_with_f(faults: u64, start_port: Option<u16>) -> 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;

Expand Down
10 changes: 10 additions & 0 deletions crates/iroha_core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_p2p/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<T: Pload, K: Kex, E: Enc> NetworkBase<T, K, E> {
#[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.
Expand Down

0 comments on commit 09066b9

Please sign in to comment.