Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Sep 13, 2024
1 parent 8c198a5 commit 7f64bbd
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions crates/threshold-signature-server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,27 +312,33 @@ async fn get_jumpstart_validators(
rpc: &LegacyRpcMethods<EntropyConfig>,
block_number: u32,
) -> Result<Vec<entropy_shared::ValidatorInfo>, UserErr> {
let total_signers_query = entropy::storage().parameters().signers_info();
let signers_info =
query_chain(api, rpc, total_signers_query, None).await?.ok_or_else(|| {
UserErr::OptionUnwrapError("Cannot get signer info from parameters pallet".to_string())
})?;
let n = signers_info.total_signers;

let mut validators_info: Vec<_> = vec![];

let validators_query = entropy::storage().session().validators();
let validators = query_chain(api, rpc, validators_query, None).await?.ok_or_else(|| {
UserErr::OptionUnwrapError("Cannot get validators info from session pallet".to_string())
})?;
// Get n from parameters
let n = {
let total_signers_query = entropy::storage().parameters().signers_info();
let signers_info =
query_chain(api, rpc, total_signers_query, None).await?.ok_or_else(|| {
UserErr::OptionUnwrapError(
"Cannot get signer info from parameters pallet".to_string(),
)
})?;
signers_info.total_signers
};

let block_number_bytes = block_number.to_le_bytes();
let mut seed = [0; 32];
seed[..4].copy_from_slice(&block_number_bytes);
let mut rng = rand::rngs::StdRng::from_seed(seed);
// Get all validators
let all_validators = {
let validators_query = entropy::storage().session().validators();
query_chain(api, rpc, validators_query, None).await?.ok_or_else(|| {
UserErr::OptionUnwrapError("Cannot get validators info from session pallet".to_string())
})?
};

// Select n validators
let mut rng = rand::rngs::StdRng::seed_from_u64(block_number.into());
let selected_validators: Vec<_> =
validators.choose_multiple(&mut rng, n.into()).cloned().collect();
all_validators.choose_multiple(&mut rng, n.into()).cloned().collect();

// Get validator info for selected validators
let mut validators_info: Vec<_> = vec![];
for validator_address in selected_validators {
let validator_query =
entropy::storage().staking_extension().threshold_servers(validator_address);
Expand Down

0 comments on commit 7f64bbd

Please sign in to comment.