From 7f64bbd3a80a59c4e5c41b4a69631354d5a6d338 Mon Sep 17 00:00:00 2001 From: peg Date: Fri, 13 Sep 2024 14:40:46 +0200 Subject: [PATCH] Tidy --- .../src/user/api.rs | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index 3bd75f857..19f1ec411 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -312,27 +312,33 @@ async fn get_jumpstart_validators( rpc: &LegacyRpcMethods, block_number: u32, ) -> Result, 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);