diff --git a/Cargo.lock b/Cargo.lock index 1e970c86d9..295a1cd6de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4989,6 +4989,7 @@ dependencies = [ "libsecp256k1", "pallet-assets", "pallet-balances", + "pallet-collator-selection", "pallet-contracts", "pallet-contracts-primitives", "pallet-dapp-staking-v3", @@ -7711,7 +7712,7 @@ dependencies = [ [[package]] name = "pallet-dapp-staking-v3" -version = "0.0.1-alpha" +version = "0.1.0" dependencies = [ "assert_matches", "astar-primitives", diff --git a/pallets/collator-selection/Cargo.toml b/pallets/collator-selection/Cargo.toml index 4374e602f4..0a217da070 100644 --- a/pallets/collator-selection/Cargo.toml +++ b/pallets/collator-selection/Cargo.toml @@ -59,6 +59,7 @@ std = [ "pallet-authorship/std", "pallet-session/std", "pallet-aura/std", + "pallet-balances/std", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/collator-selection/src/lib.rs b/pallets/collator-selection/src/lib.rs index 58c49e8866..59754c0d2a 100644 --- a/pallets/collator-selection/src/lib.rs +++ b/pallets/collator-selection/src/lib.rs @@ -109,6 +109,12 @@ pub mod pallet { } } + /// Used to check whether an account is allowed to be a candidate. + pub trait AccountCheck { + /// `true` if the account is allowed to be a candidate, `false` otherwise. + fn allowed_candidacy(account: &AccountId) -> bool; + } + /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] pub trait Config: frame_system::Config { @@ -157,6 +163,9 @@ pub mod pallet { /// How many in perc kicked collators should be slashed (set 0 to disable) type SlashRatio: Get; + /// Used to check whether an account is allowed to be a candidate. + type AccountCheck: AccountCheck; + /// The weight information of this pallet. type WeightInfo: WeightInfo; } @@ -287,6 +296,8 @@ pub mod pallet { NoAssociatedValidatorId, /// Validator ID is not yet registered ValidatorNotRegistered, + /// Account is now allowed to be a candidate due to an external reason (e.g. it might be participating in dApp staking) + NotAllowedCandidate, } #[pallet::hooks] @@ -375,6 +386,10 @@ pub mod pallet { !Self::invulnerables().contains(&who), Error::::AlreadyInvulnerable ); + ensure!( + T::AccountCheck::allowed_candidacy(&who), + Error::::NotAllowedCandidate + ); let validator_key = T::ValidatorIdOf::convert(who.clone()) .ok_or(Error::::NoAssociatedValidatorId)?; @@ -502,6 +517,11 @@ pub mod pallet { }) .collect::>() } + + /// Check whether an account is a candidate. + pub fn is_account_candidate(account: &T::AccountId) -> bool { + Self::candidates().iter().any(|c| &c.who == account) + } } /// Keep track of number of authored blocks per authority, uncles are counted as well since diff --git a/pallets/collator-selection/src/mock.rs b/pallets/collator-selection/src/mock.rs index 3ba37fac6f..27f4efc171 100644 --- a/pallets/collator-selection/src/mock.rs +++ b/pallets/collator-selection/src/mock.rs @@ -212,6 +212,15 @@ impl ValidatorRegistration for IsRegistered { } } +pub(crate) const BLACKLISTED_ACCOUNT: u64 = 987654321; + +pub struct DummyAccountCheck; +impl AccountCheck for DummyAccountCheck { + fn allowed_candidacy(account: &u64) -> bool { + *account != BLACKLISTED_ACCOUNT + } +} + impl Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -225,6 +234,7 @@ impl Config for Test { type ValidatorIdOf = IdentityCollator; type ValidatorRegistration = IsRegistered; type SlashRatio = SlashRatio; + type AccountCheck = DummyAccountCheck; type WeightInfo = (); } diff --git a/pallets/collator-selection/src/tests.rs b/pallets/collator-selection/src/tests.rs index dd60803912..a6e51f93d5 100644 --- a/pallets/collator-selection/src/tests.rs +++ b/pallets/collator-selection/src/tests.rs @@ -214,6 +214,16 @@ fn cannot_register_as_candidate_if_poor() { }); } +#[test] +fn cannot_register_candidate_if_externally_blacklisted() { + new_test_ext().execute_with(|| { + assert_noop!( + CollatorSelection::register_as_candidate(RuntimeOrigin::signed(BLACKLISTED_ACCOUNT)), + Error::::NotAllowedCandidate, + ); + }) +} + #[test] fn register_as_candidate_works() { new_test_ext().execute_with(|| { diff --git a/pallets/collator-selection/src/weights.rs b/pallets/collator-selection/src/weights.rs index 1a89e8d052..95ae3a2835 100644 --- a/pallets/collator-selection/src/weights.rs +++ b/pallets/collator-selection/src/weights.rs @@ -1,3 +1,4 @@ + // This file is part of Astar. // Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. @@ -15,19 +16,19 @@ // See the License for the specific language governing permissions and // limitations under the License. - //! Autogenerated weights for pallet_collator_selection //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-04, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 +//! DATE: 2024-02-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=shibuya-dev +// --chain=shiden-dev // --steps=50 // --repeat=20 // --pallet=pallet_collator_selection @@ -35,7 +36,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./benchmark-results/collator_selection_weights.rs +// --output=./benchmark-results/shiden-dev/collator_selection_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -43,7 +44,7 @@ #![allow(unused_imports)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; +use core::marker::PhantomData; /// Weight functions needed for pallet_collator_selection. pub trait WeightInfo { @@ -59,216 +60,248 @@ pub trait WeightInfo { /// Weights for pallet_collator_selection using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Session NextKeys (r:48 w:0) - // Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) - // Storage: CollatorSelection Invulnerables (r:0 w:1) - // Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Session NextKeys (r:48 w:0) + /// Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Invulnerables (r:0 w:1) + /// Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) /// The range of component `b` is `[1, 48]`. fn set_invulnerables(b: u32, ) -> Weight { - // Minimum execution time: 14_956 nanoseconds. - Weight::from_parts(15_730_242, 0) - .saturating_add(Weight::from_parts(0, 408)) - // Standard Error: 4_959 - .saturating_add(Weight::from_parts(2_577_606, 0).saturating_mul(b.into())) + // Proof Size summary in bytes: + // Measured: `204 + b * (79 ±0)` + // Estimated: `1194 + b * (2554 ±0)` + // Minimum execution time: 13_733_000 picoseconds. + Weight::from_parts(14_576_858, 1194) + // Standard Error: 4_742 + .saturating_add(Weight::from_parts(2_507_115, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_parts(0, 2633).saturating_mul(b.into())) + .saturating_add(Weight::from_parts(0, 2554).saturating_mul(b.into())) } - // Storage: CollatorSelection DesiredCandidates (r:0 w:1) - // Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection DesiredCandidates (r:0 w:1) + /// Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) fn set_desired_candidates() -> Weight { - // Minimum execution time: 7_042 nanoseconds. - Weight::from_parts(7_159_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_143_000 picoseconds. + Weight::from_parts(7_357_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: CollatorSelection CandidacyBond (r:0 w:1) - // Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection CandidacyBond (r:0 w:1) + /// Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) fn set_candidacy_bond() -> Weight { - // Minimum execution time: 7_245 nanoseconds. - Weight::from_parts(7_395_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_292_000 picoseconds. + Weight::from_parts(7_433_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection DesiredCandidates (r:1 w:0) - // Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection Invulnerables (r:1 w:0) - // Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) - // Storage: Session NextKeys (r:1 w:0) - // Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) - // Storage: CollatorSelection CandidacyBond (r:1 w:0) - // Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Candidates (r:1 w:1) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection DesiredCandidates (r:1 w:0) + /// Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection Invulnerables (r:1 w:0) + /// Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: DappStaking Ledger (r:1 w:0) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Session NextKeys (r:1 w:0) + /// Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection CandidacyBond (r:1 w:0) + /// Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 148]`. fn register_as_candidate(c: u32, ) -> Weight { - // Minimum execution time: 39_356 nanoseconds. - Weight::from_parts(42_616_377, 0) - .saturating_add(Weight::from_parts(0, 9891)) - // Standard Error: 670 - .saturating_add(Weight::from_parts(39_880, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Proof Size summary in bytes: + // Measured: `962 + c * (50 ±0)` + // Estimated: `4307 + c * (51 ±0)` + // Minimum execution time: 44_695_000 picoseconds. + Weight::from_parts(46_834_255, 4307) + // Standard Error: 586 + .saturating_add(Weight::from_parts(44_873, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 306).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 51).saturating_mul(c.into())) } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Candidates (r:1 w:1) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[6, 148]`. fn leave_intent(c: u32, ) -> Weight { - // Minimum execution time: 28_341 nanoseconds. - Weight::from_parts(30_119_984, 0) - .saturating_add(Weight::from_parts(0, 1369)) - // Standard Error: 1_581 - .saturating_add(Weight::from_parts(42_495, 0).saturating_mul(c.into())) + // Proof Size summary in bytes: + // Measured: `342 + c * (49 ±0)` + // Estimated: `1845 + c * (49 ±0)` + // Minimum execution time: 30_579_000 picoseconds. + Weight::from_parts(34_125_189, 1845) + // Standard Error: 1_048 + .saturating_add(Weight::from_parts(45_625, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 98).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 49).saturating_mul(c.into())) } - // Storage: System Account (r:2 w:2) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) fn note_author() -> Weight { - // Minimum execution time: 31_536 nanoseconds. - Weight::from_parts(31_986_000, 0) - .saturating_add(Weight::from_parts(0, 5497)) + // Proof Size summary in bytes: + // Measured: `226` + // Estimated: `6196` + // Minimum execution time: 43_377_000 picoseconds. + Weight::from_parts(43_827_000, 6196) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } - // Storage: CollatorSelection Candidates (r:1 w:0) - // Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection LastAuthoredBlock (r:148 w:0) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) - // Storage: CollatorSelection Invulnerables (r:1 w:0) - // Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) - // Storage: System Account (r:143 w:143) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: CollatorSelection SlashDestination (r:1 w:0) - // Proof Skipped: CollatorSelection SlashDestination (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection LastAuthoredBlock (r:148 w:0) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Invulnerables (r:1 w:0) + /// Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: System Account (r:143 w:143) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: CollatorSelection SlashDestination (r:1 w:0) + /// Proof Skipped: CollatorSelection SlashDestination (max_values: Some(1), max_size: None, mode: Measured) /// The range of component `r` is `[1, 148]`. /// The range of component `c` is `[1, 148]`. fn new_session(r: u32, c: u32, ) -> Weight { - // Minimum execution time: 16_816 nanoseconds. - Weight::from_parts(17_132_000, 0) - .saturating_add(Weight::from_parts(0, 4714)) - // Standard Error: 475_405 - .saturating_add(Weight::from_parts(15_758_567, 0).saturating_mul(c.into())) + // Proof Size summary in bytes: + // Measured: `3902 + c * (97 ±0) + r * (112 ±0)` + // Estimated: `3818 + c * (2632 ±2) + r * (2599 ±0)` + // Minimum execution time: 17_957_000 picoseconds. + Weight::from_parts(18_201_000, 3818) + // Standard Error: 564_328 + .saturating_add(Weight::from_parts(18_024_338, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) - .saturating_add(Weight::from_parts(0, 3131).saturating_mul(c.into())) - .saturating_add(Weight::from_parts(0, 2751).saturating_mul(r.into())) + .saturating_add(Weight::from_parts(0, 2632).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 2599).saturating_mul(r.into())) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Session NextKeys (r:48 w:0) - // Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) - // Storage: CollatorSelection Invulnerables (r:0 w:1) - // Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Session NextKeys (r:48 w:0) + /// Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Invulnerables (r:0 w:1) + /// Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) /// The range of component `b` is `[1, 48]`. fn set_invulnerables(b: u32, ) -> Weight { - // Minimum execution time: 14_956 nanoseconds. - Weight::from_parts(15_730_242, 0) - .saturating_add(Weight::from_parts(0, 408)) - // Standard Error: 4_959 - .saturating_add(Weight::from_parts(2_577_606, 0).saturating_mul(b.into())) + // Proof Size summary in bytes: + // Measured: `204 + b * (79 ±0)` + // Estimated: `1194 + b * (2554 ±0)` + // Minimum execution time: 13_733_000 picoseconds. + Weight::from_parts(14_576_858, 1194) + // Standard Error: 4_742 + .saturating_add(Weight::from_parts(2_507_115, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(b.into()))) .saturating_add(RocksDbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_parts(0, 2633).saturating_mul(b.into())) + .saturating_add(Weight::from_parts(0, 2554).saturating_mul(b.into())) } - // Storage: CollatorSelection DesiredCandidates (r:0 w:1) - // Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection DesiredCandidates (r:0 w:1) + /// Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) fn set_desired_candidates() -> Weight { - // Minimum execution time: 7_042 nanoseconds. - Weight::from_parts(7_159_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_143_000 picoseconds. + Weight::from_parts(7_357_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: CollatorSelection CandidacyBond (r:0 w:1) - // Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection CandidacyBond (r:0 w:1) + /// Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) fn set_candidacy_bond() -> Weight { - // Minimum execution time: 7_245 nanoseconds. - Weight::from_parts(7_395_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_292_000 picoseconds. + Weight::from_parts(7_433_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection DesiredCandidates (r:1 w:0) - // Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection Invulnerables (r:1 w:0) - // Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) - // Storage: Session NextKeys (r:1 w:0) - // Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) - // Storage: CollatorSelection CandidacyBond (r:1 w:0) - // Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Candidates (r:1 w:1) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection DesiredCandidates (r:1 w:0) + /// Proof Skipped: CollatorSelection DesiredCandidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection Invulnerables (r:1 w:0) + /// Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: DappStaking Ledger (r:1 w:0) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Session NextKeys (r:1 w:0) + /// Proof Skipped: Session NextKeys (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection CandidacyBond (r:1 w:0) + /// Proof Skipped: CollatorSelection CandidacyBond (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[1, 148]`. fn register_as_candidate(c: u32, ) -> Weight { - // Minimum execution time: 39_356 nanoseconds. - Weight::from_parts(42_616_377, 0) - .saturating_add(Weight::from_parts(0, 9891)) - // Standard Error: 670 - .saturating_add(Weight::from_parts(39_880, 0).saturating_mul(c.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) + // Proof Size summary in bytes: + // Measured: `962 + c * (50 ±0)` + // Estimated: `4307 + c * (51 ±0)` + // Minimum execution time: 44_695_000 picoseconds. + Weight::from_parts(46_834_255, 4307) + // Standard Error: 586 + .saturating_add(Weight::from_parts(44_873, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 306).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 51).saturating_mul(c.into())) } - // Storage: CollatorSelection Candidates (r:1 w:1) - // Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Candidates (r:1 w:1) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) /// The range of component `c` is `[6, 148]`. fn leave_intent(c: u32, ) -> Weight { - // Minimum execution time: 28_341 nanoseconds. - Weight::from_parts(30_119_984, 0) - .saturating_add(Weight::from_parts(0, 1369)) - // Standard Error: 1_581 - .saturating_add(Weight::from_parts(42_495, 0).saturating_mul(c.into())) + // Proof Size summary in bytes: + // Measured: `342 + c * (49 ±0)` + // Estimated: `1845 + c * (49 ±0)` + // Minimum execution time: 30_579_000 picoseconds. + Weight::from_parts(34_125_189, 1845) + // Standard Error: 1_048 + .saturating_add(Weight::from_parts(45_625, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 98).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 49).saturating_mul(c.into())) } - // Storage: System Account (r:2 w:2) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: CollatorSelection LastAuthoredBlock (r:0 w:1) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) fn note_author() -> Weight { - // Minimum execution time: 31_536 nanoseconds. - Weight::from_parts(31_986_000, 0) - .saturating_add(Weight::from_parts(0, 5497)) + // Proof Size summary in bytes: + // Measured: `226` + // Estimated: `6196` + // Minimum execution time: 43_377_000 picoseconds. + Weight::from_parts(43_827_000, 6196) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } - // Storage: CollatorSelection Candidates (r:1 w:0) - // Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) - // Storage: CollatorSelection LastAuthoredBlock (r:148 w:0) - // Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) - // Storage: CollatorSelection Invulnerables (r:1 w:0) - // Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) - // Storage: System Account (r:143 w:143) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: CollatorSelection SlashDestination (r:1 w:0) - // Proof Skipped: CollatorSelection SlashDestination (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CollatorSelection LastAuthoredBlock (r:148 w:0) + /// Proof Skipped: CollatorSelection LastAuthoredBlock (max_values: None, max_size: None, mode: Measured) + /// Storage: CollatorSelection Invulnerables (r:1 w:0) + /// Proof Skipped: CollatorSelection Invulnerables (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: System Account (r:143 w:143) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: CollatorSelection SlashDestination (r:1 w:0) + /// Proof Skipped: CollatorSelection SlashDestination (max_values: Some(1), max_size: None, mode: Measured) /// The range of component `r` is `[1, 148]`. /// The range of component `c` is `[1, 148]`. fn new_session(r: u32, c: u32, ) -> Weight { - // Minimum execution time: 16_816 nanoseconds. - Weight::from_parts(17_132_000, 0) - .saturating_add(Weight::from_parts(0, 4714)) - // Standard Error: 475_405 - .saturating_add(Weight::from_parts(15_758_567, 0).saturating_mul(c.into())) + // Proof Size summary in bytes: + // Measured: `3902 + c * (97 ±0) + r * (112 ±0)` + // Estimated: `3818 + c * (2632 ±2) + r * (2599 ±0)` + // Minimum execution time: 17_957_000 picoseconds. + Weight::from_parts(18_201_000, 3818) + // Standard Error: 564_328 + .saturating_add(Weight::from_parts(18_024_338, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) - .saturating_add(Weight::from_parts(0, 3131).saturating_mul(c.into())) - .saturating_add(Weight::from_parts(0, 2751).saturating_mul(r.into())) + .saturating_add(Weight::from_parts(0, 2632).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 2599).saturating_mul(r.into())) } -} \ No newline at end of file +} diff --git a/pallets/dapp-staking-migration/src/lib.rs b/pallets/dapp-staking-migration/src/lib.rs index a49ad9021c..68dc8c0230 100644 --- a/pallets/dapp-staking-migration/src/lib.rs +++ b/pallets/dapp-staking-migration/src/lib.rs @@ -168,7 +168,7 @@ pub mod pallet { impl Pallet { /// Execute migrations steps until the specified weight limit has been consumed. /// - /// Depending on the number of entries migrated and/or deleted, appropriate events are emited. + /// Depending on the number of entries migrated and/or deleted, appropriate events are emitted. /// /// In case at least some progress is made, `Ok(_)` is returned. /// If no progress is made, `Err(_)` is returned. @@ -295,7 +295,7 @@ pub mod pallet { /// Steps: /// 1. Attempt to `drain` a single DB entry from the old storage. If it's unregistered, move on. /// 2. Unreserve the old `RegisterDeposit` amount from the developer account. - /// 2. Re-decode old smart contract type into new one. Operation should be infalible in practice since the same underlying type is used. + /// 2. Re-decode old smart contract type into new one. Operation should be infallible in practice since the same underlying type is used. /// 3. `register` the old-new smart contract into dApp staking v3 pallet. /// /// Returns `Ok(_)` if an entry was migrated, `Err(_)` if there are no more entries to migrate. @@ -348,13 +348,6 @@ pub mod pallet { smart_contract, error, ); - - // This should never happen, but if it does, we want to know about it. - #[cfg(feature = "try-runtime")] - panic!( - "Failed to register smart contract: {:?} with error: {:?}.", - smart_contract, error - ); } } @@ -383,7 +376,7 @@ pub mod pallet { let locked = old_account_ledger.locked; // Old unbonding amount can just be released, to keep things simple. - // Alternative is to re-calculat this into unlocking chunks. + // Alternative is to re-calculate this into unlocking chunks. let _total_unbonding = old_account_ledger.unbonding_info.sum(); ::Currency::remove_lock( @@ -430,7 +423,7 @@ pub mod pallet { /// Used to remove one entry from the old _dapps_staking_v2_ storage. /// /// If there are no more entries to remove, returns `Err(_)` with consumed weight and number of deleted entries. - /// Otherwise returns `Ok(_)` with consumed weight and number of consumed enries. + /// Otherwise returns `Ok(_)` with consumed weight and number of consumed entries. pub(crate) fn cleanup_old_storage(limit: u32) -> Result<(Weight, u32), (Weight, u32)> { let hashed_prefix = twox_128(pallet_dapps_staking::Pallet::::name().as_bytes()); @@ -474,8 +467,8 @@ pub mod pallet { /// Min allowed weight that migration should be allowed to consume. /// - /// This serves as a safety marging, to prevent accidental overspending, due to - /// inprecision in implementation or benchmarks, when small weight limit is specified. + /// This serves as a safety margin, to prevent accidental overspending, due to + /// imprecision in implementation or benchmarks, when small weight limit is specified. pub(crate) fn min_call_weight() -> Weight { // 5% of block should be fine T::BlockWeights::get().max_block / 10 diff --git a/pallets/dapp-staking-migration/src/mock.rs b/pallets/dapp-staking-migration/src/mock.rs index a3de9ef81f..262c0ce340 100644 --- a/pallets/dapp-staking-migration/src/mock.rs +++ b/pallets/dapp-staking-migration/src/mock.rs @@ -182,6 +182,7 @@ impl pallet_dapp_staking_v3::Config for Test { type StakingRewardHandler = DummyStakingRewardHandler; type CycleConfiguration = DummyCycleConfiguration; type Observers = (); + type AccountCheck = (); type EraRewardSpanLength = ConstU32<8>; type RewardRetentionInPeriods = ConstU32<2>; type MaxNumberOfContracts = ConstU32<10>; diff --git a/pallets/dapp-staking-v3/Cargo.toml b/pallets/dapp-staking-v3/Cargo.toml index c79755828d..2f06a1a054 100644 --- a/pallets/dapp-staking-v3/Cargo.toml +++ b/pallets/dapp-staking-v3/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-dapp-staking-v3" -version = "0.0.1-alpha" +version = "0.1.0" description = "Pallet for dApp staking v3 protocol" authors.workspace = true edition.workspace = true diff --git a/pallets/dapp-staking-v3/src/benchmarking/mod.rs b/pallets/dapp-staking-v3/src/benchmarking/mod.rs index fbe1a97b9a..af1cf1034a 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/mod.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/mod.rs @@ -151,7 +151,7 @@ mod benchmarks { } #[benchmark] - fn lock() { + fn lock_new_account() { initial_config::(); let staker: T::AccountId = whitelisted_caller(); @@ -167,7 +167,7 @@ mod benchmarks { T::BenchmarkHelper::set_balance(&staker, amount); #[extrinsic_call] - _(RawOrigin::Signed(staker.clone()), amount); + lock(RawOrigin::Signed(staker.clone()), amount); assert_last_event::( Event::::Locked { @@ -178,6 +178,39 @@ mod benchmarks { ); } + #[benchmark] + fn lock_existing_account() { + initial_config::(); + + let staker: T::AccountId = whitelisted_caller(); + let owner: T::AccountId = account("dapp_owner", 0, SEED); + let smart_contract = T::BenchmarkHelper::get_smart_contract(1); + assert_ok!(DappStaking::::register( + RawOrigin::Root.into(), + owner.clone().into(), + smart_contract.clone(), + )); + + let amount_1 = T::MinimumLockedAmount::get(); + let amount_2 = 19; + T::BenchmarkHelper::set_balance(&staker, amount_1 + amount_2); + assert_ok!(DappStaking::::lock( + RawOrigin::Signed(staker.clone()).into(), + amount_1, + )); + + #[extrinsic_call] + lock(RawOrigin::Signed(staker.clone()), amount_2); + + assert_last_event::( + Event::::Locked { + account: staker, + amount: amount_2, + } + .into(), + ); + } + #[benchmark] fn unlock() { initial_config::(); diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index 8bf1e0d36e..ff243de881 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -52,8 +52,8 @@ pub use sp_std::vec::Vec; use astar_primitives::{ dapp_staking::{ - CycleConfiguration, DAppId, EraNumber, Observer as DAppStakingObserver, PeriodNumber, - SmartContractHandle, StakingRewardHandler, TierId, + AccountCheck, CycleConfiguration, DAppId, EraNumber, Observer as DAppStakingObserver, + PeriodNumber, SmartContractHandle, StakingRewardHandler, TierId, }, oracle::PriceProvider, Balance, BlockNumber, @@ -144,6 +144,9 @@ pub mod pallet { /// dApp staking event observers, notified when certain events occur. type Observers: DAppStakingObserver; + /// Used to check whether an account is allowed to participate in dApp staking. + type AccountCheck: AccountCheck; + /// Maximum length of a single era reward span length entry. #[pallet::constant] type EraRewardSpanLength: Get; @@ -307,6 +310,8 @@ pub mod pallet { ZeroAmount, /// Total locked amount for staker is below minimum threshold. LockedAmountBelowThreshold, + /// Account is not allowed to participate in dApp staking due to some external reason (e.g. account is already a collator). + AccountNotAvailableForDappStaking, /// Cannot add additional unlocking chunks due to capacity limit. TooManyUnlockingChunks, /// Remaining stake prevents entire balance of starting the unlocking process. @@ -765,16 +770,30 @@ pub mod pallet { /// /// Locked amount can immediately be used for staking. #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::lock())] - pub fn lock(origin: OriginFor, #[pallet::compact] amount: Balance) -> DispatchResult { + #[pallet::weight(T::WeightInfo::lock_new_account().max(T::WeightInfo::lock_existing_account()))] + pub fn lock( + origin: OriginFor, + #[pallet::compact] amount: Balance, + ) -> DispatchResultWithPostInfo { Self::ensure_pallet_enabled()?; let account = ensure_signed(origin)?; let mut ledger = Ledger::::get(&account); + // Only do the check for new accounts. + // External logic should ensure that accounts which are already participating in dApp staking aren't + // allowed to participate elsewhere where they shouldn't. + let is_new_account = ledger.is_empty(); + if is_new_account { + ensure!( + T::AccountCheck::allowed_to_stake(&account), + Error::::AccountNotAvailableForDappStaking + ); + } + // Calculate & check amount available for locking let available_balance = - T::Currency::balance(&account).saturating_sub(ledger.active_locked_amount()); + T::Currency::total_balance(&account).saturating_sub(ledger.active_locked_amount()); let amount_to_lock = available_balance.min(amount); ensure!(!amount_to_lock.is_zero(), Error::::ZeroAmount); @@ -795,7 +814,12 @@ pub mod pallet { amount: amount_to_lock, }); - Ok(()) + Ok(Some(if is_new_account { + T::WeightInfo::lock_new_account() + } else { + T::WeightInfo::lock_existing_account() + }) + .into()) } /// Attempts to start the unlocking process for the specified amount. @@ -1557,6 +1581,11 @@ pub mod pallet { } impl Pallet { + /// `true` if the account is a staker, `false` otherwise. + pub fn is_staker(account: &T::AccountId) -> bool { + Ledger::::contains_key(account) + } + /// `Err` if pallet disabled for maintenance, `Ok` otherwise. pub(crate) fn ensure_pallet_enabled() -> Result<(), Error> { if ActiveProtocolState::::get().maintenance { diff --git a/pallets/dapp-staking-v3/src/test/mock.rs b/pallets/dapp-staking-v3/src/test/mock.rs index 1be4b46eab..ae7e1c5046 100644 --- a/pallets/dapp-staking-v3/src/test/mock.rs +++ b/pallets/dapp-staking-v3/src/test/mock.rs @@ -193,6 +193,14 @@ impl DappStakingObserver for DummyDappStakingObserver { } } +pub(crate) const BLACKLISTED_ACCOUNT: AccountId = 789456123; +pub struct DummyAccountCheck; +impl AccountCheck for DummyAccountCheck { + fn allowed_to_stake(account: &AccountId) -> bool { + *account != BLACKLISTED_ACCOUNT + } +} + impl pallet_dapp_staking::Config for Test { type RuntimeEvent = RuntimeEvent; type RuntimeFreezeReason = RuntimeFreezeReason; @@ -203,6 +211,7 @@ impl pallet_dapp_staking::Config for Test { type StakingRewardHandler = DummyStakingRewardHandler; type CycleConfiguration = DummyCycleConfiguration; type Observers = DummyDappStakingObserver; + type AccountCheck = DummyAccountCheck; type EraRewardSpanLength = ConstU32<8>; type RewardRetentionInPeriods = ConstU32<2>; type MaxNumberOfContracts = ConstU32<10>; diff --git a/pallets/dapp-staking-v3/src/test/testing_utils.rs b/pallets/dapp-staking-v3/src/test/testing_utils.rs index 6c4cf6f9d9..5ddb48bf4f 100644 --- a/pallets/dapp-staking-v3/src/test/testing_utils.rs +++ b/pallets/dapp-staking-v3/src/test/testing_utils.rs @@ -26,7 +26,7 @@ use crate::{ use frame_support::{ assert_ok, - traits::{fungible::InspectFreeze, Get, OnIdle}, + traits::{fungible::InspectFreeze, Currency, Get, OnIdle}, weights::Weight, }; use sp_runtime::{traits::Zero, Perbill}; @@ -208,11 +208,11 @@ pub(crate) fn assert_unregister(smart_contract: &MockSmartContract) { pub(crate) fn assert_lock(account: AccountId, amount: Balance) { let pre_snapshot = MemorySnapshot::new(); - let free_balance = Balances::free_balance(&account); + let total_balance = Balances::total_balance(&account); let locked_balance = pre_snapshot.locked_balance(&account); let init_frozen_balance = Balances::balance_frozen(&FreezeReason::DAppStaking.into(), &account); - let available_balance = free_balance + let available_balance = total_balance .checked_sub(locked_balance) .expect("Locked amount cannot be greater than available free balance"); let expected_lock_amount = available_balance.min(amount); diff --git a/pallets/dapp-staking-v3/src/test/tests.rs b/pallets/dapp-staking-v3/src/test/tests.rs index dc00bddd63..5f83eb7b52 100644 --- a/pallets/dapp-staking-v3/src/test/tests.rs +++ b/pallets/dapp-staking-v3/src/test/tests.rs @@ -25,7 +25,10 @@ use crate::{ use frame_support::{ assert_noop, assert_ok, assert_storage_noop, error::BadOrigin, - traits::{fungible::Unbalanced as FunUnbalanced, Currency, Get, OnFinalize, OnInitialize}, + traits::{ + fungible::Unbalanced as FunUnbalanced, Currency, Get, OnFinalize, OnInitialize, + ReservableCurrency, + }, }; use sp_runtime::traits::Zero; @@ -473,7 +476,7 @@ fn lock_is_ok() { ExtBuilder::build().execute_with(|| { // Lock some amount let locker = 2; - let free_balance = Balances::free_balance(&locker); + let free_balance = Balances::total_balance(&locker); assert!(free_balance > 500, "Sanity check"); assert_lock(locker, 100); assert_lock(locker, 200); @@ -487,6 +490,25 @@ fn lock_is_ok() { }) } +#[test] +fn lock_with_reserve_is_ok() { + ExtBuilder::build().execute_with(|| { + // Prepare locker account + let locker = 30; + let minimum_locked_amount: Balance = ::MinimumLockedAmount::get(); + Balances::make_free_balance_be(&locker, minimum_locked_amount); + assert_ok!(Balances::reserve(&locker, 1)); + assert_eq!( + Balances::free_balance(&locker), + minimum_locked_amount - 1, + "Sanity check post-reserve." + ); + + // Lock must still work since account is not blacklisted and has enough total balance to cover the lock requirement + assert_lock(locker, minimum_locked_amount); + }) +} + #[test] fn lock_with_incorrect_amount_fails() { ExtBuilder::build().execute_with(|| { @@ -499,7 +521,7 @@ fn lock_with_incorrect_amount_fails() { // Attempting to lock something after everything has been locked is same // as attempting to lock with "nothing" let locker = 1; - assert_lock(locker, Balances::free_balance(&locker)); + assert_lock(locker, Balances::total_balance(&locker)); assert_noop!( DappStaking::lock(RuntimeOrigin::signed(locker), 1), Error::::ZeroAmount, @@ -515,6 +537,18 @@ fn lock_with_incorrect_amount_fails() { }) } +#[test] +fn lock_with_blacklisted_account_fails() { + ExtBuilder::build().execute_with(|| { + Balances::make_free_balance_be(&BLACKLISTED_ACCOUNT, 100000); + + assert_noop!( + DappStaking::lock(RuntimeOrigin::signed(BLACKLISTED_ACCOUNT), 1000), + Error::::AccountNotAvailableForDappStaking, + ); + }) +} + #[test] fn unbond_and_unstake_is_ok() { ExtBuilder::build().execute_with(|| { diff --git a/pallets/dapp-staking-v3/src/weights.rs b/pallets/dapp-staking-v3/src/weights.rs index 624f90020c..e1013f4c2f 100644 --- a/pallets/dapp-staking-v3/src/weights.rs +++ b/pallets/dapp-staking-v3/src/weights.rs @@ -20,16 +20,16 @@ //! Autogenerated weights for pallet_dapp_staking_v3 //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-01-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain=shibuya-dev +// --chain=shiden-dev // --steps=50 // --repeat=20 // --pallet=pallet_dapp_staking_v3 @@ -37,7 +37,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./benchmark-results/shibuya-dev/dapp_staking_v3_weights.rs +// --output=./benchmark-results/shiden-dev/dapp_staking_v3_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -54,7 +54,8 @@ pub trait WeightInfo { fn set_dapp_reward_beneficiary() -> Weight; fn set_dapp_owner() -> Weight; fn unregister() -> Weight; - fn lock() -> Weight; + fn lock_new_account() -> Weight; + fn lock_existing_account() -> Weight; fn unlock() -> Weight; fn claim_unlocked(x: u32, ) -> Weight; fn relock_unlocking() -> Weight; @@ -81,11 +82,11 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_765_000 picoseconds. - Weight::from_parts(9_104_000, 0) + // Minimum execution time: 8_967_000 picoseconds. + Weight::from_parts(9_242_000, 0) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking NextDAppId (r:1 w:1) @@ -93,46 +94,67 @@ impl WeightInfo for SubstrateWeight { fn register() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3091` - // Minimum execution time: 17_156_000 picoseconds. - Weight::from_parts(17_426_000, 3091) + // Estimated: `3086` + // Minimum execution time: 17_044_000 picoseconds. + Weight::from_parts(17_328_000, 3086) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) fn set_dapp_reward_beneficiary() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 13_565_000 picoseconds. - Weight::from_parts(13_804_000, 3091) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_369_000 picoseconds. + Weight::from_parts(13_617_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) fn set_dapp_owner() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 13_824_000 picoseconds. - Weight::from_parts(14_132_000, 3091) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_421_000 picoseconds. + Weight::from_parts(13_692_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:0 w:1) /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) fn unregister() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 17_255_000 picoseconds. - Weight::from_parts(17_659_000, 3091) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 18_458_000 picoseconds. + Weight::from_parts(18_864_000, 3086) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_new_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `138` + // Estimated: `4764` + // Minimum execution time: 62_743_000 picoseconds. + Weight::from_parts(64_992_000, 4764) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) @@ -142,12 +164,12 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - fn lock() -> Weight { + fn lock_existing_account() -> Weight { // Proof Size summary in bytes: - // Measured: `12` + // Measured: `158` // Estimated: `4764` - // Minimum execution time: 33_281_000 picoseconds. - Weight::from_parts(33_759_000, 4764) + // Minimum execution time: 38_250_000 picoseconds. + Weight::from_parts(38_835_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -161,10 +183,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn unlock() -> Weight { // Proof Size summary in bytes: - // Measured: `156` + // Measured: `158` // Estimated: `4764` - // Minimum execution time: 34_451_000 picoseconds. - Weight::from_parts(34_926_000, 4764) + // Minimum execution time: 34_582_000 picoseconds. + Weight::from_parts(35_126_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -176,15 +198,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// The range of component `x` is `[0, 8]`. + /// The range of component `x` is `[0, 16]`. fn claim_unlocked(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `187` + // Measured: `191` // Estimated: `4764` - // Minimum execution time: 37_641_000 picoseconds. - Weight::from_parts(38_890_045, 4764) - // Standard Error: 7_639 - .saturating_add(Weight::from_parts(183_994, 0).saturating_mul(x.into())) + // Minimum execution time: 37_740_000 picoseconds. + Weight::from_parts(39_064_684, 4764) + // Standard Error: 2_750 + .saturating_add(Weight::from_parts(120_539, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -198,15 +220,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn relock_unlocking() -> Weight { // Proof Size summary in bytes: - // Measured: `182` + // Measured: `200` // Estimated: `4764` - // Minimum execution time: 33_528_000 picoseconds. - Weight::from_parts(33_929_000, 4764) + // Minimum execution time: 33_298_000 picoseconds. + Weight::from_parts(33_903_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) @@ -221,15 +243,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn stake() -> Weight { // Proof Size summary in bytes: - // Measured: `250` + // Measured: `251` // Estimated: `4764` - // Minimum execution time: 45_984_000 picoseconds. - Weight::from_parts(46_329_000, 4764) + // Minimum execution time: 44_905_000 picoseconds. + Weight::from_parts(45_261_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) @@ -244,10 +266,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn unstake() -> Weight { // Proof Size summary in bytes: - // Measured: `427` + // Measured: `432` // Estimated: `4764` - // Minimum execution time: 48_584_000 picoseconds. - Weight::from_parts(49_635_000, 4764) + // Minimum execution time: 48_594_000 picoseconds. + Weight::from_parts(49_441_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -264,12 +286,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_past_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `560` + // Measured: `541` // Estimated: `4764` - // Minimum execution time: 51_711_000 picoseconds. - Weight::from_parts(50_255_137, 4764) - // Standard Error: 5_418 - .saturating_add(Weight::from_parts(3_166_243, 0).saturating_mul(x.into())) + // Minimum execution time: 52_182_000 picoseconds. + Weight::from_parts(50_073_700, 4764) + // Standard Error: 4_907 + .saturating_add(Weight::from_parts(3_301_788, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -284,12 +306,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `501` + // Measured: `519` // Estimated: `4764` - // Minimum execution time: 48_656_000 picoseconds. - Weight::from_parts(46_590_994, 4764) - // Standard Error: 4_829 - .saturating_add(Weight::from_parts(3_197_956, 0).saturating_mul(x.into())) + // Minimum execution time: 49_637_000 picoseconds. + Weight::from_parts(47_809_537, 4764) + // Standard Error: 5_850 + .saturating_add(Weight::from_parts(3_304_857, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -301,28 +323,28 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) fn claim_bonus_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `267` + // Measured: `271` // Estimated: `3775` - // Minimum execution time: 41_921_000 picoseconds. - Weight::from_parts(42_440_000, 3775) + // Minimum execution time: 41_926_000 picoseconds. + Weight::from_parts(42_718_000, 3775) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking DAppTiers (r:1 w:1) /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2585` + // Measured: `2584` // Estimated: `5048` - // Minimum execution time: 58_409_000 picoseconds. - Weight::from_parts(60_103_000, 5048) + // Minimum execution time: 57_183_000 picoseconds. + Weight::from_parts(58_197_000, 5048) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) @@ -335,14 +357,14 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn unstake_from_unregistered() -> Weight { // Proof Size summary in bytes: - // Measured: `389` + // Measured: `318` // Estimated: `4764` - // Minimum execution time: 43_579_000 picoseconds. - Weight::from_parts(44_128_000, 4764) + // Minimum execution time: 41_858_000 picoseconds. + Weight::from_parts(42_476_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } - /// Storage: DappStaking StakerInfo (r:9 w:8) + /// Storage: DappStaking StakerInfo (r:17 w:16) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) @@ -350,15 +372,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 8]`. + /// The range of component `x` is `[1, 16]`. fn cleanup_expired_entries(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `255 + x * (69 ±0)` + // Measured: `256 + x * (69 ±0)` // Estimated: `4764 + x * (2613 ±0)` - // Minimum execution time: 43_019_000 picoseconds. - Weight::from_parts(39_628_074, 4764) - // Standard Error: 15_327 - .saturating_add(Weight::from_parts(4_990_892, 0).saturating_mul(x.into())) + // Minimum execution time: 43_103_000 picoseconds. + Weight::from_parts(39_876_215, 4764) + // Standard Error: 8_123 + .saturating_add(Weight::from_parts(5_014_232, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -369,8 +391,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_301_000 picoseconds. - Weight::from_parts(11_607_000, 0) + // Minimum execution time: 11_543_000 picoseconds. + Weight::from_parts(11_735_000, 0) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) @@ -380,8 +402,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `16` // Estimated: `4254` - // Minimum execution time: 17_997_000 picoseconds. - Weight::from_parts(18_491_000, 4254) + // Minimum execution time: 17_687_000 picoseconds. + Weight::from_parts(18_283_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -401,10 +423,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `627` + // Measured: `839` // Estimated: `4254` - // Minimum execution time: 45_396_000 picoseconds. - Weight::from_parts(46_230_000, 4254) + // Minimum execution time: 47_901_000 picoseconds. + Weight::from_parts(49_554_000, 4254) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -418,8 +440,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `68` // Estimated: `4254` - // Minimum execution time: 24_161_000 picoseconds. - Weight::from_parts(24_565_000, 4254) + // Minimum execution time: 23_705_000 picoseconds. + Weight::from_parts(24_313_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -432,10 +454,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 7_878_000 picoseconds. - Weight::from_parts(12_213_692, 3061) - // Standard Error: 3_051 - .saturating_add(Weight::from_parts(2_363_936, 0).saturating_mul(x.into())) + // Minimum execution time: 7_549_000 picoseconds. + Weight::from_parts(12_476_634, 3061) + // Standard Error: 3_594 + .saturating_add(Weight::from_parts(2_387_577, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -450,8 +472,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 8_839_000 picoseconds. - Weight::from_parts(8_975_000, 4254) + // Minimum execution time: 8_529_000 picoseconds. + Weight::from_parts(8_772_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -463,11 +485,11 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_765_000 picoseconds. - Weight::from_parts(9_104_000, 0) + // Minimum execution time: 8_967_000 picoseconds. + Weight::from_parts(9_242_000, 0) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking NextDAppId (r:1 w:1) @@ -475,46 +497,67 @@ impl WeightInfo for () { fn register() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3091` - // Minimum execution time: 17_156_000 picoseconds. - Weight::from_parts(17_426_000, 3091) + // Estimated: `3086` + // Minimum execution time: 17_044_000 picoseconds. + Weight::from_parts(17_328_000, 3086) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) fn set_dapp_reward_beneficiary() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 13_565_000 picoseconds. - Weight::from_parts(13_804_000, 3091) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_369_000 picoseconds. + Weight::from_parts(13_617_000, 3086) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) fn set_dapp_owner() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 13_824_000 picoseconds. - Weight::from_parts(14_132_000, 3091) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_421_000 picoseconds. + Weight::from_parts(13_692_000, 3086) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:0 w:1) /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) fn unregister() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 17_255_000 picoseconds. - Weight::from_parts(17_659_000, 3091) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 18_458_000 picoseconds. + Weight::from_parts(18_864_000, 3086) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_new_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `138` + // Estimated: `4764` + // Minimum execution time: 62_743_000 picoseconds. + Weight::from_parts(64_992_000, 4764) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) @@ -524,12 +567,12 @@ impl WeightInfo for () { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - fn lock() -> Weight { + fn lock_existing_account() -> Weight { // Proof Size summary in bytes: - // Measured: `12` + // Measured: `158` // Estimated: `4764` - // Minimum execution time: 33_281_000 picoseconds. - Weight::from_parts(33_759_000, 4764) + // Minimum execution time: 38_250_000 picoseconds. + Weight::from_parts(38_835_000, 4764) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -543,10 +586,10 @@ impl WeightInfo for () { /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn unlock() -> Weight { // Proof Size summary in bytes: - // Measured: `156` + // Measured: `158` // Estimated: `4764` - // Minimum execution time: 34_451_000 picoseconds. - Weight::from_parts(34_926_000, 4764) + // Minimum execution time: 34_582_000 picoseconds. + Weight::from_parts(35_126_000, 4764) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -558,15 +601,15 @@ impl WeightInfo for () { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// The range of component `x` is `[0, 8]`. + /// The range of component `x` is `[0, 16]`. fn claim_unlocked(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `187` + // Measured: `191` // Estimated: `4764` - // Minimum execution time: 37_641_000 picoseconds. - Weight::from_parts(38_890_045, 4764) - // Standard Error: 7_639 - .saturating_add(Weight::from_parts(183_994, 0).saturating_mul(x.into())) + // Minimum execution time: 37_740_000 picoseconds. + Weight::from_parts(39_064_684, 4764) + // Standard Error: 2_750 + .saturating_add(Weight::from_parts(120_539, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -580,15 +623,15 @@ impl WeightInfo for () { /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn relock_unlocking() -> Weight { // Proof Size summary in bytes: - // Measured: `182` + // Measured: `200` // Estimated: `4764` - // Minimum execution time: 33_528_000 picoseconds. - Weight::from_parts(33_929_000, 4764) + // Minimum execution time: 33_298_000 picoseconds. + Weight::from_parts(33_903_000, 4764) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) @@ -603,15 +646,15 @@ impl WeightInfo for () { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn stake() -> Weight { // Proof Size summary in bytes: - // Measured: `250` + // Measured: `251` // Estimated: `4764` - // Minimum execution time: 45_984_000 picoseconds. - Weight::from_parts(46_329_000, 4764) + // Minimum execution time: 44_905_000 picoseconds. + Weight::from_parts(45_261_000, 4764) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) @@ -626,10 +669,10 @@ impl WeightInfo for () { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn unstake() -> Weight { // Proof Size summary in bytes: - // Measured: `427` + // Measured: `432` // Estimated: `4764` - // Minimum execution time: 48_584_000 picoseconds. - Weight::from_parts(49_635_000, 4764) + // Minimum execution time: 48_594_000 picoseconds. + Weight::from_parts(49_441_000, 4764) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -646,12 +689,12 @@ impl WeightInfo for () { /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_past_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `560` + // Measured: `541` // Estimated: `4764` - // Minimum execution time: 51_711_000 picoseconds. - Weight::from_parts(50_255_137, 4764) - // Standard Error: 5_418 - .saturating_add(Weight::from_parts(3_166_243, 0).saturating_mul(x.into())) + // Minimum execution time: 52_182_000 picoseconds. + Weight::from_parts(50_073_700, 4764) + // Standard Error: 4_907 + .saturating_add(Weight::from_parts(3_301_788, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -666,12 +709,12 @@ impl WeightInfo for () { /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `501` + // Measured: `519` // Estimated: `4764` - // Minimum execution time: 48_656_000 picoseconds. - Weight::from_parts(46_590_994, 4764) - // Standard Error: 4_829 - .saturating_add(Weight::from_parts(3_197_956, 0).saturating_mul(x.into())) + // Minimum execution time: 49_637_000 picoseconds. + Weight::from_parts(47_809_537, 4764) + // Standard Error: 5_850 + .saturating_add(Weight::from_parts(3_304_857, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -683,28 +726,28 @@ impl WeightInfo for () { /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) fn claim_bonus_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `267` + // Measured: `271` // Estimated: `3775` - // Minimum execution time: 41_921_000 picoseconds. - Weight::from_parts(42_440_000, 3775) + // Minimum execution time: 41_926_000 picoseconds. + Weight::from_parts(42_718_000, 3775) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking DAppTiers (r:1 w:1) /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2585` + // Measured: `2584` // Estimated: `5048` - // Minimum execution time: 58_409_000 picoseconds. - Weight::from_parts(60_103_000, 5048) + // Minimum execution time: 57_183_000 picoseconds. + Weight::from_parts(58_197_000, 5048) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) @@ -717,14 +760,14 @@ impl WeightInfo for () { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn unstake_from_unregistered() -> Weight { // Proof Size summary in bytes: - // Measured: `389` + // Measured: `318` // Estimated: `4764` - // Minimum execution time: 43_579_000 picoseconds. - Weight::from_parts(44_128_000, 4764) + // Minimum execution time: 41_858_000 picoseconds. + Weight::from_parts(42_476_000, 4764) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } - /// Storage: DappStaking StakerInfo (r:9 w:8) + /// Storage: DappStaking StakerInfo (r:17 w:16) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) @@ -732,15 +775,15 @@ impl WeightInfo for () { /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 8]`. + /// The range of component `x` is `[1, 16]`. fn cleanup_expired_entries(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `255 + x * (69 ±0)` + // Measured: `256 + x * (69 ±0)` // Estimated: `4764 + x * (2613 ±0)` - // Minimum execution time: 43_019_000 picoseconds. - Weight::from_parts(39_628_074, 4764) - // Standard Error: 15_327 - .saturating_add(Weight::from_parts(4_990_892, 0).saturating_mul(x.into())) + // Minimum execution time: 43_103_000 picoseconds. + Weight::from_parts(39_876_215, 4764) + // Standard Error: 8_123 + .saturating_add(Weight::from_parts(5_014_232, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(RocksDbWeight::get().writes(2_u64)) @@ -751,8 +794,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_301_000 picoseconds. - Weight::from_parts(11_607_000, 0) + // Minimum execution time: 11_543_000 picoseconds. + Weight::from_parts(11_735_000, 0) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) @@ -762,8 +805,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `16` // Estimated: `4254` - // Minimum execution time: 17_997_000 picoseconds. - Weight::from_parts(18_491_000, 4254) + // Minimum execution time: 17_687_000 picoseconds. + Weight::from_parts(18_283_000, 4254) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -783,10 +826,10 @@ impl WeightInfo for () { /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `627` + // Measured: `839` // Estimated: `4254` - // Minimum execution time: 45_396_000 picoseconds. - Weight::from_parts(46_230_000, 4254) + // Minimum execution time: 47_901_000 picoseconds. + Weight::from_parts(49_554_000, 4254) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) } @@ -800,8 +843,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `68` // Estimated: `4254` - // Minimum execution time: 24_161_000 picoseconds. - Weight::from_parts(24_565_000, 4254) + // Minimum execution time: 23_705_000 picoseconds. + Weight::from_parts(24_313_000, 4254) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -814,10 +857,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 7_878_000 picoseconds. - Weight::from_parts(12_213_692, 3061) - // Standard Error: 3_051 - .saturating_add(Weight::from_parts(2_363_936, 0).saturating_mul(x.into())) + // Minimum execution time: 7_549_000 picoseconds. + Weight::from_parts(12_476_634, 3061) + // Standard Error: 3_594 + .saturating_add(Weight::from_parts(2_387_577, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -832,8 +875,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 8_839_000 picoseconds. - Weight::from_parts(8_975_000, 4254) + // Minimum execution time: 8_529_000 picoseconds. + Weight::from_parts(8_772_000, 4254) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/precompiles/dapp-staking-v3/src/test/mock.rs b/precompiles/dapp-staking-v3/src/test/mock.rs index 36359b9457..f3b1a53e93 100644 --- a/precompiles/dapp-staking-v3/src/test/mock.rs +++ b/precompiles/dapp-staking-v3/src/test/mock.rs @@ -252,6 +252,7 @@ impl pallet_dapp_staking_v3::Config for Test { type StakingRewardHandler = DummyStakingRewardHandler; type CycleConfiguration = DummyCycleConfiguration; type Observers = (); + type AccountCheck = (); type EraRewardSpanLength = ConstU32<8>; type RewardRetentionInPeriods = ConstU32<2>; type MaxNumberOfContracts = ConstU32<10>; diff --git a/primitives/src/dapp_staking.rs b/primitives/src/dapp_staking.rs index ee6eeedfa5..23638089a7 100644 --- a/primitives/src/dapp_staking.rs +++ b/primitives/src/dapp_staking.rs @@ -160,3 +160,15 @@ impl SmartContractHandle for SmartContract { Self::Wasm(address) } } + +/// Used to check whether an account is allowed to participate in dApp staking or not. +pub trait AccountCheck { + /// `true` if the account is allowed to stake, `false` otherwise. + fn allowed_to_stake(account: &AccountId) -> bool; +} + +impl AccountCheck for () { + fn allowed_to_stake(_account: &AccountId) -> bool { + true + } +} diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index d381af295b..69c0a82561 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -138,7 +138,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("astar"), impl_name: create_runtime_str!("astar"), authoring_version: 1, - spec_version: 77, + spec_version: 78, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -427,6 +427,14 @@ parameter_types! { pub const KickThreshold: BlockNumber = 2 * HOURS; // 2 SessionPeriod } +pub struct CollatorSelectionAccountCheck; +impl pallet_collator_selection::AccountCheck for CollatorSelectionAccountCheck { + fn allowed_candidacy(_account: &AccountId) -> bool { + // TODO: update this when dApp staking v3 is integrated + true + } +} + impl pallet_collator_selection::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -441,6 +449,7 @@ impl pallet_collator_selection::Config for Runtime { type ValidatorIdOf = pallet_collator_selection::IdentityCollator; type ValidatorRegistration = Session; type SlashRatio = SlashRatio; + type AccountCheck = CollatorSelectionAccountCheck; type WeightInfo = pallet_collator_selection::weights::SubstrateWeight; } diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index 7455c99a88..7c5e0a6548 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -516,6 +516,7 @@ impl pallet_dapp_staking_v3::Config for Runtime { type StakingRewardHandler = Inflation; type CycleConfiguration = InflationCycleConfig; type Observers = Inflation; + type AccountCheck = (); type EraRewardSpanLength = ConstU32<8>; type RewardRetentionInPeriods = ConstU32<2>; type MaxNumberOfContracts = ConstU32<100>; diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index cf259dae79..4eb2866d9c 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -67,7 +67,10 @@ use sp_runtime::{ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use astar_primitives::{ - dapp_staking::{CycleConfiguration, DAppId, EraNumber, PeriodNumber, SmartContract, TierId}, + dapp_staking::{ + AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber, + PeriodNumber, SmartContract, TierId, + }, evm::{EvmRevertCodeHandler, HashedDefaultMappings}, xcm::AssetLocationIdConverter, Address, AssetId, BlockNumber, Hash, Header, Index, @@ -404,6 +407,13 @@ impl pallet_dapp_staking_v3::BenchmarkHelper, AccountId } } +pub struct AccountCheck; +impl DappStakingAccountCheck for AccountCheck { + fn allowed_to_stake(account: &AccountId) -> bool { + !CollatorSelection::is_account_candidate(account) + } +} + parameter_types! { pub const MinimumStakingAmount: Balance = 5 * SBY; } @@ -418,12 +428,13 @@ impl pallet_dapp_staking_v3::Config for Runtime { type StakingRewardHandler = Inflation; type CycleConfiguration = InflationCycleConfig; type Observers = Inflation; + type AccountCheck = AccountCheck; type EraRewardSpanLength = ConstU32<16>; - type RewardRetentionInPeriods = ConstU32<2>; // Low enough value so we can get some expired rewards during testing + type RewardRetentionInPeriods = ConstU32<2>; type MaxNumberOfContracts = ConstU32<500>; type MaxUnlockingChunks = ConstU32<8>; type MinimumLockedAmount = MinimumStakingAmount; - type UnlockingPeriod = ConstU32<4>; // Keep it low so it's easier to test + type UnlockingPeriod = ConstU32<4>; type MaxNumberOfStakedContracts = ConstU32<8>; type MinimumStakeAmount = MinimumStakingAmount; type NumberOfTiers = ConstU32<4>; @@ -540,6 +551,13 @@ parameter_types! { pub const KickThreshold: BlockNumber = 2 * HOURS; // 2 SessionPeriod } +pub struct CollatorSelectionAccountCheck; +impl pallet_collator_selection::AccountCheck for CollatorSelectionAccountCheck { + fn allowed_candidacy(account: &AccountId) -> bool { + !DappStaking::is_staker(account) + } +} + impl pallet_collator_selection::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -554,6 +572,7 @@ impl pallet_collator_selection::Config for Runtime { type ValidatorIdOf = pallet_collator_selection::IdentityCollator; type ValidatorRegistration = Session; type SlashRatio = SlashRatio; + type AccountCheck = CollatorSelectionAccountCheck; type WeightInfo = pallet_collator_selection::weights::SubstrateWeight; } diff --git a/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs b/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs index 88fdf31674..884f3ed120 100644 --- a/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs +++ b/runtime/shibuya/src/weights/pallet_dapp_staking_v3.rs @@ -55,11 +55,11 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_765_000 picoseconds. - Weight::from_parts(9_104_000, 0) + // Minimum execution time: 8_967_000 picoseconds. + Weight::from_parts(9_242_000, 0) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking NextDAppId (r:1 w:1) @@ -67,46 +67,67 @@ impl WeightInfo for SubstrateWeight { fn register() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3091` - // Minimum execution time: 17_156_000 picoseconds. - Weight::from_parts(17_426_000, 3091) + // Estimated: `3086` + // Minimum execution time: 17_044_000 picoseconds. + Weight::from_parts(17_328_000, 3086) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) fn set_dapp_reward_beneficiary() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 13_565_000 picoseconds. - Weight::from_parts(13_804_000, 3091) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_369_000 picoseconds. + Weight::from_parts(13_617_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) fn set_dapp_owner() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 13_824_000 picoseconds. - Weight::from_parts(14_132_000, 3091) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_421_000 picoseconds. + Weight::from_parts(13_692_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: DappStaking ContractStake (r:0 w:1) /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) fn unregister() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3091` - // Minimum execution time: 17_255_000 picoseconds. - Weight::from_parts(17_659_000, 3091) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 18_458_000 picoseconds. + Weight::from_parts(18_864_000, 3086) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_new_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `138` + // Estimated: `4764` + // Minimum execution time: 62_743_000 picoseconds. + Weight::from_parts(64_992_000, 4764) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) @@ -116,12 +137,12 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - fn lock() -> Weight { + fn lock_existing_account() -> Weight { // Proof Size summary in bytes: - // Measured: `12` + // Measured: `158` // Estimated: `4764` - // Minimum execution time: 33_281_000 picoseconds. - Weight::from_parts(33_759_000, 4764) + // Minimum execution time: 38_250_000 picoseconds. + Weight::from_parts(38_835_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -135,10 +156,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn unlock() -> Weight { // Proof Size summary in bytes: - // Measured: `156` + // Measured: `158` // Estimated: `4764` - // Minimum execution time: 34_451_000 picoseconds. - Weight::from_parts(34_926_000, 4764) + // Minimum execution time: 34_582_000 picoseconds. + Weight::from_parts(35_126_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -150,15 +171,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - /// The range of component `x` is `[0, 8]`. + /// The range of component `x` is `[0, 16]`. fn claim_unlocked(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `187` + // Measured: `191` // Estimated: `4764` - // Minimum execution time: 37_641_000 picoseconds. - Weight::from_parts(38_890_045, 4764) - // Standard Error: 7_639 - .saturating_add(Weight::from_parts(183_994, 0).saturating_mul(x.into())) + // Minimum execution time: 37_740_000 picoseconds. + Weight::from_parts(39_064_684, 4764) + // Standard Error: 2_750 + .saturating_add(Weight::from_parts(120_539, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -172,15 +193,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) fn relock_unlocking() -> Weight { // Proof Size summary in bytes: - // Measured: `182` + // Measured: `200` // Estimated: `4764` - // Minimum execution time: 33_528_000 picoseconds. - Weight::from_parts(33_929_000, 4764) + // Minimum execution time: 33_298_000 picoseconds. + Weight::from_parts(33_903_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) @@ -195,15 +216,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn stake() -> Weight { // Proof Size summary in bytes: - // Measured: `250` + // Measured: `251` // Estimated: `4764` - // Minimum execution time: 45_984_000 picoseconds. - Weight::from_parts(46_329_000, 4764) + // Minimum execution time: 44_905_000 picoseconds. + Weight::from_parts(45_261_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) @@ -218,10 +239,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn unstake() -> Weight { // Proof Size summary in bytes: - // Measured: `427` + // Measured: `432` // Estimated: `4764` - // Minimum execution time: 48_584_000 picoseconds. - Weight::from_parts(49_635_000, 4764) + // Minimum execution time: 48_594_000 picoseconds. + Weight::from_parts(49_441_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -238,12 +259,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_past_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `560` + // Measured: `541` // Estimated: `4764` - // Minimum execution time: 51_711_000 picoseconds. - Weight::from_parts(50_255_137, 4764) - // Standard Error: 5_418 - .saturating_add(Weight::from_parts(3_166_243, 0).saturating_mul(x.into())) + // Minimum execution time: 52_182_000 picoseconds. + Weight::from_parts(50_073_700, 4764) + // Standard Error: 4_907 + .saturating_add(Weight::from_parts(3_301_788, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -258,12 +279,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `x` is `[1, 16]`. fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `501` + // Measured: `519` // Estimated: `4764` - // Minimum execution time: 48_656_000 picoseconds. - Weight::from_parts(46_590_994, 4764) - // Standard Error: 4_829 - .saturating_add(Weight::from_parts(3_197_956, 0).saturating_mul(x.into())) + // Minimum execution time: 49_637_000 picoseconds. + Weight::from_parts(47_809_537, 4764) + // Standard Error: 5_850 + .saturating_add(Weight::from_parts(3_304_857, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -275,28 +296,28 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) fn claim_bonus_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `267` + // Measured: `271` // Estimated: `3775` - // Minimum execution time: 41_921_000 picoseconds. - Weight::from_parts(42_440_000, 3775) + // Minimum execution time: 41_926_000 picoseconds. + Weight::from_parts(42_718_000, 3775) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking DAppTiers (r:1 w:1) /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) fn claim_dapp_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2585` + // Measured: `2584` // Estimated: `5048` - // Minimum execution time: 58_409_000 picoseconds. - Weight::from_parts(60_103_000, 5048) + // Minimum execution time: 57_183_000 picoseconds. + Weight::from_parts(58_197_000, 5048) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: DappStaking IntegratedDApps (r:1 w:0) - /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(121), added: 2101, mode: MaxEncodedLen) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) /// Storage: DappStaking StakerInfo (r:1 w:1) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) @@ -309,14 +330,14 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) fn unstake_from_unregistered() -> Weight { // Proof Size summary in bytes: - // Measured: `389` + // Measured: `318` // Estimated: `4764` - // Minimum execution time: 43_579_000 picoseconds. - Weight::from_parts(44_128_000, 4764) + // Minimum execution time: 41_858_000 picoseconds. + Weight::from_parts(42_476_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } - /// Storage: DappStaking StakerInfo (r:9 w:8) + /// Storage: DappStaking StakerInfo (r:17 w:16) /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) @@ -324,15 +345,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// The range of component `x` is `[1, 8]`. + /// The range of component `x` is `[1, 16]`. fn cleanup_expired_entries(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `255 + x * (69 ±0)` + // Measured: `256 + x * (69 ±0)` // Estimated: `4764 + x * (2613 ±0)` - // Minimum execution time: 43_019_000 picoseconds. - Weight::from_parts(39_628_074, 4764) - // Standard Error: 15_327 - .saturating_add(Weight::from_parts(4_990_892, 0).saturating_mul(x.into())) + // Minimum execution time: 43_103_000 picoseconds. + Weight::from_parts(39_876_215, 4764) + // Standard Error: 8_123 + .saturating_add(Weight::from_parts(5_014_232, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -343,8 +364,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_301_000 picoseconds. - Weight::from_parts(11_607_000, 0) + // Minimum execution time: 11_543_000 picoseconds. + Weight::from_parts(11_735_000, 0) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) @@ -354,8 +375,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `16` // Estimated: `4254` - // Minimum execution time: 17_997_000 picoseconds. - Weight::from_parts(18_491_000, 4254) + // Minimum execution time: 17_687_000 picoseconds. + Weight::from_parts(18_283_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -375,10 +396,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) fn on_initialize_build_and_earn_to_voting() -> Weight { // Proof Size summary in bytes: - // Measured: `627` + // Measured: `839` // Estimated: `4254` - // Minimum execution time: 45_396_000 picoseconds. - Weight::from_parts(46_230_000, 4254) + // Minimum execution time: 47_901_000 picoseconds. + Weight::from_parts(49_554_000, 4254) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -392,8 +413,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `68` // Estimated: `4254` - // Minimum execution time: 24_161_000 picoseconds. - Weight::from_parts(24_565_000, 4254) + // Minimum execution time: 23_705_000 picoseconds. + Weight::from_parts(24_313_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -406,10 +427,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 7_878_000 picoseconds. - Weight::from_parts(12_213_692, 3061) - // Standard Error: 3_051 - .saturating_add(Weight::from_parts(2_363_936, 0).saturating_mul(x.into())) + // Minimum execution time: 7_549_000 picoseconds. + Weight::from_parts(12_476_634, 3061) + // Standard Error: 3_594 + .saturating_add(Weight::from_parts(2_387_577, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -424,9 +445,9 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 8_839_000 picoseconds. - Weight::from_parts(8_975_000, 4254) + // Minimum execution time: 8_529_000 picoseconds. + Weight::from_parts(8_772_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } -} \ No newline at end of file +} diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index 97e119e68d..ed4f714f26 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -66,7 +66,10 @@ use sp_runtime::{ use sp_std::{collections::btree_map::BTreeMap, prelude::*}; use astar_primitives::{ - dapp_staking::{CycleConfiguration, DAppId, EraNumber, PeriodNumber, SmartContract, TierId}, + dapp_staking::{ + AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber, + PeriodNumber, SmartContract, TierId, + }, evm::EvmRevertCodeHandler, xcm::AssetLocationIdConverter, Address, AssetId, BlockNumber, Hash, Header, Index, @@ -380,6 +383,13 @@ impl pallet_dapp_staking_v3::BenchmarkHelper, AccountId } } +pub struct AccountCheck; +impl DappStakingAccountCheck for AccountCheck { + fn allowed_to_stake(account: &AccountId) -> bool { + !CollatorSelection::is_account_candidate(account) + } +} + impl pallet_dapp_staking_v3::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeFreezeReason = RuntimeFreezeReason; @@ -390,6 +400,7 @@ impl pallet_dapp_staking_v3::Config for Runtime { type StakingRewardHandler = Inflation; type CycleConfiguration = InflationCycleConfig; type Observers = Inflation; + type AccountCheck = AccountCheck; type EraRewardSpanLength = ConstU32<16>; type RewardRetentionInPeriods = ConstU32<3>; type MaxNumberOfContracts = ConstU32<500>; @@ -516,6 +527,13 @@ parameter_types! { pub const KickThreshold: BlockNumber = 2 * HOURS; // 2 SessionPeriod } +pub struct CollatorSelectionAccountCheck; +impl pallet_collator_selection::AccountCheck for CollatorSelectionAccountCheck { + fn allowed_candidacy(account: &AccountId) -> bool { + !DappStaking::is_staker(account) + } +} + impl pallet_collator_selection::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -530,6 +548,7 @@ impl pallet_collator_selection::Config for Runtime { type ValidatorIdOf = pallet_collator_selection::IdentityCollator; type ValidatorRegistration = Session; type SlashRatio = SlashRatio; + type AccountCheck = CollatorSelectionAccountCheck; type WeightInfo = pallet_collator_selection::weights::SubstrateWeight; } @@ -1030,9 +1049,6 @@ construct_runtime!( NodeBlock = generic::Block, UncheckedExtrinsic = UncheckedExtrinsic { - // Inflation needs to execute `on_initialize` as soon as possible, and `on_finalize` as late as possible. - Inflation: pallet_inflation = 5, - System: frame_system = 10, Utility: pallet_utility = 11, Identity: pallet_identity = 12, @@ -1046,6 +1062,11 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment = 30, Balances: pallet_balances = 31, Vesting: pallet_vesting = 32, + // Inflation needs to execute `on_initialize` as soon as possible, and `on_finalize` as late as possible. + // However, we need to execute Balance genesis before Inflation genesis, otherwise we'll have zero issuance when Inflation + // logic is executed. + // TODO: Address this later. It would be best if Inflation was first pallet. + Inflation: pallet_inflation = 33, DappStaking: pallet_dapp_staking_v3 = 34, Assets: pallet_assets = 36, diff --git a/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs b/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs index e6bbef634d..a7067267f8 100644 --- a/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs +++ b/runtime/shiden/src/weights/pallet_dapp_staking_v3.rs @@ -55,8 +55,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_090_000 picoseconds. - Weight::from_parts(9_358_000, 0) + // Minimum execution time: 8_967_000 picoseconds. + Weight::from_parts(9_242_000, 0) } /// Storage: DappStaking IntegratedDApps (r:1 w:1) /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) @@ -68,8 +68,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3086` - // Minimum execution time: 17_212_000 picoseconds. - Weight::from_parts(17_529_000, 3086) + // Minimum execution time: 17_044_000 picoseconds. + Weight::from_parts(17_328_000, 3086) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -79,8 +79,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3086` - // Minimum execution time: 13_417_000 picoseconds. - Weight::from_parts(13_573_000, 3086) + // Minimum execution time: 13_369_000 picoseconds. + Weight::from_parts(13_617_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -90,8 +90,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3086` - // Minimum execution time: 13_737_000 picoseconds. - Weight::from_parts(13_916_000, 3086) + // Minimum execution time: 13_421_000 picoseconds. + Weight::from_parts(13_692_000, 3086) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -105,25 +105,44 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3086` - // Minimum execution time: 18_180_000 picoseconds. - Weight::from_parts(18_463_000, 3086) + // Minimum execution time: 18_458_000 picoseconds. + Weight::from_parts(18_864_000, 3086) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: DappStaking Ledger (r:1 w:1) /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: CollatorSelection Candidates (r:1 w:0) + /// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured) /// Storage: Balances Freezes (r:1 w:1) /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) /// Storage: Balances Locks (r:1 w:0) /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) - fn lock() -> Weight { + fn lock_new_account() -> Weight { // Proof Size summary in bytes: - // Measured: `12` + // Measured: `138` // Estimated: `4764` - // Minimum execution time: 32_874_000 picoseconds. - Weight::from_parts(33_274_000, 4764) + // Minimum execution time: 62_743_000 picoseconds. + Weight::from_parts(64_992_000, 4764) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_existing_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `158` + // Estimated: `4764` + // Minimum execution time: 38_250_000 picoseconds. + Weight::from_parts(38_835_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -139,8 +158,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `158` // Estimated: `4764` - // Minimum execution time: 34_421_000 picoseconds. - Weight::from_parts(35_413_000, 4764) + // Minimum execution time: 34_582_000 picoseconds. + Weight::from_parts(35_126_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -157,10 +176,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `191` // Estimated: `4764` - // Minimum execution time: 37_435_000 picoseconds. - Weight::from_parts(39_113_839, 4764) - // Standard Error: 3_446 - .saturating_add(Weight::from_parts(118_027, 0).saturating_mul(x.into())) + // Minimum execution time: 37_740_000 picoseconds. + Weight::from_parts(39_064_684, 4764) + // Standard Error: 2_750 + .saturating_add(Weight::from_parts(120_539, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -176,8 +195,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `200` // Estimated: `4764` - // Minimum execution time: 33_192_000 picoseconds. - Weight::from_parts(33_631_000, 4764) + // Minimum execution time: 33_298_000 picoseconds. + Weight::from_parts(33_903_000, 4764) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -199,8 +218,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `251` // Estimated: `4764` - // Minimum execution time: 45_619_000 picoseconds. - Weight::from_parts(45_985_000, 4764) + // Minimum execution time: 44_905_000 picoseconds. + Weight::from_parts(45_261_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -222,8 +241,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `432` // Estimated: `4764` - // Minimum execution time: 48_932_000 picoseconds. - Weight::from_parts(49_757_000, 4764) + // Minimum execution time: 48_594_000 picoseconds. + Weight::from_parts(49_441_000, 4764) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -242,10 +261,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `541` // Estimated: `4764` - // Minimum execution time: 51_777_000 picoseconds. - Weight::from_parts(49_689_608, 4764) - // Standard Error: 6_426 - .saturating_add(Weight::from_parts(3_298_280, 0).saturating_mul(x.into())) + // Minimum execution time: 52_182_000 picoseconds. + Weight::from_parts(50_073_700, 4764) + // Standard Error: 4_907 + .saturating_add(Weight::from_parts(3_301_788, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -262,10 +281,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `519` // Estimated: `4764` - // Minimum execution time: 49_515_000 picoseconds. - Weight::from_parts(47_526_163, 4764) - // Standard Error: 5_683 - .saturating_add(Weight::from_parts(3_267_803, 0).saturating_mul(x.into())) + // Minimum execution time: 49_637_000 picoseconds. + Weight::from_parts(47_809_537, 4764) + // Standard Error: 5_850 + .saturating_add(Weight::from_parts(3_304_857, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -279,8 +298,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `271` // Estimated: `3775` - // Minimum execution time: 42_226_000 picoseconds. - Weight::from_parts(42_414_000, 3775) + // Minimum execution time: 41_926_000 picoseconds. + Weight::from_parts(42_718_000, 3775) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -292,8 +311,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2584` // Estimated: `5048` - // Minimum execution time: 57_523_000 picoseconds. - Weight::from_parts(59_818_000, 5048) + // Minimum execution time: 57_183_000 picoseconds. + Weight::from_parts(58_197_000, 5048) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -313,8 +332,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `318` // Estimated: `4764` - // Minimum execution time: 41_488_000 picoseconds. - Weight::from_parts(42_872_000, 4764) + // Minimum execution time: 41_858_000 picoseconds. + Weight::from_parts(42_476_000, 4764) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -331,10 +350,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `256 + x * (69 ±0)` // Estimated: `4764 + x * (2613 ±0)` - // Minimum execution time: 42_933_000 picoseconds. - Weight::from_parts(39_506_127, 4764) - // Standard Error: 7_450 - .saturating_add(Weight::from_parts(5_115_797, 0).saturating_mul(x.into())) + // Minimum execution time: 43_103_000 picoseconds. + Weight::from_parts(39_876_215, 4764) + // Standard Error: 8_123 + .saturating_add(Weight::from_parts(5_014_232, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -345,8 +364,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_323_000 picoseconds. - Weight::from_parts(11_592_000, 0) + // Minimum execution time: 11_543_000 picoseconds. + Weight::from_parts(11_735_000, 0) } /// Storage: DappStaking CurrentEraInfo (r:1 w:1) /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) @@ -356,8 +375,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `16` // Estimated: `4254` - // Minimum execution time: 17_474_000 picoseconds. - Weight::from_parts(17_913_000, 4254) + // Minimum execution time: 17_687_000 picoseconds. + Weight::from_parts(18_283_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -379,8 +398,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `839` // Estimated: `4254` - // Minimum execution time: 47_997_000 picoseconds. - Weight::from_parts(49_198_000, 4254) + // Minimum execution time: 47_901_000 picoseconds. + Weight::from_parts(49_554_000, 4254) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -394,8 +413,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `68` // Estimated: `4254` - // Minimum execution time: 23_840_000 picoseconds. - Weight::from_parts(24_333_000, 4254) + // Minimum execution time: 23_705_000 picoseconds. + Weight::from_parts(24_313_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -408,10 +427,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `152 + x * (32 ±0)` // Estimated: `3061 + x * (2071 ±0)` - // Minimum execution time: 7_372_000 picoseconds. - Weight::from_parts(12_387_768, 3061) - // Standard Error: 3_378 - .saturating_add(Weight::from_parts(2_365_111, 0).saturating_mul(x.into())) + // Minimum execution time: 7_549_000 picoseconds. + Weight::from_parts(12_476_634, 3061) + // Standard Error: 3_594 + .saturating_add(Weight::from_parts(2_387_577, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) @@ -426,8 +445,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `293` // Estimated: `4254` - // Minimum execution time: 8_292_000 picoseconds. - Weight::from_parts(8_593_000, 4254) + // Minimum execution time: 8_529_000 picoseconds. + Weight::from_parts(8_772_000, 4254) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index 1d1696f550..595ee1afb2 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -25,9 +25,6 @@ pallet-assets = { workspace = true } pallet-balances = { workspace = true } pallet-contracts = { workspace = true } pallet-contracts-primitives = { workspace = true } -pallet-dapp-staking-v3 = { workspace = true } -pallet-dapps-staking = { workspace = true } -pallet-inflation = { workspace = true } pallet-proxy = { workspace = true } pallet-utility = { workspace = true } sp-core = { workspace = true } @@ -36,9 +33,13 @@ sp-runtime = { workspace = true } # astar dependencies assets-chain-extension-types = { workspace = true } +pallet-collator-selection = { workspace = true } +pallet-dapp-staking-v3 = { workspace = true } +pallet-dapps-staking = { workspace = true } pallet-ethereum-checked = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } pallet-evm-precompile-dispatch = { workspace = true } +pallet-inflation = { workspace = true } pallet-unified-accounts = { workspace = true } precompile-utils = { workspace = true } unified-accounts-chain-extension-types = { workspace = true } diff --git a/tests/integration/src/dapp_staking_v3.rs b/tests/integration/src/dapp_staking_v3.rs index 1a79c9ccbc..5fa769ea1f 100644 --- a/tests/integration/src/dapp_staking_v3.rs +++ b/tests/integration/src/dapp_staking_v3.rs @@ -20,6 +20,7 @@ use crate::setup::*; +use pallet_collator_selection::{CandidateInfo, Candidates}; use pallet_dapp_staking_v3::*; #[test] @@ -78,3 +79,49 @@ fn dapp_staking_triggers_inflation_recalculation() { ); }); } + +#[test] +fn lock_not_possible_for_collator_candidate_account() { + new_test_ext().execute_with(|| { + // Hacky approach but it works + let candidate_info = CandidateInfo { + who: ALICE.clone(), + deposit: CollatorSelection::candidacy_bond(), + }; + Candidates::::mutate(|candidates| { + candidates.push(candidate_info); + }); + + // Now try to participate in dApp staking with Alice and expect an error + let minimum_lock_amount = + ::MinimumLockedAmount::get(); + assert_noop!( + DappStaking::lock(RuntimeOrigin::signed(ALICE.clone()), minimum_lock_amount,), + pallet_dapp_staking_v3::Error::::AccountNotAvailableForDappStaking + ); + }); +} + +// Not the ideal place for such test, can be moved later. +#[test] +fn collator_selection_candidacy_not_possible_for_dapp_staking_participant() { + new_test_ext().execute_with(|| { + // Lock some amount with Alice + let minimum_lock_amount = + ::MinimumLockedAmount::get(); + assert_ok!(DappStaking::lock( + RuntimeOrigin::signed(ALICE.clone()), + minimum_lock_amount, + )); + + // Ensure it's not possible to become a candidate for collator selection while having locked funds in dApp staking + assert_ok!(CollatorSelection::set_desired_candidates( + RuntimeOrigin::root(), + 1_000_000, + )); + assert_noop!( + CollatorSelection::register_as_candidate(RuntimeOrigin::signed(ALICE.clone())), + pallet_collator_selection::Error::::NotAllowedCandidate + ); + }); +} diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index 083a560ceb..2bca834b28 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -231,6 +231,7 @@ pub fn run_to_block(n: BlockNumber) { AuraExt::on_finalize(block_number); PolkadotXcm::on_finalize(block_number); Ethereum::on_finalize(block_number); + CollatorSelection::on_finalize(block_number); DynamicEvmBaseFee::on_finalize(block_number); #[cfg(any(feature = "shibuya", feature = "shiden"))] Inflation::on_finalize(block_number); @@ -249,6 +250,7 @@ pub fn run_to_block(n: BlockNumber) { Authorship::on_initialize(block_number); Aura::on_initialize(block_number); AuraExt::on_initialize(block_number); + CollatorSelection::on_initialize(block_number); Ethereum::on_initialize(block_number); DynamicEvmBaseFee::on_initialize(block_number); #[cfg(any(feature = "shibuya", feature = "shiden"))]