Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Oct 9, 2024
1 parent 7f2346d commit a54dd56
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion crates/protocol/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ pub async fn server(
new_threshold: old_key.threshold(),
};

let new_keyshare = execute_reshare(session_id, channels, &pair, inputs, &party_ids, None).await?;
let new_keyshare =
execute_reshare(session_id, channels, &pair, inputs, &party_ids, None).await?;
Ok(ProtocolOutput::Reshare(new_keyshare.0))
},
SessionId::Dkg { .. } => {
Expand Down
3 changes: 2 additions & 1 deletion crates/threshold-signature-server/src/signing_client/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ pub async fn do_proactive_refresh(
.await?;

let result =
execute_reshare(session_id, channels, signer.signer(), inputs, &party_ids, Some(aux_info)).await?;
execute_reshare(session_id, channels, signer.signer(), inputs, &party_ids, Some(aux_info))
.await?;
Ok(result)
}

Expand Down
28 changes: 14 additions & 14 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ pub async fn new_reshare(
)
.map_err(|e| ValidatorErr::VerifyingKeyError(e.to_string()))?;

let is_proper_signer = all_holders
.iter()
.any(|validator_info| validator_info.tss_account == *signer.account_id());
let is_proper_signer =
all_holders.iter().any(|validator_info| validator_info.tss_account == *signer.account_id());

if !is_proper_signer {
return Ok(StatusCode::MISDIRECTED_REQUEST);
Expand All @@ -138,7 +137,7 @@ pub async fn new_reshare(

let verifiers: BTreeSet<PartyId> =
all_holders.iter().cloned().map(|x| PartyId::new(x.tss_account)).collect();

let old_holders = prune_old_holders(&api, &rpc, data.new_signers, validators_info).await?;
let old_holders: BTreeSet<PartyId> =
old_holders.into_iter().map(|x| PartyId::new(x.tss_account)).collect();
Expand Down Expand Up @@ -187,7 +186,8 @@ pub async fn new_reshare(
.await?;

let (new_key_share, aux_info) =
execute_reshare(session_id.clone(), channels, signer.signer(), inputs, &verifiers, None).await?;
execute_reshare(session_id.clone(), channels, signer.signer(), inputs, &verifiers, None)
.await?;

let serialized_key_share = key_serialize(&(new_key_share, aux_info))
.map_err(|_| ProtocolErr::KvSerialize("Kv Serialize Error".to_string()))?;
Expand Down Expand Up @@ -281,10 +281,10 @@ pub async fn validate_new_reshare(
.ok_or_else(|| ValidatorErr::OptionUnwrapError("Failed to get block number".to_string()))?
.number;

// // we subtract 1 as the message info is coming from the previous block
// if latest_block_number.saturating_sub(1) != chain_data.block_number {
// return Err(ValidatorErr::StaleData);
// }
// we subtract 1 as the message info is coming from the previous block
if latest_block_number.saturating_sub(1) != chain_data.block_number {
return Err(ValidatorErr::StaleData);
}

let reshare_data_info_query = entropy::storage().staking_extension().reshare_data();
let reshare_data = query_chain(api, rpc, reshare_data_info_query, None)
Expand All @@ -298,11 +298,11 @@ pub async fn validate_new_reshare(
hasher_verifying_data.update(reshare_data.new_signers.encode());
let verifying_data_hash = hasher_verifying_data.finalize();

// if verifying_data_hash != chain_data_hash
// || chain_data.block_number != reshare_data.block_number
// {
// return Err(ValidatorErr::InvalidData);
// }
if verifying_data_hash != chain_data_hash
|| chain_data.block_number != reshare_data.block_number.saturating_sub(1)
{
return Err(ValidatorErr::InvalidData);
}
kv_manager.kv().delete(LATEST_BLOCK_NUMBER_RESHARE).await?;
let reservation = kv_manager.kv().reserve_key(LATEST_BLOCK_NUMBER_RESHARE.to_string()).await?;
kv_manager.kv().put(reservation, chain_data.block_number.to_be_bytes().to_vec()).await?;
Expand Down
8 changes: 5 additions & 3 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use synedrion::k256::ecdsa::VerifyingKey;

#[tokio::test]
#[serial]
async fn test_reshare_foo() {
async fn test_reshare() {
initialize_test_logger().await;
clean_tests();

Expand Down Expand Up @@ -113,8 +113,10 @@ async fn test_reshare_foo() {
let new_signer = all_validators.iter().find(|v| !signer_stash_accounts.contains(v)).unwrap();

let block_number = TEST_RESHARE_BLOCK_NUMBER;
let onchain_reshare_request =
OcwMessageReshare { new_signers: vec![new_signer.0.to_vec()], block_number: block_number - 1 };
let onchain_reshare_request = OcwMessageReshare {
new_signers: vec![new_signer.0.to_vec()],
block_number: block_number - 1,
};

run_to_block(&rpc, block_number).await;
// Send the OCW message to all TS servers who don't have a chain node
Expand Down

0 comments on commit a54dd56

Please sign in to comment.