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

Commit

Permalink
fix(dkg): handle DKG with single participant
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Nov 23, 2020
1 parent 03873c1 commit 00c2efa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/consensus/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ impl DkgVoter {
}
}

// Special case: only one participant.
if elders_info.elders.len() == 1 {
let secret_key_set = bls::SecretKeySet::random(0, &mut rand::thread_rng());

return vec![DkgCommand::HandleParticipationResult {
dkg_key,
elders_info,
result: Ok(DkgOutcome {
public_key_set: secret_key_set.public_keys(),
secret_key_share: secret_key_set.secret_key_share(0),
}),
}];
}

let threshold = majority(elders_info.elders.len()) - 1;
let participants = elders_info
.elders
Expand Down Expand Up @@ -593,6 +607,7 @@ mod tests {
section::test_utils::{gen_addr, gen_elders_info},
ELDER_SIZE, MIN_AGE,
};
use assert_matches::assert_matches;
use proptest::prelude::*;
use rand::{rngs::SmallRng, SeedableRng};
use std::iter;
Expand Down Expand Up @@ -699,6 +714,23 @@ mod tests {
.is_none());
}

#[test]
fn single_participant() {
// If there is only one participant, the DKG should complete immediately.

let mut voter = DkgVoter::default();

let peer = Peer::new(rand::random(), gen_addr(), MIN_AGE);
let elders_info = EldersInfo::new(iter::once(peer), Prefix::default());
let dkg_key = DkgKey::new(&elders_info);

let commands = voter.start_participating(*peer.name(), dkg_key, elders_info);
assert_matches!(
&commands[..],
&[DkgCommand::HandleParticipationResult { result: Ok(_), .. }]
);
}

proptest! {
// Run a DKG session where every participant handles every message sent to them.
// Expect the session to successfully complete without timed transitions.
Expand Down

0 comments on commit 00c2efa

Please sign in to comment.