Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix: clear peer_mgr candidate post pfx change.
Browse files Browse the repository at this point in the history
We do not carry over candidates into new prefix, cos its not expected to succeed after merge if the voters arent super-majority in new pfx. This change clears the candidate state in peer_mgr accordingly.
  • Loading branch information
Viv-Rajkumar committed Apr 18, 2019
1 parent cf6168d commit 57cd490
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ impl PeerManager {
);
}

/// Removes any existing candidate
pub fn clear_candidate(&mut self) {
self.candidate = Candidate::None;
}

/// Adds a potential candidate to the candidate list setting its state to `VotedFor`. If
/// another ongoing (i.e. unapproved) candidate exists, or if the candidate is unsuitable for
/// adding to our section, returns an error.
Expand Down
6 changes: 4 additions & 2 deletions src/states/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ impl Node {
self.gen_pfx_info = Some(gen_pfx_info);
let _ = self.init_parsec()?; // We don't reset the chain on prefix change.

// Clear any pending candidate
// TODO: maybe also disconnect if currently connected.
self.peer_mgr.clear_candidate();

let neighbour_infos: Vec<_> = self.chain.neighbour_infos().cloned().collect();
for ni in neighbour_infos {
if sibling_pfx != *ni.prefix() {
Expand Down Expand Up @@ -1021,8 +1025,6 @@ impl Node {
cached_events
.iter()
.filter(|event| match **event {
// FIXME: once has_unconsensused_observations only considers votes than Obs
// can enable this similar to Offline event
NetworkEvent::Online(_pub_id, _) => false,
NetworkEvent::Offline(pub_id) => {
our_pfx.matches(pub_id.name()) && !completed_events.contains(event)
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_crust/churn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn random_churn<R: Rng>(
let len = nodes.len();
let section_count = count_sections(nodes);
if section_count > 1 && !rng.gen_weighted_bool(section_count as u32) {
// Use min_sec_size than section size to prevent collapsing any groups.
// Use min_sec_size rather than section size to prevent collapsing any groups.
let max_drop = (nodes[0].chain().min_sec_size() - 1)
* (QUORUM_DENOMINATOR - QUORUM_NUMERATOR)
/ QUORUM_DENOMINATOR;
Expand Down

0 comments on commit 57cd490

Please sign in to comment.