diff --git a/CHANGELOG.md b/CHANGELOG.md index c31561298..d8148a6b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ At the moment this project **does not** adhere to cleaned up. A lot of storage entries, events, and extrinsics were removed from the `Registry` pallet. The genesis build config was also removed. Additionally, the `new/user/` HTTP endpoint in the TSS was removed since it was no longer necessary. -- In [#1045](https://github.com/entropyxyz/entropy-core/pull/1045), `ProgramsInfo` now takes `version_number` to maintain backwards compatibility if programs runtime is updated +- In [#1045](https://github.com/entropyxyz/entropy-core/pull/1045), `ProgramsInfo` now takes `version_number` to maintain backwards compatibility if programs runtime is updated ### Added - Jumpstart network ([#918](https://github.com/entropyxyz/entropy-core/pull/918)) @@ -34,6 +34,7 @@ At the moment this project **does not** adhere to - Attestation pallet ([#1003](https://github.com/entropyxyz/entropy-core/pull/1003)) - Update test CLI for new registration and signing flows ([#1008](https://github.com/entropyxyz/entropy-core/pull/1008)) - Add remove program function to entropy-client ([#1023](https://github.com/entropyxyz/entropy-core/pull/1023)) +- Select validators for jumpstart DKG [#1053](https://github.com/entropyxyz/entropy-core/pull/1053)) - Add a programs version ([#1045](https://github.com/entropyxyz/entropy-core/pull/1045)) ### Changed diff --git a/Cargo.lock b/Cargo.lock index 5ca4c7ed3..490f94385 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7273,6 +7273,7 @@ dependencies = [ "pallet-staking-reward-curve", "pallet-timestamp", "parity-scale-codec", + "rand", "scale-info", "sp-core 29.0.0", "sp-io 31.0.0", @@ -14041,7 +14042,7 @@ dependencies = [ [[package]] name = "synedrion" version = "0.1.0" -source = "git+https://github.com/entropyxyz/synedrion?rev=1d210d149dfeb0dca1dd41d7fac4d0bf03c686fa#1d210d149dfeb0dca1dd41d7fac4d0bf03c686fa" +source = "git+https://github.com/entropyxyz/synedrion/?rev=1d210d149dfeb0dca1dd41d7fac4d0bf03c686fa#1d210d149dfeb0dca1dd41d7fac4d0bf03c686fa" dependencies = [ "base64 0.21.7", "bincode 2.0.0-rc.3", diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index 496d24037..adb357cc3 100644 Binary files a/crates/client/entropy_metadata.scale and b/crates/client/entropy_metadata.scale differ diff --git a/crates/protocol/src/lib.rs b/crates/protocol/src/lib.rs index 4a4ef4234..648f0d96c 100644 --- a/crates/protocol/src/lib.rs +++ b/crates/protocol/src/lib.rs @@ -157,8 +157,8 @@ impl RecoverableSignature { /// An identifier to specify and particular protocol session #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] pub enum SessionId { - /// A distributed key generation protocol session for registering - Dkg { user: AccountId32, block_number: u32 }, + /// A distributed key generation protocol session for initial network jumpstart + Dkg { block_number: u32 }, /// A proactive refresh session Reshare { verifying_key: Vec, block_number: u32 }, /// A signing session @@ -181,8 +181,7 @@ pub struct SigningSessionInfo { impl Hash for SessionId { fn hash(&self, state: &mut H) { match self { - SessionId::Dkg { user, block_number } => { - user.0.hash(state); + SessionId::Dkg { block_number } => { block_number.hash(state); }, SessionId::Reshare { verifying_key, block_number } => { diff --git a/crates/protocol/tests/protocol.rs b/crates/protocol/tests/protocol.rs index a2e287203..73c19d814 100644 --- a/crates/protocol/tests/protocol.rs +++ b/crates/protocol/tests/protocol.rs @@ -143,7 +143,7 @@ async fn test_dkg_with_parties(num_parties: usize) { let parties: Vec<_> = pairs.iter().map(|pair| ValidatorSecretInfo::pair_only(pair.clone())).collect(); let threshold = parties.len(); - let session_id = SessionId::Dkg { user: AccountId32([0; 32]), block_number: 0 }; + let session_id = SessionId::Dkg { block_number: 0 }; let mut outputs = test_protocol_with_parties(parties, session_id, threshold).await; if let ProtocolOutput::Dkg(_keyshare) = outputs.pop().unwrap() { } else { @@ -159,7 +159,7 @@ async fn test_dkg_and_sign_with_parties(num_parties: usize) { let (pairs, ids) = get_keypairs_and_ids(num_parties); let dkg_parties = pairs.iter().map(|pair| ValidatorSecretInfo::pair_only(pair.clone())).collect(); - let session_id = SessionId::Dkg { user: AccountId32([0; 32]), block_number: 0 }; + let session_id = SessionId::Dkg { block_number: 0 }; let outputs = test_protocol_with_parties(dkg_parties, session_id, threshold).await; let signing_committee = (0..threshold) diff --git a/crates/shared/src/types.rs b/crates/shared/src/types.rs index 49b558186..48a5ab089 100644 --- a/crates/shared/src/types.rs +++ b/crates/shared/src/types.rs @@ -41,13 +41,12 @@ pub struct ValidatorInfo { pub tss_account: codec::alloc::vec::Vec, } -/// Offchain worker message for initiating a dkg +/// Offchain worker message for initiating the initial jumpstart DKG #[cfg(not(feature = "wasm"))] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)] pub struct OcwMessageDkg { pub block_number: BlockNumber, - pub sig_request_accounts: Vec>, pub validators_info: Vec, } diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index ff117ed57..b60666988 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -282,7 +282,8 @@ pub async fn jump_start_network_with_signer( let jump_start_request = entropy::tx().registry().jump_start_network(); let _result = submit_transaction(api, rpc, signer, &jump_start_request, None).await.unwrap(); - let validators_names = vec![ValidatorName::Bob, ValidatorName::Charlie, ValidatorName::Dave]; + let validators_names = + vec![ValidatorName::Alice, ValidatorName::Bob, ValidatorName::Charlie, ValidatorName::Dave]; for validator_name in validators_names { let mnemonic = development_mnemonic(&Some(validator_name)); let (tss_signer, _static_secret) = @@ -290,7 +291,9 @@ pub async fn jump_start_network_with_signer( let jump_start_confirm_request = entropy::tx().registry().confirm_jump_start(BoundedVec(EVE_VERIFYING_KEY.to_vec())); - submit_transaction(api, rpc, &tss_signer, &jump_start_confirm_request, None).await.unwrap(); + // Ignore the error as one confirmation will fail + let _result = + submit_transaction(api, rpc, &tss_signer, &jump_start_confirm_request, None).await; } } diff --git a/crates/threshold-signature-server/src/helpers/user.rs b/crates/threshold-signature-server/src/helpers/user.rs index 263aac1e9..34aaeb41e 100644 --- a/crates/threshold-signature-server/src/helpers/user.rs +++ b/crates/threshold-signature-server/src/helpers/user.rs @@ -43,10 +43,9 @@ pub async fn do_dkg( signer: &PairSigner, x25519_secret_key: &StaticSecret, state: &ListenerState, - sig_request_account: AccountId32, block_number: u32, ) -> Result { - let session_id = SessionId::Dkg { user: sig_request_account.clone(), block_number }; + let session_id = SessionId::Dkg { block_number }; let account_id = AccountId32(signer.signer().public().0); let mut converted_validator_info = vec![]; let mut tss_accounts = vec![]; diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index 199259c55..2b779be3e 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -45,6 +45,7 @@ use futures::{ }; use num::{bigint::BigInt, FromPrimitive, Num, ToPrimitive}; use parity_scale_codec::{Decode, DecodeAll, Encode}; +use rand_core::OsRng; use serde::{Deserialize, Serialize}; use sp_core::{crypto::AccountId32, H256}; use subxt::{ @@ -55,6 +56,7 @@ use subxt::{ Config, OnlineClient, }; use synedrion::ThresholdKeyShare; +use tokio::select; use tracing::instrument; use x25519_dalek::StaticSecret; use zeroize::Zeroize; @@ -265,7 +267,7 @@ pub async fn generate_network_key( let data = OcwMessageDkg::decode(&mut encoded_data.as_ref())?; tracing::Span::current().record("block_number", data.block_number); - if data.sig_request_accounts.is_empty() { + if data.validators_info.is_empty() { return Ok(StatusCode::NO_CONTENT); } @@ -317,49 +319,33 @@ async fn setup_dkg( app_state: AppState, ) -> Result<(), UserErr> { tracing::debug!("Preparing to execute DKG"); - for sig_request_account in data.sig_request_accounts.into_iter() { - let address_slice: &[u8; 32] = &sig_request_account - .clone() - .try_into() - .map_err(|_| UserErr::AddressConversionError("Invalid Length".to_string()))?; - let sig_request_address = SubxtAccountId32(*address_slice); - - let (key_share, aux_info) = do_dkg( - &data.validators_info, - &signer, - x25519_secret_key, - &app_state.listener_state, - sig_request_address.clone(), - data.block_number, - ) - .await?; + let (key_share, aux_info) = do_dkg( + &data.validators_info, + &signer, + x25519_secret_key, + &app_state.listener_state, + data.block_number, + ) + .await?; - let verifying_key = key_share.verifying_key().to_encoded_point(true).as_bytes().to_vec(); - let string_verifying_key = if sig_request_account == NETWORK_PARENT_KEY.encode() { - hex::encode(NETWORK_PARENT_KEY) - } else { - hex::encode(verifying_key.clone()) - } - .to_string(); + let verifying_key = key_share.verifying_key().to_encoded_point(true).as_bytes().to_vec(); - let serialized_key_share = key_serialize(&(key_share, aux_info)) - .map_err(|_| UserErr::KvSerialize("Kv Serialize Error".to_string()))?; + let serialized_key_share = key_serialize(&(key_share, aux_info)) + .map_err(|_| UserErr::KvSerialize("Kv Serialize Error".to_string()))?; - let reservation = app_state.kv_store.kv().reserve_key(string_verifying_key.clone()).await?; - app_state.kv_store.kv().put(reservation, serialized_key_share.clone()).await?; + let reservation = app_state.kv_store.kv().reserve_key(hex::encode(NETWORK_PARENT_KEY)).await?; + app_state.kv_store.kv().put(reservation, serialized_key_share.clone()).await?; - let block_hash = rpc - .chain_get_block_hash(None) - .await? - .ok_or_else(|| UserErr::OptionUnwrapError("Error getting block hash".to_string()))?; + let block_hash = rpc + .chain_get_block_hash(None) + .await? + .ok_or_else(|| UserErr::OptionUnwrapError("Error getting block hash".to_string()))?; - let nonce_call = - entropy::apis().account_nonce_api().account_nonce(signer.account_id().clone()); - let nonce = api.runtime_api().at(block_hash).call(nonce_call).await?; + let nonce_call = entropy::apis().account_nonce_api().account_nonce(signer.account_id().clone()); + let nonce = api.runtime_api().at(block_hash).call(nonce_call).await?; - // TODO: Error handling really complex needs to be thought about. - confirm_jump_start(&api, rpc, sig_request_address, &signer, verifying_key, nonce).await?; - } + // TODO: Error handling really complex needs to be thought about. + confirm_jump_start(&api, rpc, &signer, verifying_key, nonce).await?; Ok(()) } @@ -367,7 +353,6 @@ async fn setup_dkg( pub async fn confirm_jump_start( api: &OnlineClient, rpc: &LegacyRpcMethods, - who: SubxtAccountId32, signer: &PairSigner, verifying_key: Vec, nonce: u32, @@ -377,10 +362,6 @@ pub async fn confirm_jump_start( // TODO: Understand this better, potentially use sign_and_submit_default // or other method under sign_and_* - if who.encode() != NETWORK_PARENT_KEY.encode() { - return Err(UserErr::UnableToConfirmJumpStart); - } - let jump_start_request = entropy::tx().registry().confirm_jump_start( entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec(verifying_key), ); @@ -419,18 +400,11 @@ async fn validate_jump_start( return Err(UserErr::StaleData); } - let mut hasher_chain_data = Blake2s256::new(); - hasher_chain_data.update(Some(chain_data.sig_request_accounts.clone()).encode()); - let chain_data_hash = hasher_chain_data.finalize(); - let mut hasher_verifying_data = Blake2s256::new(); - + // Check that the on-chain selected validators match those from the HTTP request let verifying_data_query = entropy::storage().registry().jumpstart_dkg(chain_data.block_number); - - let verifying_data = query_chain(api, rpc, verifying_data_query, None).await?; - hasher_verifying_data.update(verifying_data.encode()); - - let verifying_data_hash = hasher_verifying_data.finalize(); - if verifying_data_hash != chain_data_hash { + let verifying_data = query_chain(api, rpc, verifying_data_query, None).await?.unwrap(); + let verifying_data: Vec<_> = verifying_data.into_iter().map(|v| v.0).collect(); + if verifying_data != chain_data.validators_info { return Err(UserErr::InvalidData); } diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 397e2242c..101ee9c6e 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -95,6 +95,7 @@ use synedrion::{ k256::ecdsa::{RecoveryId, Signature as k256Signature, VerifyingKey}, AuxInfo, ThresholdKeyShare, }; +use tokio::select; use tokio::{ io::{AsyncRead, AsyncReadExt}, task::JoinHandle, @@ -612,7 +613,7 @@ async fn test_fails_to_sign_if_non_signing_group_participants_are_used() { for res in test_user_bad_connection_res { assert_eq!( res.unwrap().text().await.unwrap(), - "{\"Err\":\"Oneshot timeout error: channel closed\"}" + "{\"Err\":\"Subscribe message rejected: NoListener(\\\"no listener\\\")\"}" ); } @@ -715,46 +716,33 @@ async fn test_jumpstart_network() { let alice = AccountKeyring::Alice; - let cxt = test_context_stationary().await; + let add_parent_key = false; let (_validator_ips, _validator_ids) = - spawn_testing_validators(false, ChainSpecType::Development).await; - let api = get_api(&cxt.node_proc.ws_url).await.unwrap(); - let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap(); + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; + + let force_authoring = true; + let substrate_context = test_node_process_testing_state(force_authoring).await; + + let api = get_api(&substrate_context.ws_url).await.unwrap(); + let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); let client = reqwest::Client::new(); let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; - let validators_info = vec![ - entropy_shared::ValidatorInfo { - ip_address: b"127.0.0.1:3001".to_vec(), - x25519_public_key: X25519_PUBLIC_KEYS[0], - tss_account: TSS_ACCOUNTS[0].clone().encode(), - }, - entropy_shared::ValidatorInfo { - ip_address: b"127.0.0.1:3002".to_vec(), - x25519_public_key: X25519_PUBLIC_KEYS[1], - tss_account: TSS_ACCOUNTS[1].clone().encode(), - }, - entropy_shared::ValidatorInfo { - ip_address: b"127.0.0.1:3003".to_vec(), - x25519_public_key: X25519_PUBLIC_KEYS[2], - tss_account: TSS_ACCOUNTS[2].clone().encode(), - }, - ]; - let onchain_user_request = OcwMessageDkg { - sig_request_accounts: vec![NETWORK_PARENT_KEY.encode()], - block_number, - validators_info, - }; - put_jumpstart_request_on_chain(&api, &rpc, &alice).await; run_to_block(&rpc, block_number + 1).await; + let selected_validators_query = entropy::storage().registry().jumpstart_dkg(block_number); + let validators_info = + query_chain(&api, &rpc, selected_validators_query, None).await.unwrap().unwrap(); + let validators_info: Vec<_> = validators_info.into_iter().map(|v| v.0).collect(); + let onchain_user_request = OcwMessageDkg { block_number, validators_info }; + // succeeds let response_results = join_all( - vec![3002, 3003] + vec![3002, 3003, 3004] .iter() .map(|port| { client diff --git a/pallets/propagation/src/lib.rs b/pallets/propagation/src/lib.rs index 630aa4396..e7542c891 100644 --- a/pallets/propagation/src/lib.rs +++ b/pallets/propagation/src/lib.rs @@ -38,7 +38,6 @@ pub mod pallet { use codec::Encode; use entropy_shared::{ OcwMessageAttestationRequest, OcwMessageDkg, OcwMessageProactiveRefresh, OcwMessageReshare, - ValidatorInfo, }; use frame_support::{pallet_prelude::*, sp_runtime::traits::Saturating}; use frame_system::pallet_prelude::*; @@ -110,7 +109,7 @@ pub mod pallet { /// Submits a distributed key generation request to jumpstart the network to the threshold /// servers. pub fn post_dkg(block_number: BlockNumberFor) -> Result<(), http::Error> { - let messages = pallet_registry::Pallet::::jumpstart_dkg( + let validators_info = pallet_registry::Pallet::::jumpstart_dkg( block_number.saturating_sub(1u32.into()), ); @@ -121,24 +120,13 @@ pub mod pallet { let url = str::from_utf8(&from_local).unwrap_or("http://localhost:3001/generate_network_key"); - log::warn!("propagation::post::messages: {:?}", &messages); + log::warn!("propagation::post::validators_info: {:?}", &validators_info); let converted_block_number: u32 = BlockNumberFor::::try_into(block_number).unwrap_or_default(); - let servers_info = - pallet_registry::Pallet::::get_validators_info().unwrap_or_default(); - let validators_info = servers_info - .iter() - .map(|server_info| ValidatorInfo { - x25519_public_key: server_info.x25519_public_key, - ip_address: server_info.endpoint.clone(), - tss_account: server_info.tss_account.encode(), - }) - .collect::>(); // the data is serialized / encoded to Vec by parity-scale-codec::encode() let req_body = OcwMessageDkg { // subtract 1 from blocknumber since the request is from the last block block_number: converted_block_number.saturating_sub(1), - sig_request_accounts: messages, validators_info, }; diff --git a/pallets/propagation/src/tests.rs b/pallets/propagation/src/tests.rs index 05172236c..d01559a5a 100644 --- a/pallets/propagation/src/tests.rs +++ b/pallets/propagation/src/tests.rs @@ -33,13 +33,7 @@ fn knows_how_to_mock_several_http_calls() { uri: "http://localhost:3001/generate_network_key".into(), sent: true, response: Some([].to_vec()), - body: [ - 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 10, 32, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, - 11, 32, 4, 0, 0, 0, 0, 0, 0, 0, - ] - .to_vec(), + body: [0, 0, 0, 0, 0].to_vec(), ..Default::default() }); diff --git a/pallets/registry/Cargo.toml b/pallets/registry/Cargo.toml index d8825e2a8..1929f477a 100644 --- a/pallets/registry/Cargo.toml +++ b/pallets/registry/Cargo.toml @@ -17,6 +17,7 @@ codec ={ package="parity-scale-codec", version="3.6.3", default-features=fal log ={ version="0.4.22", default-features=false } scale-info={ version="2.11", default-features=false, features=["derive"] } synedrion ={ git="https://github.com/entropyxyz/synedrion/", rev="1d210d149dfeb0dca1dd41d7fac4d0bf03c686fa", default-features=false } +rand ={ version="0.8.5", default-features=false, features=["alloc"] } frame-benchmarking={ version="29.0.0", default-features=false, optional=true } frame-support ={ version="29.0.0", default-features=false } diff --git a/pallets/registry/src/benchmarking.rs b/pallets/registry/src/benchmarking.rs index dfbffede0..92021f801 100644 --- a/pallets/registry/src/benchmarking.rs +++ b/pallets/registry/src/benchmarking.rs @@ -14,7 +14,8 @@ // along with this program. If not, see . //! Benchmarking setup for pallet-propgation -use entropy_shared::MAX_SIGNERS; +use codec::Encode; +use entropy_shared::{ValidatorInfo, MAX_SIGNERS}; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_support::{ traits::{Currency, Get}, @@ -102,6 +103,14 @@ benchmarks! { parent_key_threshold: 2 }); + // Add the jump start record + let block_number = >::block_number(); + let initial_signers = accounts.iter().map(|account_id| ValidatorInfo { + x25519_public_key: [0; 32], + ip_address: vec![20], + tss_account: account_id.encode(), + }).collect(); + >::set(block_number, initial_signers); let balance = ::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&accounts[1], balance); @@ -117,12 +126,22 @@ benchmarks! { let threshold_account: T::AccountId = whitelisted_caller(); let expected_verifying_key = BoundedVec::default(); - // add validators and a registering user + // add validators for i in 0..MAX_SIGNERS { let validators = add_non_syncing_validators::(MAX_SIGNERS as u32, 0); >::set(validators.clone()); >::insert(&threshold_account, &validators[i as usize]); } + + // Add the jump start record + let block_number = >::block_number(); + let initial_signers = (0..MAX_SIGNERS).map(|i| ValidatorInfo { + x25519_public_key: [0; 32], + ip_address: vec![20], + tss_account: threshold_account.encode(), + }).collect(); + >::set(block_number, initial_signers); + >::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![], diff --git a/pallets/registry/src/lib.rs b/pallets/registry/src/lib.rs index c22f42231..899438a1b 100644 --- a/pallets/registry/src/lib.rs +++ b/pallets/registry/src/lib.rs @@ -52,7 +52,7 @@ pub mod weights; #[frame_support::pallet] pub mod pallet { - use entropy_shared::{MAX_SIGNERS, NETWORK_PARENT_KEY}; + use entropy_shared::{ValidatorInfo, MAX_SIGNERS, NETWORK_PARENT_KEY}; use frame_support::{ dispatch::DispatchResultWithPostInfo, pallet_prelude::*, traits::ConstU32, }; @@ -60,6 +60,7 @@ pub mod pallet { use pallet_staking_extension::{ JumpStartDetails, JumpStartProgress, JumpStartStatus, ServerInfo, VerifyingKey, }; + use rand::seq::SliceRandom; use scale_info::TypeInfo; use sp_std::vec; use sp_std::vec::Vec; @@ -125,11 +126,11 @@ pub mod pallet { pub struct Pallet(_); /// Used for triggering a network wide distributed key generation request via an offchain - /// worker. + /// worker. Maps block number to the selected validators for jumpstart DKG. #[pallet::storage] #[pallet::getter(fn jumpstart_dkg)] pub type JumpstartDkg = - StorageMap<_, Blake2_128Concat, BlockNumberFor, Vec>, ValueQuery>; + StorageMap<_, Blake2_128Concat, BlockNumberFor, Vec, ValueQuery>; /// An item tracking all the users registered on the Entropy network. /// @@ -189,6 +190,8 @@ pub mod pallet { NoRegisteringFromParentKey, InvalidBip32DerivationPath, Bip32AccountDerivationFailed, + NotEnoughValidatorsForJumpStart, + CannotFindValidatorInfo, } /// Allows anyone to create a parent key for the network if the network is read and a parent key @@ -218,14 +221,33 @@ pub mod pallet { _ => return Err(Error::::JumpStartProgressNotReady.into()), }; - // TODO (#923): Add checks for network state. - JumpstartDkg::::try_mutate( - current_block_number, - |messages| -> Result<_, DispatchError> { - messages.push(NETWORK_PARENT_KEY.encode()); - Ok(()) - }, - )?; + // Ensure we have at least n validators + // TODO (#923): Add other checks for network state. + let total_signers = pallet_parameters::Pallet::::signers_info().total_signers; + let validators = pallet_session::Pallet::::validators(); + ensure!( + validators.len() >= total_signers.into(), + Error::::NotEnoughValidatorsForJumpStart + ); + + // Select validators for jump start + let mut rng = pallet_staking_extension::Pallet::::get_randomness(); + let selected_validators: Vec<_> = + validators.choose_multiple(&mut rng, total_signers.into()).cloned().collect(); + + // Get validator info for each selected validator + let mut validators_info = Vec::new(); + for validator_address in selected_validators { + let server_info = + pallet_staking_extension::Pallet::::threshold_server(&validator_address) + .ok_or(Error::::CannotFindValidatorInfo)?; + validators_info.push(ValidatorInfo { + x25519_public_key: server_info.x25519_public_key, + ip_address: server_info.endpoint.clone(), + tss_account: server_info.tss_account.encode(), + }); + } + JumpstartDkg::::set(current_block_number, validators_info); JumpStartProgress::::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(converted_block_number), confirmations: vec![], @@ -246,14 +268,23 @@ pub mod pallet { origin: OriginFor, verifying_key: VerifyingKey, ) -> DispatchResultWithPostInfo { - // check is validator let ts_server_account = ensure_signed(origin)?; - let validator_stash = pallet_staking_extension::Pallet::::threshold_to_stash(&ts_server_account) .ok_or(Error::::NoThresholdKey)?; - let validators = pallet_session::Pallet::::validators(); - ensure!(validators.contains(&validator_stash), Error::::NotValidator); + + // Check that the confirmation is coming from one of the selected validators. + // In case there was more than one jumpstart attempt, get the latest one by selecting the + // entry with the highest block number. + let (_block_number, selected_validators) = JumpstartDkg::::iter() + .max_by(|(k1, _v1), (k2, _v2)| k1.cmp(k2)) + .ok_or(Error::::JumpStartNotInProgress)?; + let selected_validators: Vec<_> = + selected_validators.into_iter().map(|v| v.tss_account).collect(); + ensure!( + selected_validators.contains(&ts_server_account.encode()), + Error::::NotValidator + ); let mut jump_start_info = JumpStartProgress::::get(); match jump_start_info.verifying_key { diff --git a/pallets/registry/src/tests.rs b/pallets/registry/src/tests.rs index d4ec8f439..ccde65810 100644 --- a/pallets/registry/src/tests.rs +++ b/pallets/registry/src/tests.rs @@ -16,8 +16,7 @@ #[allow(unused)] use pallet_registry::Call as RegistryCall; -use codec::Encode; -use entropy_shared::{NETWORK_PARENT_KEY, VERIFICATION_KEY_LENGTH}; +use entropy_shared::{ValidatorInfo, VERIFICATION_KEY_LENGTH}; use frame_support::{assert_noop, assert_ok, BoundedVec}; use pallet_programs::ProgramInfo; use pallet_staking_extension::{JumpStartDetails, JumpStartProgress, JumpStartStatus, ServerInfo}; @@ -301,7 +300,24 @@ fn it_jumps_the_network() { assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1))); assert_eq!( Registry::jumpstart_dkg(0), - vec![NETWORK_PARENT_KEY.encode()], + // From the mock genesis config + vec![ + ValidatorInfo { + x25519_public_key: [0; 32], + ip_address: vec![20], + tss_account: vec![7, 0, 0, 0, 0, 0, 0, 0] + }, + ValidatorInfo { + x25519_public_key: [0; 32], + ip_address: vec![10], + tss_account: vec![3, 0, 0, 0, 0, 0, 0, 0] + }, + ValidatorInfo { + x25519_public_key: [0; 32], + ip_address: vec![11], + tss_account: vec![4, 0, 0, 0, 0, 0, 0, 0] + }, + ], "ensures a dkg message for the jump start network is prepped" ); assert_eq!( @@ -345,55 +361,55 @@ fn it_tests_jump_start_result() { Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()), Error::::NoThresholdKey ); - pallet_staking_extension::ThresholdToStash::::insert(1, 1); + pallet_staking_extension::ThresholdToStash::::insert(1, 1); pallet_staking_extension::ThresholdToStash::::insert(7, 7); - assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(7), expected_verifying_key.clone()), - Error::::NotValidator - ); - assert_noop!( Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()), Error::::JumpStartNotInProgress ); + // trigger jump start assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1))); + assert_noop!( + Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()), + Error::::NotValidator + ); assert_ok!(Registry::confirm_jump_start( - RuntimeOrigin::signed(1), + RuntimeOrigin::signed(7), expected_verifying_key.clone() )); assert_eq!( Staking::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), - confirmations: vec![1], + confirmations: vec![7], verifying_key: Some(expected_verifying_key.clone()), parent_key_threshold: 2, }, "Jump start recieves a confirmation" ); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()), + Registry::confirm_jump_start(RuntimeOrigin::signed(7), expected_verifying_key.clone()), Error::::AlreadyConfirmed ); let bad_verifying_key = BoundedVec::try_from(vec![0; VERIFICATION_KEY_LENGTH as usize]).unwrap(); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1), bad_verifying_key.clone()), + Registry::confirm_jump_start(RuntimeOrigin::signed(7), bad_verifying_key.clone()), Error::::MismatchedVerifyingKey ); - pallet_staking_extension::ThresholdToStash::::insert(2, 2); - pallet_staking_extension::ThresholdToStash::::insert(5, 5); + pallet_staking_extension::ThresholdToStash::::insert(3, 3); + pallet_staking_extension::ThresholdToStash::::insert(4, 4); assert_ok!(Registry::confirm_jump_start( - RuntimeOrigin::signed(2), + RuntimeOrigin::signed(3), expected_verifying_key.clone() )); assert_ok!(Registry::confirm_jump_start( - RuntimeOrigin::signed(5), + RuntimeOrigin::signed(4), expected_verifying_key.clone() )); assert_eq!( @@ -408,12 +424,32 @@ fn it_tests_jump_start_result() { ); assert_eq!( pallet_staking_extension::Signers::::get(), - vec![1, 2, 5], + vec![7, 3, 4], "Jumpstart sets inital signers" ); }); } +#[test] +fn it_checks_ordering_of_block_numbers_in_a_storage_map() { + new_test_ext().execute_with(|| { + let validator = ValidatorInfo { + x25519_public_key: [0; 32], + ip_address: vec![20], + tss_account: vec![0, 0, 0, 0, 0, 0, 0, 0], + }; + pallet_registry::JumpstartDkg::::set(0, vec![validator.clone()]); + pallet_registry::JumpstartDkg::::set(1, vec![validator.clone()]); + pallet_registry::JumpstartDkg::::set(2, vec![validator.clone()]); + pallet_registry::JumpstartDkg::::set(3, vec![validator.clone()]); + pallet_registry::JumpstartDkg::::set(4, vec![validator]); + let last_entry = pallet_registry::JumpstartDkg::::iter() + .max_by(|(k1, _v1), (k2, _v2)| k1.cmp(k2)) + .unwrap(); + assert_eq!(last_entry.0, 4); + }) +} + #[test] fn it_changes_a_program_instance() { new_test_ext().execute_with(|| { diff --git a/pallets/registry/src/weights.rs b/pallets/registry/src/weights.rs index a9862b35e..951575ecc 100644 --- a/pallets/registry/src/weights.rs +++ b/pallets/registry/src/weights.rs @@ -13,13 +13,13 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -//! Autogenerated weights for pallet_registry +//! Autogenerated weights for `pallet_registry` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 +//! DATE: 2024-09-16, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `hcastano`, CPU: `` -//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `turnip`, CPU: `Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // ./target/release/entropy @@ -27,19 +27,12 @@ // pallet // --chain // dev -// --wasm-execution=compiled -// --pallet -// pallet_registry -// --extrinsic -// * -// --steps -// 50 -// --repeat -// 20 -// --template -// .maintain/frame-weight-template.hbs -// --output -// pallets/registry/src/weights.rs +// --pallet=pallet_registry +// --extrinsic=* +// --steps=5 +// --repeat=2 +// --header=.maintain/AGPL-3.0-header.txt +// --output=./runtime/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -62,58 +55,74 @@ pub trait WeightInfo { /// Weights for pallet_registry using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `Registry::Dkg` (r:1 w:1) - /// Proof: `Registry::Dkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Session::Validators` (r:1 w:0) + /// Proof: `Session::Validators` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Babe::NextRandomness` (r:1 w:0) + /// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Babe::EpochStart` (r:1 w:0) + /// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `StakingExtension::ThresholdServers` (r:3 w:0) + /// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Registry::JumpstartDkg` (r:0 w:1) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) fn jump_start_network() -> Weight { // Proof Size summary in bytes: - // Measured: `80` - // Estimated: `3545` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) - .saturating_add(Weight::from_parts(0, 3545)) - .saturating_add(T::DbWeight::get().reads(2)) + // Measured: `1069` + // Estimated: `9484` + // Minimum execution time: 65_265_000 picoseconds. + Weight::from_parts(72_083_000, 0) + .saturating_add(Weight::from_parts(0, 9484)) + .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0) /// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `StakingExtension::ValidatorToSubgroup` (r:1 w:0) - /// Proof: `StakingExtension::ValidatorToSubgroup` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 2]`. + /// Storage: `Registry::JumpstartDkg` (r:2 w:0) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::Signers` (r:0 w:1) + /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 15]`. fn confirm_jump_start_done(_c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1314` - // Estimated: `4779` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(17_000_000, 0) - .saturating_add(Weight::from_parts(0, 4779)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(1)) + // Measured: `999` + // Estimated: `6939` + // Minimum execution time: 55_835_000 picoseconds. + Weight::from_parts(70_728_113, 0) + .saturating_add(Weight::from_parts(0, 6939)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0) /// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `StakingExtension::ValidatorToSubgroup` (r:1 w:0) - /// Proof: `StakingExtension::ValidatorToSubgroup` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 2]`. + /// Storage: `Registry::JumpstartDkg` (r:2 w:0) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 15]`. fn confirm_jump_start_confirm(_c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1313` - // Estimated: `4778` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(16_916_666, 0) - .saturating_add(Weight::from_parts(0, 4778)) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `701` + // Estimated: `6641` + // Minimum execution time: 52_934_000 picoseconds. + Weight::from_parts(73_613_162, 0) + .saturating_add(Weight::from_parts(0, 6641)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Programs::Programs` (r:1 w:1) /// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:0) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:0) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Registry::CounterForRegistered` (r:1 w:1) /// Proof: `Registry::CounterForRegistered` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `Registry::Registered` (r:1 w:1) @@ -121,13 +130,15 @@ impl WeightInfo for SubstrateWeight { /// Storage: `Registry::ModifiableKeys` (r:1 w:1) /// Proof: `Registry::ModifiableKeys` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `p` is `[1, 5]`. - fn register(_p: u32, ) -> Weight { + fn register(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `563` - // Estimated: `4028` - // Minimum execution time: 525_000_000 picoseconds. - Weight::from_parts(540_700_000, 0) - .saturating_add(Weight::from_parts(0, 4028)) + // Measured: `550` + // Estimated: `4015` + // Minimum execution time: 929_049_000 picoseconds. + Weight::from_parts(947_220_150, 0) + .saturating_add(Weight::from_parts(0, 4015)) + // Standard Error: 8_259_373 + .saturating_add(Weight::from_parts(6_818_350, 0).saturating_mul(p.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -137,17 +148,20 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Registry::Registered` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `n` is `[1, 5]`. /// The range of component `o` is `[1, 5]`. - fn change_program_instance(n: u32, _o: u32, ) -> Weight { + fn change_program_instance(n: u32, o: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `633` - // Estimated: `6573` - // Minimum execution time: 23_000_000 picoseconds. - Weight::from_parts(21_750_000, 0) - .saturating_add(Weight::from_parts(0, 6573)) - // Standard Error: 140_236 - .saturating_add(Weight::from_parts(1_980_952, 0).saturating_mul(n.into())) + // Measured: `537 + o * (33 ±0)` + // Estimated: `6477 + o * (33 ±0)` + // Minimum execution time: 65_712_000 picoseconds. + Weight::from_parts(50_253_750, 0) + .saturating_add(Weight::from_parts(0, 6477)) + // Standard Error: 3_573_191 + .saturating_add(Weight::from_parts(3_433_552, 0).saturating_mul(n.into())) + // Standard Error: 3_573_191 + .saturating_add(Weight::from_parts(5_104_569, 0).saturating_mul(o.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 33).saturating_mul(o.into())) } /// Storage: `Registry::Registered` (r:1 w:1) /// Proof: `Registry::Registered` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -156,11 +170,11 @@ impl WeightInfo for SubstrateWeight { /// The range of component `n` is `[1, 25]`. fn change_program_modification_account(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `328 + n * (1 ±0)` - // Estimated: `3793 + n * (1 ±0)` - // Minimum execution time: 15_000_000 picoseconds. - Weight::from_parts(16_608_333, 0) - .saturating_add(Weight::from_parts(0, 3793)) + // Measured: `251 + n * (1 ±0)` + // Estimated: `3716 + n * (1 ±0)` + // Minimum execution time: 37_528_000 picoseconds. + Weight::from_parts(48_652_091, 0) + .saturating_add(Weight::from_parts(0, 3716)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) @@ -169,58 +183,74 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `Registry::Dkg` (r:1 w:1) - /// Proof: `Registry::Dkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Session::Validators` (r:1 w:0) + /// Proof: `Session::Validators` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Babe::NextRandomness` (r:1 w:0) + /// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Babe::EpochStart` (r:1 w:0) + /// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `StakingExtension::ThresholdServers` (r:3 w:0) + /// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Registry::JumpstartDkg` (r:0 w:1) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) fn jump_start_network() -> Weight { // Proof Size summary in bytes: - // Measured: `80` - // Estimated: `3545` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(10_000_000, 0) - .saturating_add(Weight::from_parts(0, 3545)) - .saturating_add(RocksDbWeight::get().reads(2)) + // Measured: `1069` + // Estimated: `9484` + // Minimum execution time: 65_265_000 picoseconds. + Weight::from_parts(72_083_000, 0) + .saturating_add(Weight::from_parts(0, 9484)) + .saturating_add(RocksDbWeight::get().reads(8)) .saturating_add(RocksDbWeight::get().writes(2)) } /// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0) /// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `StakingExtension::ValidatorToSubgroup` (r:1 w:0) - /// Proof: `StakingExtension::ValidatorToSubgroup` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 2]`. + /// Storage: `Registry::JumpstartDkg` (r:2 w:0) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::Signers` (r:0 w:1) + /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 15]`. fn confirm_jump_start_done(_c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1314` - // Estimated: `4779` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(17_000_000, 0) - .saturating_add(Weight::from_parts(0, 4779)) - .saturating_add(RocksDbWeight::get().reads(3)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Measured: `999` + // Estimated: `6939` + // Minimum execution time: 55_835_000 picoseconds. + Weight::from_parts(70_728_113, 0) + .saturating_add(Weight::from_parts(0, 6939)) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) } /// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0) /// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `StakingExtension::ValidatorToSubgroup` (r:1 w:0) - /// Proof: `StakingExtension::ValidatorToSubgroup` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 2]`. + /// Storage: `Registry::JumpstartDkg` (r:2 w:0) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 15]`. fn confirm_jump_start_confirm(_c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1313` - // Estimated: `4778` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(16_916_666, 0) - .saturating_add(Weight::from_parts(0, 4778)) - .saturating_add(RocksDbWeight::get().reads(3)) + // Measured: `701` + // Estimated: `6641` + // Minimum execution time: 52_934_000 picoseconds. + Weight::from_parts(73_613_162, 0) + .saturating_add(Weight::from_parts(0, 6641)) + .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } /// Storage: `Programs::Programs` (r:1 w:1) /// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:0) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:0) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Registry::CounterForRegistered` (r:1 w:1) /// Proof: `Registry::CounterForRegistered` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `Registry::Registered` (r:1 w:1) @@ -228,13 +258,15 @@ impl WeightInfo for () { /// Storage: `Registry::ModifiableKeys` (r:1 w:1) /// Proof: `Registry::ModifiableKeys` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `p` is `[1, 5]`. - fn register(_p: u32, ) -> Weight { + fn register(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `563` - // Estimated: `4028` - // Minimum execution time: 525_000_000 picoseconds. - Weight::from_parts(540_700_000, 0) - .saturating_add(Weight::from_parts(0, 4028)) + // Measured: `550` + // Estimated: `4015` + // Minimum execution time: 929_049_000 picoseconds. + Weight::from_parts(947_220_150, 0) + .saturating_add(Weight::from_parts(0, 4015)) + // Standard Error: 8_259_373 + .saturating_add(Weight::from_parts(6_818_350, 0).saturating_mul(p.into())) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(4)) } @@ -244,17 +276,20 @@ impl WeightInfo for () { /// Proof: `Registry::Registered` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `n` is `[1, 5]`. /// The range of component `o` is `[1, 5]`. - fn change_program_instance(n: u32, _o: u32, ) -> Weight { + fn change_program_instance(n: u32, o: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `633` - // Estimated: `6573` - // Minimum execution time: 23_000_000 picoseconds. - Weight::from_parts(21_750_000, 0) - .saturating_add(Weight::from_parts(0, 6573)) - // Standard Error: 140_236 - .saturating_add(Weight::from_parts(1_980_952, 0).saturating_mul(n.into())) + // Measured: `537 + o * (33 ±0)` + // Estimated: `6477 + o * (33 ±0)` + // Minimum execution time: 65_712_000 picoseconds. + Weight::from_parts(50_253_750, 0) + .saturating_add(Weight::from_parts(0, 6477)) + // Standard Error: 3_573_191 + .saturating_add(Weight::from_parts(3_433_552, 0).saturating_mul(n.into())) + // Standard Error: 3_573_191 + .saturating_add(Weight::from_parts(5_104_569, 0).saturating_mul(o.into())) .saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 33).saturating_mul(o.into())) } /// Storage: `Registry::Registered` (r:1 w:1) /// Proof: `Registry::Registered` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -263,11 +298,11 @@ impl WeightInfo for () { /// The range of component `n` is `[1, 25]`. fn change_program_modification_account(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `328 + n * (1 ±0)` - // Estimated: `3793 + n * (1 ±0)` - // Minimum execution time: 15_000_000 picoseconds. - Weight::from_parts(16_608_333, 0) - .saturating_add(Weight::from_parts(0, 3793)) + // Measured: `251 + n * (1 ±0)` + // Estimated: `3716 + n * (1 ±0)` + // Minimum execution time: 37_528_000 picoseconds. + Weight::from_parts(48_652_091, 0) + .saturating_add(Weight::from_parts(0, 3716)) .saturating_add(RocksDbWeight::get().reads(2)) .saturating_add(RocksDbWeight::get().writes(2)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) diff --git a/runtime/src/weights/pallet_registry.rs b/runtime/src/weights/pallet_registry.rs index bae0793a0..8628da44d 100644 --- a/runtime/src/weights/pallet_registry.rs +++ b/runtime/src/weights/pallet_registry.rs @@ -16,9 +16,9 @@ //! Autogenerated weights for `pallet_registry` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 -//! DATE: 2024-08-02, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-09-18, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `hcastano`, CPU: `` +//! HOSTNAME: `turnip`, CPU: `Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: @@ -45,62 +45,78 @@ use core::marker::PhantomData; /// Weight functions for `pallet_registry`. pub struct WeightInfo(PhantomData); impl pallet_registry::WeightInfo for WeightInfo { - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpstartDkg` (r:1 w:1) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Session::Validators` (r:1 w:0) + /// Proof: `Session::Validators` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Babe::NextRandomness` (r:1 w:0) + /// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Babe::EpochStart` (r:1 w:0) + /// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `StakingExtension::ThresholdServers` (r:3 w:0) + /// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Registry::JumpstartDkg` (r:0 w:1) /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) fn jump_start_network() -> Weight { // Proof Size summary in bytes: - // Measured: `140` - // Estimated: `3605` - // Minimum execution time: 13_000_000 picoseconds. - Weight::from_parts(28_000_000, 0) - .saturating_add(Weight::from_parts(0, 3605)) - .saturating_add(T::DbWeight::get().reads(2)) + // Measured: `1069` + // Estimated: `9484` + // Minimum execution time: 74_099_000 picoseconds. + Weight::from_parts(95_220_000, 0) + .saturating_add(Weight::from_parts(0, 9484)) + .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0) /// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Session::Validators` (r:1 w:0) - /// Proof: `Session::Validators` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Registry::JumpstartDkg` (r:2 w:0) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `StakingExtension::Signers` (r:0 w:1) /// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 3]`. + /// The range of component `c` is `[0, 15]`. fn confirm_jump_start_done(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `793` - // Estimated: `4258` - // Minimum execution time: 18_000_000 picoseconds. - Weight::from_parts(17_600_000, 0) - .saturating_add(Weight::from_parts(0, 4258)) - // Standard Error: 916_515 - .saturating_add(Weight::from_parts(1_600_000, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `1937` + // Estimated: `7877` + // Minimum execution time: 64_195_000 picoseconds. + Weight::from_parts(87_555_019, 0) + .saturating_add(Weight::from_parts(0, 7877)) + // Standard Error: 1_609_292 + .saturating_add(Weight::from_parts(498_108, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0) /// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Session::Validators` (r:1 w:0) - /// Proof: `Session::Validators` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:1) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 3]`. - fn confirm_jump_start_confirm(_c: u32, ) -> Weight { + /// Storage: `Registry::JumpstartDkg` (r:2 w:0) + /// Proof: `Registry::JumpstartDkg` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Parameters::SignersInfo` (r:1 w:0) + /// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 15]`. + fn confirm_jump_start_confirm(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `693` - // Estimated: `4158` - // Minimum execution time: 18_000_000 picoseconds. - Weight::from_parts(19_200_000, 0) - .saturating_add(Weight::from_parts(0, 4158)) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `1639` + // Estimated: `7579` + // Minimum execution time: 61_266_000 picoseconds. + Weight::from_parts(81_265_779, 0) + .saturating_add(Weight::from_parts(0, 7579)) + // Standard Error: 1_522_011 + .saturating_add(Weight::from_parts(392_225, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Programs::Programs` (r:1 w:1) /// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Registry::JumpStartProgress` (r:1 w:0) - /// Proof: `Registry::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `StakingExtension::JumpStartProgress` (r:1 w:0) + /// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Registry::CounterForRegistered` (r:1 w:1) /// Proof: `Registry::CounterForRegistered` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `Registry::Registered` (r:1 w:1) @@ -108,13 +124,15 @@ impl pallet_registry::WeightInfo for WeightInfo { /// Storage: `Registry::ModifiableKeys` (r:1 w:1) /// Proof: `Registry::ModifiableKeys` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `p` is `[1, 5]`. - fn register(_p: u32, ) -> Weight { + fn register(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `563` - // Estimated: `4028` - // Minimum execution time: 525_000_000 picoseconds. - Weight::from_parts(540_700_000, 0) - .saturating_add(Weight::from_parts(0, 4028)) + // Measured: `551` + // Estimated: `4016` + // Minimum execution time: 955_079_000 picoseconds. + Weight::from_parts(1_247_622_550, 0) + .saturating_add(Weight::from_parts(0, 4016)) + // Standard Error: 92_666_943 + .saturating_add(Weight::from_parts(37_198_550, 0).saturating_mul(p.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -126,15 +144,15 @@ impl pallet_registry::WeightInfo for WeightInfo { /// The range of component `o` is `[1, 5]`. fn change_program_instance(n: u32, o: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `674 + o * (33 ±0)` - // Estimated: `6614 + o * (33 ±0)` - // Minimum execution time: 34_000_000 picoseconds. - Weight::from_parts(27_500_000, 0) - .saturating_add(Weight::from_parts(0, 6614)) - // Standard Error: 377_136 - .saturating_add(Weight::from_parts(2_126_190, 0).saturating_mul(n.into())) - // Standard Error: 377_136 - .saturating_add(Weight::from_parts(1_059_523, 0).saturating_mul(o.into())) + // Measured: `539 + o * (33 ±0)` + // Estimated: `6479 + o * (33 ±0)` + // Minimum execution time: 77_019_000 picoseconds. + Weight::from_parts(95_738_250, 0) + .saturating_add(Weight::from_parts(0, 6479)) + // Standard Error: 8_121_180 + .saturating_add(Weight::from_parts(2_755_195, 0).saturating_mul(n.into())) + // Standard Error: 8_121_180 + .saturating_add(Weight::from_parts(4_188_811, 0).saturating_mul(o.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 33).saturating_mul(o.into())) @@ -146,13 +164,13 @@ impl pallet_registry::WeightInfo for WeightInfo { /// The range of component `n` is `[1, 25]`. fn change_program_modification_account(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `388 + n * (1 ±0)` - // Estimated: `3853 + n * (1 ±0)` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(16_808_333, 0) - .saturating_add(Weight::from_parts(0, 3853)) - // Standard Error: 26_187 - .saturating_add(Weight::from_parts(91_666, 0).saturating_mul(n.into())) + // Measured: `251 + n * (1 ±0)` + // Estimated: `3716 + n * (1 ±0)` + // Minimum execution time: 37_583_000 picoseconds. + Weight::from_parts(42_687_133, 0) + .saturating_add(Weight::from_parts(0, 3716)) + // Standard Error: 192_389 + .saturating_add(Weight::from_parts(154_266, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into()))