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

Commit

Permalink
fix: don't fail in update_state if secret key share is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Jan 18, 2021
1 parent c8db72f commit 97d8266
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/routing/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ impl Approved {
sibling.section.elders_info()
);

if self.is_elder() {
if self.section_keys_provider.has_key_share() {
// We can update the sibling knowledge already because we know they also reached
// consensus on our `OurKey` so they know our latest key. Need to vote for it first
// though, to accumulate the signatures.
Expand All @@ -1475,7 +1475,6 @@ impl Approved {
fn update_state(&mut self, section: Section, network: Network) -> Result<Vec<Command>> {
let mut commands = vec![];

let old_elders_info = self.section.elders_info().clone();
let old_is_elder = self.is_elder();
let old_last_key = *self.section.chain().last_key();
let old_prefix = *self.section.prefix();
Expand All @@ -1493,7 +1492,7 @@ impl Approved {
if new_prefix != old_prefix {
info!("Split");

if new_is_elder {
if new_is_elder && self.section_keys_provider.has_key_share() {
// We can update the sibling knowledge already because we know they also reached
// consensus on our `OurKey` so they know our latest key. Need to vote for it first
// though, to accumulate the signatures.
Expand All @@ -1515,7 +1514,12 @@ impl Approved {
self.section.elders_info().peers().format(", ")
);

commands.extend(self.promote_and_demote_elders()?);
if self.section_keys_provider.has_key_share() {
commands.extend(self.promote_and_demote_elders()?);
// Whenever there is an elders change, casting a round of joins_allowed vote to sync.
commands.extend(self.vote(Vote::JoinsAllowed(self.joins_allowed))?);
}

self.print_network_stats();
}

Expand Down Expand Up @@ -1545,9 +1549,6 @@ impl Approved {

if !new_is_elder {
commands.extend(self.return_relocate_promise());
} else if &old_elders_info != self.section.elders_info() {
// Whenever there is an elders change, casting a round of joins_allowed vote to sync.
commands.extend(self.vote(Vote::JoinsAllowed(self.joins_allowed))?);
}

Ok(commands)
Expand Down
4 changes: 4 additions & 0 deletions src/section/section_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl SectionKeysProvider {
self.current.as_ref().ok_or(Error::MissingSecretKeyShare)
}

pub fn has_key_share(&self) -> bool {
self.current.is_some()
}

pub fn insert_dkg_outcome(&mut self, share: SectionKeyShare) {
self.pending = Some(share);
}
Expand Down

0 comments on commit 97d8266

Please sign in to comment.