diff --git a/bridges/snowbridge/runtime/test-common/Cargo.toml b/bridges/snowbridge/runtime/test-common/Cargo.toml index fd71d5fcf6ba..2930d092ac8b 100644 --- a/bridges/snowbridge/runtime/test-common/Cargo.toml +++ b/bridges/snowbridge/runtime/test-common/Cargo.toml @@ -78,6 +78,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-utility/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", diff --git a/cumulus/pallets/collator-selection/Cargo.toml b/cumulus/pallets/collator-selection/Cargo.toml index 98960b0776d1..dcc75bc88ea2 100644 --- a/cumulus/pallets/collator-selection/Cargo.toml +++ b/cumulus/pallets/collator-selection/Cargo.toml @@ -44,6 +44,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", diff --git a/cumulus/pallets/collator-selection/src/benchmarking.rs b/cumulus/pallets/collator-selection/src/benchmarking.rs index 706695106ba6..5d34641aee75 100644 --- a/cumulus/pallets/collator-selection/src/benchmarking.rs +++ b/cumulus/pallets/collator-selection/src/benchmarking.rs @@ -79,6 +79,7 @@ fn register_validators(count: u32) -> Vec(c)).collect::>(); for (who, keys) in validators.clone() { + >::ensure_can_pay_key_deposit(&who).unwrap(); >::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap(); } @@ -158,6 +159,7 @@ mod benchmarks { candidates.push((new_invulnerable.clone(), new_invulnerable_keys)); // set their keys ... for (who, keys) in candidates.clone() { + >::ensure_can_pay_key_deposit(&who).unwrap(); >::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()) .unwrap(); } @@ -298,6 +300,7 @@ mod benchmarks { let bond: BalanceOf = ::Currency::minimum_balance() * 2u32.into(); ::Currency::make_free_balance_be(&caller, bond); + >::ensure_can_pay_key_deposit(&caller).unwrap(); >::set_keys( RawOrigin::Signed(caller.clone()).into(), keys::(c + 1), @@ -325,6 +328,7 @@ mod benchmarks { let bond: BalanceOf = ::Currency::minimum_balance() * 10u32.into(); ::Currency::make_free_balance_be(&caller, bond); + >::ensure_can_pay_key_deposit(&caller).unwrap(); >::set_keys( RawOrigin::Signed(caller.clone()).into(), keys::(c + 1), @@ -456,5 +460,5 @@ mod benchmarks { } } - impl_benchmark_test_suite!(CollatorSelection, crate::mock::new_test_ext(), crate::mock::Test,); + impl_benchmark_test_suite!(CollatorSelection, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/cumulus/pallets/session-benchmarking/Cargo.toml b/cumulus/pallets/session-benchmarking/Cargo.toml index ad2c48d9d067..7b499a657bcd 100644 --- a/cumulus/pallets/session-benchmarking/Cargo.toml +++ b/cumulus/pallets/session-benchmarking/Cargo.toml @@ -29,6 +29,7 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] std = [ diff --git a/cumulus/pallets/session-benchmarking/src/inner.rs b/cumulus/pallets/session-benchmarking/src/inner.rs index 6c5188921362..be7d7740be6b 100644 --- a/cumulus/pallets/session-benchmarking/src/inner.rs +++ b/cumulus/pallets/session-benchmarking/src/inner.rs @@ -35,6 +35,7 @@ mod benchmarks { frame_system::Pallet::::inc_providers(&caller); let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap(); let proof: Vec = vec![0, 1, 2, 3]; + >::ensure_can_pay_key_deposit(&caller).unwrap(); #[extrinsic_call] _(RawOrigin::Signed(caller), keys, proof); @@ -48,6 +49,7 @@ mod benchmarks { frame_system::Pallet::::inc_providers(&caller); let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap(); let proof: Vec = vec![0, 1, 2, 3]; + >::ensure_can_pay_key_deposit(&caller).unwrap(); let _t = pallet_session::Pallet::::set_keys( RawOrigin::Signed(caller.clone()).into(), keys, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index 49fb2fc852f8..62e7a99f9bdd 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -123,6 +123,7 @@ runtime-benchmarks = [ "pallet-nft-fractionalization/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index 90a5d3fcf965..fe4c51d44e83 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -175,6 +175,7 @@ runtime-benchmarks = [ "pallet-referenda/runtime-benchmarks", "pallet-revive/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking-async-rc-client/runtime-benchmarks", "pallet-staking-async/runtime-benchmarks", "pallet-staking/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 8e9c250bd5d5..6a5013559c07 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -236,6 +236,7 @@ runtime-benchmarks = [ "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", "pallet-utility/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml index c4bd83a9282a..006993901702 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml @@ -245,6 +245,7 @@ runtime-benchmarks = [ "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", "pallet-utility/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml index 63892980b976..842d1d333c2c 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml @@ -120,6 +120,7 @@ runtime-benchmarks = [ "pallet-referenda/runtime-benchmarks", "pallet-salary/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-state-trie-migration/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml index 097dda46ad69..793bf13d105a 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml @@ -164,6 +164,7 @@ runtime-benchmarks = [ "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml index 202842f49ea0..d22502f28107 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml @@ -163,6 +163,7 @@ runtime-benchmarks = [ "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml b/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml index 85929c5a0916..dc29fefc6f13 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml @@ -164,6 +164,7 @@ runtime-benchmarks = [ "pallet-migrations/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", "pallet-utility/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/people/people-westend/Cargo.toml b/cumulus/parachains/runtimes/people/people-westend/Cargo.toml index d3e2b1cfbf72..12b63c50d7a8 100644 --- a/cumulus/parachains/runtimes/people/people-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/people/people-westend/Cargo.toml @@ -166,6 +166,7 @@ runtime-benchmarks = [ "pallet-migrations/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", "pallet-utility/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/testing/penpal/Cargo.toml b/cumulus/parachains/runtimes/testing/penpal/Cargo.toml index f2b0dc6b801d..488c7ab80c93 100644 --- a/cumulus/parachains/runtimes/testing/penpal/Cargo.toml +++ b/cumulus/parachains/runtimes/testing/penpal/Cargo.toml @@ -171,6 +171,7 @@ runtime-benchmarks = [ "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-revive/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 37cc82be4cb0..3dafbb43b673 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -127,6 +127,7 @@ runtime-benchmarks = [ "pallet-election-provider-multi-phase/runtime-benchmarks", "pallet-fast-unstake/runtime-benchmarks", "pallet-identity/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-transaction-payment/runtime-benchmarks", diff --git a/polkadot/runtime/parachains/Cargo.toml b/polkadot/runtime/parachains/Cargo.toml index 1bfff997a64b..bd148c2b9999 100644 --- a/polkadot/runtime/parachains/Cargo.toml +++ b/polkadot/runtime/parachains/Cargo.toml @@ -125,6 +125,7 @@ runtime-benchmarks = [ "pallet-broker/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-mmr/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", diff --git a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs index f99aa2d1b193..4aa076faac43 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing/benchmarking.rs @@ -76,6 +76,7 @@ where let proof: Vec = vec![]; whitelist_account!(controller); + pallet_session::Pallet::::ensure_can_pay_key_deposit(&controller).unwrap(); pallet_session::Pallet::::set_keys(RawOrigin::Signed(controller).into(), keys, proof) .expect("session::set_keys should work"); } diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 4cef84fa1816..e7ee3e86b284 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -239,6 +239,7 @@ runtime-benchmarks = [ "pallet-recovery/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-state-trie-migration/runtime-benchmarks", diff --git a/polkadot/runtime/test-runtime/Cargo.toml b/polkadot/runtime/test-runtime/Cargo.toml index f2446a545f56..50a3c4b14add 100644 --- a/polkadot/runtime/test-runtime/Cargo.toml +++ b/polkadot/runtime/test-runtime/Cargo.toml @@ -131,6 +131,7 @@ runtime-benchmarks = [ "pallet-grandpa/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-offences/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index aa2639c2c5f0..c3354d28f28e 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -263,6 +263,7 @@ runtime-benchmarks = [ "pallet-referenda/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", "pallet-session-benchmarking/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking-async-ah-client/runtime-benchmarks", "pallet-staking-async-rc-client/runtime-benchmarks", "pallet-staking/runtime-benchmarks", diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 0ad369e8cc03..c8d7e8063522 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -509,6 +509,8 @@ impl pallet_authorship::Config for Runtime { parameter_types! { pub const Period: BlockNumber = 10 * MINUTES; pub const Offset: BlockNumber = 0; + // 5 keys of 32 bytes, plus beefy key 33 bytes + pub const KeyDeposit: Balance = deposit(1, 5 * 32 + 33); } impl_opaque_keys! { @@ -534,7 +536,7 @@ impl pallet_session::Config for Runtime { type DisablingStrategy = pallet_session::disabling::UpToLimitWithReEnablingDisablingStrategy; type WeightInfo = weights::pallet_session::WeightInfo; type Currency = Balances; - type KeyDeposit = (); + type KeyDeposit = KeyDeposit; } impl pallet_session::historical::Config for Runtime { diff --git a/polkadot/runtime/westend/src/weights/pallet_session.rs b/polkadot/runtime/westend/src/weights/pallet_session.rs index 813c6e3a6671..9f93de3cb9e6 100644 --- a/polkadot/runtime/westend/src/weights/pallet_session.rs +++ b/polkadot/runtime/westend/src/weights/pallet_session.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `pallet_session` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2025-02-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-08-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `3a2e9ae8a8f5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `276823fd1fd5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: @@ -51,36 +51,36 @@ use core::marker::PhantomData; /// Weight functions for `pallet_session`. pub struct WeightInfo(PhantomData); impl pallet_session::WeightInfo for WeightInfo { - /// Storage: `Staking::Ledger` (r:1 w:0) - /// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`) /// Storage: `Session::NextKeys` (r:1 w:1) /// Proof: `Session::NextKeys` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `Session::KeyOwner` (r:6 w:6) /// Proof: `Session::KeyOwner` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(139), added: 2614, mode: `MaxEncodedLen`) fn set_keys() -> Weight { // Proof Size summary in bytes: - // Measured: `1899` - // Estimated: `17739` - // Minimum execution time: 71_274_000 picoseconds. - Weight::from_parts(73_693_000, 0) - .saturating_add(Weight::from_parts(0, 17739)) + // Measured: `1154` + // Estimated: `16994` + // Minimum execution time: 98_517_000 picoseconds. + Weight::from_parts(101_461_000, 0) + .saturating_add(Weight::from_parts(0, 16994)) .saturating_add(T::DbWeight::get().reads(8)) - .saturating_add(T::DbWeight::get().writes(7)) + .saturating_add(T::DbWeight::get().writes(8)) } - /// Storage: `Staking::Ledger` (r:1 w:0) - /// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`) /// Storage: `Session::NextKeys` (r:1 w:1) /// Proof: `Session::NextKeys` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(139), added: 2614, mode: `MaxEncodedLen`) /// Storage: `Session::KeyOwner` (r:0 w:6) /// Proof: `Session::KeyOwner` (`max_values`: None, `max_size`: None, mode: `Measured`) fn purge_keys() -> Weight { // Proof Size summary in bytes: - // Measured: `1814` - // Estimated: `5279` - // Minimum execution time: 52_441_000 picoseconds. - Weight::from_parts(55_437_000, 0) - .saturating_add(Weight::from_parts(0, 5279)) + // Measured: `1141` + // Estimated: `4606` + // Minimum execution time: 71_897_000 picoseconds. + Weight::from_parts(74_310_000, 0) + .saturating_add(Weight::from_parts(0, 4606)) .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(7)) + .saturating_add(T::DbWeight::get().writes(8)) } } diff --git a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs index d75724d1ae0f..866a160598ac 100644 --- a/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs +++ b/polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_disputes_slashing.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `polkadot_runtime_parachains::disputes::slashing` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-08-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `3a2e9ae8a8f5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `276823fd1fd5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: @@ -61,12 +61,16 @@ impl polkadot_runtime_parachains::disputes::slashing::W /// Proof: `Offences::ConcurrentReportsIndex` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `Offences::Reports` (r:1 w:1) /// Proof: `Offences::Reports` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `StakingAhClient::Mode` (r:1 w:0) + /// Proof: `StakingAhClient::Mode` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `Staking::SlashRewardFraction` (r:1 w:0) + /// Proof: `Staking::SlashRewardFraction` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `Staking::ActiveEra` (r:1 w:0) /// Proof: `Staking::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`) /// Storage: `Staking::ErasStartSessionIndex` (r:1 w:0) /// Proof: `Staking::ErasStartSessionIndex` (`max_values`: None, `max_size`: Some(16), added: 2491, mode: `MaxEncodedLen`) /// Storage: `Staking::Invulnerables` (r:1 w:0) - /// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`) + /// Proof: `Staking::Invulnerables` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Staking::ErasStakersOverview` (r:1 w:0) /// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`) /// Storage: `Session::DisabledValidators` (r:1 w:1) @@ -75,22 +79,24 @@ impl polkadot_runtime_parachains::disputes::slashing::W /// Proof: `Session::Validators` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Staking::ValidatorSlashInEra` (r:1 w:1) /// Proof: `Staking::ValidatorSlashInEra` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) - /// Storage: `Staking::OffenceQueue` (r:1 w:1) - /// Proof: `Staking::OffenceQueue` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) - /// Storage: `Staking::OffenceQueueEras` (r:1 w:1) - /// Proof: `Staking::OffenceQueueEras` (`max_values`: Some(1), `max_size`: Some(9), added: 504, mode: `MaxEncodedLen`) + /// Storage: `Staking::SlashingSpans` (r:1 w:1) + /// Proof: `Staking::SlashingSpans` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Staking::SpanSlash` (r:1 w:1) + /// Proof: `Staking::SpanSlash` (`max_values`: None, `max_size`: Some(76), added: 2551, mode: `MaxEncodedLen`) + /// Storage: `Staking::UnappliedSlashes` (r:1 w:1) + /// Proof: `Staking::UnappliedSlashes` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `n` is `[4, 300]`. fn report_dispute_lost_unsigned(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `2024 + n * (33 ±0)` - // Estimated: `5386 + n * (34 ±0)` - // Minimum execution time: 88_786_000 picoseconds. - Weight::from_parts(127_346_367, 0) - .saturating_add(Weight::from_parts(0, 5386)) - // Standard Error: 3_530 - .saturating_add(Weight::from_parts(144_389, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(14)) - .saturating_add(T::DbWeight::get().writes(7)) + // Measured: `2145 + n * (33 ±0)` + // Estimated: `5588 + n * (34 ±0)` + // Minimum execution time: 106_507_000 picoseconds. + Weight::from_parts(151_695_565, 0) + .saturating_add(Weight::from_parts(0, 5588)) + // Standard Error: 4_446 + .saturating_add(Weight::from_parts(202_889, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(17)) + .saturating_add(T::DbWeight::get().writes(8)) .saturating_add(Weight::from_parts(0, 34).saturating_mul(n.into())) } } diff --git a/prdoc/pr_9415.prdoc b/prdoc/pr_9415.prdoc new file mode 100644 index 000000000000..f16ff64d8fd4 --- /dev/null +++ b/prdoc/pr_9415.prdoc @@ -0,0 +1,9 @@ +title: Cleanup staking try states + fix min bonds +doc: +- audience: Runtime Dev + description: ensures staking try-state code passes, and fixes issues of having a mistakenly high min-bond for validators +crates: +- name: pallet-nomination-pools + bump: patch +- name: pallet-staking-async + bump: patch diff --git a/prdoc/pr_9504.prdoc b/prdoc/pr_9504.prdoc new file mode 100644 index 000000000000..0e4eff770f91 --- /dev/null +++ b/prdoc/pr_9504.prdoc @@ -0,0 +1,62 @@ +title: Fix `pallet_session` benchmarks +doc: +- audience: Runtime Dev + description: |- + Fixes the benchmarking code of `pallet_session` such that it works with any `KeyDeposit`. +crates: +- name: westend-runtime + bump: minor +- name: pallet-session-benchmarking + bump: patch +- name: pallet-session + bump: patch +- name: polkadot-sdk + bump: patch +- name: polkadot-runtime-parachains + bump: patch +- name: pallet-babe + bump: patch +- name: pallet-staking + bump: patch +- name: pallet-grandpa + bump: patch +- name: polkadot-runtime-common + bump: patch +- name: pallet-beefy-mmr + bump: patch +- name: pallet-offences-benchmarking + bump: patch +- name: pallet-im-online + bump: patch +- name: pallet-staking-async-ah-client + bump: patch +- name: rococo-runtime + bump: patch +- name: pallet-collator-selection + bump: patch +- name: cumulus-pallet-session-benchmarking + bump: patch +- name: pallet-root-offences + bump: patch +- name: snowbridge-runtime-test-common + bump: patch +- name: asset-hub-rococo-runtime + bump: patch +- name: asset-hub-westend-runtime + bump: patch +- name: bridge-hub-rococo-runtime + bump: patch +- name: bridge-hub-westend-runtime + bump: patch +- name: collectives-westend-runtime + bump: patch +- name: coretime-rococo-runtime + bump: patch +- name: coretime-westend-runtime + bump: patch +- name: people-rococo-runtime + bump: patch +- name: people-westend-runtime + bump: patch +- name: penpal-runtime + bump: patch diff --git a/prdoc/pr_9511.prdoc b/prdoc/pr_9511.prdoc new file mode 100644 index 000000000000..35aa5f493e04 --- /dev/null +++ b/prdoc/pr_9511.prdoc @@ -0,0 +1,11 @@ +title: 'EPMB/Signed: Make invulnerables non-eject-able' +doc: +- audience: Runtime Dev + description: 'Follow-up to https://github.com/paritytech/polkadot-sdk/pull/8877 + and audits: Make it such that invulnerable accounts cannot be ejected from the + election signed queue altogether. ' +crates: +- name: pallet-election-provider-multi-block + bump: patch +- name: pallet-staking-async + bump: patch diff --git a/prdoc/pr_9513.prdoc b/prdoc/pr_9513.prdoc new file mode 100644 index 000000000000..6363278b399a --- /dev/null +++ b/prdoc/pr_9513.prdoc @@ -0,0 +1,75 @@ +title: '[AHM] Fixes to unstable2507' +doc: +- audience: Runtime Dev + description: See prdoc/pr_9415.prdoc, prdoc/pr_9504.prdoc and prdoc/pr_9511.prdoc. +crates: +- name: pallet-offences-benchmarking + bump: patch +- name: pallet-nomination-pools + bump: patch +- name: pallet-staking-async + bump: patch +- name: pallet-bounties + bump: patch +- name: pallet-nomination-pools-benchmarking + bump: patch +- name: snowbridge-runtime-test-common + bump: patch +- name: pallet-collator-selection + bump: patch +- name: cumulus-pallet-session-benchmarking + bump: patch +- name: asset-hub-rococo-runtime + bump: patch +- name: asset-hub-westend-runtime + bump: patch +- name: bridge-hub-rococo-runtime + bump: patch +- name: bridge-hub-westend-runtime + bump: patch +- name: collectives-westend-runtime + bump: patch +- name: coretime-rococo-runtime + bump: patch +- name: coretime-westend-runtime + bump: patch +- name: people-rococo-runtime + bump: patch +- name: people-westend-runtime + bump: patch +- name: penpal-runtime + bump: patch +- name: polkadot-runtime-common + bump: patch +- name: polkadot-runtime-parachains + bump: patch +- name: rococo-runtime + bump: patch +- name: westend-runtime + bump: minor +- name: pallet-babe + bump: patch +- name: pallet-beefy-mmr + bump: patch +- name: pallet-grandpa + bump: patch +- name: pallet-im-online + bump: patch +- name: pallet-root-offences + bump: patch +- name: pallet-session + bump: patch +- name: pallet-session-benchmarking + bump: patch +- name: pallet-staking-async-ah-client + bump: patch +- name: pallet-staking-async-parachain-runtime + bump: patch +- name: pallet-staking-async-rc-runtime + bump: patch +- name: pallet-staking + bump: patch +- name: polkadot-sdk + bump: patch +- name: pallet-election-provider-multi-block + bump: patch diff --git a/substrate/frame/babe/Cargo.toml b/substrate/frame/babe/Cargo.toml index 2f1f70e71640..920cbcf65149 100644 --- a/substrate/frame/babe/Cargo.toml +++ b/substrate/frame/babe/Cargo.toml @@ -69,6 +69,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-offences/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/substrate/frame/beefy-mmr/Cargo.toml b/substrate/frame/beefy-mmr/Cargo.toml index 05e6a5b278ad..adc2c4a88bac 100644 --- a/substrate/frame/beefy-mmr/Cargo.toml +++ b/substrate/frame/beefy-mmr/Cargo.toml @@ -74,6 +74,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-mmr/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", ] diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index 42b52d062d7a..e0955c03f07a 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -148,9 +148,9 @@ pub struct Bounty { /// The deposit of curator. pub curator_deposit: Balance, /// The amount held on deposit (reserved) for making this proposal. - bond: Balance, + pub bond: Balance, /// The status of this bounty. - status: BountyStatus, + pub status: BountyStatus, } impl diff --git a/substrate/frame/election-provider-multi-block/src/signed/mod.rs b/substrate/frame/election-provider-multi-block/src/signed/mod.rs index 7326e5886147..f0061ad9bdc2 100644 --- a/substrate/frame/election-provider-multi-block/src/signed/mod.rs +++ b/substrate/frame/election-provider-multi-block/src/signed/mod.rs @@ -455,13 +455,13 @@ pub mod pallet { ) -> Result { let mut sorted_scores = SortedScores::::get(round); - let discarded = if let Some(_) = sorted_scores.iter().position(|(x, _)| x == who) { + let did_eject = if let Some(_) = sorted_scores.iter().position(|(x, _)| x == who) { return Err(Error::::Duplicate.into()); } else { // must be new. debug_assert!(!SubmissionMetadataStorage::::contains_key(round, who)); - let pos = match sorted_scores + let insert_idx = match sorted_scores .binary_search_by_key(&metadata.claimed_score, |(_, y)| *y) { // an equal score exists, unlikely, but could very well happen. We just put them @@ -471,10 +471,23 @@ pub mod pallet { Err(pos) => pos, }; - let record = (who.clone(), metadata.claimed_score); - match sorted_scores.force_insert_keep_right(pos, record) { - Ok(None) => false, - Ok(Some((discarded, _score))) => { + let mut record = (who.clone(), metadata.claimed_score); + if sorted_scores.is_full() { + let remove_idx = sorted_scores + .iter() + .position(|(x, _)| !Pallet::::is_invulnerable(x)) + .ok_or(Error::::QueueFull)?; + if insert_idx > remove_idx { + // we have a better solution + sp_std::mem::swap(&mut sorted_scores[remove_idx], &mut record); + // slicing safety note: + // - `insert_idx` is at most `sorted_scores.len()`, obtained from + // `binary_search_by_key`, valid for the upper bound of slicing. + // - `remove_idx` is a valid index, less then `insert_idx`, obtained from + // `.iter().position()` + sorted_scores[remove_idx..insert_idx].rotate_left(1); + + let discarded = record.0; let maybe_metadata = SubmissionMetadataStorage::::take(round, &discarded).defensive(); // Note: safe to remove unbounded, as at most `Pages` pages are stored. @@ -489,24 +502,27 @@ pub mod pallet { Pallet::::settle_deposit( &discarded, metadata.deposit, - if Pallet::::is_invulnerable(&discarded) { - One::one() - } else { - T::EjectGraceRatio::get() - }, + T::EjectGraceRatio::get(), ); } Pallet::::deposit_event(Event::::Ejected(round, discarded)); true - }, - Err(_) => return Err(Error::::QueueFull.into()), + } else { + // we don't have a better solution + return Err(Error::::QueueFull.into()) + } + } else { + sorted_scores + .try_insert(insert_idx, record) + .expect("length checked above; qed"); + false } }; SortedScores::::insert(round, sorted_scores); SubmissionMetadataStorage::::insert(round, who, metadata); - Ok(discarded) + Ok(did_eject) } /// Submit a page of `solution` to the `page` index of `who`'s submission. @@ -1023,6 +1039,7 @@ impl Pallet { ); debug_assert_eq!(_res, Ok(slash)); Self::deposit_event(Event::::Slashed(current_round, loser.clone(), slash)); + Invulnerables::::mutate(|x| x.retain(|y| y != &loser)); // Try to start verification again if we still have submissions if let crate::types::Phase::SignedValidation(remaining_blocks) = diff --git a/substrate/frame/election-provider-multi-block/src/signed/tests.rs b/substrate/frame/election-provider-multi-block/src/signed/tests.rs index cbd64adf84c7..085cec58935c 100644 --- a/substrate/frame/election-provider-multi-block/src/signed/tests.rs +++ b/substrate/frame/election-provider-multi-block/src/signed/tests.rs @@ -29,6 +29,10 @@ use sp_npos_elections::ElectionScore; pub type T = Runtime; +fn score_from(x: u128) -> ElectionScore { + ElectionScore { minimal_stake: x, ..Default::default() } +} + mod calls { use super::*; use sp_runtime::{DispatchError, TokenError::FundsUnavailable}; @@ -213,13 +217,11 @@ mod calls { } #[test] - fn metadata_submission_sorted_based_on_stake() { + fn metadata_submission_sorted_based_on_score() { ExtBuilder::signed().build_and_execute(|| { roll_to_signed_open(); assert_full_snapshot(); - let score_from = |x| ElectionScore { minimal_stake: x, ..Default::default() }; - assert_ok!(SignedPallet::register(RuntimeOrigin::signed(91), score_from(100))); assert_eq!(*Submissions::::leaderboard(0), vec![(91, score_from(100))]); assert_eq!(balances(91), (95, 5)); @@ -1259,6 +1261,8 @@ mod e2e { } mod invulnerables { + use frame_support::hypothetically; + use super::*; fn make_invulnerable(who: AccountId) { @@ -1395,73 +1399,102 @@ mod invulnerables { } #[test] - fn ejected_invulnerable_gets_deposit_back() { - ExtBuilder::signed().max_signed_submissions(2).build_and_execute(|| { + fn invulnerable_cannot_eject_first() { + ExtBuilder::signed().max_signed_submissions(3).build_and_execute(|| { roll_to_signed_open(); assert_full_snapshot(); make_invulnerable(99); - // by default, we pay back 20% of the discarded deposit back + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(99), score_from(100))); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(98), score_from(150))); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(97), score_from(200))); + assert_eq!( - ::EjectGraceRatio::get(), - Perbill::from_percent(20) + Submissions::::leaderboard(0), + vec![(99, score_from(100)), (98, score_from(150)), (97, score_from(200))] ); - // submit 99 as invulnerable - assert_ok!(SignedPallet::register( - RuntimeOrigin::signed(99), - ElectionScore { minimal_stake: 100, ..Default::default() } - )); - assert!(matches!( - Submissions::::metadata_of(0, 99).unwrap(), - SubmissionMetadata { deposit: 7, .. } - )); + // inserting someone who would eject 99 won't work. + assert_noop!( + SignedPallet::register(RuntimeOrigin::signed(96), score_from(100)), + Error::::QueueFull, + ); + // inserting someone who would eject 98 will work. + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(96), score_from(155))); + assert_eq!( + Submissions::::leaderboard(0), + vec![(99, score_from(100)), (96, score_from(155)), (97, score_from(200))] + ); + }) + } - // submit 98 as normal - assert_ok!(SignedPallet::register( - RuntimeOrigin::signed(98), - ElectionScore { minimal_stake: 101, ..Default::default() } - )); - assert!(matches!( - Submissions::::metadata_of(0, 98).unwrap(), - SubmissionMetadata { deposit: 5, .. } - )); - let _ = signed_events_since_last_call(); - assert_eq!(balances(99), (93, 7)); - assert_eq!(balances(98), (95, 5)); + #[test] + fn invulnerable_cannot_eject_middle() { + ExtBuilder::signed().max_signed_submissions(3).build_and_execute(|| { + roll_to_signed_open(); + assert_full_snapshot(); + make_invulnerable(99); - // submit 97 and 96 with higher scores, eject both of the previous ones - assert_ok!(SignedPallet::register( - RuntimeOrigin::signed(97), - ElectionScore { minimal_stake: 200, ..Default::default() } - )); - assert_ok!(SignedPallet::register( - RuntimeOrigin::signed(96), - ElectionScore { minimal_stake: 201, ..Default::default() } - )); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(99), score_from(150))); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(98), score_from(100))); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(97), score_from(200))); assert_eq!( - signed_events_since_last_call(), - vec![ - Event::Ejected(0, 99), - Event::Registered( - 0, - 97, - ElectionScore { minimal_stake: 200, sum_stake: 0, sum_stake_squared: 0 } - ), - Event::Ejected(0, 98), - Event::Registered( - 0, - 96, - ElectionScore { minimal_stake: 201, sum_stake: 0, sum_stake_squared: 0 } - ) - ] + Submissions::::leaderboard(0), + vec![(98, score_from(100)), (99, score_from(150)), (97, score_from(200))] ); - // 99 gets everything back - assert_eq!(balances(99), (100, 0)); - // 98 gets 20% x 5 = 1 back - assert_eq!(balances(98), (96, 0)); + // worse than all + assert_noop!( + SignedPallet::register(RuntimeOrigin::signed(96), score_from(50)), + Error::::QueueFull, + ); + + // better than our first item + hypothetically!({ + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(96), score_from(125))); + assert_eq!( + Submissions::::leaderboard(0), + vec![(96, score_from(125)), (99, score_from(150)), (97, score_from(200))] + ); + }); + + // better than inv + hypothetically!({ + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(96), score_from(175))); + assert_eq!( + Submissions::::leaderboard(0), + vec![(99, score_from(150)), (96, score_from(175)), (97, score_from(200))] + ); + }); + + // better than all + hypothetically!({ + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(96), score_from(225))); + assert_eq!( + Submissions::::leaderboard(0), + vec![(99, score_from(150)), (97, score_from(200)), (96, score_from(225))] + ); + }); + }) + } + + #[test] + fn all_invulnerables() { + ExtBuilder::signed().max_signed_submissions(3).build_and_execute(|| { + roll_to_signed_open(); + assert_full_snapshot(); + assert_ok!(SignedPallet::set_invulnerables(RuntimeOrigin::root(), vec![99, 98, 97])); + + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(99), score_from(150))); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(98), score_from(100))); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(97), score_from(200))); + + // Nothing can touch our boys now. + assert_noop!( + SignedPallet::register(RuntimeOrigin::signed(96), score_from(1000)), + Error::::QueueFull, + ); }) } @@ -1559,6 +1592,48 @@ mod invulnerables { assert_eq!(new_deposit, 5); // Should not be fixed deposit anymore }); } + + #[test] + fn slashed_invulnerable_is_expelled() { + ExtBuilder::signed().build_and_execute(|| { + roll_to_signed_open(); + assert_full_snapshot(); + make_invulnerable(99); + assert!(Invulnerables::::get().contains(&99)); + + let invalid_score = score_from(777); + assert_ok!(SignedPallet::register(RuntimeOrigin::signed(99), invalid_score)); + + roll_to_signed_validation_open(); + roll_next(); // one block so signed pallet will send start signal. + roll_to_full_verification(); + + // Check that rejection events were properly generated + assert_eq!( + verifier_events_since_last_call(), + vec![ + crate::verifier::Event::Verified(2, 0), // empty page + crate::verifier::Event::Verified(1, 0), // empty page + crate::verifier::Event::Verified(0, 0), // empty page + crate::verifier::Event::VerificationFailed(0, FeasibilityError::InvalidScore), + ] + ); + + // Check that expected events were emitted for the rejection + assert_eq!( + signed_events(), + vec![Event::Registered(0, 99, invalid_score), Event::Slashed(0, 99, 7)] /* slash + * amount + * is indeed + * the invulnerable + * deposit + * (7) ^^^^ */ + ); + + // Verify invulnerable is expelled + assert!(!Invulnerables::::get().contains(&99)); + }); + } } mod defensive_tests { diff --git a/substrate/frame/grandpa/Cargo.toml b/substrate/frame/grandpa/Cargo.toml index 2d8d27bfda82..54afb90d8d12 100644 --- a/substrate/frame/grandpa/Cargo.toml +++ b/substrate/frame/grandpa/Cargo.toml @@ -70,6 +70,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-offences/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/substrate/frame/im-online/Cargo.toml b/substrate/frame/im-online/Cargo.toml index dd7d87998c37..aa9212794b2c 100644 --- a/substrate/frame/im-online/Cargo.toml +++ b/substrate/frame/im-online/Cargo.toml @@ -55,6 +55,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", ] diff --git a/substrate/frame/offences/benchmarking/Cargo.toml b/substrate/frame/offences/benchmarking/Cargo.toml index 0dc8cfb8e433..0b2e3448f9b9 100644 --- a/substrate/frame/offences/benchmarking/Cargo.toml +++ b/substrate/frame/offences/benchmarking/Cargo.toml @@ -70,6 +70,7 @@ runtime-benchmarks = [ "pallet-grandpa/runtime-benchmarks", "pallet-im-online/runtime-benchmarks", "pallet-offences/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/substrate/frame/offences/benchmarking/src/inner.rs b/substrate/frame/offences/benchmarking/src/inner.rs index cb8e3cf56d02..0a7cc7c6f3c8 100644 --- a/substrate/frame/offences/benchmarking/src/inner.rs +++ b/substrate/frame/offences/benchmarking/src/inner.rs @@ -112,6 +112,7 @@ fn create_offender(n: u32, nominators: u32) -> Result, &' ::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) .unwrap(); let proof: Vec = vec![0, 1, 2, 3]; + Session::::ensure_can_pay_key_deposit(&stash)?; Session::::set_keys(RawOrigin::Signed(stash.clone()).into(), keys, proof)?; let mut individual_exposures = vec![]; @@ -183,17 +184,22 @@ fn make_offenders( } #[cfg(test)] -fn assert_all_slashes_applied(offender_count: usize) -where +fn assert_all_slashes_applied( + offender_count: usize, + reporter: ::AccountId, +) where T: Config, ::RuntimeEvent: TryInto>, ::RuntimeEvent: TryInto>, ::RuntimeEvent: TryInto, ::RuntimeEvent: TryInto>, { - // make sure that all slashes have been applied - // deposit to reporter + reporter account endowed. - assert_eq!(System::::read_events_for_pallet::>().len(), 2); + // make sure reporter got deposited. + assert!(System::::read_events_for_pallet::>() + .into_iter() + .any( + |e| matches!(e, pallet_balances::Event::::Deposit { who, .. } if who == reporter ) + )); // (n nominators + one validator) * slashed + Slash Reported + Slash Computed assert_eq!( System::::read_events_for_pallet::>().len(), @@ -221,9 +227,9 @@ mod benchmarks { ) -> Result<(), BenchmarkError> { // for grandpa equivocation reports the number of reporters // and offenders is always 1 - let reporters = vec![account("reporter", 1, SEED)]; + let reporter = account::("reporter", 1, SEED); - // make sure reporters actually get rewarded + // make sure reporter actually gets rewarded Staking::::set_slash_reward_fraction(Perbill::one()); let mut offenders = make_offenders::(1, n)?; @@ -239,12 +245,12 @@ mod benchmarks { #[block] { - let _ = Offences::::report_offence(reporters, offence); + let _ = Offences::::report_offence(vec![reporter.clone()], offence); } #[cfg(test)] { - assert_all_slashes_applied::(n as usize); + assert_all_slashes_applied::(n as usize, reporter); } Ok(()) @@ -256,7 +262,7 @@ mod benchmarks { ) -> Result<(), BenchmarkError> { // for babe equivocation reports the number of reporters // and offenders is always 1 - let reporters = vec![account("reporter", 1, SEED)]; + let reporter = account::("reporter", 1, SEED); // make sure reporters actually get rewarded Staking::::set_slash_reward_fraction(Perbill::one()); @@ -274,11 +280,11 @@ mod benchmarks { #[block] { - let _ = Offences::::report_offence(reporters, offence); + let _ = Offences::::report_offence(vec![reporter.clone()], offence); } #[cfg(test)] { - assert_all_slashes_applied::(n as usize); + assert_all_slashes_applied::(n as usize, reporter); } Ok(()) diff --git a/substrate/frame/root-offences/Cargo.toml b/substrate/frame/root-offences/Cargo.toml index d57f2bc9db43..6d051bd89ebb 100644 --- a/substrate/frame/root-offences/Cargo.toml +++ b/substrate/frame/root-offences/Cargo.toml @@ -53,6 +53,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/substrate/frame/session/Cargo.toml b/substrate/frame/session/Cargo.toml index 57f3b326913f..ca777b137ee1 100644 --- a/substrate/frame/session/Cargo.toml +++ b/substrate/frame/session/Cargo.toml @@ -58,3 +58,11 @@ try-runtime = [ "pallet-timestamp/try-runtime", "sp-runtime/try-runtime", ] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "sp-staking/runtime-benchmarks", +] diff --git a/substrate/frame/session/benchmarking/Cargo.toml b/substrate/frame/session/benchmarking/Cargo.toml index 3e457fc3cf5e..b9380702d964 100644 --- a/substrate/frame/session/benchmarking/Cargo.toml +++ b/substrate/frame/session/benchmarking/Cargo.toml @@ -55,6 +55,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/substrate/frame/session/benchmarking/src/inner.rs b/substrate/frame/session/benchmarking/src/inner.rs index f3707763f350..bcff238d4ea0 100644 --- a/substrate/frame/session/benchmarking/src/inner.rs +++ b/substrate/frame/session/benchmarking/src/inner.rs @@ -23,7 +23,10 @@ use sp_runtime::traits::{One, StaticLookup, TrailingZeroInput}; use codec::Decode; use frame_benchmarking::v2::*; -use frame_support::traits::{Get, KeyOwnerProofSystem, OnInitialize}; +use frame_support::{ + assert_ok, + traits::{Get, KeyOwnerProofSystem, OnInitialize}, +}; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use pallet_session::{historical::Pallet as Historical, Pallet as Session, *}; use pallet_staking::{ @@ -66,6 +69,7 @@ mod benchmarks { // Whitelist controller account from further DB operations. let v_controller_key = frame_system::Account::::hashed_key_for(&v_controller); frame_benchmarking::benchmarking::add_to_whitelist(v_controller_key.into()); + assert_ok!(Session::::ensure_can_pay_key_deposit(&v_controller)); #[extrinsic_call] _(RawOrigin::Signed(v_controller), keys, proof); @@ -86,6 +90,7 @@ mod benchmarks { let v_controller = pallet_staking::Pallet::::bonded(&v_stash).ok_or("not stash")?; let keys = T::Keys::decode(&mut TrailingZeroInput::zeroes()).unwrap(); let proof: Vec = vec![0, 1, 2, 3]; + assert_ok!(Session::::ensure_can_pay_key_deposit(&v_controller)); Session::::set_keys(RawOrigin::Signed(v_controller.clone()).into(), keys, proof)?; // Whitelist controller account from further DB operations. let v_controller_key = frame_system::Account::::hashed_key_for(&v_controller); diff --git a/substrate/frame/session/benchmarking/src/mock.rs b/substrate/frame/session/benchmarking/src/mock.rs index 288bf56ad25e..5910772e6d0f 100644 --- a/substrate/frame/session/benchmarking/src/mock.rs +++ b/substrate/frame/session/benchmarking/src/mock.rs @@ -107,7 +107,9 @@ impl pallet_session::Config for Test { type DisablingStrategy = (); type WeightInfo = (); type Currency = Balances; - type KeyDeposit = (); + // Note: setting to a large amount to ensure bench setup can handle increasing the balance of + // the validator before setting session keys; see `ensure_can_pay_key_deposit`. + type KeyDeposit = ConstU64<2000000000>; } pallet_staking_reward_curve::build! { const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!( diff --git a/substrate/frame/session/src/lib.rs b/substrate/frame/session/src/lib.rs index bfa754013229..ffafbd540d18 100644 --- a/substrate/frame/session/src/lib.rs +++ b/substrate/frame/session/src/lib.rs @@ -129,7 +129,7 @@ use frame_support::{ dispatch::DispatchResult, ensure, traits::{ - fungible::{hold::Mutate as HoldMutate, Inspect}, + fungible::{hold::Mutate as HoldMutate, Inspect, Mutate}, Defensive, EstimateNextNewSession, EstimateNextSessionRotation, FindAuthor, Get, OneSessionHandler, ValidatorRegistration, ValidatorSet, }, @@ -447,7 +447,7 @@ pub mod pallet { type WeightInfo: WeightInfo; /// The currency type for placing holds when setting keys. - type Currency: Inspect + type Currency: Mutate + HoldMutate>; /// The amount to be held when setting keys. @@ -668,6 +668,25 @@ pub mod pallet { Ok(()) } } + + #[cfg(feature = "runtime-benchmarks")] + impl Pallet { + /// Mint enough funds into `who`, such that they can pay the session key setting deposit. + /// + /// Meant to be used if any pallet's benchmarking code wishes to set session keys, and wants + /// to make sure it will succeed. + pub fn ensure_can_pay_key_deposit(who: &T::AccountId) -> Result<(), DispatchError> { + use frame_support::traits::tokens::{Fortitude, Preservation}; + let deposit = T::KeyDeposit::get(); + let has = T::Currency::reducible_balance(who, Preservation::Protect, Fortitude::Force); + if let Some(deficit) = deposit.checked_sub(&has) { + T::Currency::mint_into(who, deficit.max(T::Currency::minimum_balance())) + .map(|_inc| ()) + } else { + Ok(()) + } + } + } } impl Pallet { diff --git a/substrate/frame/staking-async/ah-client/Cargo.toml b/substrate/frame/staking-async/ah-client/Cargo.toml index 6de8fea9b4cf..af87ccf174ea 100644 --- a/substrate/frame/staking-async/ah-client/Cargo.toml +++ b/substrate/frame/staking-async/ah-client/Cargo.toml @@ -45,6 +45,7 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking-async-rc-client/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", diff --git a/substrate/frame/staking-async/runtimes/parachain/Cargo.toml b/substrate/frame/staking-async/runtimes/parachain/Cargo.toml index 337f18a4c9a1..28156d8aed79 100644 --- a/substrate/frame/staking-async/runtimes/parachain/Cargo.toml +++ b/substrate/frame/staking-async/runtimes/parachain/Cargo.toml @@ -166,6 +166,7 @@ runtime-benchmarks = [ "pallet-proxy/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-staking-async-rc-client/runtime-benchmarks", "pallet-staking-async/runtime-benchmarks", "pallet-state-trie-migration/runtime-benchmarks", diff --git a/substrate/frame/staking-async/runtimes/rc/Cargo.toml b/substrate/frame/staking-async/runtimes/rc/Cargo.toml index bc0c48f5fc07..b98d7d3a03a6 100644 --- a/substrate/frame/staking-async/runtimes/rc/Cargo.toml +++ b/substrate/frame/staking-async/runtimes/rc/Cargo.toml @@ -268,6 +268,7 @@ runtime-benchmarks = [ "pallet-referenda/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", "pallet-session-benchmarking/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-staking-async-ah-client/runtime-benchmarks", "pallet-staking-async-rc-client/runtime-benchmarks", diff --git a/substrate/frame/staking-async/src/pallet/impls.rs b/substrate/frame/staking-async/src/pallet/impls.rs index 0aefbeeb8915..22f36e09a01a 100644 --- a/substrate/frame/staking-async/src/pallet/impls.rs +++ b/substrate/frame/staking-async/src/pallet/impls.rs @@ -73,16 +73,10 @@ use sp_runtime::TryRuntimeError; const NPOS_MAX_ITERATIONS_COEFFICIENT: u32 = 2; impl Pallet { - /// Returns the minimum required bond for participation, considering nominators, - /// and the chain’s existential deposit. - /// - /// This function computes the smallest allowed bond among `MinValidatorBond` and - /// `MinNominatorBond`, but ensures it is not below the existential deposit required to keep an - /// account alive. + /// Returns the minimum required bond for participation in staking as a chilled account. pub(crate) fn min_chilled_bond() -> BalanceOf { - MinValidatorBond::::get() - .min(MinNominatorBond::::get()) - .max(asset::existential_deposit::()) + // Note: in the future we might add a configurable `MinChilledBond`, else ED is good. + asset::existential_deposit::() } /// Returns the minimum required bond for participation in staking as a validator account. @@ -749,11 +743,6 @@ impl Pallet { .defensive_unwrap_or_default(); } Nominators::::insert(who, nominations); - - debug_assert_eq!( - Nominators::::count() + Validators::::count(), - T::VoterList::count() - ); } /// This function will remove a nominator from the `Nominators` storage map, @@ -773,11 +762,6 @@ impl Pallet { false }; - debug_assert_eq!( - Nominators::::count() + Validators::::count(), - T::VoterList::count() - ); - outcome } @@ -794,11 +778,6 @@ impl Pallet { let _ = T::VoterList::on_insert(who.clone(), Self::weight_of(who)); } Validators::::insert(who, prefs); - - debug_assert_eq!( - Nominators::::count() + Validators::::count(), - T::VoterList::count() - ); } /// This function will remove a validator from the `Validators` storage map. @@ -817,11 +796,6 @@ impl Pallet { false }; - debug_assert_eq!( - Nominators::::count() + Validators::::count(), - T::VoterList::count() - ); - outcome } diff --git a/substrate/frame/staking/Cargo.toml b/substrate/frame/staking/Cargo.toml index 58f6bea55567..c29818013187 100644 --- a/substrate/frame/staking/Cargo.toml +++ b/substrate/frame/staking/Cargo.toml @@ -71,6 +71,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-bags-list/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-session/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "rand_chacha", "sp-runtime/runtime-benchmarks", diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 2415857cb826..26be722d2177 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -317,6 +317,7 @@ runtime-benchmarks = [ "pallet-salary?/runtime-benchmarks", "pallet-scheduler?/runtime-benchmarks", "pallet-session-benchmarking?/runtime-benchmarks", + "pallet-session?/runtime-benchmarks", "pallet-skip-feeless-payment?/runtime-benchmarks", "pallet-society?/runtime-benchmarks", "pallet-staking-async-ah-client?/runtime-benchmarks",