From 33762d53e3cf593f2ebace1425b604b4d42e77b7 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 1 Aug 2024 16:15:13 -0400 Subject: [PATCH] Add parent key threshold to chain --- Cargo.lock | 2 + crates/client/entropy_metadata.scale | Bin 206255 -> 206302 bytes .../src/user/tests.rs | 2 +- .../src/validator/api.rs | 2 +- pallets/registry/Cargo.toml | 2 + pallets/registry/src/lib.rs | 43 +++------------ pallets/registry/src/mock.rs | 19 ++++++- pallets/registry/src/tests.rs | 31 ++++++----- pallets/staking/Cargo.toml | 2 + pallets/staking/src/lib.rs | 51 ++++++++++++++++-- pallets/staking/src/mock.rs | 18 ++++++- pallets/staking/src/tests.rs | 11 ++++ 12 files changed, 125 insertions(+), 58 deletions(-) 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 3862a3625f3521632100ca17e71dd31f6bb85a83..32d54760e269953ef63543a81e90697deef06e41 100644 GIT binary patch delta 3291 zcmZuz3s9A18vdU5{G9(+ArAs}Ktag$f@y-6l2z8w)Vz>T=!`QVo%E<@BkeQ(eE ze$V%vct7;h_d~b5f^qBF*^Qw?U3lP^C3$Oeii$mj#n!*Lq^QElle#gFs+?SQ4eq#% zwVpz6esRtd-qM`nHHF?aMFqJl4HzZUl&Wz0Kf02@wcVI*?Qgh-(G&>IZPPpVAD~>`--fuiiOD)$_CsxSLKn{h8P9G(~11sKMz^zLGS#(WyNm0;<^w z_fqeQ8Ckzjs?ib*b+tK^Op8_-x7fN`oo>}?%kgP1hM4^5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%mbUhUX}s3sh~{<8l7G$omuC82l5Nj1nt)dG;xSr5awRfbXsEQs z^({0}8sWPwG~Si1Ul)Fb>zcf+lq6&L2^u7^=srR6Iy*u2(mZ6|rAdOGKSe_wBaG3e zcA5etNNqhs%LFOytY}H&)Uy(qvF6ifDMtV^FSS!2N9Px# 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,