Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Braun committed Sep 21, 2023
1 parent ce90511 commit 8789050
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 51 deletions.
96 changes: 45 additions & 51 deletions dkg-gadget/src/async_protocols/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#![allow(clippy::unwrap_used)] // allow unwraps in tests
use crate::{
async_protocols::{blockchain_interface::BlockchainInterface, types::LocalKeyType, BatchKey},
async_protocols::{
blockchain_interface::BlockchainInterface,
types::{LocalKeyType, VoteResult},
BatchKey,
},
db::DKGDbBackend,
};
use codec::Encode;
use curv::{elliptic::curves::Secp256k1, BigInt};
use dkg_primitives::{
types::{DKGError, DKGMessage, SessionId, SignedDKGMessage},
utils::convert_signature,
};
use dkg_primitives::types::{DKGError, DKGMessage, SessionId, SignedDKGMessage};
use dkg_runtime_primitives::{
crypto::Public, gossip_messages::PublicKeyMessage, BatchId, MaxProposalLength,
MaxProposalsInBatch, MaxSignatureLength, SignedProposalBatch, StoredUnsignedProposalBatch,
};
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::{
party_i::SignatureRecid, state_machine::keygen::LocalKey,
MaxProposalsInBatch, MaxSignatureLength, SignedProposalBatch,
};
use parking_lot::Mutex;
use std::{collections::HashMap, sync::Arc};
Expand Down Expand Up @@ -79,53 +76,50 @@ impl BlockchainInterface for TestDummyIface {
Ok(())
}

fn process_vote_result(
&self,
signature: SignatureRecid,
unsigned_proposal_batch: StoredUnsignedProposalBatch<
Self::BatchId,
Self::MaxProposalLength,
Self::MaxProposalsInBatch,
Self::Clock,
>,
_session_id: SessionId,
batch_key: BatchKey,
_message: BigInt,
) -> Result<(), DKGError> {
let mut lock = self.vote_results.lock();

let signature = convert_signature(&signature).ok_or_else(|| DKGError::CriticalError {
reason: "Unable to serialize signature".to_string(),
})?;

let mut signed_proposals = vec![];

// convert all unsigned proposals to signed
for unsigned_proposal in unsigned_proposal_batch.proposals.iter() {
signed_proposals.push(Proposal::Signed {
kind: unsigned_proposal.proposal.kind(),
data: unsigned_proposal
.data()
.clone()
.try_into()
.expect("should not happen since its a valid proposal"),
fn process_vote_result(&self, result: VoteResult<Self>) -> Result<(), DKGError> {
if let VoteResult::ECDSA {
signature,
unsigned_proposal_batch,
session_id: _sid,
batch_key,
} = result
{
let mut lock = self.vote_results.lock();

let mut signed_proposals = vec![];

// convert all unsigned proposals to signed
for unsigned_proposal in unsigned_proposal_batch.proposals.iter() {
signed_proposals.push(Proposal::Signed {
kind: unsigned_proposal.proposal.kind(),
data: unsigned_proposal
.data()
.clone()
.try_into()
.expect("should not happen since its a valid proposal"),
signature: signature
.encode()
.try_into()
.expect("Signature exceeds runtime bounds!"),
});
}

let signed_proposal_batch = SignedProposalBatch {
batch_id: unsigned_proposal_batch.batch_id,
proposals: signed_proposals.try_into().expect("Proposals exceeds runtime bounds!"),
signature: signature
.encode()
.try_into()
.expect("Signature exceeds runtime bounds!"),
});
}

let signed_proposal_batch = SignedProposalBatch {
batch_id: unsigned_proposal_batch.batch_id,
proposals: signed_proposals.try_into().expect("Proposals exceeds runtime bounds!"),
signature: signature.encode().try_into().expect("Signature exceeds runtime bounds!"),
};
};

let proposals_for_this_batch = lock.entry(batch_key).or_default();
proposals_for_this_batch.push(signed_proposal_batch);
let proposals_for_this_batch = lock.entry(batch_key).or_default();
proposals_for_this_batch.push(signed_proposal_batch);

Ok(())
Ok(())
} else {
panic!("Only ECDSA is supported in the test interface");
}
}

fn gossip_public_key(&self, _key: PublicKeyMessage) -> Result<(), DKGError> {
Expand Down
3 changes: 3 additions & 0 deletions dkg-gadget/src/dkg_modules/wt_frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ pub trait NetInterface: Send {
mod tests {
use crate::dkg_modules::wt_frost::{FrostMessage, NetInterface};
use futures::{stream::FuturesUnordered, TryStreamExt};
use rand::prelude::SliceRandom;

struct TestNetworkLayer {
tx: tokio::sync::broadcast::Sender<FrostMessage>,
Expand Down Expand Up @@ -575,6 +576,8 @@ mod tests {
// best authorities, we will choose the best of the best of authorities, so from 0..T
let signers = FuturesUnordered::new();

// parties.shuffle(rng);

for (party, network) in parties.iter_mut().zip(networks.iter_mut()).take(T as _) {
let public_key = public_key.clone();
signers.push(Box::pin(async move {
Expand Down

0 comments on commit 8789050

Please sign in to comment.