Skip to content

Commit

Permalink
feat: reached termination cache (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach authored Oct 12, 2022
1 parent 0e75d73 commit 415a91e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct DkgState {
keygen: SyncKeyGen<NodeId>,
our_part: Part,
all_votes: BTreeSet<DkgSignedVote>,
reached_termination: bool,
}

/// State after handling a vote
Expand Down Expand Up @@ -74,6 +75,7 @@ impl DkgState {
keygen: sync_key_gen,
all_votes: BTreeSet::new(),
our_part: opt_part.ok_or(Error::NotInPubKeySet)?,
reached_termination: false,
})
}

Expand Down Expand Up @@ -258,9 +260,7 @@ impl DkgState {

/// Checks if we reached termination
pub fn reached_termination(&self) -> Result<bool> {
let votes = self.all_checked_votes()?;
let state = self.current_dkg_state(votes);
Ok(matches!(state, DkgCurrentState::Termination(_)))
Ok(self.reached_termination)
}

/// Handle a DKG vote, save the information if we learned any, broadcast:
Expand Down Expand Up @@ -295,6 +295,7 @@ impl DkgState {
DkgCurrentState::Termination(acks) => {
self.handle_all_acks(acks)?;
if let (pubs, Some(sec)) = self.keygen.generate()? {
self.reached_termination = true;
Ok(vec![VoteResponse::DkgComplete(pubs, sec)])
} else {
Err(Error::FailedToGenerateSecretKeyShare)
Expand Down

0 comments on commit 415a91e

Please sign in to comment.