Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block tss chain when signer #1078

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ At the moment this project **does not** adhere to
- Select validators for jumpstart DKG [#1053](https://github.com/entropyxyz/entropy-core/pull/1053))
- Add a programs version ([#1045](https://github.com/entropyxyz/entropy-core/pull/1045))
- Handle Provisioning Certification Keys (PCKs) ([#1051](https://github.com/entropyxyz/entropy-core/pull/1051))
- Block tss chain when signer ([#1078](https://github.com/entropyxyz/entropy-core/pull/1078))

### Changed
- Fix TSS `AccountId` keys in chainspec ([#993](https://github.com/entropyxyz/entropy-core/pull/993))
Expand Down
5 changes: 4 additions & 1 deletion pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,17 @@ benchmarks! {
}

change_threshold_accounts {
let s in 0 .. MAX_SIGNERS as u32;
let caller: T::AccountId = whitelisted_caller();
let _bonder: T::AccountId = account("bond", 0, SEED);
let validator_id_res = <T as pallet_session::Config>::ValidatorId::try_from(_bonder.clone()).or(Err(Error::<T>::InvalidValidatorId));
let validator_id_signers = <T as pallet_session::Config>::ValidatorId::try_from(caller.clone()).or(Err(Error::<T>::InvalidValidatorId)).unwrap();
let bonder: T::ValidatorId = validator_id_res.expect("Issue converting account id into validator id");
let threshold: T::AccountId = account("threshold", 0, SEED);
let x25519_public_key: [u8; 32] = NULL_ARR;
prep_bond_and_validate::<T>(true, caller.clone(), _bonder.clone(), threshold, NULL_ARR);

let signers = vec![validator_id_signers.clone(); s as usize];
Signers::<T>::put(signers.clone());

}: _(RawOrigin::Signed(_bonder.clone()), _bonder.clone(), NULL_ARR)
verify {
Expand Down
14 changes: 11 additions & 3 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub mod pallet {
NoUnbondingWhenNextSigner,
NoUnnominatingWhenSigner,
NoUnnominatingWhenNextSigner,
NoChangingThresholdAccountWhenSigner,
}

#[pallet::event]
Expand Down Expand Up @@ -373,12 +374,12 @@ pub mod pallet {
/// Allows a validator to change their threshold key so can confirm done when coms manager
/// `new_account`: nodes's threshold account
#[pallet::call_index(1)]
#[pallet::weight(<T as Config>::WeightInfo::change_threshold_accounts())]
#[pallet::weight(<T as Config>::WeightInfo::change_threshold_accounts(MAX_SIGNERS as u32))]
pub fn change_threshold_accounts(
origin: OriginFor<T>,
tss_account: T::AccountId,
x25519_public_key: X25519PublicKey,
) -> DispatchResult {
) -> DispatchResultWithPostInfo {
ensure!(
!ThresholdToStash::<T>::contains_key(&tss_account),
Error::<T>::TssAccountAlreadyExists
Expand All @@ -389,6 +390,12 @@ pub mod pallet {
let validator_id = <T as pallet_session::Config>::ValidatorId::try_from(stash)
.or(Err(Error::<T>::InvalidValidatorId))?;

let signers = Self::signers();
ensure!(
!signers.contains(&validator_id),
Error::<T>::NoChangingThresholdAccountWhenSigner
);

let new_server_info: ServerInfo<T::AccountId> =
ThresholdServers::<T>::try_mutate(&validator_id, |maybe_server_info| {
if let Some(server_info) = maybe_server_info {
Expand All @@ -401,7 +408,8 @@ pub mod pallet {
}
})?;
Self::deposit_event(Event::ThresholdAccountChanged(validator_id, new_server_info));
Ok(())
Ok(Some(<T as Config>::WeightInfo::change_threshold_accounts(signers.len() as u32))
.into())
}

/// Wraps's Substrate's `unbond` extrinsic but checks to make sure targeted account is not a signer or next signer
Expand Down
6 changes: 6 additions & 0 deletions pallets/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ fn it_changes_threshold_account() {
Staking::change_threshold_accounts(RuntimeOrigin::signed(1), 5, NULL_ARR),
Error::<Test>::TssAccountAlreadyExists
);

Signers::<Test>::put(vec![1]);
assert_noop!(
Staking::change_threshold_accounts(RuntimeOrigin::signed(1), 9, NULL_ARR,),
Error::<Test>::NoChangingThresholdAccountWhenSigner
);
});
}

Expand Down
52 changes: 33 additions & 19 deletions pallets/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use core::marker::PhantomData;
/// Weight functions needed for pallet_staking_extension.
pub trait WeightInfo {
fn change_endpoint() -> Weight;
fn change_threshold_accounts() -> Weight;
fn change_threshold_accounts(s: u32) -> Weight;
fn chill(c: u32, n: u32) -> Weight;
fn unbond(c: u32, n: u32) -> Weight;
fn withdraw_unbonded(c: u32, n: u32) -> Weight;
Expand Down Expand Up @@ -81,20 +81,27 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:1)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::Ledger` (r:1 w:0)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:1 w:0)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::ThresholdServers` (r:1 w:1)
/// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::ThresholdToStash` (r:0 w:1)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn change_threshold_accounts() -> Weight {
/// The range of component `s` is `[0, 15]`.
fn change_threshold_accounts(s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1118`
// Estimated: `4583`
// Minimum execution time: 23_000_000 picoseconds.
Weight::from_parts(24_000_000, 4583)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
// Measured: `1455 + s * (32 ±0)`
// Estimated: `4918 + s * (32 ±0)`
// Minimum execution time: 27_000_000 picoseconds.
Weight::from_parts(31_058_011, 0)
.saturating_add(Weight::from_parts(0, 4918))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(s.into()))
}
/// Storage: `Staking::Ledger` (r:1 w:1)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
Expand Down Expand Up @@ -349,20 +356,27 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:1)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::Ledger` (r:1 w:0)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:1 w:0)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::ThresholdServers` (r:1 w:1)
/// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::ThresholdToStash` (r:0 w:1)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn change_threshold_accounts() -> Weight {
/// The range of component `s` is `[0, 15]`.
fn change_threshold_accounts(s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1118`
// Estimated: `4583`
// Minimum execution time: 23_000_000 picoseconds.
Weight::from_parts(24_000_000, 4583)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
// Measured: `1455 + s * (32 ±0)`
// Estimated: `4918 + s * (32 ±0)`
// Minimum execution time: 27_000_000 picoseconds.
Weight::from_parts(31_058_011, 0)
.saturating_add(Weight::from_parts(0, 4918))
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(s.into()))
}
/// Storage: `Staking::Ledger` (r:1 w:1)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
Expand Down
90 changes: 46 additions & 44 deletions runtime/src/weights/pallet_staking_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! Autogenerated weights for `pallet_staking_extension`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0
//! DATE: 2024-09-21, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-09-30, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024
Expand Down Expand Up @@ -53,11 +53,11 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn change_endpoint() -> Weight {
// Proof Size summary in bytes:
// Measured: `1309`
// Estimated: `4774`
// Minimum execution time: 24_000_000 picoseconds.
Weight::from_parts(26_000_000, 0)
.saturating_add(Weight::from_parts(0, 4774))
// Measured: `1310`
// Estimated: `4775`
// Minimum execution time: 22_000_000 picoseconds.
Weight::from_parts(24_000_000, 0)
.saturating_add(Weight::from_parts(0, 4775))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -67,17 +67,21 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:1 w:0)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::ThresholdServers` (r:1 w:1)
/// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn change_threshold_accounts() -> Weight {
/// The range of component `s` is `[0, 15]`.
fn change_threshold_accounts(s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1430`
// Estimated: `4895`
// Minimum execution time: 28_000_000 picoseconds.
Weight::from_parts(28_000_000, 0)
.saturating_add(Weight::from_parts(0, 4895))
.saturating_add(T::DbWeight::get().reads(4))
// Measured: `1455 + s * (32 ±0)`
// Estimated: `4918 + s * (32 ±0)`
// Minimum execution time: 27_000_000 picoseconds.
Weight::from_parts(31_058_011, 0)
.saturating_add(Weight::from_parts(0, 4918))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(s.into()))
}
/// Storage: `Staking::Ledger` (r:1 w:1)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
Expand Down Expand Up @@ -107,13 +111,13 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1986 + n * (32 ±0) + s * (64 ±0)`
// Estimated: `4764 + n * (32 ±0) + s * (64 ±0)`
// Minimum execution time: 72_000_000 picoseconds.
Weight::from_parts(71_588_925, 0)
// Minimum execution time: 70_000_000 picoseconds.
Weight::from_parts(66_699_022, 0)
.saturating_add(Weight::from_parts(0, 4764))
// Standard Error: 254_432
.saturating_add(Weight::from_parts(266_286, 0).saturating_mul(s.into()))
// Standard Error: 244_899
.saturating_add(Weight::from_parts(241_693, 0).saturating_mul(n.into()))
// Standard Error: 268_057
.saturating_add(Weight::from_parts(210_260, 0).saturating_mul(s.into()))
// Standard Error: 258_014
.saturating_add(Weight::from_parts(711_767, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(11))
.saturating_add(T::DbWeight::get().writes(4))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(n.into()))
Expand Down Expand Up @@ -145,13 +149,11 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1864 + c * (64 ±0) + n * (32 ±0)`
// Estimated: `6248 + c * (64 ±0) + n * (32 ±0)`
// Minimum execution time: 59_000_000 picoseconds.
Weight::from_parts(57_194_136, 0)
// Minimum execution time: 55_000_000 picoseconds.
Weight::from_parts(60_245_602, 0)
.saturating_add(Weight::from_parts(0, 6248))
// Standard Error: 195_789
.saturating_add(Weight::from_parts(161_563, 0).saturating_mul(c.into()))
// Standard Error: 188_454
.saturating_add(Weight::from_parts(295_602, 0).saturating_mul(n.into()))
// Standard Error: 151_233
.saturating_add(Weight::from_parts(59_201, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(11))
.saturating_add(T::DbWeight::get().writes(6))
.saturating_add(Weight::from_parts(0, 64).saturating_mul(c.into()))
Expand Down Expand Up @@ -181,13 +183,9 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1534 + c * (64 ±0) + n * (32 ±0)`
// Estimated: `4764 + c * (64 ±0) + n * (32 ±0)`
// Minimum execution time: 47_000_000 picoseconds.
Weight::from_parts(47_473_941, 0)
// Minimum execution time: 46_000_000 picoseconds.
Weight::from_parts(56_933_876, 0)
.saturating_add(Weight::from_parts(0, 4764))
// Standard Error: 190_804
.saturating_add(Weight::from_parts(73_615, 0).saturating_mul(c.into()))
// Standard Error: 183_655
.saturating_add(Weight::from_parts(405_456, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(Weight::from_parts(0, 64).saturating_mul(c.into()))
Expand Down Expand Up @@ -223,8 +221,8 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1918`
// Estimated: `6248`
// Minimum execution time: 64_000_000 picoseconds.
Weight::from_parts(66_000_000, 0)
// Minimum execution time: 61_000_000 picoseconds.
Weight::from_parts(68_000_000, 0)
.saturating_add(Weight::from_parts(0, 6248))
.saturating_add(T::DbWeight::get().reads(13))
.saturating_add(T::DbWeight::get().writes(8))
Expand All @@ -237,8 +235,8 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `320`
// Estimated: `3785`
// Minimum execution time: 9_000_000 picoseconds.
Weight::from_parts(18_000_000, 0)
// Minimum execution time: 10_000_000 picoseconds.
Weight::from_parts(10_000_000, 0)
.saturating_add(Weight::from_parts(0, 3785))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -253,10 +251,10 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Measured: `797 + c * (32 ±0)`
// Estimated: `4298 + c * (29 ±1)`
// Minimum execution time: 11_000_000 picoseconds.
Weight::from_parts(11_715_469, 0)
Weight::from_parts(11_892_265, 0)
.saturating_add(Weight::from_parts(0, 4298))
// Standard Error: 48_988
.saturating_add(Weight::from_parts(11_740, 0).saturating_mul(c.into()))
// Standard Error: 236_921
.saturating_add(Weight::from_parts(181_629, 0).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 29).saturating_mul(c.into()))
Expand All @@ -273,7 +271,7 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1309`
// Estimated: `4774`
// Minimum execution time: 11_000_000 picoseconds.
// Minimum execution time: 13_000_000 picoseconds.
Weight::from_parts(13_000_000, 0)
.saturating_add(Weight::from_parts(0, 4774))
.saturating_add(T::DbWeight::get().reads(2))
Expand All @@ -289,8 +287,10 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Measured: `266 + s * (32 ±0)`
// Estimated: `1751 + s * (32 ±0)`
// Minimum execution time: 5_000_000 picoseconds.
Weight::from_parts(6_171_206, 0)
Weight::from_parts(6_448_443, 0)
.saturating_add(Weight::from_parts(0, 1751))
// Standard Error: 246_978
.saturating_add(Weight::from_parts(18_482, 0).saturating_mul(s.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(s.into()))
}
Expand All @@ -310,15 +310,17 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[1, 14]`.
/// The range of component `l` is `[0, 15]`.
fn new_session(c: u32, _l: u32, ) -> Weight {
fn new_session(c: u32, l: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `494 + c * (32 ±0)`
// Estimated: `1978 + c * (32 ±0)`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_883_398, 0)
Weight::from_parts(12_568_591, 0)
.saturating_add(Weight::from_parts(0, 1978))
// Standard Error: 33_391
.saturating_add(Weight::from_parts(69_713, 0).saturating_mul(c.into()))
// Standard Error: 87_519
.saturating_add(Weight::from_parts(2_584, 0).saturating_mul(c.into()))
// Standard Error: 74_987
.saturating_add(Weight::from_parts(69_217, 0).saturating_mul(l.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into()))
Expand Down
Loading