Skip to content

Commit

Permalink
Restore key gen message match from develop
Browse files Browse the repository at this point in the history
It was modified in response to the handover completion bug, which has now been
resolved.
  • Loading branch information
kayabaNerve committed Jun 10, 2024
1 parent 5a9ebc8 commit 44d0eee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
44 changes: 23 additions & 21 deletions tests/coordinator/src/tests/key_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ciphersuite::{
group::{ff::Field, GroupEncoding},
Ciphersuite, Ristretto, Secp256k1,
};
use dkg::ThresholdParams;

use serai_client::{
primitives::NetworkId,
Expand All @@ -31,30 +32,31 @@ pub async fn key_gen<C: Ciphersuite>(
let id = KeyGenId { session: set.session, attempt: 0 };

for (i, processor) in processors.iter_mut().enumerate() {
loop {
let msg = processor.recv_message().await;
match &msg {
CoordinatorMessage::KeyGen(messages::key_gen::CoordinatorMessage::GenerateKey {
id: this_id,
params,
shares,
}) => {
assert_eq!(id, *this_id);
assert_eq!(params.t(), u16::try_from(((coordinators * 2) / 3) + 1).unwrap());
assert_eq!(params.n(), u16::try_from(coordinators).unwrap());
assert_eq!(*shares, 1);
participant_is.push(params.i());
break;
}
CoordinatorMessage::Substrate(
messages::substrate::CoordinatorMessage::ConfirmKeyPair { .. },
) => {
continue;
}
_ => panic!("unexpected message: {msg:?}"),
let msg = processor.recv_message().await;
match &msg {
CoordinatorMessage::KeyGen(messages::key_gen::CoordinatorMessage::GenerateKey {
params,
..
}) => {
participant_is.push(params.i());
}
_ => panic!("unexpected message: {msg:?}"),
}

assert_eq!(
msg,
CoordinatorMessage::KeyGen(messages::key_gen::CoordinatorMessage::GenerateKey {
id,
params: ThresholdParams::new(
u16::try_from(((coordinators * 2) / 3) + 1).unwrap(),
u16::try_from(coordinators).unwrap(),
participant_is[i],
)
.unwrap(),
shares: 1,
})
);

processor
.send_message(messages::key_gen::ProcessorMessage::Commitments {
id,
Expand Down
9 changes: 8 additions & 1 deletion tests/coordinator/src/tests/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async fn set_rotation_test() {
new_test(
|mut processors: Vec<Processor>| async move {
// exclude the last processor from keygen since we will add him later
let excluded = processors.pop().unwrap();
let mut excluded = processors.pop().unwrap();
assert_eq!(processors.len(), COORDINATORS);

let pair5 = insecure_pair_from_name("Eve");
Expand All @@ -142,6 +142,13 @@ async fn set_rotation_test() {

// genesis keygen
let _ = key_gen::<Secp256k1>(&mut processors, Session(0)).await;
// Even the excluded processor should receive the key pair confirmation
match excluded.recv_message().await {
CoordinatorMessage::Substrate(
messages::substrate::CoordinatorMessage::ConfirmKeyPair { session, .. },
) => assert_eq!(session, Session(0)),
_ => panic!("excluded got message other than ConfirmKeyPair"),
}

// wait until next session to see the effect on coordinator
wait_till_next_epoch(&serai).await;
Expand Down

0 comments on commit 44d0eee

Please sign in to comment.