Skip to content

Commit

Permalink
[fix] #3995: Fix topology peer update
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
Co-authored-by: Sam H. Smith <[email protected]>
  • Loading branch information
Erigara and SamHSmith committed Oct 31, 2023
1 parent aedccdd commit e6a2292
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions core/src/sumeragi/network_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,8 @@ impl Topology {

/// Add or remove peers from the topology.
pub fn update_peer_list(&mut self, new_peers: UniqueVec<PeerId>) {
self.ordered_peers = new_peers
}

/// Rotate peers after each failed attempt to create a block.
pub fn rotate_all(&mut self) {
self.rotate_all_n(1);
self.modify_peers_directly(|peers| peers.retain(|peer| new_peers.contains(peer)));
self.ordered_peers.extend(new_peers);
}

/// Rotate peers n times where n is a number of failed attempt to create a block.
Expand Down Expand Up @@ -297,13 +293,6 @@ mod tests {
.collect()
}

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

#[test]
fn rotate_set_a() {
let mut topology = topology();
Expand Down Expand Up @@ -331,9 +320,9 @@ mod tests {
// New peers will be 0, 2, 5, 7
let new_peers = {
let mut peers = unique_vec![
topology.ordered_peers[5].clone(),
topology.ordered_peers[0].clone(),
topology.ordered_peers[2].clone(),
topology.ordered_peers[5].clone(),
];
peers.extend(test_peers![7]);
peers
Expand Down

0 comments on commit e6a2292

Please sign in to comment.