Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Oct 3, 2024
1 parent 454c9ad commit 940b650
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct OcwMessageDkg {
#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
pub struct OcwMessageReshare {
// Stash address of new signer
pub new_signer: Vec<u8>,
pub new_signers: Vec<Vec<u8>>,
pub block_number: BlockNumber,
}

Expand Down
42 changes: 27 additions & 15 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
AppState,
};
use axum::{body::Bytes, extract::State, http::StatusCode};
use blake2::{Blake2s256, Digest};
use entropy_kvdb::kv_manager::{helpers::serialize as key_serialize, KvManager};
pub use entropy_protocol::{
decode_verifying_key,
Expand Down Expand Up @@ -106,7 +107,7 @@ pub async fn new_reshare(
.map_err(|e| ValidatorErr::UserError(e.to_string()))?;

let old_holder: Option<OldHolder<KeyParams, PartyId>> =
if data.new_signer == my_stash_address.encode() {
if data.new_signers.contains(&my_stash_address.encode()) {
None
} else {
let kvdb_result = app_state.kv_store.kv().get(&hex::encode(NETWORK_PARENT_KEY)).await?;
Expand All @@ -120,7 +121,7 @@ pub async fn new_reshare(
validators_info.iter().cloned().map(|x| PartyId::new(x.tss_account)).collect();

let pruned_old_holders =
prune_old_holders(&api, &rpc, data.new_signer, validators_info.clone()).await?;
prune_old_holders(&api, &rpc, data.new_signers, validators_info.clone()).await?;

let old_holders: BTreeSet<PartyId> =
pruned_old_holders.into_iter().map(|x| PartyId::new(x.tss_account)).collect();
Expand Down Expand Up @@ -273,7 +274,14 @@ pub async fn validate_new_reshare(
.await?
.ok_or_else(|| ValidatorErr::ChainFetch("Not Currently in a reshare"))?;

if reshare_data.new_signer != chain_data.new_signer
let mut hasher_chain_data = Blake2s256::new();
hasher_chain_data.update(chain_data.new_signers.encode());
let chain_data_hash = hasher_chain_data.finalize();
let mut hasher_verifying_data = Blake2s256::new();
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);
Expand Down Expand Up @@ -365,20 +373,24 @@ pub fn check_forbidden_key(key: &str) -> Result<(), ValidatorErr> {
pub async fn prune_old_holders(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
new_signer: Vec<u8>,
new_signers: Vec<Vec<u8>>,
validators_info: Vec<ValidatorInfo>,
) -> Result<Vec<ValidatorInfo>, ValidatorErr> {
Ok(if !new_signer.is_empty() {
let address_slice: &[u8; 32] = &new_signer.clone().try_into().unwrap();
let new_signer_address = AccountId32(*address_slice);
let new_signer_info = &get_validators_info(api, rpc, vec![new_signer_address])
.await
.map_err(|e| ValidatorErr::UserError(e.to_string()))?[0];
validators_info
.iter()
.filter(|x| x.tss_account != new_signer_info.tss_account)
.cloned()
.collect()
Ok(if !new_signers.is_empty() {
let mut filtered_validators_info = vec![];
for new_signer in new_signers {
let address_slice: &[u8; 32] = &new_signer.clone().try_into().unwrap();
let new_signer_address = AccountId32(*address_slice);
let new_signer_info = &get_validators_info(api, rpc, vec![new_signer_address])
.await
.map_err(|e| ValidatorErr::UserError(e.to_string()))?[0];
filtered_validators_info = validators_info
.iter()
.filter(|x| x.tss_account != new_signer_info.tss_account)
.cloned()
.collect::<Vec<_>>();
}
filtered_validators_info
} else {
validators_info.clone()
})
Expand Down
2 changes: 1 addition & 1 deletion pallets/propagation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub mod pallet {
BlockNumberFor::<T>::try_into(block_number).unwrap_or_default();

let req_body = OcwMessageReshare {
new_signer: reshare_data.new_signer,
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
12 changes: 6 additions & 6 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub mod pallet {

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, Default)]
pub struct ReshareInfo<BlockNumber> {
pub new_signer: Vec<Vec<u8>>,
pub new_signers: Vec<Vec<u8>>,
pub block_number: BlockNumber,
}

Expand Down Expand Up @@ -316,7 +316,7 @@ pub mod pallet {
next_signers.push(self.mock_signer_rotate.2[0].clone());
let next_signers = next_signers.to_vec();
NextSigners::<T>::put(NextSignerInfo { next_signers, confirmations: vec![] });
let new_signer = self
let new_signers = self
.mock_signer_rotate
.clone()
.2
Expand All @@ -326,7 +326,7 @@ pub mod pallet {
ReshareData::<T>::put(ReshareInfo {
// To give enough time for test_reshare setup
block_number: TEST_RESHARE_BLOCK_NUMBER.into(),
new_signer,
new_signers,
})
}
}
Expand Down Expand Up @@ -719,7 +719,7 @@ pub mod pallet {
return Ok(weight);
}

let mut new_signer: Vec<Vec<u8>> = vec![];
let mut new_signers: Vec<Vec<u8>> = vec![];
let mut count = 0u32;

// removes first signer and pushes new signer to back if total signers not increased
Expand Down Expand Up @@ -757,7 +757,7 @@ pub mod pallet {
}

current_signers.push(next_signer_up.clone());
new_signer.push(next_signer_up.encode());
new_signers.push(next_signer_up.encode());
}

NextSigners::<T>::put(NextSignerInfo {
Expand All @@ -769,7 +769,7 @@ pub mod pallet {
let current_block_number = <frame_system::Pallet<T>>::block_number();
let reshare_info = ReshareInfo {
block_number: current_block_number + sp_runtime::traits::One::one(),
new_signer,
new_signers,
};

ReshareData::<T>::put(reshare_info);
Expand Down
2 changes: 1 addition & 1 deletion pallets/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ fn it_tests_new_session_handler() {
"Check reshare block start at 100 + 1"
);
assert_eq!(
Staking::reshare_data().new_signer,
Staking::reshare_data().new_signers,
vec![1u64.encode(), 3u64.encode()],
"Check reshare next signer up is 3"
);
Expand Down

0 comments on commit 940b650

Please sign in to comment.