diff --git a/Cargo.lock b/Cargo.lock index 4c1752039..ed9f2fc65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7177,6 +7177,7 @@ dependencies = [ "pallet-authorship", "pallet-bags-list", "pallet-balances", + "pallet-parameters", "pallet-programs", "pallet-session", "pallet-staking", @@ -7315,6 +7316,7 @@ dependencies = [ "log", "pallet-bags-list", "pallet-balances", + "pallet-parameters", "pallet-session", "pallet-staking", "pallet-staking-reward-curve", diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index 3862a3625..32d54760e 100644 Binary files a/crates/client/entropy_metadata.scale and b/crates/client/entropy_metadata.scale differ diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 0e4ad7fe4..2f30a0cdc 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -803,7 +803,7 @@ async fn test_jumpstart_network() { let key_share: Option = entropy_kvdb::kv_manager::helpers::deserialize(&response_key); assert_eq!(key_share.is_some(), true); - let jump_start_progress_query = entropy::storage().registry().jump_start_progress(); + let jump_start_progress_query = entropy::storage().staking_extension().jump_start_progress(); let jump_start_progress = query_chain(&api, &rpc, jump_start_progress_query, None).await.unwrap().unwrap(); let verifying_key = diff --git a/crates/threshold-signature-server/src/validator/api.rs b/crates/threshold-signature-server/src/validator/api.rs index c6a220ea1..338cc85e0 100644 --- a/crates/threshold-signature-server/src/validator/api.rs +++ b/crates/threshold-signature-server/src/validator/api.rs @@ -83,7 +83,7 @@ pub async fn new_reshare( .await .map_err(|e| ValidatorErr::UserError(e.to_string()))?; - let verifying_key_query = entropy::storage().registry().jump_start_progress(); + let verifying_key_query = entropy::storage().staking_extension().jump_start_progress(); let verifying_key = query_chain(&api, &rpc, verifying_key_query, None) .await? .ok_or_else(|| ValidatorErr::ChainFetch("Parent verifying key error"))? diff --git a/pallets/registry/Cargo.toml b/pallets/registry/Cargo.toml index 0494173d0..f942b0586 100644 --- a/pallets/registry/Cargo.toml +++ b/pallets/registry/Cargo.toml @@ -31,6 +31,7 @@ entropy-shared={ version="0.2.0", path="../../crates/shared", features=[ ], default-features=false } pallet-programs={ version="0.2.0", path="../programs", default-features=false } pallet-staking-extension={ version="0.2.0", path="../staking", default-features=false } +pallet-parameters={ version="0.2.0", path="../parameters", default-features=false } [dev-dependencies] frame-election-provider-support={ version="29.0.0", default-features=false } @@ -54,6 +55,7 @@ std=[ 'frame-system/std', 'log/std', 'pallet-balances/std', + 'pallet-parameters/std', 'pallet-programs/std', 'pallet-staking-extension/std', 'scale-info/std', diff --git a/pallets/registry/src/lib.rs b/pallets/registry/src/lib.rs index 95a325328..c541c3a44 100644 --- a/pallets/registry/src/lib.rs +++ b/pallets/registry/src/lib.rs @@ -60,7 +60,9 @@ pub mod pallet { traits::{ConstU32, IsSubType}, }; use frame_system::pallet_prelude::*; - use pallet_staking_extension::ServerInfo; + use pallet_staking_extension::{ + JumpStartDetails, JumpStartProgress, JumpStartStatus, ServerInfo, VerifyingKey, + }; use scale_info::TypeInfo; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use sp_std::vec; @@ -82,6 +84,7 @@ pub mod pallet { + pallet_authorship::Config + pallet_staking_extension::Config + pallet_programs::Config + + pallet_parameters::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -93,7 +96,6 @@ pub mod pallet { type WeightInfo: WeightInfo; } pub type ProgramPointers = BoundedVec; - pub type VerifyingKey = BoundedVec>; #[derive(Clone, Encode, Decode, Eq, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)] #[scale_info(skip_type_params(T))] @@ -119,23 +121,6 @@ pub mod pallet { pub program_modification_account: T::AccountId, pub version_number: u8, } - /// Details of status of jump starting the network - #[derive( - Clone, - Encode, - Decode, - Eq, - PartialEqNoBound, - RuntimeDebug, - TypeInfo, - frame_support::DefaultNoBound, - )] - #[scale_info(skip_type_params(T))] - pub struct JumpStartDetails { - pub jump_start_status: JumpStartStatus, - pub confirmations: Vec, - pub verifying_key: Option, - } #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] @@ -144,17 +129,6 @@ pub mod pallet { pub registered_accounts: Vec<(T::AccountId, VerifyingKey)>, } - #[derive( - Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen, Default, - )] - pub enum JumpStartStatus { - #[default] - Ready, - // u32 is block number process was started, after X blocks we assume failed and retry - InProgress(u32), - Done, - } - #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { @@ -211,11 +185,6 @@ pub mod pallet { ValueQuery, >; - /// A concept of what progress status the jumpstart is - #[pallet::storage] - #[pallet::getter(fn jump_start_progress)] - pub type JumpStartProgress = StorageValue<_, JumpStartDetails, ValueQuery>; - // Pallets use events to inform users when important changes are made. // https://substrate.dev/docs/en/knowledgebase/runtime/events #[pallet::event] @@ -282,7 +251,7 @@ pub mod pallet { let current_block_number = >::block_number(); let converted_block_number: u32 = BlockNumberFor::::try_into(current_block_number).unwrap_or_default(); - + let parent_key_threhsold = pallet_parameters::Pallet::::signers_info().threshold; // make sure jumpstart is ready, or in progress but X amount of time has passed match JumpStartProgress::::get().jump_start_status { JumpStartStatus::Ready => (), @@ -308,6 +277,7 @@ pub mod pallet { jump_start_status: JumpStartStatus::InProgress(converted_block_number), confirmations: vec![], verifying_key: None, + parent_key_threhsold, }); Self::deposit_event(Event::StartedNetworkJumpStart()); Ok(()) @@ -366,6 +336,7 @@ pub mod pallet { jump_start_status: JumpStartStatus::Done, confirmations: vec![], verifying_key: jump_start_info.verifying_key, + parent_key_threhsold: jump_start_info.parent_key_threhsold, }); // Jumpstart participants become first network signers pallet_staking_extension::Signers::::put(jump_start_info.confirmations); diff --git a/pallets/registry/src/mock.rs b/pallets/registry/src/mock.rs index e5e5825a2..ae17f6fdd 100644 --- a/pallets/registry/src/mock.rs +++ b/pallets/registry/src/mock.rs @@ -21,7 +21,8 @@ use frame_support::{ derive_impl, parameter_types, traits::{ConstU32, FindAuthor, OneSessionHandler, Randomness}, }; -use frame_system as system; +use frame_system::{self as system, EnsureRoot}; + use pallet_session::historical as pallet_session_historical; use sp_core::H256; use sp_runtime::{ @@ -56,6 +57,7 @@ frame_support::construct_runtime!( Historical: pallet_session_historical, BagsList: pallet_bags_list, Programs: pallet_programs, + Parameters: pallet_parameters, } ); @@ -352,6 +354,12 @@ impl pallet_programs::Config for Test { type WeightInfo = (); } +impl pallet_parameters::Config for Test { + type RuntimeEvent = RuntimeEvent; + type UpdateOrigin = EnsureRoot; + type WeightInfo = (); +} + // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); @@ -374,6 +382,15 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let keys: Vec<_> = stakers.iter().cloned().map(|i| (i, i, UintAuthorityId(i).into())).collect(); pallet_session::GenesisConfig:: { keys }.assimilate_storage(&mut t).unwrap(); + pallet_parameters::GenesisConfig:: { + request_limit: 5u32, + max_instructions_per_programs: 5u64, + total_signers: 5u8, + threshold: 2u8, + _config: Default::default(), + } + .assimilate_storage(&mut t) + .unwrap(); t.into() } diff --git a/pallets/registry/src/tests.rs b/pallets/registry/src/tests.rs index d6b3136ad..bf785a5a6 100644 --- a/pallets/registry/src/tests.rs +++ b/pallets/registry/src/tests.rs @@ -23,7 +23,7 @@ use frame_support::{ }; use pallet_programs::ProgramInfo; use pallet_registry::Call as RegistryCall; -use pallet_staking_extension::ServerInfo; +use pallet_staking_extension::{JumpStartDetails, JumpStartStatus, ServerInfo}; use sp_runtime::{ traits::{Hash, SignedExtension}, transaction_validity::{TransactionValidity, ValidTransaction}, @@ -31,8 +31,8 @@ use sp_runtime::{ use crate as pallet_registry; use crate::{ - mock::*, Error, JumpStartDetails, JumpStartStatus, ModifiableKeys, ProgramInstance, Registered, - RegisteredInfo, RegisteringDetails, ValidateConfirmRegistered, + mock::*, Error, ModifiableKeys, ProgramInstance, Registered, RegisteredInfo, + RegisteringDetails, ValidateConfirmRegistered, }; const NULL_ARR: [u8; 32] = [0; 32]; @@ -92,11 +92,12 @@ fn it_registers_a_user() { fn it_jumps_the_network() { new_test_ext().execute_with(|| { assert_eq!( - Registry::jump_start_progress(), + Staking::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::Ready, confirmations: vec![], - verifying_key: None + verifying_key: None, + parent_key_threhsold: 0 }, "Checks default status of jump start detail" ); @@ -107,11 +108,12 @@ fn it_jumps_the_network() { "ensures a dkg message for the jump start network is prepped" ); assert_eq!( - Registry::jump_start_progress(), + Staking::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![], - verifying_key: None + verifying_key: None, + parent_key_threhsold: 2 }, "Checks that jump start is in progress" ); @@ -125,11 +127,12 @@ fn it_jumps_the_network() { assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1))); assert_eq!( - Registry::jump_start_progress(), + Staking::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(100), confirmations: vec![], - verifying_key: None + verifying_key: None, + parent_key_threhsold: 2 }, "ensures jump start is called again if too many blocks passed" ); @@ -165,11 +168,12 @@ fn it_tests_jump_start_result() { expected_verifying_key.clone() )); assert_eq!( - Registry::jump_start_progress(), + Staking::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![1], - verifying_key: Some(expected_verifying_key.clone()) + verifying_key: Some(expected_verifying_key.clone()), + parent_key_threhsold: 2 }, "Jump start recieves a confirmation" ); @@ -196,11 +200,12 @@ fn it_tests_jump_start_result() { expected_verifying_key.clone() )); assert_eq!( - Registry::jump_start_progress(), + Staking::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::Done, confirmations: vec![], - verifying_key: Some(expected_verifying_key) + verifying_key: Some(expected_verifying_key), + parent_key_threhsold: 2 }, "Jump start in done status after all confirmations" ); diff --git a/pallets/staking/Cargo.toml b/pallets/staking/Cargo.toml index 46a3e1295..e142bfe25 100644 --- a/pallets/staking/Cargo.toml +++ b/pallets/staking/Cargo.toml @@ -29,6 +29,7 @@ sp-staking ={ version="27.0.0", default-features=false } sp-std ={ version="14.0.0", default-features=false } sp-consensus-babe ={ version="0.33.0", default-features=false } +pallet-parameters={ version="0.2.0", path="../parameters", default-features=false } entropy-shared={ version="0.2.0", path="../../crates/shared", features=[ "wasm-no-std", ], default-features=false } @@ -55,6 +56,7 @@ std=[ 'frame-system/std', 'log/std', 'pallet-balances/std', + 'pallet-parameters/std', 'pallet-session/std', 'pallet-staking/std', 'scale-info/std', diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index 43dbd78c4..d0fd71aae 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -59,6 +59,7 @@ use sp_staking::SessionIndex; pub mod pallet { use entropy_shared::{ ValidatorInfo, X25519PublicKey, TEST_RESHARE_BLOCK_NUMBER, TOTAL_SIGNERS, + VERIFICATION_KEY_LENGTH, }; use frame_support::{ dispatch::{DispatchResult, DispatchResultWithPostInfo}, @@ -78,9 +79,14 @@ pub mod pallet { use super::*; + pub type VerifyingKey = BoundedVec>; + #[pallet::config] pub trait Config: - pallet_session::Config + frame_system::Config + pallet_staking::Config + pallet_session::Config + + frame_system::Config + + pallet_staking::Config + + pallet_parameters::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Something that provides randomness in the runtime. @@ -169,6 +175,36 @@ pub mod pallet { ValueQuery, >; + #[derive( + Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen, Default, + )] + pub enum JumpStartStatus { + #[default] + Ready, + // u32 is block number process was started, after X blocks we assume failed and retry + InProgress(u32), + Done, + } + + /// Details of status of jump starting the network + #[derive( + Clone, + Encode, + Decode, + Eq, + PartialEqNoBound, + RuntimeDebug, + TypeInfo, + frame_support::DefaultNoBound, + )] + #[scale_info(skip_type_params(T))] + pub struct JumpStartDetails { + pub jump_start_status: JumpStartStatus, + pub confirmations: Vec, + pub verifying_key: Option, + pub parent_key_threhsold: u8, + } + /// A trigger for the proactive refresh OCW #[pallet::storage] #[pallet::getter(fn proactive_refresh)] @@ -189,6 +225,11 @@ pub mod pallet { #[pallet::getter(fn reshare_data)] pub type ReshareData = StorageValue<_, ReshareInfo>, ValueQuery>; + /// A concept of what progress status the jumpstart is + #[pallet::storage] + #[pallet::getter(fn jump_start_progress)] + pub type JumpStartProgress = StorageValue<_, JumpStartDetails, ValueQuery>; + /// A type used to simplify the genesis configuration definition. pub type ThresholdServersConfig = ( ::ValidatorId, @@ -527,10 +568,10 @@ pub mod pallet { new_signer: next_signer_up.encode(), }; ReshareData::::put(reshare_info); - - // for next PR - // confirm action has taken place - + JumpStartProgress::::mutate(|jump_start_details| { + jump_start_details.parent_key_threhsold = + pallet_parameters::Pallet::::signers_info().threshold; + }); Ok(()) } } diff --git a/pallets/staking/src/mock.rs b/pallets/staking/src/mock.rs index 56f6646f2..4031a2ce6 100644 --- a/pallets/staking/src/mock.rs +++ b/pallets/staking/src/mock.rs @@ -24,7 +24,7 @@ use frame_support::{ derive_impl, parameter_types, traits::{ConstU32, Get, Hooks, OneSessionHandler, Randomness}, }; -use frame_system as system; +use frame_system::{self as system, EnsureRoot}; use pallet_session::{historical as pallet_session_historical, ShouldEndSession}; use sp_core::H256; use sp_runtime::{ @@ -58,6 +58,7 @@ frame_support::construct_runtime!( Session: pallet_session, Historical: pallet_session_historical, BagsList: pallet_bags_list, + Parameters: pallet_parameters, } ); @@ -385,6 +386,12 @@ impl pallet_staking_extension::Config for Test { type WeightInfo = (); } +impl pallet_parameters::Config for Test { + type RuntimeEvent = RuntimeEvent; + type UpdateOrigin = EnsureRoot; + type WeightInfo = (); +} + // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); @@ -399,6 +406,15 @@ pub fn new_test_ext() -> sp_io::TestExternalities { }; pallet_balances.assimilate_storage(&mut t).unwrap(); pallet_staking_extension.assimilate_storage(&mut t).unwrap(); + pallet_parameters::GenesisConfig:: { + request_limit: 5u32, + max_instructions_per_programs: 5u64, + total_signers: 5u8, + threshold: 2u8, + _config: Default::default(), + } + .assimilate_storage(&mut t) + .unwrap(); t.into() } diff --git a/pallets/staking/src/tests.rs b/pallets/staking/src/tests.rs index d492b0283..e9d394ed2 100644 --- a/pallets/staking/src/tests.rs +++ b/pallets/staking/src/tests.rs @@ -336,6 +336,12 @@ fn it_tests_new_session_handler() { // no next signers at start assert_eq!(Staking::next_signers(), None); assert_eq!(Staking::reshare_data().block_number, 0, "Check reshare block start at zero"); + assert_eq!( + Staking::jump_start_progress().parent_key_threhsold, + 0, + "parent key threhsold start at zero" + ); + System::set_block_number(100); assert_ok!(Staking::new_session_handler(&[1, 2, 3])); @@ -352,6 +358,11 @@ fn it_tests_new_session_handler() { 1u64.encode(), "Check reshare next signer up is 1" ); + assert_eq!( + Staking::jump_start_progress().parent_key_threhsold, + 2, + "parent key threhsold updated" + ); assert_eq!( Staking::reshare_data().block_number,