Skip to content

Commit

Permalink
remove old signer
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Oct 16, 2024
1 parent ed32eba commit 4482fd6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 58 deletions.
Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
2 changes: 0 additions & 2 deletions crates/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ pub struct OcwMessageDkg {
pub struct OcwMessageReshare {
// Stash address of new signers
pub new_signers: Vec<Vec<u8>>,
// Stash address of old signers to take part in the reshare
pub old_signers: Vec<Vec<u8>>,
pub block_number: BlockNumber,
}

Expand Down
42 changes: 8 additions & 34 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,10 @@ pub async fn new_reshare(
.ok_or_else(|| ValidatorErr::ChainFetch("Error getting next signers"))?
.next_signers;

let signers_query = entropy::storage().staking_extension().signers();
let old_signers_stash: Vec<AccountId32> = data
.old_signers
.into_iter()
.map(|s| {
let address_slice: &[u8; 32] = &s
.clone()
.try_into()
.map_err(|_| ProtocolErr::AddressConversionError("Invalid Length".to_string()))
.unwrap();
AccountId32(*address_slice)
})
.collect();

let old_signers = get_validators_info(&api, &rpc, old_signers_stash)
.await
.map_err(|e| ValidatorErr::UserError(e.to_string()))?;

let validators_info = get_validators_info(&api, &rpc, next_signers)
.await
.map_err(|e| ValidatorErr::UserError(e.to_string()))?;
let mut all_holders = validators_info.clone();
for old_signers_info in old_signers.clone() {
let contains =
all_holders.iter().position(|v| v.tss_account == old_signers_info.tss_account);
if contains.is_none() {
all_holders.push(old_signers_info);
}
}

let (signer, x25519_secret_key) = get_signer_and_x25519_secret(&app_state.kv_store)
.await
.map_err(|e| ValidatorErr::UserError(e.to_string()))?;
Expand All @@ -119,8 +94,9 @@ 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 = validators_info
.iter()
.any(|validator_info| validator_info.tss_account == *signer.account_id());

if !is_proper_signer {
return Ok(StatusCode::MISDIRECTED_REQUEST);
Expand All @@ -144,10 +120,8 @@ pub async fn new_reshare(
let new_holders: BTreeSet<PartyId> =
validators_info.iter().cloned().map(|x| PartyId::new(x.tss_account)).collect();

let verifiers: BTreeSet<PartyId> =
validators_info.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 =
&prune_old_holders(&api, &rpc, data.new_signers, validators_info.clone()).await?;
let old_holders: BTreeSet<PartyId> =
old_holders.into_iter().map(|x| PartyId::new(x.tss_account.clone())).collect();

Expand All @@ -174,7 +148,7 @@ pub async fn new_reshare(

let mut converted_validator_info = vec![];
let mut tss_accounts = vec![];
for validator_info in all_holders {
for validator_info in validators_info {
let validator_info = ValidatorInfo {
x25519_public_key: validator_info.x25519_public_key,
ip_address: validator_info.ip_address,
Expand All @@ -194,7 +168,7 @@ pub async fn new_reshare(
.await?;

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

let serialized_key_share = key_serialize(&(new_key_share, aux_info))
Expand Down
18 changes: 4 additions & 14 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ async fn test_reshare_foo() {
let block_number = TEST_RESHARE_BLOCK_NUMBER;
let onchain_reshare_request = OcwMessageReshare {
new_signers: vec![new_signer.0.to_vec()],
old_signers: vec![
AccountKeyring::BobStash.public().encode(),
AccountKeyring::DaveStash.public().encode(),
],
block_number: block_number - 1,
};

Expand Down Expand Up @@ -329,11 +325,8 @@ async fn test_reshare_validation_fail() {
let kv = setup_client().await;

let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;
let mut ocw_message = OcwMessageReshare {
new_signers: vec![dave.public().encode()],
old_signers: vec![],
block_number,
};
let mut ocw_message =
OcwMessageReshare { new_signers: vec![dave.public().encode()], block_number };

let err_stale_data =
validate_new_reshare(&api, &rpc, &ocw_message, &kv).await.map_err(|e| e.to_string());
Expand Down Expand Up @@ -371,11 +364,8 @@ async fn test_reshare_validation_fail_not_in_reshare() {
let kv = setup_client().await;

let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;
let ocw_message = OcwMessageReshare {
new_signers: vec![alice.public().encode()],
old_signers: vec![],
block_number,
};
let ocw_message =
OcwMessageReshare { new_signers: vec![alice.public().encode()], block_number };

run_to_block(&rpc, block_number + 1).await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ async fn do_reshare(api: &OnlineClient<EntropyConfig>, rpc: &LegacyRpcMethods<En
let block_number = TEST_RESHARE_BLOCK_NUMBER;
let onchain_reshare_request = OcwMessageReshare {
new_signers: reshare_data.new_signers.into_iter().map(|s| s.to_vec()).collect(),
old_signers: vec![],
block_number: block_number - 1,
};

Expand Down
1 change: 0 additions & 1 deletion pallets/propagation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ pub mod pallet {
BlockNumberFor::<T>::try_into(block_number).unwrap_or_default();

let req_body = OcwMessageReshare {
old_signers: reshare_data.old_signers,
new_signers: reshare_data.new_signers,
// subtract 1 from blocknumber since the request is from the last block
block_number: converted_block_number.saturating_sub(1),
Expand Down
6 changes: 0 additions & 6 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ pub mod pallet {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, Default)]
pub struct ReshareInfo<BlockNumber> {
pub new_signers: Vec<Vec<u8>>,
pub old_signers: Vec<Vec<u8>>,
pub block_number: BlockNumber,
}

Expand Down Expand Up @@ -321,14 +320,11 @@ pub mod pallet {
new_signers.push(new_signer.encode())
}
let next_signers = next_signers.to_vec();
let old_signers: Vec<Vec<u8>> =
self.mock_signer_rotate.3.clone().into_iter().map(|s| s.encode()).collect();
NextSigners::<T>::put(NextSignerInfo { next_signers, confirmations: vec![] });
ReshareData::<T>::put(ReshareInfo {
// To give enough time for test_reshare setup
block_number: TEST_RESHARE_BLOCK_NUMBER.into(),
new_signers,
old_signers,
})
}
}
Expand Down Expand Up @@ -771,8 +767,6 @@ pub mod pallet {
let reshare_info = ReshareInfo {
block_number: current_block_number + sp_runtime::traits::One::one(),
new_signers,
// TODO: fix
old_signers: vec![],
};

ReshareData::<T>::put(reshare_info);
Expand Down

0 comments on commit 4482fd6

Please sign in to comment.