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

Commit

Permalink
feat(event): expose previous key in elderschanged
Browse files Browse the repository at this point in the history
  • Loading branch information
oetyng authored and joshuef committed Mar 22, 2021
1 parent 3e3be0c commit 0718e0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,14 @@ async fn handle_event(index: usize, node: &mut Routing, event: Event) -> bool {
Event::EldersChanged {
prefix,
key,
previous_key,
sibling_key,
elders,
self_status_change,
} => {
info!(
"Node #{} elders changed - prefix: {:b}, key: {:?}, sibling key: {:?}, elders: {:?}, node elder status change: {:?}",
index, prefix, key, sibling_key, elders, self_status_change
"Node #{} elders changed - prefix: {:b}, key: {:?}, previous_key: {:?}, sibling key: {:?}, elders: {:?}, node elder status change: {:?}",
index, prefix, key, previous_key, sibling_key, elders, self_status_change
);
}
Event::MessageReceived { content, src, dst } => info!(
Expand Down
4 changes: 4 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub enum Event {
prefix: Prefix,
/// The BLS public key of our section.
key: bls::PublicKey,
/// The previous BLS public key of our section.
previous_key: bls::PublicKey,
/// The BLS public key of the sibling section, if this event is fired during a split.
/// Otherwise `None`.
sibling_key: Option<bls::PublicKey>,
Expand Down Expand Up @@ -133,13 +135,15 @@ impl Debug for Event {
Self::EldersChanged {
prefix,
key,
previous_key,
sibling_key,
elders,
self_status_change,
} => formatter
.debug_struct("EldersChanged")
.field("prefix", prefix)
.field("key", key)
.field("previous_key", previous_key)
.field("sibling_key", sibling_key)
.field("elders", elders)
.field("self_status_change", self_status_change)
Expand Down
15 changes: 8 additions & 7 deletions src/routing/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,11 +1450,11 @@ impl Approved {
return Ok(commands);
}

// Do not carry out relocation in genesis section.
if self.section.prefix().is_empty() {
// TEMP: Do not carry out relocations (used to be disabled only in genesis section)
if self.section.prefix().bit_count() < u16::MAX as usize {
return Ok(commands);
}

let relocations =
relocation::actions(&self.section, &self.network, churn_name, churn_signature);

Expand Down Expand Up @@ -1769,8 +1769,8 @@ impl Approved {
if new_is_elder {
info!(
"Section updated: prefix: ({:b}), key: {:?}, elders: {}",
self.section.prefix(),
self.section.chain().last_key(),
new_prefix,
new_last_key,
self.section.elders_info().peers().format(", ")
);

Expand Down Expand Up @@ -1807,8 +1807,9 @@ impl Approved {
};

self.send_event(Event::EldersChanged {
prefix: *self.section.prefix(),
key: *self.section.chain().last_key(),
prefix: new_prefix,
key: new_last_key,
previous_key: old_last_key,
sibling_key,
elders: self.section.elders_info().elders.keys().copied().collect(),
self_status_change,
Expand Down
1 change: 1 addition & 0 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl Routing {
state.send_event(Event::EldersChanged {
prefix: *section.prefix(),
key: *section.chain().last_key(),
previous_key: *section.chain().last_key(),
sibling_key: None,
elders: section.elders_info().elders.keys().copied().collect(),
self_status_change: NodeElderChange::Promoted,
Expand Down

0 comments on commit 0718e0c

Please sign in to comment.