Skip to content

Commit

Permalink
Add parent key threshold dynamically (#974)
Browse files Browse the repository at this point in the history
* Add parent key threshold to chain

* fix benches

* changelog

* fix

* Update pallets/staking/src/lib.rs

Co-authored-by: peg <[email protected]>

* fix

* fix lint

---------

Co-authored-by: peg <[email protected]>
  • Loading branch information
JesseAbram and ameba23 authored Aug 2, 2024
1 parent 4306148 commit 85a798b
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 68 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 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
6 changes: 1 addition & 5 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -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)].
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions pallets/propagation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
9 changes: 8 additions & 1 deletion pallets/propagation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -58,6 +58,7 @@ frame_support::construct_runtime!(
Session: pallet_session,
Historical: pallet_session_historical,
BagsList: pallet_bags_list,
Parameters: pallet_parameters,
}
);

Expand Down Expand Up @@ -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<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 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
10 changes: 6 additions & 4 deletions pallets/registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -99,7 +99,8 @@ benchmarks! {
<JumpStartProgress<T>>::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
});


Expand All @@ -126,7 +127,8 @@ benchmarks! {
<JumpStartProgress<T>>::put(JumpStartDetails {
jump_start_status: JumpStartStatus::InProgress(0),
confirmations: vec![],
verifying_key: None
verifying_key: None,
parent_key_threshold: 2
});


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_threshold = 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_threshold,
});
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_threshold: jump_start_info.parent_key_threshold,
});
// 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()
}
Loading

0 comments on commit 85a798b

Please sign in to comment.