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

Commit

Permalink
chore: fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Oct 7, 2020
1 parent 783961f commit dd070bd
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/consensus/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Debug for DkgKey {
/// 7. On DKG completion or failure, the participants send `DKGResult` message to the current
/// elders (observers)
/// 8. The observers call `observe_result` with each received `DKGResult`.
/// 9. When it returns success, that means we accumulated at least majority of successful DKG results
/// 9. When it returns success, that means we accumulated majority of successful DKG results
/// and can proceed with voting for the section update.
/// 10. When it fails, the observers restart the process from step 1.
///
Expand Down
9 changes: 3 additions & 6 deletions src/node/stage/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,8 @@ impl Approved {
(MIN_AGE, None, None)
};

let mut updated_peer = peer;
updated_peer.age = age;

self.vote(Vote::Online {
member_info: MemberInfo::joined(updated_peer),
member_info: MemberInfo::joined(peer.with_age(age)),
previous_name,
their_knowledge,
})
Expand Down Expand Up @@ -1161,7 +1158,7 @@ impl Approved {
proof: Proof,
) -> Result<()> {
let peer = member_info.peer;
let age = peer.age;
let age = peer.age();
let signature = proof.signature.clone();

if !self.shared_state.update_member(member_info, proof) {
Expand Down Expand Up @@ -1193,7 +1190,7 @@ impl Approved {

async fn handle_offline_event(&mut self, member_info: MemberInfo, proof: Proof) -> Result<()> {
let peer = member_info.peer;
let age = peer.age;
let age = peer.age();
let signature = proof.signature.clone();

if !self.shared_state.update_member(member_info, proof) {
Expand Down
8 changes: 4 additions & 4 deletions src/node/stage/bootstrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ impl Bootstrapping {
}

async fn send_bootstrap_request(&self, dst: SocketAddr) -> Result<()> {
let destination = match &self.relocate_details {
Some(details) => *details.destination(),
None => self.node_info.name(),
let (destination, age) = match &self.relocate_details {
Some(details) => (*details.destination(), details.relocate_details().age),
None => (self.node_info.name(), MIN_AGE),
};

let message = Message::single_src(
&self.node_info.keypair,
MIN_AGE,
age,
DstLocation::Direct,
Variant::BootstrapRequest(destination),
None,
Expand Down
8 changes: 4 additions & 4 deletions src/node/stage/joining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ impl Joining {
}

async fn send_join_requests(&mut self) -> Result<()> {
let relocate_payload = match &self.join_type {
JoinType::First { .. } => None,
JoinType::Relocate(payload) => Some(payload),
let (relocate_payload, age) = match &self.join_type {
JoinType::First { .. } => (None, MIN_AGE),
JoinType::Relocate(payload) => (Some(payload), payload.relocate_details().age),
};

let recipients: Vec<_> = self
Expand All @@ -235,7 +235,7 @@ impl Joining {
let variant = Variant::JoinRequest(Box::new(join_request));
let message = Message::single_src(
&self.node_info.keypair,
MIN_AGE,
age,
DstLocation::Direct,
variant,
None,
Expand Down
14 changes: 12 additions & 2 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use xor_name::XorName;
pub struct Peer {
name: XorName,
addr: SocketAddr,
pub age: u8,
age: u8,
}

impl Peer {
/// Creates a new `Peer` given `Name`, `ConnectionInfo` and `age`.
/// Creates a new `Peer` given `Name`, `SocketAddr` and `age`.
pub fn new(name: XorName, addr: SocketAddr, age: u8) -> Self {
Self { name, addr, age }
}
Expand All @@ -36,6 +36,16 @@ impl Peer {
&self.addr
}

/// Returns the age.
pub fn age(&self) -> u8 {
self.age
}

// Converts this info into one with the input age.
pub fn with_age(self, age: u8) -> Self {
Self { age, ..self }
}

// Converts this info into one with the age increased by one.
pub fn increment_age(self) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/section/member_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl MemberInfo {
}

pub fn is_adult(&self) -> bool {
self.peer.age > MIN_AGE
self.peer.age() > MIN_AGE
}

pub fn leave(self) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions src/section/section_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl SectionPeers {
// - Relocated -> Left (should not happen, but needed for consistency)
match (entry.get().value.state, new_info.state) {
(PeerState::Joined, PeerState::Joined)
if new_info.peer.age > entry.get().value.peer.age => {}
if new_info.peer.age() > entry.get().value.peer.age() => {}
(PeerState::Joined, PeerState::Left)
| (PeerState::Joined, PeerState::Relocated(_))
| (PeerState::Relocated(_), PeerState::Left) => {}
Expand Down Expand Up @@ -217,8 +217,8 @@ fn cmp_elder_candidates(
// signature and therefore game its chances of promotion.
rhs.value
.peer
.age
.cmp(&lhs.value.peer.age)
.age()
.cmp(&lhs.value.peer.age())
.then_with(|| {
let lhs_is_elder = current_elders.elders.contains_key(lhs.value.peer.name());
let rhs_is_elder = current_elders.elders.contains_key(rhs.value.peer.name());
Expand Down
6 changes: 3 additions & 3 deletions src/section/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl SharedState {
self.our_members
.all()
.find(|info| info.peer.name() == name)
.map(|info| info.peer.age)
.map(|info| info.peer.age())
}

/// All section keys we know of, including the past keys of our section.
Expand Down Expand Up @@ -313,7 +313,7 @@ impl SharedState {
) -> Vec<(MemberInfo, RelocateAction)> {
self.our_members
.joined_proven()
.filter(|info| relocation::check(info.value.peer.age, churn_signature))
.filter(|info| relocation::check(info.value.peer.age(), churn_signature))
.map(|info| {
(
info.value.clone(),
Expand All @@ -337,7 +337,7 @@ impl SharedState {
pub_id: *info.peer.name(),
destination,
destination_key,
age: info.peer.age.saturating_add(1),
age: info.peer.age().saturating_add(1),
}
}

Expand Down

0 comments on commit dd070bd

Please sign in to comment.