From 97d8266042d1c21c02b8015aa5be38ad009c8224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Cig=C3=A1nek?= Date: Thu, 14 Jan 2021 16:23:50 +0100 Subject: [PATCH] fix: don't fail in update_state if secret key share is missing --- src/routing/approved.rs | 15 ++++++++------- src/section/section_keys.rs | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/routing/approved.rs b/src/routing/approved.rs index c3b7e0ac95..f6f181a287 100644 --- a/src/routing/approved.rs +++ b/src/routing/approved.rs @@ -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. @@ -1475,7 +1475,6 @@ impl Approved { fn update_state(&mut self, section: Section, network: Network) -> Result> { 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(); @@ -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. @@ -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(); } @@ -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) diff --git a/src/section/section_keys.rs b/src/section/section_keys.rs index 2189831dad..c7af11687f 100644 --- a/src/section/section_keys.rs +++ b/src/section/section_keys.rs @@ -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); }