diff --git a/CHANGELOG.md b/CHANGELOG.md index f8151e4c9..f74fd62a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/pallets/staking/src/benchmarking.rs b/pallets/staking/src/benchmarking.rs index 3b9d612b9..6e3731f2f 100644 --- a/pallets/staking/src/benchmarking.rs +++ b/pallets/staking/src/benchmarking.rs @@ -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 = ::ValidatorId::try_from(_bonder.clone()).or(Err(Error::::InvalidValidatorId)); + let validator_id_signers = ::ValidatorId::try_from(caller.clone()).or(Err(Error::::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::(true, caller.clone(), _bonder.clone(), threshold, NULL_ARR); - + let signers = vec![validator_id_signers.clone(); s as usize]; + Signers::::put(signers.clone()); }: _(RawOrigin::Signed(_bonder.clone()), _bonder.clone(), NULL_ARR) verify { diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index c83e94eef..6fafa0a00 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -311,6 +311,7 @@ pub mod pallet { NoUnbondingWhenNextSigner, NoUnnominatingWhenSigner, NoUnnominatingWhenNextSigner, + NoChangingThresholdAccountWhenSigner, } #[pallet::event] @@ -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(::WeightInfo::change_threshold_accounts())] + #[pallet::weight(::WeightInfo::change_threshold_accounts(MAX_SIGNERS as u32))] pub fn change_threshold_accounts( origin: OriginFor, tss_account: T::AccountId, x25519_public_key: X25519PublicKey, - ) -> DispatchResult { + ) -> DispatchResultWithPostInfo { ensure!( !ThresholdToStash::::contains_key(&tss_account), Error::::TssAccountAlreadyExists @@ -389,6 +390,12 @@ pub mod pallet { let validator_id = ::ValidatorId::try_from(stash) .or(Err(Error::::InvalidValidatorId))?; + let signers = Self::signers(); + ensure!( + !signers.contains(&validator_id), + Error::::NoChangingThresholdAccountWhenSigner + ); + let new_server_info: ServerInfo = ThresholdServers::::try_mutate(&validator_id, |maybe_server_info| { if let Some(server_info) = maybe_server_info { @@ -401,7 +408,8 @@ pub mod pallet { } })?; Self::deposit_event(Event::ThresholdAccountChanged(validator_id, new_server_info)); - Ok(()) + Ok(Some(::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 diff --git a/pallets/staking/src/tests.rs b/pallets/staking/src/tests.rs index 70c0c80a5..b4ae4137b 100644 --- a/pallets/staking/src/tests.rs +++ b/pallets/staking/src/tests.rs @@ -233,6 +233,12 @@ fn it_changes_threshold_account() { Staking::change_threshold_accounts(RuntimeOrigin::signed(1), 5, NULL_ARR), Error::::TssAccountAlreadyExists ); + + Signers::::put(vec![1]); + assert_noop!( + Staking::change_threshold_accounts(RuntimeOrigin::signed(1), 9, NULL_ARR,), + Error::::NoChangingThresholdAccountWhenSigner + ); }); } diff --git a/pallets/staking/src/weights.rs b/pallets/staking/src/weights.rs index fedc25021..5faf7880e 100644 --- a/pallets/staking/src/weights.rs +++ b/pallets/staking/src/weights.rs @@ -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; @@ -81,20 +81,27 @@ impl WeightInfo for SubstrateWeight { .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`) @@ -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`) diff --git a/runtime/src/weights/pallet_staking_extension.rs b/runtime/src/weights/pallet_staking_extension.rs index 158c1fb48..6364cbdef 100644 --- a/runtime/src/weights/pallet_staking_extension.rs +++ b/runtime/src/weights/pallet_staking_extension.rs @@ -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: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -53,11 +53,11 @@ impl 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)) } @@ -67,17 +67,21 @@ impl 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`) @@ -107,13 +111,13 @@ impl 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())) @@ -145,13 +149,11 @@ impl 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())) @@ -181,13 +183,9 @@ impl 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())) @@ -223,8 +221,8 @@ impl 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)) @@ -237,8 +235,8 @@ impl 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)) @@ -253,10 +251,10 @@ impl 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())) @@ -273,7 +271,7 @@ impl 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)) @@ -289,8 +287,10 @@ impl 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())) } @@ -310,15 +310,17 @@ impl 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()))