Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 9, 2024
1 parent 4becd43 commit 07bc6cd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
3 changes: 1 addition & 2 deletions crates/protocol/src/execute_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ pub async fn execute_dkg(
}

/// Execute proactive refresh.
#[allow(clippy::type_complexity)]
#[tracing::instrument(
skip_all,
fields(threshold_accounts, my_idx),
Expand All @@ -339,8 +340,6 @@ pub async fn execute_proactive_refresh(
chans: Channels,
threshold_pair: &sr25519::Pair,
threshold_accounts: Vec<AccountId32>,
verifying_key: VerifyingKey,
threshold: usize,
inputs: KeyResharingInputs<KeyParams, PartyId>,
) -> Result<
(ThresholdKeyShare<KeyParams, PartyId>, Broadcaster, mpsc::Receiver<ProtocolMessage>),
Expand Down
30 changes: 20 additions & 10 deletions crates/protocol/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ use entropy_shared::X25519PublicKey;
use futures::future;
use sp_core::{sr25519, Pair};
use std::{
collections::BTreeSet,
fmt,
sync::{Arc, Mutex},
time::Duration,
};
use subxt::utils::AccountId32;
use synedrion::{AuxInfo, KeyShare, ThresholdKeyShare};
use synedrion::{AuxInfo, KeyResharingInputs, KeyShare, NewHolder, OldHolder, ThresholdKeyShare};
use tokio::{
net::{TcpListener, TcpStream},
time::timeout,
Expand Down Expand Up @@ -131,15 +132,24 @@ pub async fn server(
Ok(ProtocolOutput::Sign(RecoverableSignature { signature, recovery_id }))
},
SessionId::Reshare { .. } => {
let new_keyshare = execute_proactive_refresh(
session_id,
channels,
&pair,
tss_accounts,
threshold_keyshare.unwrap(),
)
.await?;
Ok(ProtocolOutput::Reshare(new_keyshare))
let old_key = threshold_keyshare.unwrap();
let party_ids: BTreeSet<PartyId> =
tss_accounts.iter().cloned().map(PartyId::new).collect();
let inputs = KeyResharingInputs {
old_holder: Some(OldHolder { key_share: old_key.clone() }),
new_holder: Some(NewHolder {
verifying_key: old_key.verifying_key(),
old_threshold: party_ids.len(),
old_holders: party_ids.clone(),
}),
new_holders: party_ids.clone(),
new_threshold: old_key.threshold(),
};

let new_keyshare =
execute_proactive_refresh(session_id, channels, &pair, tss_accounts, inputs)
.await?;
Ok(ProtocolOutput::Reshare(new_keyshare.0))
},
SessionId::Dkg { .. } => {
let keyshare_and_aux_info =
Expand Down
14 changes: 4 additions & 10 deletions crates/threshold-signature-server/src/signing_client/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ async fn handle_socket_result(socket: WebSocket, app_state: AppState) {
};
}

#[allow(clippy::type_complexity)]
#[tracing::instrument(
skip_all,
fields(validators_info, verifying_key, my_subgroup),
Expand Down Expand Up @@ -216,16 +217,9 @@ pub async fn do_proactive_refresh(
)
.await?;

let result = execute_proactive_refresh(
session_id,
channels,
signer.signer(),
tss_accounts,
old_key.verifying_key(),
old_key.threshold(),
inputs,
)
.await?;
let result =
execute_proactive_refresh(session_id, channels, signer.signer(), tss_accounts, inputs)
.await?;
Ok(result)
}

Expand Down
15 changes: 5 additions & 10 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use crate::{
launch::{FORBIDDEN_KEYS, LATEST_BLOCK_NUMBER_RESHARE},
substrate::{get_stash_address, get_validators_info, query_chain, submit_transaction},
},
signing_client::{
api::get_channels, protocol_transport::open_protocol_connections, ProtocolErr,
},
signing_client::{api::get_channels, ProtocolErr},
validator::errors::ValidatorErr,
AppState,
};
Expand All @@ -40,20 +38,19 @@ pub use entropy_protocol::{
},
KeyParams, KeyShareWithAuxInfo, Listener, PartyId, SessionId, ValidatorInfo,
};
use entropy_shared::{OcwMessageReshare, NETWORK_PARENT_KEY, SETUP_TIMEOUT_SECONDS};
use entropy_shared::{OcwMessageReshare, NETWORK_PARENT_KEY};
use parity_scale_codec::{Decode, Encode};
use rand_core::OsRng;
use sp_core::Pair;
use std::{collections::BTreeSet, str::FromStr, time::Duration};
use std::{collections::BTreeSet, str::FromStr};
use subxt::{
backend::legacy::LegacyRpcMethods, ext::sp_core::sr25519, tx::PairSigner, utils::AccountId32,
OnlineClient,
};
use synedrion::{
make_aux_gen_session, make_key_resharing_session, sessions::SessionId as SynedrionSessionId,
AuxInfo, KeyResharingInputs, NewHolder, OldHolder,
make_aux_gen_session, sessions::SessionId as SynedrionSessionId, AuxInfo, KeyResharingInputs,
NewHolder, OldHolder,
};
use tokio::time::timeout;

/// HTTP POST endpoint called by the off-chain worker (propagation pallet) during network reshare.
///
Expand Down Expand Up @@ -183,8 +180,6 @@ pub async fn new_reshare(
channels,
signer.signer(),
tss_accounts,
decoded_verifying_key,
threshold as usize,
inputs,
)
.await?;
Expand Down

0 comments on commit 07bc6cd

Please sign in to comment.