From 85a798b811635d683fde7772a41d973c94884156 Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:45:00 -0400 Subject: [PATCH] Add parent key threshold dynamically (#974) * Add parent key threshold to chain * fix benches * changelog * fix * Update pallets/staking/src/lib.rs Co-authored-by: peg * fix * fix lint --------- Co-authored-by: peg --- CHANGELOG.md | 1 + Cargo.lock | 3 ++ crates/client/entropy_metadata.scale | Bin 206255 -> 206302 bytes .../src/user/tests.rs | 2 +- .../src/validator/api.rs | 2 +- deny.toml | 6 +-- pallets/propagation/Cargo.toml | 1 + pallets/propagation/src/mock.rs | 9 +++- pallets/registry/Cargo.toml | 2 + pallets/registry/src/benchmarking.rs | 10 ++-- 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 ++++ 17 files changed, 143 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d27efe12..eba38865d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ At the moment this project **does not** adhere to - Split jumpstart and register flows ([#952](https://github.com/entropyxyz/entropy-core/pull/952)) - Reshare confirmation ([#965](https://github.com/entropyxyz/entropy-core/pull/965)) - Set inital signers ([#971](https://github.com/entropyxyz/entropy-core/pull/971)) +- Add parent key threshold dynamically ([#974](https://github.com/entropyxyz/entropy-core/pull/974)) ## [0.2.0](https://github.com/entropyxyz/entropy-core/compare/release/v0.1.0...release/v0.2.0) - 2024-07-11 diff --git a/Cargo.lock b/Cargo.lock index 3b74ab27e..933418350 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7113,6 +7113,7 @@ dependencies = [ "pallet-babe", "pallet-bags-list", "pallet-balances", + "pallet-parameters", "pallet-programs", "pallet-registry", "pallet-session", @@ -7177,6 +7178,7 @@ dependencies = [ "pallet-authorship", "pallet-bags-list", "pallet-balances", + "pallet-parameters", "pallet-programs", "pallet-session", "pallet-staking", @@ -7315,6 +7317,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..ca660edb961a4b8c8b60feab477c09402654f724 100644 GIT binary patch delta 3291 zcmZuz4Nz5O8vdU59_~3Rw@iA6-h|x?W7T_BUR^XbJ@9Hf+Ekp1K}i z#@0HOqB^INPicl~b*Or~*WjF@8hF|U+)XE){>&?Pnj*6h)adjlUrL(X?9?6+0oCe+ zd#QKDjI3WM)ocldx;h+6rbVla+iYF!PPb~e<+#an{Yomxos1C(%4gr zHsfGqw-eK{Jh{20GiG^mJ^3rVqPsh|K5PpX-~xNLAO}6%yaf;8D!aB~1g>$?R&4vP z(Z~=e)nnToeYwxy-hTdGww-fbQoWY9GP-IRSthDPznkCOhFOuk;DbHX<2tT+B^Z3&psG|Y8Kl5+VX6-K25QXU$RDAJkL{NCYg+YS>BZm@n|Lz-inYnuquhFQW9viwu?)VLkVFGX2hYBR~ofTM# zsl1^A_tI2rUnJk3g`e@&3Jj$b-GBeXQDzL|3qoqeew0yKP}ghw5rH}U;eLFB`TY6; z#7OhW0c0ValMZ4cGWoHC7>6b1a|f~4fn^+9jXcV}Z6PiZ!3yx`w=2M71(pcq)%`mk z9nL>gV+;9i%fz-hf--siWb!PTHiufrT{S2iQ6fXlNXHaaYWI>{YNOrRs_)g+R$g~V zQnUFb%)xeUeF+7$-HvEXnI2SK-cNOzE$HghRJrs>hI_gEWsC{kXD_%bbyXR}!@`!T z?0#xZpQhS=nqwT9mTZ4jXGlH7W%yTD~ptB)447hZu754F;Am*TRQfd7DT6` zUrZgAlh-uW$y@6s)!pXNdWHe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UglXLGIKD)NdG)wd1e$5ndgk<4I6QVtq!MBLG6gay)G^c?sYkvf{psEbI`98JMZ&bx$7 z(qH>_Nl4+(=GBEXlqU^j! z3cdM-Q+$P9e^!B1M5V$wtymger@?cJk!}h9Q!xgT>I`cBz8Djv30qc}NnfG-7Abgd zhSN@Hl}_y7@Mol+m-M4}sejx0Q4+fOxD48LCw>gHIwLv9MI$-IMKM~4{>#<`&8=fs zpyFyYzvq%J6VKne=wXcJ)Cjsm(mpSOMoEvVvW9tlEP|3z%Rfd?5;f|99Yz#S>Q6BO zKxTj0k~)P@H}C3Cu>c?GPot%+er*k7IWAHN<;Z0IvmYc#N(>lcW_3!>=BEX0{-)=;@-pwWR36e`Wbr8EGjGEY87 zCm_9``gxim{(tv8t&)nryo~0e(fpu{iXid3ZzGjDTAl5@+)a0zKW?NFpv!!woOIx_ z`RohymT_yh)2-qr=N9EG@{78jiRacC`MG(y1>URzs4GtPF_p-B#QcJ33* z*Oaz0VFstZNFM(742AI0z4U|x;N)H^m(urG9c3WRe7%m&0%`o*KEY_J*}0FrkZ@0| zr^!;~*45Kfgqh|Ke-&dT?yduL=S`WG=szY*_pK=4LAz-XFFQatN$8$BKo3d*d-nhp z!q4MP+JJ0+*QC=}ZdM+oN}!C#9HQf>*m9V@Lbds?!{pQ@jlO%EhD)?!-=X=A{d$AB z@*R371dW{9Og9@%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/deny.toml b/deny.toml index 277786485..fbec41912 100644 --- a/deny.toml +++ b/deny.toml @@ -1,7 +1,6 @@ [licenses] # The lint level for crates which do not have a detectable license -unlicensed="deny" - +version=2 # List of explicitly allowed licenses # See https://spdx.org/licenses/ for list of possible licenses # [possible values: any SPDX 3.11 short identifier (+ optional exception)]. @@ -18,9 +17,6 @@ allow=[ "MPL-2.0", ] -# Lint level for licenses considered copyleft -copyleft="deny" - # If true, ignores workspace crates that aren't published, or are only # published to private registries. # To see how to mark a crate as unpublished (to the official registry), diff --git a/pallets/propagation/Cargo.toml b/pallets/propagation/Cargo.toml index d086c5323..f9e688e23 100644 --- a/pallets/propagation/Cargo.toml +++ b/pallets/propagation/Cargo.toml @@ -46,6 +46,7 @@ pallet-staking-reward-curve ={ version="11.0.0" } pallet-timestamp ={ version="28.0.0", default-features=false } sp-keystore ={ version="0.35.0" } sp-npos-elections ={ version="27.0.0", default-features=false } +pallet-parameters ={ version="0.2.0", path="../parameters", default-features=false } [features] default=['std'] diff --git a/pallets/propagation/src/mock.rs b/pallets/propagation/src/mock.rs index f71fa18f4..0c02d2f76 100644 --- a/pallets/propagation/src/mock.rs +++ b/pallets/propagation/src/mock.rs @@ -21,7 +21,7 @@ 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::{ @@ -58,6 +58,7 @@ frame_support::construct_runtime!( Session: pallet_session, Historical: pallet_session_historical, BagsList: pallet_bags_list, + Parameters: pallet_parameters, } ); @@ -360,6 +361,12 @@ impl pallet_propagation::Config for Test { type RuntimeEvent = RuntimeEvent; } +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(); 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/benchmarking.rs b/pallets/registry/src/benchmarking.rs index 625c62477..cce775989 100644 --- a/pallets/registry/src/benchmarking.rs +++ b/pallets/registry/src/benchmarking.rs @@ -24,8 +24,8 @@ use frame_system::{EventRecord, RawOrigin}; use pallet_programs::{ProgramInfo, Programs}; use pallet_session::Validators; use pallet_staking_extension::{ - benchmarking::create_validators, IsValidatorSynced, ServerInfo, ThresholdServers, - ThresholdToStash, + benchmarking::create_validators, IsValidatorSynced, JumpStartDetails, JumpStartProgress, + JumpStartStatus, ServerInfo, ThresholdServers, ThresholdToStash, }; use sp_runtime::traits::Hash; use sp_std::{vec, vec::Vec}; @@ -99,7 +99,8 @@ benchmarks! { >::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![validators[0].clone(), validators[0].clone()], - verifying_key: None + verifying_key: None, + parent_key_threshold: 2 }); @@ -126,7 +127,8 @@ benchmarks! { >::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), confirmations: vec![], - verifying_key: None + verifying_key: None, + parent_key_threshold: 2 }); diff --git a/pallets/registry/src/lib.rs b/pallets/registry/src/lib.rs index 95a325328..6ffbcb780 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_threshold = 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_threshold, }); 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_threshold: jump_start_info.parent_key_threshold, }); // 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..f9944f08e 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_threshold: 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_threshold: 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_threshold: 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_threshold: 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_threshold: 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..5cd291e01 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_threshold: 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_threshold = + 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..3b255dde1 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_threshold, + 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_threshold, + 2, + "parent key threhsold updated" + ); assert_eq!( Staking::reshare_data().block_number,