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

Commit

Permalink
fix: only send adult list notification when no elder changing
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and Yoga07 committed Apr 30, 2021
1 parent e5419c7 commit 4964a20
Showing 1 changed file with 17 additions and 34 deletions.
51 changes: 17 additions & 34 deletions src/routing/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,17 +1134,7 @@ impl Core {
return Ok(vec![]);
}

let old_adults: BTreeSet<_> = self
.section
.active_members()
.filter_map(|peer| {
if self.section.is_elder(peer.name()) {
None
} else {
Some(*peer.name())
}
})
.collect();
let old_adults: BTreeSet<_> = self.section.adults().map(|peer| *peer.name()).collect();

let snapshot = self.state_snapshot();
trace!(
Expand All @@ -1156,17 +1146,7 @@ impl Core {
self.network.merge(network, self.section.chain());

if !self.is_elder() {
let new_adults: BTreeSet<_> = self
.section
.active_members()
.filter_map(|peer| {
if self.section.is_elder(peer.name()) {
None
} else {
Some(*peer.name())
}
})
.collect();
let new_adults: BTreeSet<_> = self.section.adults().map(|peer| *peer.name()).collect();
if old_adults != new_adults {
self.send_event(Event::AdultsChanged(new_adults));
}
Expand Down Expand Up @@ -1694,10 +1674,14 @@ impl Core {

commands
.extend(self.relocate_peers(new_info.value.peer.name(), &new_info.proof.signature)?);
commands.extend(self.promote_and_demote_elders()?);
commands.push(self.send_node_approval(new_info, their_knowledge)?);

commands.extend(self.send_sync_to_adults()?);
let result = self.promote_and_demote_elders()?;
if result.is_empty() {
commands.extend(self.send_sync_to_adults()?);
}

commands.extend(result);
commands.push(self.send_node_approval(new_info, their_knowledge)?);

self.print_network_stats();

Expand Down Expand Up @@ -1726,9 +1710,13 @@ impl Core {
info!("handle Offline: {:?}", peer);

commands.extend(self.relocate_peers(peer.name(), &signature)?);
commands.extend(self.promote_and_demote_elders()?);

commands.extend(self.send_sync_to_adults()?);
let result = self.promote_and_demote_elders()?;
if result.is_empty() {
commands.extend(self.send_sync_to_adults()?);
}

commands.extend(result);

self.send_event(Event::MemberLeft {
name: *peer.name(),
Expand Down Expand Up @@ -2058,18 +2046,13 @@ impl Core {

let mut commands = vec![];

let non_elders: Vec<_> = self
.section
.active_members()
.filter(|peer| !self.section.is_elder(peer.name()))
.copied()
.collect();
let adults: Vec<_> = self.section.adults().copied().collect();

let variant = Variant::Sync {
section: self.section.clone(),
network: Network::new(),
};
commands.push(send(variant, non_elders)?);
commands.push(send(variant, adults)?);

Ok(commands)
}
Expand Down

0 comments on commit 4964a20

Please sign in to comment.