Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(topology): dont depend on signatures for update #5039

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl Sumeragi {
let prev_role = self.role();

self.topology
.block_committed(block.as_ref(), state_block.world.peers().cloned());
.block_committed(state_block.world.peers().cloned());

let state_events =
state_block.apply_without_execution(&block, self.topology.as_ref().to_owned());
Expand Down
2 changes: 1 addition & 1 deletion core/src/sumeragi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl SumeragiHandle {
*topology = Topology::new(state_block.world.trusted_peers_ids.clone());
}

topology.block_committed(block.as_ref(), state_block.world.peers().cloned());
topology.block_committed(state_block.world.peers().cloned());

state_block
.apply_without_execution(&block, topology.as_ref().to_owned())
Expand Down
38 changes: 2 additions & 36 deletions core/src/sumeragi/network_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
use derive_more::Display;
use indexmap::IndexSet;
use iroha_crypto::PublicKey;
use iroha_data_model::{
block::{BlockSignature, SignedBlock},
prelude::PeerId,
};
use iroha_data_model::{block::BlockSignature, prelude::PeerId};

/// The ordering of the peers which defines their roles in the current round of consensus.
///
Expand Down Expand Up @@ -203,30 +200,8 @@ impl Topology {
self.0[..rotate_at].rotate_left(1);
}

/// Pull peers up in the topology to the top of the a set while preserving local order.
fn lift_up_peers(&mut self, to_lift_up: impl IntoIterator<Item = usize>) {
let to_lift_up = IndexSet::<usize>::from_iter(to_lift_up);

to_lift_up.iter().for_each(|&idx| {
assert!(idx < self.0.len(), "Unknown block signature");
});

let mut topology = self.0.drain(..).enumerate().collect::<Vec<_>>();
topology.sort_by_key(|(signatory_idx, _)| !to_lift_up.contains(signatory_idx));
self.0 = topology.into_iter().map(|(_, peer)| peer).collect();
}

/// Rotate topology after a block has been committed
pub fn block_committed(
&mut self,
block: &SignedBlock,
new_peers: impl IntoIterator<Item = PeerId>,
) {
self.lift_up_peers(
block
.signatures()
.map(|s| s.0.try_into().expect("Peer index should fit into usize")),
);
pub fn block_committed(&mut self, new_peers: impl IntoIterator<Item = PeerId>) {
self.rotate_set_a();
self.update_peer_list(new_peers);
self.1 = 0;
Expand Down Expand Up @@ -325,15 +300,6 @@ mod tests {
assert_eq!(extract_ports(&topology), vec![1, 2, 3, 4, 0, 5, 6])
}

#[test]
fn lift_up_peers() {
let mut topology = topology();
// Will lift up 1, 2, 4, 6
let to_lift_up = [1, 2, 4, 6];
topology.lift_up_peers(to_lift_up);
assert_eq!(extract_ports(&topology), vec![1, 2, 4, 6, 0, 3, 5])
}

#[test]
fn update_peer_list() {
let mut topology = topology();
Expand Down
Loading