Skip to content

Commit

Permalink
rename signing_round to signer where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
xoloki committed Oct 23, 2023
1 parent 7089f29 commit 6148b04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
26 changes: 12 additions & 14 deletions src/state_machine/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub mod test {
key_ids: key_ids_map,
};

let signing_rounds = key_pairs
let signers = key_pairs
.iter()
.enumerate()
.map(|(signer_id, (private_key, _public_key))| {
Expand All @@ -302,26 +302,24 @@ pub mod test {
message_private_key: key_pairs[0].0,
};
let coordinator = Coordinator::new(config);
(coordinator, signing_rounds)
(coordinator, signers)
}

/// Helper function for feeding messages back from the processor into the signing rounds and coordinator
pub fn feedback_messages<Coordinator: CoordinatorTrait, SignerType: SignerTrait>(
coordinator: &mut Coordinator,
signing_rounds: &mut Vec<Signer<SignerType>>,
signers: &mut Vec<Signer<SignerType>>,
messages: &[Packet],
) -> (Vec<Packet>, Vec<OperationResult>) {
let mut inbound_messages = vec![];
let mut feedback_messages = vec![];
for signing_round in signing_rounds.as_mut_slice() {
let outbound_messages = signing_round.process_inbound_messages(messages).unwrap();
for signer in signers.as_mut_slice() {
let outbound_messages = signer.process_inbound_messages(messages).unwrap();
feedback_messages.extend_from_slice(outbound_messages.as_slice());
inbound_messages.extend(outbound_messages);
}
for signing_round in signing_rounds.as_mut_slice() {
let outbound_messages = signing_round
.process_inbound_messages(&feedback_messages)
.unwrap();
for signer in signers.as_mut_slice() {
let outbound_messages = signer.process_inbound_messages(&feedback_messages).unwrap();
inbound_messages.extend(outbound_messages);
}
coordinator
Expand All @@ -330,7 +328,7 @@ pub mod test {
}

pub fn process_inbound_messages<Coordinator: CoordinatorTrait, SignerType: SignerTrait>() {
let (mut coordinator, mut signing_rounds) = setup::<Coordinator, SignerType>();
let (mut coordinator, mut signers) = setup::<Coordinator, SignerType>();

// We have started a dkg round
let message = coordinator.start_dkg_round().unwrap();
Expand All @@ -339,7 +337,7 @@ pub mod test {

// Send the DKG Begin message to all signers and gather responses by sharing with all other signers and coordinator
let (outbound_messages, operation_results) =
feedback_messages(&mut coordinator, &mut signing_rounds, &[message]);
feedback_messages(&mut coordinator, &mut signers, &[message]);
assert!(operation_results.is_empty());
assert_eq!(coordinator.get_state(), State::DkgEndGather);

Expand All @@ -353,7 +351,7 @@ pub mod test {
}
// Send the DKG Private Begin message to all signers and share their responses with the coordinator and signers
let (outbound_messages, operation_results) =
feedback_messages(&mut coordinator, &mut signing_rounds, &outbound_messages);
feedback_messages(&mut coordinator, &mut signers, &outbound_messages);
assert!(outbound_messages.is_empty());
assert_eq!(operation_results.len(), 1);
match operation_results[0] {
Expand Down Expand Up @@ -381,7 +379,7 @@ pub mod test {

// Send the message to all signers and gather responses by sharing with all other signers and coordinator
let (outbound_messages, operation_results) =
feedback_messages(&mut coordinator, &mut signing_rounds, &[message]);
feedback_messages(&mut coordinator, &mut signers, &[message]);
assert!(operation_results.is_empty());
assert_eq!(
coordinator.get_state(),
Expand All @@ -397,7 +395,7 @@ pub mod test {
}
// Send the SignatureShareRequest message to all signers and share their responses with the coordinator and signers
let (outbound_messages, operation_results) =
feedback_messages(&mut coordinator, &mut signing_rounds, &outbound_messages);
feedback_messages(&mut coordinator, &mut signers, &outbound_messages);
assert!(outbound_messages.is_empty());
assert_eq!(operation_results.len(), 1);
match &operation_results[0] {
Expand Down
32 changes: 16 additions & 16 deletions src/state_machine/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ pub mod test {

fn dkg_public_share<SignerType: SignerTrait>() {
let mut rnd = OsRng;
let mut signing_round =
let mut signer =
Signer::<SignerType>::new(1, 1, 1, 1, vec![1], Default::default(), Default::default());
let public_share = DkgPublicShares {
dkg_id: 0,
Expand All @@ -610,8 +610,8 @@ pub mod test {
},
)],
};
signing_round.dkg_public_share(&public_share).unwrap();
assert_eq!(1, signing_round.commitments.len())
signer.dkg_public_share(&public_share).unwrap();
assert_eq!(1, signer.commitments.len())
}

#[test]
Expand All @@ -626,14 +626,14 @@ pub mod test {

fn public_shares_done<SignerType: SignerTrait>() {
let mut rnd = OsRng;
let mut signing_round =
let mut signer =
Signer::<SignerType>::new(1, 1, 1, 1, vec![1], Default::default(), Default::default());
// publich_shares_done starts out as false
assert!(!signing_round.public_shares_done());
assert!(!signer.public_shares_done());

// meet the conditions for all public keys received
signing_round.state = SignerState::DkgPublicGather;
signing_round.commitments.insert(
signer.state = SignerState::DkgPublicGather;
signer.commitments.insert(
1,
PolyCommitment {
id: ID::new(&Scalar::new(), &Scalar::new(), &mut rnd),
Expand All @@ -642,7 +642,7 @@ pub mod test {
);

// public_shares_done should be true
assert!(signing_round.public_shares_done());
assert!(signer.public_shares_done());
}

#[test]
Expand All @@ -657,25 +657,25 @@ pub mod test {

fn can_dkg_end<SignerType: SignerTrait>() {
let mut rnd = OsRng;
let mut signing_round =
let mut signer =
Signer::<SignerType>::new(1, 1, 1, 1, vec![1], Default::default(), Default::default());
// can_dkg_end starts out as false
assert!(!signing_round.can_dkg_end());
assert!(!signer.can_dkg_end());

// meet the conditions for DKG_END
signing_round.state = SignerState::DkgPrivateGather;
signing_round.commitments.insert(
signer.state = SignerState::DkgPrivateGather;
signer.commitments.insert(
1,
PolyCommitment {
id: ID::new(&Scalar::new(), &Scalar::new(), &mut rnd),
poly: vec![],
},
);
let shares: HashMap<u32, Scalar> = HashMap::new();
signing_round.decrypted_shares.insert(1, shares);
signer.decrypted_shares.insert(1, shares);

// can_dkg_end should be true
assert!(signing_round.can_dkg_end());
assert!(signer.can_dkg_end());
}

#[test]
Expand All @@ -689,9 +689,9 @@ pub mod test {
}

fn dkg_ended<SignerType: SignerTrait>() {
let mut signing_round =
let mut signer =
Signer::<SignerType>::new(1, 1, 1, 1, vec![1], Default::default(), Default::default());
if let Ok(Message::DkgEnd(dkg_end)) = signing_round.dkg_ended() {
if let Ok(Message::DkgEnd(dkg_end)) = signer.dkg_ended() {
match dkg_end.status {
DkgStatus::Failure(_) => {}
_ => panic!("Expected DkgStatus::Failure"),
Expand Down

0 comments on commit 6148b04

Please sign in to comment.