Skip to content

Commit

Permalink
Add parent key threshold to chain
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 1, 2024
1 parent 704ada4 commit 33762d5
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 58 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ async fn test_jumpstart_network() {
let key_share: Option<KeyShareWithAuxInfo> =
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 =
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))?
Expand Down
2 changes: 2 additions & 0 deletions pallets/registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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',
Expand Down
43 changes: 7 additions & 36 deletions pallets/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand All @@ -93,7 +96,6 @@ pub mod pallet {
type WeightInfo: WeightInfo;
}
pub type ProgramPointers<Hash, MaxProgramHashes> = BoundedVec<Hash, MaxProgramHashes>;
pub type VerifyingKey = BoundedVec<u8, ConstU32<VERIFICATION_KEY_LENGTH>>;

#[derive(Clone, Encode, Decode, Eq, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)]
#[scale_info(skip_type_params(T))]
Expand All @@ -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<T: Config> {
pub jump_start_status: JumpStartStatus,
pub confirmations: Vec<T::ValidatorId>,
pub verifying_key: Option<VerifyingKey>,
}

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
Expand All @@ -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<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
Expand Down Expand Up @@ -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<T: Config> = StorageValue<_, JumpStartDetails<T>, ValueQuery>;

// Pallets use events to inform users when important changes are made.
// https://substrate.dev/docs/en/knowledgebase/runtime/events
#[pallet::event]
Expand Down Expand Up @@ -282,7 +251,7 @@ pub mod pallet {
let current_block_number = <frame_system::Pallet<T>>::block_number();
let converted_block_number: u32 =
BlockNumberFor::<T>::try_into(current_block_number).unwrap_or_default();

let parent_key_threhsold = pallet_parameters::Pallet::<T>::signers_info().threshold;
// make sure jumpstart is ready, or in progress but X amount of time has passed
match JumpStartProgress::<T>::get().jump_start_status {
JumpStartStatus::Ready => (),
Expand All @@ -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(())
Expand Down Expand Up @@ -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::<T>::put(jump_start_info.confirmations);
Expand Down
19 changes: 18 additions & 1 deletion pallets/registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -56,6 +57,7 @@ frame_support::construct_runtime!(
Historical: pallet_session_historical,
BagsList: pallet_bags_list,
Programs: pallet_programs,
Parameters: pallet_parameters,
}
);

Expand Down Expand Up @@ -352,6 +354,12 @@ impl pallet_programs::Config for Test {
type WeightInfo = ();
}

impl pallet_parameters::Config for Test {
type RuntimeEvent = RuntimeEvent;
type UpdateOrigin = EnsureRoot<Self::AccountId>;
type WeightInfo = ();
}

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
Expand All @@ -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::<Test> { keys }.assimilate_storage(&mut t).unwrap();
pallet_parameters::GenesisConfig::<Test> {
request_limit: 5u32,
max_instructions_per_programs: 5u64,
total_signers: 5u8,
threshold: 2u8,
_config: Default::default(),
}
.assimilate_storage(&mut t)
.unwrap();

t.into()
}
31 changes: 18 additions & 13 deletions pallets/registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ 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},
};

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];
Expand Down Expand Up @@ -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"
);
Expand All @@ -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"
);
Expand All @@ -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"
);
Expand Down Expand Up @@ -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"
);
Expand All @@ -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"
);
Expand Down
2 changes: 2 additions & 0 deletions pallets/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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',
Expand Down
Loading

0 comments on commit 33762d5

Please sign in to comment.