From f885e715d08dcb54d41e9e1f9b29f5630bd4338b Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 19 Dec 2022 21:03:23 +0100 Subject: [PATCH 01/44] Ambassador Program minimum setup --- Cargo.lock | 4 + .../collectives-polkadot/Cargo.toml | 16 ++ .../src/ambassador/mod.rs | 98 +++++++++++ .../src/ambassador/pallet.rs | 158 ++++++++++++++++++ .../src/ambassador/tracks.rs | 125 ++++++++++++++ .../src/ambassador/types.rs | 46 +++++ .../collectives-polkadot/src/impls.rs | 49 +++--- .../collectives-polkadot/src/lib.rs | 63 ++++++- 8 files changed, 534 insertions(+), 25 deletions(-) create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs diff --git a/Cargo.lock b/Cargo.lock index 5954e32ed15..9d496a15c20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1158,7 +1158,11 @@ dependencies = [ "pallet-collator-selection", "pallet-collective", "pallet-multisig", + "pallet-preimage", "pallet-proxy", + "pallet-ranked-collective", + "pallet-referenda", + "pallet-scheduler", "pallet-session", "pallet-timestamp", "pallet-transaction-payment", diff --git a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index f299377c79a..0daa365224b 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -26,12 +26,16 @@ pallet-authorship = { git = "https://github.com/paritytech/substrate", default-f pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-ranked-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } @@ -95,6 +99,10 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", + "pallet-ranked-collective/runtime-benchmarks", ] try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", @@ -119,6 +127,10 @@ try-runtime = [ "pallet-utility/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-preimage/try-runtime", + "pallet-referenda/try-runtime", + "pallet-ranked-collective/try-runtime", ] std = [ "codec/std", @@ -170,4 +182,8 @@ std = [ "pallet-collator-selection/std", "parachain-info/std", "parachains-common/std", + "pallet-scheduler/std", + "pallet-preimage/std", + "pallet-referenda/std", + "pallet-ranked-collective/std", ] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs new file mode 100644 index 00000000000..b74553c8d16 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -0,0 +1,98 @@ +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// The Ambassador Program. +/// todo docs +mod pallet; +mod tracks; +pub mod types; + +use super::*; +use frame_support::traits::MapSuccess; +pub use pallet::pallet as pallet_ambassador; +use pallet::pallet::{ + Ambassador as AmbassadorOrigin, Origin, SeniorAmbassador as SeniorAmbassadorOrigin, +}; +use sp_runtime::traits::Replace; + +impl pallet_ambassador::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AmbassadorOrigin = AmbassadorOrigin; + type MemberOrigin = pallet_ranked_collective::EnsureMember< + Runtime, + AmbassadorCollectiveInstance, + 1, // todo types::ranks::AMBASSADOR + >; + type MaxAnnouncementsCount = ConstU32<100>; +} + +parameter_types! { + pub const AlarmInterval: BlockNumber = 1; + pub const SubmissionDeposit: Balance = 0; + pub const UndecidingTimeout: BlockNumber = 7 * DAYS; +} + +pub type AmbassadorReferendaInstance = pallet_referenda::Instance1; + +impl pallet_referenda::Config for Runtime { + type WeightInfo = (); // TODO use actual weights + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + type SubmitOrigin = pallet_ranked_collective::EnsureMember< + Runtime, + AmbassadorCollectiveInstance, + 1, // todo types::ranks::AMBASSADOR + >; + type CancelOrigin = EitherOf, SeniorAmbassadorOrigin>; + type KillOrigin = EitherOf, SeniorAmbassadorOrigin>; + type Slash = ToParentTreasury; + type Votes = pallet_ranked_collective::Votes; + type Tally = pallet_ranked_collective::TallyOf; + type SubmissionDeposit = SubmissionDeposit; + type MaxQueued = ConstU32<100>; + type UndecidingTimeout = UndecidingTimeout; + type AlarmInterval = AlarmInterval; + type Tracks = tracks::TracksInfo; + type Preimages = Preimage; +} + +parameter_types! { + pub const CandidateRank: types::Rank = types::ranks::CANDIDATE; + pub const AmbassadorRank: types::Rank = types::ranks::AMBASSADOR; + pub const SeniorAmbassadorRank: types::Rank = types::ranks::SENIOR_AMBASSADOR; +} + +pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance1; + +impl pallet_ranked_collective::Config for Runtime { + type WeightInfo = (); // TODO use actual weights + type RuntimeEvent = RuntimeEvent; + type PromoteOrigin = EitherOf< + frame_system::EnsureRootWithSuccess, + EitherOf< + MapSuccess>, + MapSuccess>, + >, + >; + type DemoteOrigin = EitherOf< + frame_system::EnsureRootWithSuccess, + MapSuccess>, + >; + type Polls = AmbassadorReferenda; + type MinRankOfClass = sp_runtime::traits::Identity; + type VoteWeight = pallet_ranked_collective::Geometric; +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs new file mode 100644 index 00000000000..793f691b931 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs @@ -0,0 +1,158 @@ +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet] +pub mod pallet { + use super::super::types::Cid; + + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + + #[pallet::pallet] + #[pallet::generate_store(pub (super) trait Store)] + #[pallet::storage_version(STORAGE_VERSION)] + pub struct Pallet(PhantomData); + + /// The module configuration trait. + #[pallet::config] + pub trait Config: frame_system::Config { + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + /// A member of the Ambassador Program. + type MemberOrigin: EnsureOrigin; + + /// Ambassador plurality voice. + type AmbassadorOrigin: EnsureOrigin; + + /// The maximum number of announcements. + #[pallet::constant] + type MaxAnnouncementsCount: Get; + } + + #[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)] + #[pallet::origin] + pub enum Origin { + /// Candidates plurality voice given via referendum. + Candidate, + /// Ambassador plurality voice given via referendum. + Ambassador, + /// SeniorAmbassador plurality voice given via referendum. + SeniorAmbassador, + } + + #[pallet::error] + pub enum Error { + /// The announcement is not found. + MissingAnnouncement, + /// Number of announcements exceeds `MaxAnnouncementsCount`. + TooManyAnnouncements, + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// A new charter has been set. + NewCharterSet { cid: Cid }, + /// A new announcement has been proposed. + AnnouncementAnnounced { cid: Cid }, + /// An on-chain announcement has been removed. + AnnouncementRemoved { cid: Cid }, + } + + /// The Ambassador Program's charter. + #[pallet::storage] + #[pallet::getter(fn charter)] + pub type Charter = StorageValue<_, Cid, OptionQuery>; + + /// The Ambassador Program's announcements. + #[pallet::storage] + #[pallet::getter(fn announcements)] + pub type Announcements = + StorageValue<_, BoundedVec, ValueQuery>; + + #[pallet::call] + impl Pallet { + /// Set the Ambassador Program's charter. + #[pallet::call_index(0)] + #[pallet::weight(0)] // TODO + pub fn set_charter(origin: OriginFor, cid: Cid) -> DispatchResult { + T::AmbassadorOrigin::ensure_origin(origin)?; + + Charter::::put(&cid); + + Self::deposit_event(Event::::NewCharterSet { cid }); + Ok(()) + } + + /// Publish an announcement. + #[pallet::call_index(1)] + #[pallet::weight(0)] // TODO + pub fn announce(origin: OriginFor, cid: Cid) -> DispatchResult { + T::MemberOrigin::ensure_origin(origin)?; + + let mut announcements = >::get(); + announcements + .try_push(cid.clone()) + .map_err(|_| Error::::TooManyAnnouncements)?; + >::put(announcements); + + Self::deposit_event(Event::::AnnouncementAnnounced { cid }); + Ok(()) + } + + /// Remove an announcement. + #[pallet::call_index(2)] + #[pallet::weight(0)] // TODO + pub fn remove_announcement(origin: OriginFor, cid: Cid) -> DispatchResult { + T::MemberOrigin::ensure_origin(origin)?; + + let mut announcements = >::get(); + let pos = + announcements.binary_search(&cid).ok().ok_or(Error::::MissingAnnouncement)?; + announcements.remove(pos); + >::put(announcements); + + Self::deposit_event(Event::::AnnouncementRemoved { cid }); + Ok(()) + } + } + + pub struct Ambassador; + // todo P2 check impl + impl> + From> EnsureOrigin for Ambassador { + type Success = (); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::Ambassador => Ok(()), + r => Err(O::from(r)), + }) + } + } + + pub struct SeniorAmbassador; + impl> + From> EnsureOrigin for SeniorAmbassador { + type Success = (); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::SeniorAmbassador => Ok(()), + r => Err(O::from(r)), + }) + } + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs new file mode 100644 index 00000000000..77ee889ba40 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs @@ -0,0 +1,125 @@ +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// The Ambassador Program referendum voting tracks. +use super::{types, Origin}; +use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES, UNITS}; +use sp_runtime::Perbill; + +/// The type implementing the [`pallet_referenda::TracksInfo`] trait for referenda pallet. +pub struct TracksInfo; + +/// Information on the voting tracks. +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = types::TrackId; + + type RuntimeOrigin = ::PalletsOrigin; + + /// Return the array of available tracks and their information. + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + static DATA: [(u16, pallet_referenda::TrackInfo); 3] = [ + ( + types::tracks::CANDIDATE, + pallet_referenda::TrackInfo { + name: "candidate", + max_deciding: 50, + decision_deposit: 10 * UNITS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 1 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + types::tracks::AMBASSADOR, + pallet_referenda::TrackInfo { + name: "ambassador", + max_deciding: 50, + decision_deposit: 10 * UNITS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 1 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + types::tracks::SENIOR_AMBASSADOR, + pallet_referenda::TrackInfo { + name: "senior ambassador", + max_deciding: 50, + decision_deposit: 10 * UNITS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 1 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ]; + &DATA[..] + } + + /// Determine the voting track for the given `origin`. + fn track_for(id: &Self::RuntimeOrigin) -> Result { + #[cfg(feature = "runtime-benchmarks")] + { + // For benchmarks, we enable a root origin. + // It is important that this is not available in production! + let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into(); + if &root == id { + return Ok(types::tracks::SENIOR_AMBASSADOR) + } + } + + match Origin::try_from(id.clone()) { + Ok(Origin::Candidate) => Ok(types::tracks::CANDIDATE), + Ok(Origin::Ambassador) => Ok(types::tracks::AMBASSADOR), + Ok(Origin::SeniorAmbassador) => Ok(types::tracks::SENIOR_AMBASSADOR), + _ => Err(()), + } + } +} + +// implements [`frame_support::traits::Get`] for [`TracksInfo`] +pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs new file mode 100644 index 00000000000..672f3a5e14a --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs @@ -0,0 +1,46 @@ +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// Types and constants concerning the Ambassador Program. +use frame_support::BoundedVec; +use sp_core::ConstU32; + +/// Referendum TrackId type. +pub type TrackId = u16; + +/// Referendum tracks ids. +pub mod tracks { + use super::TrackId; + + pub const CANDIDATE: TrackId = 0; + pub const AMBASSADOR: TrackId = 1; + pub const SENIOR_AMBASSADOR: TrackId = 2; +} + +/// Members rank type. +pub type Rank = pallet_ranked_collective::Rank; + +/// Members ranks. +pub mod ranks { + use super::Rank; + + pub const CANDIDATE: Rank = 0; + pub const AMBASSADOR: Rank = 1; + pub const SENIOR_AMBASSADOR: Rank = 2; +} + +/// IPFS compatible CID. +// worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. +pub type Cid = BoundedVec>; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs index 9373f1ef8f5..9aae44465e9 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs @@ -13,14 +13,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +use super::{AccountId, OriginCaller}; +use crate::{PolkadotXcm, RelayTreasuryAccId, RuntimeOrigin, SlashedImbalanceAccId}; use frame_support::{ dispatch::{DispatchError, DispatchResultWithPostInfo}, log, - traits::{Currency, Get, Imbalance, OnUnbalanced, OriginTrait}, + traits::{Currency, Imbalance, OnUnbalanced, PrivilegeCmp}, weights::Weight, }; use pallet_alliance::{ProposalIndex, ProposalProvider}; -use sp_std::{marker::PhantomData, prelude::*}; +use sp_std::{cmp::Ordering, marker::PhantomData, prelude::*}; use xcm::latest::{Fungibility, Junction, NetworkId, Parent}; type AccountIdOf = ::AccountId; @@ -33,36 +35,29 @@ type NegativeImbalanceOf = <>::Currency as ::AccountId, >>::NegativeImbalance; -type CurrencyOf = >::Currency; - type BalanceOf = <>::Currency as Currency< ::AccountId, >>::Balance; /// Implements `OnUnbalanced::on_unbalanced` to teleport slashed assets to relay chain treasury account. -pub struct ToParentTreasury( - PhantomData<(TreasuryAcc, TempAcc, T, I)>, -); +pub struct ToParentTreasury(PhantomData<(T, I)>); -impl OnUnbalanced> - for ToParentTreasury +impl OnUnbalanced> for ToParentTreasury where - TreasuryAcc: Get>, - TempAcc: Get>, - T: pallet_xcm::Config + frame_system::Config + pallet_alliance::Config, - [u8; 32]: From>, + T: pallet_alliance::Config + frame_system::Config, + [u8; 32]: From, BalanceOf: Into, - <::RuntimeOrigin as OriginTrait>::AccountId: From>, + ::AccountId: From, { fn on_unbalanced(amount: NegativeImbalanceOf) { - let temp_account: AccountIdOf = TempAcc::get(); - let treasury_acc: AccountIdOf = TreasuryAcc::get(); + let temp_account: AccountId = SlashedImbalanceAccId::get(); + let treasury_acc: AccountId = RelayTreasuryAccId::get(); let imbalance = amount.peek(); - >::resolve_creating(&temp_account, amount); + T::Currency::resolve_creating(&temp_account.clone().into(), amount); - let result = pallet_xcm::Pallet::::teleport_assets( - ::RuntimeOrigin::signed(temp_account.into()), + let result = PolkadotXcm::teleport_assets( + RuntimeOrigin::signed(temp_account.into()), Box::new(Parent.into()), Box::new( Junction::AccountId32 { network: NetworkId::Any, id: treasury_acc.into() } @@ -131,3 +126,19 @@ where pallet_collective::Pallet::::proposal_of(proposal_hash) } } + +/// Used the compare the privilege of an origin inside the scheduler. +pub struct EqualOrGreatestRootCmp; + +impl PrivilegeCmp for EqualOrGreatestRootCmp { + fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option { + if left == right { + return Some(Ordering::Equal) + } + match (left, right) { + // Root is greater than anything. + (OriginCaller::system(frame_system::RawOrigin::Root), _) => Some(Ordering::Greater), + _ => None, + } + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index b37e9a6c738..1295fc432d1 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -37,20 +37,22 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +mod ambassador; pub mod constants; pub mod impls; mod weights; pub mod xcm_config; +use ambassador::pallet_ambassador; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use impls::{AllianceProposalProvider, ToParentTreasury}; +use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp, ToParentTreasury}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT}, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, + ApplyExtrinsicResult, Perbill, }; use sp_std::prelude::*; @@ -64,7 +66,7 @@ use frame_support::{ construct_runtime, dispatch::DispatchClass, parameter_types, - traits::{ConstU16, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter}, + traits::{ConstU16, ConstU32, ConstU64, ConstU8, EitherOf, EitherOfDiverse, InstanceFilter}, weights::{ConstantMultiplier, Weight}, PalletId, RuntimeDebug, }; @@ -75,7 +77,7 @@ use frame_system::{ pub use parachains_common as common; use parachains_common::{ impls::DealWithFees, opaque, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, - Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, + Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; use xcm_config::{DotLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}; @@ -293,7 +295,13 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances { .. }), + ProxyType::NonTransfer => !matches!( + c, + RuntimeCall::Scheduler { .. } | + RuntimeCall::AmbassadorCollective { .. } | + RuntimeCall::AmbassadorReferenda { .. } | + RuntimeCall::Balances { .. } + ), ProxyType::CancelProxy => matches!( c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | @@ -467,7 +475,7 @@ impl pallet_alliance::Config for Runtime { type MembershipManager = RootOrAllianceTwoThirdsMajority; type AnnouncementOrigin = RootOrAllianceTwoThirdsMajority; type Currency = Balances; - type Slashed = ToParentTreasury; + type Slashed = ToParentTreasury; type InitializeMembers = AllianceMotion; type MembershipChanged = AllianceMotion; type RetirementPeriod = AllianceRetirementPeriod; @@ -484,6 +492,38 @@ impl pallet_alliance::Config for Runtime { type WeightInfo = weights::pallet_alliance::WeightInfo; } +parameter_types! { + pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; + pub const MaxScheduledPerBlock: u32 = 50; +} + +impl pallet_scheduler::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type PalletsOrigin = OriginCaller; + type RuntimeCall = RuntimeCall; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureRoot; + type MaxScheduledPerBlock = MaxScheduledPerBlock; + type WeightInfo = (); // todo weights + type OriginPrivilegeCmp = EqualOrGreatestRootCmp; + type Preimages = Preimage; +} + +parameter_types! { + pub const PreimageBaseDeposit: Balance = deposit(2, 64); + pub const PreimageByteDeposit: Balance = deposit(0, 1); +} + +impl pallet_preimage::Config for Runtime { + type WeightInfo = (); // todo weights + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type BaseDeposit = PreimageBaseDeposit; + type ByteDeposit = PreimageByteDeposit; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -520,10 +560,17 @@ construct_runtime!( Utility: pallet_utility::{Pallet, Call, Event} = 40, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 41, Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 42, + Preimage: pallet_preimage::{Pallet, Call, Storage, Event} = 43, + Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event} = 44, // The main stage. Alliance: pallet_alliance::{Pallet, Call, Storage, Event, Config} = 50, AllianceMotion: pallet_collective::::{Pallet, Call, Storage, Origin, Event, Config} = 51, + + // Ambassador Program + AmbassadorCollective: pallet_ranked_collective::::{Pallet, Call, Storage, Event} = 60, + AmbassadorReferenda: pallet_referenda::::{Pallet, Call, Storage, Event} = 61, + Ambassador: pallet_ambassador::{Pallet, Origin, Call, Storage, Event} = 62, } ); @@ -586,6 +633,10 @@ mod benches { [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_alliance, Alliance] [pallet_collective, AllianceMotion] + [pallet_preimage, Preimage] + [pallet_scheduler, Scheduler] + [pallet_referenda, AmbassadorReferenda] + [pallet_ranked_collective, AmbassadorCollective] ); } From 8e76281de5f10c2a524e0648ed90c72fd97d9a5f Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 9 Jan 2023 17:17:08 +0100 Subject: [PATCH 02/44] head ambassador rank --- Cargo.lock | 1 + .../collectives-polkadot/Cargo.toml | 1 + .../src/ambassador/mod.rs | 64 ++++++++++++------- .../src/ambassador/pallet.rs | 52 +++++++++++---- .../src/ambassador/tracks.rs | 59 +++++++++++++---- .../src/ambassador/types.rs | 46 ------------- 6 files changed, 132 insertions(+), 91 deletions(-) delete mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs diff --git a/Cargo.lock b/Cargo.lock index 9d496a15c20..85e75e0f8b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1179,6 +1179,7 @@ dependencies = [ "scale-info", "smallvec", "sp-api", + "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", diff --git a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index 0daa365224b..b1e313e371e 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -37,6 +37,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", default-feat pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-ranked-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" } sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index b74553c8d16..e3dae4b1528 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -13,27 +13,42 @@ // See the License for the specific language governing permissions and // limitations under the License. -/// The Ambassador Program. -/// todo docs +//! The Ambassador Program. +//! todo docs + mod pallet; mod tracks; -pub mod types; use super::*; -use frame_support::traits::MapSuccess; -pub use pallet::pallet as pallet_ambassador; -use pallet::pallet::{ - Ambassador as AmbassadorOrigin, Origin, SeniorAmbassador as SeniorAmbassadorOrigin, +use frame_support::traits::TryMapSuccess; +pub use pallet::pallet_ambassador; +use pallet::pallet_ambassador::{ + EnsureAmbassador, EnsureRankedAmbassador, EnsureSeniorAmbassador, Origin, +}; +use sp_arithmetic::traits::CheckedSub; +use sp_runtime::{ + morph_types, + traits::{ConstU16, TypedGet}, }; -use sp_runtime::traits::Replace; + +/// The Ambassador Program members ranks. +pub mod ranks { + use pallet_ranked_collective::Rank; + + #[allow(dead_code)] + pub const CANDIDATE: Rank = 0; + pub const AMBASSADOR: Rank = 1; + pub const SENIOR_AMBASSADOR: Rank = 2; + pub const HEAD_AMBASSADOR: Rank = 3; +} impl pallet_ambassador::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type AmbassadorOrigin = AmbassadorOrigin; + type AmbassadorOrigin = EnsureAmbassador; type MemberOrigin = pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, - 1, // todo types::ranks::AMBASSADOR + { ranks::AMBASSADOR }, >; type MaxAnnouncementsCount = ConstU32<100>; } @@ -55,10 +70,10 @@ impl pallet_referenda::Config for Runtime { type SubmitOrigin = pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, - 1, // todo types::ranks::AMBASSADOR + { ranks::AMBASSADOR }, >; - type CancelOrigin = EitherOf, SeniorAmbassadorOrigin>; - type KillOrigin = EitherOf, SeniorAmbassadorOrigin>; + type CancelOrigin = EitherOf, EnsureSeniorAmbassador>; + type KillOrigin = EitherOf, EnsureSeniorAmbassador>; type Slash = ToParentTreasury; type Votes = pallet_ranked_collective::Votes; type Tally = pallet_ranked_collective::TallyOf; @@ -71,9 +86,15 @@ impl pallet_referenda::Config for Runtime { } parameter_types! { - pub const CandidateRank: types::Rank = types::ranks::CANDIDATE; - pub const AmbassadorRank: types::Rank = types::ranks::AMBASSADOR; - pub const SeniorAmbassadorRank: types::Rank = types::ranks::SENIOR_AMBASSADOR; + pub const HeadAmbassadorRank: pallet_ranked_collective::Rank = ranks::HEAD_AMBASSADOR; +} + +morph_types! { + /// A `TryMorph` implementation to reduce a scalar by a particular amount, checking for + /// underflow. + pub type CheckedReduceBy: TryMorph = |r: N::Type| -> Result { + r.checked_sub(&N::get()).ok_or(()) + } where N::Type: CheckedSub; } pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance1; @@ -82,15 +103,12 @@ impl pallet_ranked_collective::Config for Runtime type WeightInfo = (); // TODO use actual weights type RuntimeEvent = RuntimeEvent; type PromoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess, - EitherOf< - MapSuccess>, - MapSuccess>, - >, + frame_system::EnsureRootWithSuccess, + TryMapSuccess>>, >; type DemoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess, - MapSuccess>, + frame_system::EnsureRootWithSuccess, + TryMapSuccess>>, >; type Polls = AmbassadorReferenda; type MinRankOfClass = sp_runtime::traits::Identity; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs index 793f691b931..a67885196c1 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs @@ -13,12 +13,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[frame_support::pallet] -pub mod pallet { - use super::super::types::Cid; +//! TODO docs + +use frame_support::BoundedVec; +use sp_core::ConstU32; + +/// IPFS compatible CID. +// worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. +pub type Cid = BoundedVec>; +#[frame_support::pallet] +pub mod pallet_ambassador { + use super::{super::ranks, Cid}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; + use pallet_ranked_collective::Rank; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); @@ -48,14 +57,17 @@ pub mod pallet { #[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)] #[pallet::origin] pub enum Origin { - /// Candidates plurality voice given via referendum. + /// Plurality voice of the [ranks::CANDIDATE] members or above given via referendum. Candidate, - /// Ambassador plurality voice given via referendum. + /// Plurality voice of the [ranks::AMBASSADOR] members or above given via referendum. Ambassador, - /// SeniorAmbassador plurality voice given via referendum. + /// Plurality voice of the [ranks::SENIOR_AMBASSADOR] members or above given via referendum. SeniorAmbassador, + /// Plurality voice of the [ranks::HEAD_AMBASSADOR] members or above given via referendum. + HeadAmbassador, } + /// todo docs #[pallet::error] pub enum Error { /// The announcement is not found. @@ -64,6 +76,7 @@ pub mod pallet { TooManyAnnouncements, } + /// todo docs #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -133,9 +146,9 @@ pub mod pallet { } } - pub struct Ambassador; - // todo P2 check impl - impl> + From> EnsureOrigin for Ambassador { + /// Implementation of the [EnsureOrigin] trait for the [Origin::Ambassador] origin. + pub struct EnsureAmbassador; + impl> + From> EnsureOrigin for EnsureAmbassador { type Success = (); fn try_origin(o: O) -> Result { o.into().and_then(|o| match o { @@ -145,8 +158,9 @@ pub mod pallet { } } - pub struct SeniorAmbassador; - impl> + From> EnsureOrigin for SeniorAmbassador { + /// Implementation of the [EnsureOrigin] trait for the [Origin::SeniorAmbassador] origin. + pub struct EnsureSeniorAmbassador; + impl> + From> EnsureOrigin for EnsureSeniorAmbassador { type Success = (); fn try_origin(o: O) -> Result { o.into().and_then(|o| match o { @@ -155,4 +169,20 @@ pub mod pallet { }) } } + + /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the success result + /// of the corresponding [Rank]. Not implemented for the [Origin::Candidate]. + pub struct EnsureRankedAmbassador; + + impl> + From> EnsureOrigin for EnsureRankedAmbassador { + type Success = Rank; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::Ambassador => Ok(ranks::AMBASSADOR), + Origin::SeniorAmbassador => Ok(ranks::SENIOR_AMBASSADOR), + Origin::HeadAmbassador => Ok(ranks::HEAD_AMBASSADOR), + r => Err(O::from(r)), + }) + } + } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs index 77ee889ba40..517e40e4cbb 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs @@ -13,25 +13,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -/// The Ambassador Program referendum voting tracks. -use super::{types, Origin}; +//! The Ambassador Program referendum voting tracks. + +use super::Origin; use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES, UNITS}; use sp_runtime::Perbill; +/// Referendum TrackId type. +pub type TrackId = u16; + +/// Referendum tracks ids. +pub mod constants { + use super::TrackId; + + pub const CANDIDATE: TrackId = 0; + pub const AMBASSADOR: TrackId = 1; + pub const SENIOR_AMBASSADOR: TrackId = 2; + pub const HEAD_AMBASSADOR: TrackId = 3; +} + /// The type implementing the [`pallet_referenda::TracksInfo`] trait for referenda pallet. pub struct TracksInfo; /// Information on the voting tracks. impl pallet_referenda::TracksInfo for TracksInfo { - type Id = types::TrackId; + type Id = TrackId; type RuntimeOrigin = ::PalletsOrigin; /// Return the array of available tracks and their information. fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { - static DATA: [(u16, pallet_referenda::TrackInfo); 3] = [ + static DATA: [(TrackId, pallet_referenda::TrackInfo); 4] = [ ( - types::tracks::CANDIDATE, + constants::CANDIDATE, pallet_referenda::TrackInfo { name: "candidate", max_deciding: 50, @@ -53,7 +67,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, ), ( - types::tracks::AMBASSADOR, + constants::AMBASSADOR, pallet_referenda::TrackInfo { name: "ambassador", max_deciding: 50, @@ -75,7 +89,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, ), ( - types::tracks::SENIOR_AMBASSADOR, + constants::SENIOR_AMBASSADOR, pallet_referenda::TrackInfo { name: "senior ambassador", max_deciding: 50, @@ -96,6 +110,28 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, }, ), + ( + constants::HEAD_AMBASSADOR, + pallet_referenda::TrackInfo { + name: "head ambassador", + max_deciding: 50, + decision_deposit: 10 * UNITS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 1 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), ]; &DATA[..] } @@ -108,14 +144,15 @@ impl pallet_referenda::TracksInfo for TracksInfo { // It is important that this is not available in production! let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into(); if &root == id { - return Ok(types::tracks::SENIOR_AMBASSADOR) + return Ok(constants::HEAD_AMBASSADOR) } } match Origin::try_from(id.clone()) { - Ok(Origin::Candidate) => Ok(types::tracks::CANDIDATE), - Ok(Origin::Ambassador) => Ok(types::tracks::AMBASSADOR), - Ok(Origin::SeniorAmbassador) => Ok(types::tracks::SENIOR_AMBASSADOR), + Ok(Origin::Candidate) => Ok(constants::CANDIDATE), + Ok(Origin::Ambassador) => Ok(constants::AMBASSADOR), + Ok(Origin::SeniorAmbassador) => Ok(constants::SENIOR_AMBASSADOR), + Ok(Origin::HeadAmbassador) => Ok(constants::HEAD_AMBASSADOR), _ => Err(()), } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs deleted file mode 100644 index 672f3a5e14a..00000000000 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/types.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/// Types and constants concerning the Ambassador Program. -use frame_support::BoundedVec; -use sp_core::ConstU32; - -/// Referendum TrackId type. -pub type TrackId = u16; - -/// Referendum tracks ids. -pub mod tracks { - use super::TrackId; - - pub const CANDIDATE: TrackId = 0; - pub const AMBASSADOR: TrackId = 1; - pub const SENIOR_AMBASSADOR: TrackId = 2; -} - -/// Members rank type. -pub type Rank = pallet_ranked_collective::Rank; - -/// Members ranks. -pub mod ranks { - use super::Rank; - - pub const CANDIDATE: Rank = 0; - pub const AMBASSADOR: Rank = 1; - pub const SENIOR_AMBASSADOR: Rank = 2; -} - -/// IPFS compatible CID. -// worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. -pub type Cid = BoundedVec>; From 0541b4b70ece03a7426e14ed214ee78e6031e86c Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 9 Jan 2023 18:56:04 +0100 Subject: [PATCH 03/44] docs --- .../collectives-polkadot/src/ambassador/mod.rs | 16 ++++++++++++++-- .../src/ambassador/pallet.rs | 16 +++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index e3dae4b1528..6d995228696 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -14,7 +14,12 @@ // limitations under the License. //! The Ambassador Program. -//! todo docs +//! +//! The module defines the following on-chain functionality of the Ambassador Program: +//! - managed set of the program members, where every member has a [rank](ranks) (via [pallet_ranked_collective]). +//! - referendum functionality for the program members to propose, vote and execute passed proposals on behalf +//! of the members of a certain [rank](Origin) (via [pallet_referenda]). +//! - managed content (charter, announcements) (via [pallet_ambassador]). mod pallet; mod tracks; @@ -44,7 +49,7 @@ pub mod ranks { impl pallet_ambassador::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type AmbassadorOrigin = EnsureAmbassador; + type CharterOrigin = EnsureAmbassador; type MemberOrigin = pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, @@ -67,6 +72,7 @@ impl pallet_referenda::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; type Currency = Balances; + // A proposal can be submitted by a member of the Ambassador Program of [ranks::AMBASSADOR] rank or higher. type SubmitOrigin = pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, @@ -102,10 +108,16 @@ pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance1; impl pallet_ranked_collective::Config for Runtime { type WeightInfo = (); // TODO use actual weights type RuntimeEvent = RuntimeEvent; + // Promotion is by any of: + // - Root can promote arbitrarily. + // - a vote by the rank above the new rank. type PromoteOrigin = EitherOf< frame_system::EnsureRootWithSuccess, TryMapSuccess>>, >; + // Demotion is by any of: + // - Root can demote arbitrarily. + // - a vote by the rank above the current rank. type DemoteOrigin = EitherOf< frame_system::EnsureRootWithSuccess, TryMapSuccess>>, diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs index a67885196c1..30644847879 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! TODO docs +//! The module containing custom pallet/s of the Ambassador Program. use frame_support::BoundedVec; use sp_core::ConstU32; @@ -46,8 +46,8 @@ pub mod pallet_ambassador { /// A member of the Ambassador Program. type MemberOrigin: EnsureOrigin; - /// Ambassador plurality voice. - type AmbassadorOrigin: EnsureOrigin; + /// The origin to control the Ambassador Program charter. + type CharterOrigin: EnsureOrigin; /// The maximum number of announcements. #[pallet::constant] @@ -67,7 +67,7 @@ pub mod pallet_ambassador { HeadAmbassador, } - /// todo docs + /// Errors encountered by the pallet (not a full list). #[pallet::error] pub enum Error { /// The announcement is not found. @@ -76,7 +76,7 @@ pub mod pallet_ambassador { TooManyAnnouncements, } - /// todo docs + /// Events emitted by the pallet. #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -105,7 +105,7 @@ pub mod pallet_ambassador { #[pallet::call_index(0)] #[pallet::weight(0)] // TODO pub fn set_charter(origin: OriginFor, cid: Cid) -> DispatchResult { - T::AmbassadorOrigin::ensure_origin(origin)?; + T::CharterOrigin::ensure_origin(origin)?; Charter::::put(&cid); @@ -158,13 +158,15 @@ pub mod pallet_ambassador { } } - /// Implementation of the [EnsureOrigin] trait for the [Origin::SeniorAmbassador] origin. + /// Implementation of the [EnsureOrigin] trait for the [Origin::SeniorAmbassador] + /// and [Origin::HeadAmbassador] origins. pub struct EnsureSeniorAmbassador; impl> + From> EnsureOrigin for EnsureSeniorAmbassador { type Success = (); fn try_origin(o: O) -> Result { o.into().and_then(|o| match o { Origin::SeniorAmbassador => Ok(()), + Origin::HeadAmbassador => Ok(()), r => Err(O::from(r)), }) } From 5cf1abfbc3bfa6acb467453177cfdde32b5cef74 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 11 Jan 2023 19:54:53 +0100 Subject: [PATCH 04/44] pallet_collective_content, tests, benches --- Cargo.lock | 16 + Cargo.toml | 1 + .../pallets/collective-content/Cargo.toml | 40 +++ .../collective-content/src/benchmarking.rs | 62 ++++ .../collective-content/src/lib.rs} | 102 ++----- .../pallets/collective-content/src/mock.rs | 95 ++++++ .../pallets/collective-content/src/tests.rs | 116 +++++++ .../pallets/collective-content/src/weights.rs | 41 +++ .../collectives-polkadot/Cargo.toml | 2 + .../src/ambassador/mod.rs | 27 +- .../src/ambassador/origins.rs | 100 ++++++ .../collectives-polkadot/src/impls.rs | 6 +- .../collectives-polkadot/src/lib.rs | 14 +- .../collectives-polkadot/src/weights/mod.rs | 5 + .../weights/pallet_ambassador_collective.rs | 106 +++++++ .../src/weights/pallet_ambassador_content.rs | 55 ++++ .../weights/pallet_ambassador_referenda.rs | 289 ++++++++++++++++++ .../src/weights/pallet_preimage.rs | 132 ++++++++ .../src/weights/pallet_scheduler.rs | 126 ++++++++ 19 files changed, 1247 insertions(+), 88 deletions(-) create mode 100644 parachains/pallets/collective-content/Cargo.toml create mode 100644 parachains/pallets/collective-content/src/benchmarking.rs rename parachains/{runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs => pallets/collective-content/src/lib.rs} (56%) create mode 100644 parachains/pallets/collective-content/src/mock.rs create mode 100644 parachains/pallets/collective-content/src/tests.rs create mode 100644 parachains/pallets/collective-content/src/weights.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_collective.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_referenda.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs diff --git a/Cargo.lock b/Cargo.lock index 85e75e0f8b5..9ebdd96ad84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1157,6 +1157,7 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-collective", + "pallet-collective-content", "pallet-multisig", "pallet-preimage", "pallet-proxy", @@ -5694,6 +5695,21 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-collective-content" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-contracts" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index e80bd8f81f5..f937609ff92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ members = [ "primitives/utility", "polkadot-parachain", "parachains/common", + "parachains/pallets/collective-content", "parachains/pallets/parachain-info", "parachains/pallets/ping", "parachains/runtimes/testing/rococo-parachain", diff --git a/parachains/pallets/collective-content/Cargo.toml b/parachains/pallets/collective-content/Cargo.toml new file mode 100644 index 00000000000..2c6e54b5b93 --- /dev/null +++ b/parachains/pallets/collective-content/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "pallet-collective-content" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2021" +description = "Managed content" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] } +scale-info = { version = "2.3.0", default-features = false, features = ["derive"] } + +frame-benchmarking = { git = "https://github.com/paritytech/substrate", optional = true, default-features = false, branch = "master" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } + +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } + +[dev-dependencies] +sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } + +[features] +default = [ "std" ] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] + +std = [ + "codec/std", + "scale-info/std", + "frame-support/std", + "frame-system/std", + "sp-core/std", + "sp-runtime/std", + "sp-std/std", +] diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs new file mode 100644 index 00000000000..5bea1557105 --- /dev/null +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -0,0 +1,62 @@ +// Copyright (C) 2023 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! The pallet benchmarks. + +use super::{Pallet as CollectiveContent, *}; +use frame_benchmarking::benchmarks; +use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; + +fn assert_last_event(generic_event: ::RuntimeEvent) { + frame_system::Pallet::::assert_last_event(generic_event.into()); +} + +benchmarks! { + set_charter { + let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let call = Call::::set_charter { cid: cid.clone() }; + let origin = T::CharterOrigin::successful_origin(); + }: { call.dispatch_bypass_filter(origin)? } + verify { + assert_eq!(CollectiveContent::::charter(), Some(cid.clone())); + assert_last_event::(Event::NewCharterSet { cid }.into()); + } + + announce { + let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let call = Call::::announce { cid: cid.clone() }; + let origin = T::AnnouncementOrigin::successful_origin(); + }: { call.dispatch_bypass_filter(origin)? } + verify { + assert_eq!(CollectiveContent::::announcements().len(), 1); + assert_last_event::(Event::AnnouncementAnnounced { cid }.into()); + } + + remove_announcement { + let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let origin = T::AnnouncementOrigin::successful_origin(); + + CollectiveContent::::announce(origin.clone(), cid.clone())?; + assert_eq!(CollectiveContent::::announcements().len(), 1); + + let call = Call::::remove_announcement { cid: cid.clone() }; + }: { call.dispatch_bypass_filter(origin)? } + verify { + assert_eq!(CollectiveContent::::announcements().len(), 0); + assert_last_event::(Event::AnnouncementRemoved { cid }.into()); + } + + impl_benchmark_test_suite!(CollectiveContent, super::mock::new_bench_ext(), super::mock::Test); +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs b/parachains/pallets/collective-content/src/lib.rs similarity index 56% rename from parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs rename to parachains/pallets/collective-content/src/lib.rs index 30644847879..e7d9762dadb 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/pallet.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// Copyright (C) 2023 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The module containing custom pallet/s of the Ambassador Program. +//! Collective content. +//! TODO docs + +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(test)] +mod mock; +#[cfg(test)] +mod tests; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +pub mod weights; + +pub use pallet::*; +pub use weights::WeightInfo; use frame_support::BoundedVec; use sp_core::ConstU32; @@ -23,11 +38,10 @@ use sp_core::ConstU32; pub type Cid = BoundedVec>; #[frame_support::pallet] -pub mod pallet_ambassador { - use super::{super::ranks, Cid}; +pub mod pallet { + use super::{Cid, WeightInfo}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - use pallet_ranked_collective::Rank; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); @@ -43,28 +57,18 @@ pub mod pallet_ambassador { /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// A member of the Ambassador Program. - type MemberOrigin: EnsureOrigin; + /// The origin to control the collective announcements. + type AnnouncementOrigin: EnsureOrigin; - /// The origin to control the Ambassador Program charter. + /// The origin to control the collective charter. type CharterOrigin: EnsureOrigin; /// The maximum number of announcements. #[pallet::constant] type MaxAnnouncementsCount: Get; - } - #[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)] - #[pallet::origin] - pub enum Origin { - /// Plurality voice of the [ranks::CANDIDATE] members or above given via referendum. - Candidate, - /// Plurality voice of the [ranks::AMBASSADOR] members or above given via referendum. - Ambassador, - /// Plurality voice of the [ranks::SENIOR_AMBASSADOR] members or above given via referendum. - SeniorAmbassador, - /// Plurality voice of the [ranks::HEAD_AMBASSADOR] members or above given via referendum. - HeadAmbassador, + /// Weights information needed for the pallet. + type WeightInfo: WeightInfo; } /// Errors encountered by the pallet (not a full list). @@ -88,12 +92,12 @@ pub mod pallet_ambassador { AnnouncementRemoved { cid: Cid }, } - /// The Ambassador Program's charter. + /// The collective charter. #[pallet::storage] #[pallet::getter(fn charter)] pub type Charter = StorageValue<_, Cid, OptionQuery>; - /// The Ambassador Program's announcements. + /// The collective announcements. #[pallet::storage] #[pallet::getter(fn announcements)] pub type Announcements = @@ -101,9 +105,9 @@ pub mod pallet_ambassador { #[pallet::call] impl Pallet { - /// Set the Ambassador Program's charter. + /// Set the collective charter. #[pallet::call_index(0)] - #[pallet::weight(0)] // TODO + #[pallet::weight(T::WeightInfo::set_charter())] pub fn set_charter(origin: OriginFor, cid: Cid) -> DispatchResult { T::CharterOrigin::ensure_origin(origin)?; @@ -115,9 +119,9 @@ pub mod pallet_ambassador { /// Publish an announcement. #[pallet::call_index(1)] - #[pallet::weight(0)] // TODO + #[pallet::weight(T::WeightInfo::announce())] pub fn announce(origin: OriginFor, cid: Cid) -> DispatchResult { - T::MemberOrigin::ensure_origin(origin)?; + T::AnnouncementOrigin::ensure_origin(origin)?; let mut announcements = >::get(); announcements @@ -131,9 +135,9 @@ pub mod pallet_ambassador { /// Remove an announcement. #[pallet::call_index(2)] - #[pallet::weight(0)] // TODO + #[pallet::weight(T::WeightInfo::remove_announcement())] pub fn remove_announcement(origin: OriginFor, cid: Cid) -> DispatchResult { - T::MemberOrigin::ensure_origin(origin)?; + T::AnnouncementOrigin::ensure_origin(origin)?; let mut announcements = >::get(); let pos = @@ -145,46 +149,4 @@ pub mod pallet_ambassador { Ok(()) } } - - /// Implementation of the [EnsureOrigin] trait for the [Origin::Ambassador] origin. - pub struct EnsureAmbassador; - impl> + From> EnsureOrigin for EnsureAmbassador { - type Success = (); - fn try_origin(o: O) -> Result { - o.into().and_then(|o| match o { - Origin::Ambassador => Ok(()), - r => Err(O::from(r)), - }) - } - } - - /// Implementation of the [EnsureOrigin] trait for the [Origin::SeniorAmbassador] - /// and [Origin::HeadAmbassador] origins. - pub struct EnsureSeniorAmbassador; - impl> + From> EnsureOrigin for EnsureSeniorAmbassador { - type Success = (); - fn try_origin(o: O) -> Result { - o.into().and_then(|o| match o { - Origin::SeniorAmbassador => Ok(()), - Origin::HeadAmbassador => Ok(()), - r => Err(O::from(r)), - }) - } - } - - /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the success result - /// of the corresponding [Rank]. Not implemented for the [Origin::Candidate]. - pub struct EnsureRankedAmbassador; - - impl> + From> EnsureOrigin for EnsureRankedAmbassador { - type Success = Rank; - fn try_origin(o: O) -> Result { - o.into().and_then(|o| match o { - Origin::Ambassador => Ok(ranks::AMBASSADOR), - Origin::SeniorAmbassador => Ok(ranks::SENIOR_AMBASSADOR), - Origin::HeadAmbassador => Ok(ranks::HEAD_AMBASSADOR), - r => Err(O::from(r)), - }) - } - } } diff --git a/parachains/pallets/collective-content/src/mock.rs b/parachains/pallets/collective-content/src/mock.rs new file mode 100644 index 00000000000..ac13907de45 --- /dev/null +++ b/parachains/pallets/collective-content/src/mock.rs @@ -0,0 +1,95 @@ +// Copyright (C) 2023 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Test utilities. + +pub use crate as pallet_collective_content; +use frame_support::{ + ord_parameter_types, + traits::{ConstU32, ConstU64}, +}; +use frame_system::EnsureSignedBy; +use sp_runtime::traits::IdentityLookup; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system, + CollectiveContent: pallet_collective_content, + } +); + +type BlockNumber = u64; +type AccountId = u64; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +ord_parameter_types! { + pub const CharterManager: u64 = 1; + pub const AnnouncementManager: u64 = 2; + pub const OtherAccount: u64 = 3; +} + +impl pallet_collective_content::Config for Test { + type RuntimeEvent = RuntimeEvent; + type CharterOrigin = EnsureSignedBy; + type AnnouncementOrigin = EnsureSignedBy; + type MaxAnnouncementsCount = ConstU32<2>; + type WeightInfo = (); +} + +impl frame_system::Config for Test { + type BaseCallFilter = (); + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Index = u64; + type BlockNumber = BlockNumber; + type Hash = sp_core::H256; + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = sp_runtime::testing::Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +// Build test environment. +pub fn new_test_ext() -> sp_io::TestExternalities { + let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} + +#[cfg(feature = "runtime-benchmarks")] +pub fn new_bench_ext() -> sp_io::TestExternalities { + frame_system::GenesisConfig::default().build_storage().unwrap().into() +} diff --git a/parachains/pallets/collective-content/src/tests.rs b/parachains/pallets/collective-content/src/tests.rs new file mode 100644 index 00000000000..0066e775f71 --- /dev/null +++ b/parachains/pallets/collective-content/src/tests.rs @@ -0,0 +1,116 @@ +// Copyright (C) 2023 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Tests. + +use super::{mock::*, *}; +use frame_support::{assert_noop, assert_ok, error::BadOrigin}; + +#[test] +fn set_charter_works() { + new_test_ext().execute_with(|| { + // wrong origin. + let origin = RuntimeOrigin::signed(OtherAccount::get()); + let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + + assert_noop!(CollectiveContent::set_charter(origin, cid), BadOrigin); + + // success. + let origin = RuntimeOrigin::signed(CharterManager::get()); + let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + + assert_ok!(CollectiveContent::set_charter(origin, cid.clone())); + assert_eq!(CollectiveContent::charter(), Some(cid.clone())); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::NewCharterSet { cid })); + + // reset. success. + let origin = RuntimeOrigin::signed(CharterManager::get()); + let cid: Cid = b"ipfs_hash_reset_success".to_vec().try_into().unwrap(); + + assert_ok!(CollectiveContent::set_charter(origin, cid.clone())); + assert_eq!(CollectiveContent::charter(), Some(cid.clone())); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::NewCharterSet { cid })); + }); +} + +#[test] +fn announce_works() { + new_test_ext().execute_with(|| { + // wrong origin. + let origin = RuntimeOrigin::signed(OtherAccount::get()); + let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + + assert_noop!(CollectiveContent::announce(origin, cid), BadOrigin); + + // success. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + + assert_ok!(CollectiveContent::announce(origin, cid.clone())); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { + cid, + })); + + // one more. success. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + + assert_ok!(CollectiveContent::announce(origin, cid.clone())); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { + cid, + })); + + // too many announcements. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + + assert_noop!(CollectiveContent::announce(origin, cid), Error::::TooManyAnnouncements); + }); +} + +#[test] +fn remove_announcement_works() { + new_test_ext().execute_with(|| { + // wrong origin. + let origin = RuntimeOrigin::signed(OtherAccount::get()); + let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + + assert_noop!(CollectiveContent::remove_announcement(origin, cid), BadOrigin); + + // missing announcement. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_missing".to_vec().try_into().unwrap(); + + assert_noop!( + CollectiveContent::remove_announcement(origin, cid), + Error::::MissingAnnouncement + ); + + // success. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + + assert_ok!(CollectiveContent::announce(origin.clone(), cid.clone())); + + assert_ok!(CollectiveContent::remove_announcement(origin.clone(), cid.clone())); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { + cid: cid.clone(), + })); + assert_noop!( + CollectiveContent::remove_announcement(origin, cid), + Error::::MissingAnnouncement + ); + }); +} diff --git a/parachains/pallets/collective-content/src/weights.rs b/parachains/pallets/collective-content/src/weights.rs new file mode 100644 index 00000000000..363fe8fa328 --- /dev/null +++ b/parachains/pallets/collective-content/src/weights.rs @@ -0,0 +1,41 @@ +// Copyright (C) 2023 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! The pallet weight info trait and its unit implementation. + +use frame_support::weights::Weight; + +/// Weights information needed for the pallet. +pub trait WeightInfo { + /// Returns the weight of the set_charter extrinsic. + fn set_charter() -> Weight; + /// Returns the announce of the set_charter extrinsic. + fn announce() -> Weight; + /// Returns the remove_announcement of the set_charter extrinsic. + fn remove_announcement() -> Weight; +} + +/// Unit implementation of the [WeightInfo]. +impl WeightInfo for () { + fn set_charter() -> Weight { + Weight::zero() + } + fn announce() -> Weight { + Weight::zero() + } + fn remove_announcement() -> Weight { + Weight::zero() + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index b1e313e371e..e71f768eb6d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -72,6 +72,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } +pallet-collective-content = { path = "../../../pallets/collective-content", default-features = false } [dev-dependencies] hex-literal = "0.3.4" @@ -104,6 +105,7 @@ runtime-benchmarks = [ "pallet-preimage/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", "pallet-ranked-collective/runtime-benchmarks", + "pallet-collective-content/runtime-benchmarks", ] try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 6d995228696..3ae108cc206 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -19,15 +19,15 @@ //! - managed set of the program members, where every member has a [rank](ranks) (via [pallet_ranked_collective]). //! - referendum functionality for the program members to propose, vote and execute passed proposals on behalf //! of the members of a certain [rank](Origin) (via [pallet_referenda]). -//! - managed content (charter, announcements) (via [pallet_ambassador]). +//! - managed content (charter, announcements) (via [pallet_collective_content]). -mod pallet; +mod origins; mod tracks; use super::*; use frame_support::traits::TryMapSuccess; -pub use pallet::pallet_ambassador; -use pallet::pallet_ambassador::{ +pub use origins::pallet_origins as pallet_ambassador_origins; +use origins::pallet_origins::{ EnsureAmbassador, EnsureRankedAmbassador, EnsureSeniorAmbassador, Origin, }; use sp_arithmetic::traits::CheckedSub; @@ -47,17 +47,20 @@ pub mod ranks { pub const HEAD_AMBASSADOR: Rank = 3; } -impl pallet_ambassador::Config for Runtime { +impl pallet_collective_content::Config for Runtime { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EnsureAmbassador; - type MemberOrigin = pallet_ranked_collective::EnsureMember< + type AnnouncementOrigin = pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, { ranks::AMBASSADOR }, >; type MaxAnnouncementsCount = ConstU32<100>; + type WeightInfo = weights::pallet_ambassador_content::WeightInfo; } +impl pallet_ambassador_origins::Config for Runtime {} + parameter_types! { pub const AlarmInterval: BlockNumber = 1; pub const SubmissionDeposit: Balance = 0; @@ -84,7 +87,7 @@ impl pallet_referenda::Config for Runtime { type Votes = pallet_ranked_collective::Votes; type Tally = pallet_ranked_collective::TallyOf; type SubmissionDeposit = SubmissionDeposit; - type MaxQueued = ConstU32<100>; + type MaxQueued = ConstU32<20>; type UndecidingTimeout = UndecidingTimeout; type AlarmInterval = AlarmInterval; type Tracks = tracks::TracksInfo; @@ -92,7 +95,9 @@ impl pallet_referenda::Config for Runtime { } parameter_types! { - pub const HeadAmbassadorRank: pallet_ranked_collective::Rank = ranks::HEAD_AMBASSADOR; + // TODO remove "+10", use [ranks::HEAD_AMBASSADOR] instead. To make this possible the benches + // of pallet_ranked_collective should be improved. + pub const MaxAmbassadorRank: pallet_ranked_collective::Rank = ranks::HEAD_AMBASSADOR + 10; } morph_types! { @@ -106,20 +111,20 @@ morph_types! { pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance1; impl pallet_ranked_collective::Config for Runtime { - type WeightInfo = (); // TODO use actual weights + type WeightInfo = weights::pallet_ambassador_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; // Promotion is by any of: // - Root can promote arbitrarily. // - a vote by the rank above the new rank. type PromoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess, + frame_system::EnsureRootWithSuccess, TryMapSuccess>>, >; // Demotion is by any of: // - Root can demote arbitrarily. // - a vote by the rank above the current rank. type DemoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess, + frame_system::EnsureRootWithSuccess, TryMapSuccess>>, >; type Polls = AmbassadorReferenda; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs new file mode 100644 index 00000000000..8c58ba1bc28 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -0,0 +1,100 @@ +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! The Ambassador Program origins. + +#[frame_support::pallet] +pub mod pallet_origins { + use super::super::ranks; + use frame_support::pallet_prelude::*; + use pallet_ranked_collective::Rank; + + #[pallet::pallet] + pub struct Pallet(PhantomData); + + /// The pallet configuration trait. + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)] + #[pallet::origin] + pub enum Origin { + /// Plurality voice of the [ranks::CANDIDATE] members or above given via referendum. + Candidate, + /// Plurality voice of the [ranks::AMBASSADOR] members or above given via referendum. + Ambassador, + /// Plurality voice of the [ranks::SENIOR_AMBASSADOR] members or above given via referendum. + SeniorAmbassador, + /// Plurality voice of the [ranks::HEAD_AMBASSADOR] members or above given via referendum. + HeadAmbassador, + } + + /// Implementation of the [EnsureOrigin] trait for the [Origin::Ambassador] origin. + pub struct EnsureAmbassador; + impl> + From> EnsureOrigin for EnsureAmbassador { + type Success = (); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::Ambassador => Ok(()), + r => Err(O::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::Ambassador)) + } + } + + /// Implementation of the [EnsureOrigin] trait for the [Origin::SeniorAmbassador] + /// and [Origin::HeadAmbassador] origins. + pub struct EnsureSeniorAmbassador; + impl> + From> EnsureOrigin for EnsureSeniorAmbassador { + type Success = (); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::SeniorAmbassador => Ok(()), + Origin::HeadAmbassador => Ok(()), + r => Err(O::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::HeadAmbassador)) + } + } + + /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the success result + /// of the corresponding [Rank]. Not implemented for the [Origin::Candidate]. + pub struct EnsureRankedAmbassador; + + impl> + From> EnsureOrigin for EnsureRankedAmbassador { + type Success = Rank; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::Ambassador => Ok(ranks::AMBASSADOR), + Origin::SeniorAmbassador => Ok(ranks::SENIOR_AMBASSADOR), + Origin::HeadAmbassador => Ok(ranks::HEAD_AMBASSADOR), + r => Err(O::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::HeadAmbassador)) + } + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs index 9aae44465e9..335bcab5dbe 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs @@ -50,9 +50,13 @@ where ::AccountId: From, { fn on_unbalanced(amount: NegativeImbalanceOf) { + let amount = match amount.drop_zero() { + Ok(..) => return, + Err(amount) => amount, + }; + let imbalance = amount.peek(); let temp_account: AccountId = SlashedImbalanceAccId::get(); let treasury_acc: AccountId = RelayTreasuryAccId::get(); - let imbalance = amount.peek(); T::Currency::resolve_creating(&temp_account.clone().into(), amount); diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 1295fc432d1..f390edbff0f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -31,7 +31,7 @@ //! #![cfg_attr(not(feature = "std"), no_std)] -#![recursion_limit = "256"] +#![recursion_limit = "10000"] // Make the WASM binary available. #[cfg(feature = "std")] @@ -42,7 +42,7 @@ pub mod constants; pub mod impls; mod weights; pub mod xcm_config; -use ambassador::pallet_ambassador; +pub use ambassador::pallet_ambassador_origins; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp, ToParentTreasury}; @@ -494,7 +494,7 @@ impl pallet_alliance::Config for Runtime { parameter_types! { pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; - pub const MaxScheduledPerBlock: u32 = 50; + pub const MaxScheduledPerBlock: u32 = 200; // TODO replace by 50, after fixing referendum benches } impl pallet_scheduler::Config for Runtime { @@ -505,7 +505,7 @@ impl pallet_scheduler::Config for Runtime { type MaximumWeight = MaximumSchedulerWeight; type ScheduleOrigin = EnsureRoot; type MaxScheduledPerBlock = MaxScheduledPerBlock; - type WeightInfo = (); // todo weights + type WeightInfo = weights::pallet_scheduler::WeightInfo; type OriginPrivilegeCmp = EqualOrGreatestRootCmp; type Preimages = Preimage; } @@ -516,7 +516,7 @@ parameter_types! { } impl pallet_preimage::Config for Runtime { - type WeightInfo = (); // todo weights + type WeightInfo = weights::pallet_preimage::WeightInfo; type RuntimeEvent = RuntimeEvent; type Currency = Balances; type ManagerOrigin = EnsureRoot; @@ -570,7 +570,8 @@ construct_runtime!( // Ambassador Program AmbassadorCollective: pallet_ranked_collective::::{Pallet, Call, Storage, Event} = 60, AmbassadorReferenda: pallet_referenda::::{Pallet, Call, Storage, Event} = 61, - Ambassador: pallet_ambassador::{Pallet, Origin, Call, Storage, Event} = 62, + AmbassadorContent: pallet_collective_content::{Pallet, Call, Storage, Event} = 62, + AmbassadorOrigins: pallet_ambassador_origins::{Origin} = 63, } ); @@ -637,6 +638,7 @@ mod benches { [pallet_scheduler, Scheduler] [pallet_referenda, AmbassadorReferenda] [pallet_ranked_collective, AmbassadorCollective] + [pallet_collective_content, AmbassadorContent] ); } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs index bf736022ca7..857ca72d919 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs @@ -3,11 +3,16 @@ pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; pub mod pallet_alliance; +pub mod pallet_ambassador_collective; +pub mod pallet_ambassador_content; +pub mod pallet_ambassador_referenda; pub mod pallet_balances; pub mod pallet_collator_selection; pub mod pallet_collective; pub mod pallet_multisig; +pub mod pallet_preimage; pub mod pallet_proxy; +pub mod pallet_scheduler; pub mod pallet_session; pub mod pallet_timestamp; pub mod pallet_utility; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_collective.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_collective.rs new file mode 100644 index 00000000000..1cd0f6876a1 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_collective.rs @@ -0,0 +1,106 @@ + +//! Autogenerated weights for `pallet_ranked_collective` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-01-11, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `cob`, CPU: `` +//! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/debug/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --steps=20 +// --repeat=1 +// --pallet=pallet_ranked_collective +// --extrinsic=* +// --execution=native +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_ranked_collective`. +pub struct WeightInfo(PhantomData); +impl pallet_ranked_collective::WeightInfo for WeightInfo { + // Storage: AmbassadorCollective Members (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:1) + // Storage: AmbassadorCollective IndexToId (r:0 w:1) + // Storage: AmbassadorCollective IdToIndex (r:0 w:1) + fn add_member() -> Weight { + // Minimum execution time: 299_000 nanoseconds. + Weight::from_ref_time(299_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorCollective Members (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:1) + // Storage: AmbassadorCollective IdToIndex (r:1 w:1) + // Storage: AmbassadorCollective IndexToId (r:1 w:1) + /// The range of component `r` is `[0, 10]`. + fn remove_member(r: u32, ) -> Weight { + // Minimum execution time: 484_000 nanoseconds. + Weight::from_ref_time(737_453_843) + // Standard Error: 28_524_997 + .saturating_add(Weight::from_ref_time(87_120_034).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(r.into()))) + .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(r.into()))) + } + // Storage: AmbassadorCollective Members (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:1) + // Storage: AmbassadorCollective IndexToId (r:0 w:1) + // Storage: AmbassadorCollective IdToIndex (r:0 w:1) + /// The range of component `r` is `[0, 10]`. + fn promote_member(r: u32, ) -> Weight { + // Minimum execution time: 358_000 nanoseconds. + Weight::from_ref_time(385_820_805) + // Standard Error: 2_396_847 + .saturating_add(Weight::from_ref_time(7_995_427).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorCollective Members (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:1) + // Storage: AmbassadorCollective IdToIndex (r:1 w:1) + // Storage: AmbassadorCollective IndexToId (r:1 w:1) + /// The range of component `r` is `[0, 10]`. + fn demote_member(r: u32, ) -> Weight { + // Minimum execution time: 486_000 nanoseconds. + Weight::from_ref_time(520_244_641) + // Standard Error: 2_585_811 + .saturating_add(Weight::from_ref_time(13_583_595).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorCollective Members (r:1 w:0) + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective Voting (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn vote() -> Weight { + // Minimum execution time: 660_000 nanoseconds. + Weight::from_ref_time(660_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:0) + // Storage: AmbassadorCollective VotingCleanup (r:1 w:0) + // Storage: AmbassadorCollective Voting (r:0 w:5) + /// The range of component `n` is `[0, 100]`. + fn cleanup_poll(n: u32, ) -> Weight { + // Minimum execution time: 243_000 nanoseconds. + Weight::from_ref_time(293_017_277) + // Standard Error: 659_221 + .saturating_add(Weight::from_ref_time(12_955_251).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs new file mode 100644 index 00000000000..5ad93718efd --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs @@ -0,0 +1,55 @@ + +//! Autogenerated weights for `pallet_collective_content` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-01-11, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `cob`, CPU: `` +//! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/debug/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --steps=20 +// --repeat=1 +// --pallet=pallet_collective_content +// --extrinsic=* +// --execution=native +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_collective_content`. +pub struct WeightInfo(PhantomData); +impl pallet_collective_content::WeightInfo for WeightInfo { + // Storage: AmbassadorContent Charter (r:0 w:1) + fn set_charter() -> Weight { + // Minimum execution time: 220_000 nanoseconds. + Weight::from_ref_time(220_000_000) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: AmbassadorCollective Members (r:1 w:0) + // Storage: AmbassadorContent Announcements (r:1 w:1) + fn announce() -> Weight { + // Minimum execution time: 316_000 nanoseconds. + Weight::from_ref_time(316_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: AmbassadorCollective Members (r:1 w:0) + // Storage: AmbassadorContent Announcements (r:1 w:1) + fn remove_announcement() -> Weight { + // Minimum execution time: 355_000 nanoseconds. + Weight::from_ref_time(355_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_referenda.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_referenda.rs new file mode 100644 index 00000000000..84ccbd1a002 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_referenda.rs @@ -0,0 +1,289 @@ + +//! Autogenerated weights for `pallet_referenda` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-01-11, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `cob`, CPU: `` +//! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/debug/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --steps=20 +// --repeat=1 +// --pallet=pallet_referenda +// --extrinsic=* +// --execution=native +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_referenda`. +pub struct WeightInfo(PhantomData); +impl pallet_referenda::WeightInfo for WeightInfo { + // Storage: AmbassadorCollective Members (r:1 w:0) + // Storage: AmbassadorReferenda ReferendumCount (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: AmbassadorReferenda ReferendumInfoFor (r:0 w:1) + fn submit() -> Weight { + // Minimum execution time: 418_000 nanoseconds. + Weight::from_ref_time(418_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn place_decision_deposit_preparing() -> Weight { + // Minimum execution time: 597_000 nanoseconds. + Weight::from_ref_time(597_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:0) + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + fn place_decision_deposit_queued() -> Weight { + // Minimum execution time: 735_000 nanoseconds. + Weight::from_ref_time(735_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:0) + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + fn place_decision_deposit_not_queued() -> Weight { + // Minimum execution time: 797_000 nanoseconds. + Weight::from_ref_time(797_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + fn place_decision_deposit_passing() -> Weight { + // Minimum execution time: 1_163_000 nanoseconds. + Weight::from_ref_time(1_163_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + fn place_decision_deposit_failing() -> Weight { + // Minimum execution time: 741_000 nanoseconds. + Weight::from_ref_time(741_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + fn refund_decision_deposit() -> Weight { + // Minimum execution time: 441_000 nanoseconds. + Weight::from_ref_time(441_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + fn refund_submission_deposit() -> Weight { + // Minimum execution time: 324_000 nanoseconds. + Weight::from_ref_time(324_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn cancel() -> Weight { + // Minimum execution time: 646_000 nanoseconds. + Weight::from_ref_time(646_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + // Storage: System Account (r:1 w:1) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + fn kill() -> Weight { + // Minimum execution time: 1_390_000 nanoseconds. + Weight::from_ref_time(1_390_000_000) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(6)) + } + // Storage: AmbassadorReferenda TrackQueue (r:1 w:0) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:1) + fn one_fewer_deciding_queue_empty() -> Weight { + // Minimum execution time: 168_000 nanoseconds. + Weight::from_ref_time(168_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + fn one_fewer_deciding_failing() -> Weight { + // Minimum execution time: 1_311_000 nanoseconds. + Weight::from_ref_time(1_311_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + fn one_fewer_deciding_passing() -> Weight { + // Minimum execution time: 1_154_000 nanoseconds. + Weight::from_ref_time(1_154_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_requeued_insertion() -> Weight { + // Minimum execution time: 750_000 nanoseconds. + Weight::from_ref_time(750_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_requeued_slide() -> Weight { + // Minimum execution time: 845_000 nanoseconds. + Weight::from_ref_time(845_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:0) + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_queued() -> Weight { + // Minimum execution time: 851_000 nanoseconds. + Weight::from_ref_time(851_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:0) + // Storage: AmbassadorReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_not_queued() -> Weight { + // Minimum execution time: 884_000 nanoseconds. + Weight::from_ref_time(884_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_no_deposit() -> Weight { + // Minimum execution time: 472_000 nanoseconds. + Weight::from_ref_time(472_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_preparing() -> Weight { + // Minimum execution time: 443_000 nanoseconds. + Weight::from_ref_time(443_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + fn nudge_referendum_timed_out() -> Weight { + // Minimum execution time: 321_000 nanoseconds. + Weight::from_ref_time(321_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_deciding_failing() -> Weight { + // Minimum execution time: 585_000 nanoseconds. + Weight::from_ref_time(585_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorReferenda DecidingCount (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_deciding_passing() -> Weight { + // Minimum execution time: 805_000 nanoseconds. + Weight::from_ref_time(805_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_confirming() -> Weight { + // Minimum execution time: 809_000 nanoseconds. + Weight::from_ref_time(809_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_end_confirming() -> Weight { + // Minimum execution time: 787_000 nanoseconds. + Weight::from_ref_time(787_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_continue_not_confirming() -> Weight { + // Minimum execution time: 852_000 nanoseconds. + Weight::from_ref_time(852_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_continue_confirming() -> Weight { + // Minimum execution time: 761_000 nanoseconds. + Weight::from_ref_time(761_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + // Storage: Scheduler Lookup (r:1 w:1) + fn nudge_referendum_approved() -> Weight { + // Minimum execution time: 1_194_000 nanoseconds. + Weight::from_ref_time(1_194_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + // Storage: AmbassadorReferenda ReferendumInfoFor (r:1 w:1) + // Storage: AmbassadorCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_rejected() -> Weight { + // Minimum execution time: 807_000 nanoseconds. + Weight::from_ref_time(807_000_000) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs new file mode 100644 index 00000000000..dabfe5a02a1 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs @@ -0,0 +1,132 @@ + +//! Autogenerated weights for `pallet_preimage` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-01-11, STEPS: `20`, REPEAT: 2, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `cob`, CPU: `` +//! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/debug/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --steps=20 +// --repeat=2 +// --pallet=pallet_preimage +// --extrinsic=* +// --execution=native +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_preimage`. +pub struct WeightInfo(PhantomData); +impl pallet_preimage::WeightInfo for WeightInfo { + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + /// The range of component `s` is `[0, 4194304]`. + fn note_preimage(s: u32, ) -> Weight { + // Minimum execution time: 396_000 nanoseconds. + Weight::from_ref_time(36_411_249) + // Standard Error: 70 + .saturating_add(Weight::from_ref_time(35_754).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + /// The range of component `s` is `[0, 4194304]`. + fn note_requested_preimage(s: u32, ) -> Weight { + // Minimum execution time: 310_000 nanoseconds. + Weight::from_ref_time(287_561_140) + // Standard Error: 48 + .saturating_add(Weight::from_ref_time(35_508).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + /// The range of component `s` is `[0, 4194304]`. + fn note_no_deposit_preimage(s: u32, ) -> Weight { + // Minimum execution time: 301_000 nanoseconds. + Weight::from_ref_time(155_025_370) + // Standard Error: 46 + .saturating_add(Weight::from_ref_time(35_484).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + fn unnote_preimage() -> Weight { + // Minimum execution time: 503_000 nanoseconds. + Weight::from_ref_time(530_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + fn unnote_no_deposit_preimage() -> Weight { + // Minimum execution time: 363_000 nanoseconds. + Weight::from_ref_time(369_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Preimage StatusFor (r:1 w:1) + fn request_preimage() -> Weight { + // Minimum execution time: 362_000 nanoseconds. + Weight::from_ref_time(371_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Preimage StatusFor (r:1 w:1) + fn request_no_deposit_preimage() -> Weight { + // Minimum execution time: 176_000 nanoseconds. + Weight::from_ref_time(211_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Preimage StatusFor (r:1 w:1) + fn request_unnoted_preimage() -> Weight { + // Minimum execution time: 268_000 nanoseconds. + Weight::from_ref_time(341_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Preimage StatusFor (r:1 w:1) + fn request_requested_preimage() -> Weight { + // Minimum execution time: 147_000 nanoseconds. + Weight::from_ref_time(157_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + fn unrequest_preimage() -> Weight { + // Minimum execution time: 381_000 nanoseconds. + Weight::from_ref_time(422_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Preimage StatusFor (r:1 w:1) + fn unrequest_unnoted_preimage() -> Weight { + // Minimum execution time: 147_000 nanoseconds. + Weight::from_ref_time(162_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Preimage StatusFor (r:1 w:1) + fn unrequest_multi_referenced_preimage() -> Weight { + // Minimum execution time: 132_000 nanoseconds. + Weight::from_ref_time(150_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs new file mode 100644 index 00000000000..b22d6682751 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs @@ -0,0 +1,126 @@ + +//! Autogenerated weights for `pallet_scheduler` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-01-11, STEPS: `20`, REPEAT: 2, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `cob`, CPU: `` +//! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/debug/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --steps=20 +// --repeat=2 +// --pallet=pallet_scheduler +// --extrinsic=* +// --execution=native +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_scheduler`. +pub struct WeightInfo(PhantomData); +impl pallet_scheduler::WeightInfo for WeightInfo { + // Storage: Scheduler IncompleteSince (r:1 w:1) + fn service_agendas_base() -> Weight { + // Minimum execution time: 73_000 nanoseconds. + Weight::from_ref_time(73_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Scheduler Agenda (r:1 w:1) + /// The range of component `s` is `[0, 50]`. + fn service_agenda_base(s: u32, ) -> Weight { + // Minimum execution time: 53_000 nanoseconds. + Weight::from_ref_time(74_451_705) + // Standard Error: 67_176 + .saturating_add(Weight::from_ref_time(2_065_103).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + fn service_task_base() -> Weight { + // Minimum execution time: 170_000 nanoseconds. + Weight::from_ref_time(186_000_000) + } + // Storage: Preimage PreimageFor (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + /// The range of component `s` is `[128, 4194304]`. + fn service_task_fetched(s: u32, ) -> Weight { + // Minimum execution time: 283_000 nanoseconds. + Weight::from_ref_time(22_298_830) + // Standard Error: 61 + .saturating_add(Weight::from_ref_time(847).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Scheduler Lookup (r:0 w:1) + fn service_task_named() -> Weight { + // Minimum execution time: 167_000 nanoseconds. + Weight::from_ref_time(168_000_000) + .saturating_add(T::DbWeight::get().writes(1)) + } + fn service_task_periodic() -> Weight { + // Minimum execution time: 156_000 nanoseconds. + Weight::from_ref_time(163_000_000) + } + fn execute_dispatch_signed() -> Weight { + // Minimum execution time: 54_000 nanoseconds. + Weight::from_ref_time(58_000_000) + } + fn execute_dispatch_unsigned() -> Weight { + // Minimum execution time: 54_000 nanoseconds. + Weight::from_ref_time(56_000_000) + } + // Storage: Scheduler Agenda (r:1 w:1) + /// The range of component `s` is `[0, 49]`. + fn schedule(s: u32, ) -> Weight { + // Minimum execution time: 272_000 nanoseconds. + Weight::from_ref_time(274_280_034) + // Standard Error: 116_351 + .saturating_add(Weight::from_ref_time(2_072_555).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Scheduler Lookup (r:0 w:1) + /// The range of component `s` is `[1, 50]`. + fn cancel(s: u32, ) -> Weight { + // Minimum execution time: 267_000 nanoseconds. + Weight::from_ref_time(281_886_205) + // Standard Error: 192_132 + .saturating_add(Weight::from_ref_time(1_662_227).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Scheduler Lookup (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + /// The range of component `s` is `[0, 49]`. + fn schedule_named(s: u32, ) -> Weight { + // Minimum execution time: 283_000 nanoseconds. + Weight::from_ref_time(299_792_418) + // Standard Error: 150_695 + .saturating_add(Weight::from_ref_time(2_538_776).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + // Storage: Scheduler Lookup (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + /// The range of component `s` is `[1, 50]`. + fn cancel_named(s: u32, ) -> Weight { + // Minimum execution time: 296_000 nanoseconds. + Weight::from_ref_time(323_468_813) + // Standard Error: 184_620 + .saturating_add(Weight::from_ref_time(1_829_588).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} From 07075dde43723810079fdae4833b2459439d9694 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 11 Jan 2023 19:58:51 +0100 Subject: [PATCH 05/44] clean dev code --- parachains/runtimes/collectives/collectives-polkadot/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index f390edbff0f..ad1b2467896 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -31,7 +31,7 @@ //! #![cfg_attr(not(feature = "std"), no_std)] -#![recursion_limit = "10000"] +#![recursion_limit = "256"] // Make the WASM binary available. #[cfg(feature = "std")] From 80df39c8262aeaab98c7c5d554c4bf623e0cc20c Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 12:58:51 +0100 Subject: [PATCH 06/44] docs, worst case fot bench --- .../collective-content/src/benchmarking.rs | 18 +++++++---- .../pallets/collective-content/src/lib.rs | 30 +++++++++++++++++-- .../src/ambassador/mod.rs | 2 +- .../src/weights/pallet_ambassador_content.rs | 14 ++++----- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index 5bea1557105..bec4394032f 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -18,6 +18,8 @@ use super::{Pallet as CollectiveContent, *}; use frame_benchmarking::benchmarks; use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; +use sp_core::Get; +use sp_std::vec; fn assert_last_event(generic_event: ::RuntimeEvent) { frame_system::Pallet::::assert_last_event(generic_event.into()); @@ -25,7 +27,7 @@ fn assert_last_event(generic_event: ::RuntimeEvent) { benchmarks! { set_charter { - let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); let call = Call::::set_charter { cid: cid.clone() }; let origin = T::CharterOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } @@ -35,7 +37,7 @@ benchmarks! { } announce { - let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); let call = Call::::announce { cid: cid.clone() }; let origin = T::AnnouncementOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } @@ -45,16 +47,20 @@ benchmarks! { } remove_announcement { - let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); let origin = T::AnnouncementOrigin::successful_origin(); + let max_count = T::MaxAnnouncementsCount::get() as usize; - CollectiveContent::::announce(origin.clone(), cid.clone())?; - assert_eq!(CollectiveContent::::announcements().len(), 1); + // fill the announcements vec for the worst case. + let announcements = vec![cid.clone(); max_count]; + let announcements: BoundedVec<_, T::MaxAnnouncementsCount> = BoundedVec::try_from(announcements).unwrap(); + Announcements::::put(announcements); + assert_eq!(CollectiveContent::::announcements().len(), max_count); let call = Call::::remove_announcement { cid: cid.clone() }; }: { call.dispatch_bypass_filter(origin)? } verify { - assert_eq!(CollectiveContent::::announcements().len(), 0); + assert_eq!(CollectiveContent::::announcements().len(), max_count - 1); assert_last_event::(Event::AnnouncementRemoved { cid }.into()); } diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index e7d9762dadb..f5cb478590d 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -13,8 +13,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Collective content. -//! TODO docs +//! Managed collective content. +//! +//! The pallet provides the functionality to store different types of the content. +//! The content presented as a [Cid] of the IPFS document which might contain any type of data. +//! Every type of the content has its own origin to be manage. The origins are configurable by clients. +//! +//! Content types: +//! - the collective [charter](pallet::Charter). A single document managed by [CharterOrigin](pallet::Config::CharterOrigin). +//! - the collective [announcements](pallet::Announcements). A list of announcements managed by [AnnouncementOrigin](pallet::Config::AnnouncementOrigin). #![cfg_attr(not(feature = "std"), no_std)] @@ -103,9 +110,16 @@ pub mod pallet { pub type Announcements = StorageValue<_, BoundedVec, ValueQuery>; + // TODO make generic over instance (I), we probably will have multiple instances (Ambassador, Alliance). #[pallet::call] impl Pallet { /// Set the collective charter. + /// + /// Parameters: + /// - `origin`: Must be the [T::CharterOrigin]. + /// - `cid`: [CID](super::Cid) of the IPFS document of the collective charter. + /// + /// Weight: `O(1)`. #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::set_charter())] pub fn set_charter(origin: OriginFor, cid: Cid) -> DispatchResult { @@ -118,6 +132,12 @@ pub mod pallet { } /// Publish an announcement. + /// + /// Parameters: + /// - `origin`: Must be the [T::CharterOrigin]. + /// - `cid`: [CID](super::Cid) of the IPFS document to announce. + /// + /// Weight: `O(1)`. #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::announce())] pub fn announce(origin: OriginFor, cid: Cid) -> DispatchResult { @@ -134,6 +154,12 @@ pub mod pallet { } /// Remove an announcement. + /// + /// Parameters: + /// - `origin`: Must be the [T::CharterOrigin]. + /// - `cid`: [CID](super::Cid) of the IPFS document to remove. + /// + /// Weight: `O(1)`, less of the [T::MaxAnnouncementsCount] is lower. #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::remove_announcement())] pub fn remove_announcement(origin: OriginFor, cid: Cid) -> DispatchResult { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 3ae108cc206..630e9aa5c63 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -70,7 +70,7 @@ parameter_types! { pub type AmbassadorReferendaInstance = pallet_referenda::Instance1; impl pallet_referenda::Config for Runtime { - type WeightInfo = (); // TODO use actual weights + type WeightInfo = weights::pallet_ambassador_referenda; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs index 5ad93718efd..7e429e6d71d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_collective_content` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-01-11, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-01-12, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `cob`, CPU: `` //! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 @@ -32,23 +32,23 @@ pub struct WeightInfo(PhantomData); impl pallet_collective_content::WeightInfo for WeightInfo { // Storage: AmbassadorContent Charter (r:0 w:1) fn set_charter() -> Weight { - // Minimum execution time: 220_000 nanoseconds. - Weight::from_ref_time(220_000_000) + // Minimum execution time: 245_000 nanoseconds. + Weight::from_ref_time(245_000_000) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: AmbassadorCollective Members (r:1 w:0) // Storage: AmbassadorContent Announcements (r:1 w:1) fn announce() -> Weight { - // Minimum execution time: 316_000 nanoseconds. - Weight::from_ref_time(316_000_000) + // Minimum execution time: 352_000 nanoseconds. + Weight::from_ref_time(352_000_000) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: AmbassadorCollective Members (r:1 w:0) // Storage: AmbassadorContent Announcements (r:1 w:1) fn remove_announcement() -> Weight { - // Minimum execution time: 355_000 nanoseconds. - Weight::from_ref_time(355_000_000) + // Minimum execution time: 432_000 nanoseconds. + Weight::from_ref_time(432_000_000) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } From 8c288e3a0145c4ed5e05a73d0da749e70fe9d0f0 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 15:34:09 +0100 Subject: [PATCH 07/44] docs --- parachains/pallets/collective-content/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index f5cb478590d..16893724280 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -18,6 +18,7 @@ //! The pallet provides the functionality to store different types of the content. //! The content presented as a [Cid] of the IPFS document which might contain any type of data. //! Every type of the content has its own origin to be manage. The origins are configurable by clients. +//! Storing the content does not require a deposit, the content expected to be managed by a trusted collective. //! //! Content types: //! - the collective [charter](pallet::Charter). A single document managed by [CharterOrigin](pallet::Config::CharterOrigin). From 5bd566db0dc9dc1abe15ca8d86d935da6ae236ad Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 15:58:30 +0100 Subject: [PATCH 08/44] collective content pallet generic over instance (I) --- .../collective-content/src/benchmarking.rs | 28 ++++++------- .../pallets/collective-content/src/lib.rs | 42 ++++++++++--------- .../src/ambassador/mod.rs | 6 ++- .../collectives-polkadot/src/lib.rs | 2 +- .../src/weights/pallet_ambassador_content.rs | 12 +++--- 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index bec4394032f..fa7afd56212 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -16,34 +16,34 @@ //! The pallet benchmarks. use super::{Pallet as CollectiveContent, *}; -use frame_benchmarking::benchmarks; +use frame_benchmarking::benchmarks_instance_pallet; use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; use sp_core::Get; use sp_std::vec; -fn assert_last_event(generic_event: ::RuntimeEvent) { +fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { frame_system::Pallet::::assert_last_event(generic_event.into()); } -benchmarks! { +benchmarks_instance_pallet! { set_charter { let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); - let call = Call::::set_charter { cid: cid.clone() }; + let call = Call::::set_charter { cid: cid.clone() }; let origin = T::CharterOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } verify { - assert_eq!(CollectiveContent::::charter(), Some(cid.clone())); - assert_last_event::(Event::NewCharterSet { cid }.into()); + assert_eq!(CollectiveContent::::charter(), Some(cid.clone())); + assert_last_event::(Event::NewCharterSet { cid }.into()); } announce { let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); - let call = Call::::announce { cid: cid.clone() }; + let call = Call::::announce { cid: cid.clone() }; let origin = T::AnnouncementOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } verify { - assert_eq!(CollectiveContent::::announcements().len(), 1); - assert_last_event::(Event::AnnouncementAnnounced { cid }.into()); + assert_eq!(CollectiveContent::::announcements().len(), 1); + assert_last_event::(Event::AnnouncementAnnounced { cid }.into()); } remove_announcement { @@ -54,14 +54,14 @@ benchmarks! { // fill the announcements vec for the worst case. let announcements = vec![cid.clone(); max_count]; let announcements: BoundedVec<_, T::MaxAnnouncementsCount> = BoundedVec::try_from(announcements).unwrap(); - Announcements::::put(announcements); - assert_eq!(CollectiveContent::::announcements().len(), max_count); + Announcements::::put(announcements); + assert_eq!(CollectiveContent::::announcements().len(), max_count); - let call = Call::::remove_announcement { cid: cid.clone() }; + let call = Call::::remove_announcement { cid: cid.clone() }; }: { call.dispatch_bypass_filter(origin)? } verify { - assert_eq!(CollectiveContent::::announcements().len(), max_count - 1); - assert_last_event::(Event::AnnouncementRemoved { cid }.into()); + assert_eq!(CollectiveContent::::announcements().len(), max_count - 1); + assert_last_event::(Event::AnnouncementRemoved { cid }.into()); } impl_benchmark_test_suite!(CollectiveContent, super::mock::new_bench_ext(), super::mock::Test); diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 16893724280..cf0a68e3cd5 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -57,13 +57,14 @@ pub mod pallet { #[pallet::pallet] #[pallet::generate_store(pub (super) trait Store)] #[pallet::storage_version(STORAGE_VERSION)] - pub struct Pallet(PhantomData); + pub struct Pallet(PhantomData<(T, I)>); /// The module configuration trait. #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config { /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type RuntimeEvent: From> + + IsType<::RuntimeEvent>; /// The origin to control the collective announcements. type AnnouncementOrigin: EnsureOrigin; @@ -81,7 +82,7 @@ pub mod pallet { /// Errors encountered by the pallet (not a full list). #[pallet::error] - pub enum Error { + pub enum Error { /// The announcement is not found. MissingAnnouncement, /// Number of announcements exceeds `MaxAnnouncementsCount`. @@ -91,7 +92,7 @@ pub mod pallet { /// Events emitted by the pallet. #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { + pub enum Event, I: 'static = ()> { /// A new charter has been set. NewCharterSet { cid: Cid }, /// A new announcement has been proposed. @@ -103,17 +104,16 @@ pub mod pallet { /// The collective charter. #[pallet::storage] #[pallet::getter(fn charter)] - pub type Charter = StorageValue<_, Cid, OptionQuery>; + pub type Charter, I: 'static = ()> = StorageValue<_, Cid, OptionQuery>; /// The collective announcements. #[pallet::storage] #[pallet::getter(fn announcements)] - pub type Announcements = + pub type Announcements, I: 'static = ()> = StorageValue<_, BoundedVec, ValueQuery>; - // TODO make generic over instance (I), we probably will have multiple instances (Ambassador, Alliance). #[pallet::call] - impl Pallet { + impl, I: 'static> Pallet { /// Set the collective charter. /// /// Parameters: @@ -126,9 +126,9 @@ pub mod pallet { pub fn set_charter(origin: OriginFor, cid: Cid) -> DispatchResult { T::CharterOrigin::ensure_origin(origin)?; - Charter::::put(&cid); + Charter::::put(&cid); - Self::deposit_event(Event::::NewCharterSet { cid }); + Self::deposit_event(Event::::NewCharterSet { cid }); Ok(()) } @@ -144,13 +144,13 @@ pub mod pallet { pub fn announce(origin: OriginFor, cid: Cid) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; - let mut announcements = >::get(); + let mut announcements = >::get(); announcements .try_push(cid.clone()) - .map_err(|_| Error::::TooManyAnnouncements)?; - >::put(announcements); + .map_err(|_| Error::::TooManyAnnouncements)?; + >::put(announcements); - Self::deposit_event(Event::::AnnouncementAnnounced { cid }); + Self::deposit_event(Event::::AnnouncementAnnounced { cid }); Ok(()) } @@ -166,13 +166,15 @@ pub mod pallet { pub fn remove_announcement(origin: OriginFor, cid: Cid) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; - let mut announcements = >::get(); - let pos = - announcements.binary_search(&cid).ok().ok_or(Error::::MissingAnnouncement)?; + let mut announcements = >::get(); + let pos = announcements + .binary_search(&cid) + .ok() + .ok_or(Error::::MissingAnnouncement)?; announcements.remove(pos); - >::put(announcements); + >::put(announcements); - Self::deposit_event(Event::::AnnouncementRemoved { cid }); + Self::deposit_event(Event::::AnnouncementRemoved { cid }); Ok(()) } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 630e9aa5c63..d9687ddca7a 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -47,7 +47,9 @@ pub mod ranks { pub const HEAD_AMBASSADOR: Rank = 3; } -impl pallet_collective_content::Config for Runtime { +pub type AmbassadorContentInstance = pallet_collective_content::Instance1; + +impl pallet_collective_content::Config for Runtime { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EnsureAmbassador; type AnnouncementOrigin = pallet_ranked_collective::EnsureMember< @@ -70,7 +72,7 @@ parameter_types! { pub type AmbassadorReferendaInstance = pallet_referenda::Instance1; impl pallet_referenda::Config for Runtime { - type WeightInfo = weights::pallet_ambassador_referenda; + type WeightInfo = weights::pallet_ambassador_referenda::WeightInfo; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index ad1b2467896..b5662b77a13 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -570,7 +570,7 @@ construct_runtime!( // Ambassador Program AmbassadorCollective: pallet_ranked_collective::::{Pallet, Call, Storage, Event} = 60, AmbassadorReferenda: pallet_referenda::::{Pallet, Call, Storage, Event} = 61, - AmbassadorContent: pallet_collective_content::{Pallet, Call, Storage, Event} = 62, + AmbassadorContent: pallet_collective_content::::{Pallet, Call, Storage, Event} = 62, AmbassadorOrigins: pallet_ambassador_origins::{Origin} = 63, } ); diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs index 7e429e6d71d..dca3ed4d0e8 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs @@ -32,23 +32,23 @@ pub struct WeightInfo(PhantomData); impl pallet_collective_content::WeightInfo for WeightInfo { // Storage: AmbassadorContent Charter (r:0 w:1) fn set_charter() -> Weight { - // Minimum execution time: 245_000 nanoseconds. - Weight::from_ref_time(245_000_000) + // Minimum execution time: 214_000 nanoseconds. + Weight::from_ref_time(214_000_000) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: AmbassadorCollective Members (r:1 w:0) // Storage: AmbassadorContent Announcements (r:1 w:1) fn announce() -> Weight { - // Minimum execution time: 352_000 nanoseconds. - Weight::from_ref_time(352_000_000) + // Minimum execution time: 317_000 nanoseconds. + Weight::from_ref_time(317_000_000) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: AmbassadorCollective Members (r:1 w:0) // Storage: AmbassadorContent Announcements (r:1 w:1) fn remove_announcement() -> Weight { - // Minimum execution time: 432_000 nanoseconds. - Weight::from_ref_time(432_000_000) + // Minimum execution time: 394_000 nanoseconds. + Weight::from_ref_time(394_000_000) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } From 5356d1102e27ecee166995f804d21309d23e2754 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 16:12:31 +0100 Subject: [PATCH 09/44] fix docs --- parachains/pallets/collective-content/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index cf0a68e3cd5..fadbdc5e573 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -117,7 +117,7 @@ pub mod pallet { /// Set the collective charter. /// /// Parameters: - /// - `origin`: Must be the [T::CharterOrigin]. + /// - `origin`: Must be the [Config::CharterOrigin]. /// - `cid`: [CID](super::Cid) of the IPFS document of the collective charter. /// /// Weight: `O(1)`. @@ -135,7 +135,7 @@ pub mod pallet { /// Publish an announcement. /// /// Parameters: - /// - `origin`: Must be the [T::CharterOrigin]. + /// - `origin`: Must be the [Config::CharterOrigin]. /// - `cid`: [CID](super::Cid) of the IPFS document to announce. /// /// Weight: `O(1)`. @@ -157,10 +157,10 @@ pub mod pallet { /// Remove an announcement. /// /// Parameters: - /// - `origin`: Must be the [T::CharterOrigin]. + /// - `origin`: Must be the [Config::CharterOrigin]. /// - `cid`: [CID](super::Cid) of the IPFS document to remove. /// - /// Weight: `O(1)`, less of the [T::MaxAnnouncementsCount] is lower. + /// Weight: `O(1)`, less of the [Config::MaxAnnouncementsCount] is lower. #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::remove_announcement())] pub fn remove_announcement(origin: OriginFor, cid: Cid) -> DispatchResult { From 8112e4857a8b5651c2ecd66a16659265281d93c2 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 16:30:04 +0100 Subject: [PATCH 10/44] ranks public --- .../collectives/collectives-polkadot/src/ambassador/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index d9687ddca7a..0d794cde515 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -27,6 +27,7 @@ mod tracks; use super::*; use frame_support::traits::TryMapSuccess; pub use origins::pallet_origins as pallet_ambassador_origins; +pub use ranks; use origins::pallet_origins::{ EnsureAmbassador, EnsureRankedAmbassador, EnsureSeniorAmbassador, Origin, }; From 0ffbaafc020cf057181dafd0637b3ae1b0b79e3c Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 16:32:04 +0100 Subject: [PATCH 11/44] rustfmt --- .../collectives/collectives-polkadot/src/ambassador/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 0d794cde515..78985dccc59 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -27,10 +27,10 @@ mod tracks; use super::*; use frame_support::traits::TryMapSuccess; pub use origins::pallet_origins as pallet_ambassador_origins; -pub use ranks; use origins::pallet_origins::{ EnsureAmbassador, EnsureRankedAmbassador, EnsureSeniorAmbassador, Origin, }; +pub use ranks; use sp_arithmetic::traits::CheckedSub; use sp_runtime::{ morph_types, From b81ba289aaa072ee8ec6b1f5e71200fd769b151a Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 16:44:44 +0100 Subject: [PATCH 12/44] fix --- .../collectives/collectives-polkadot/src/ambassador/mod.rs | 3 +-- .../runtimes/collectives/collectives-polkadot/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 78985dccc59..1b586a935be 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -21,7 +21,7 @@ //! of the members of a certain [rank](Origin) (via [pallet_referenda]). //! - managed content (charter, announcements) (via [pallet_collective_content]). -mod origins; +pub mod origins; mod tracks; use super::*; @@ -30,7 +30,6 @@ pub use origins::pallet_origins as pallet_ambassador_origins; use origins::pallet_origins::{ EnsureAmbassador, EnsureRankedAmbassador, EnsureSeniorAmbassador, Origin, }; -pub use ranks; use sp_arithmetic::traits::CheckedSub; use sp_runtime::{ morph_types, diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index b5662b77a13..ae09fd4bbc4 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -37,7 +37,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -mod ambassador; +pub mod ambassador; pub mod constants; pub mod impls; mod weights; From 9b89c1d359d59a7778a564dbe0d4b8990854ac9d Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 12 Jan 2023 17:42:40 +0100 Subject: [PATCH 13/44] add try runtime feature to collective content pallet --- parachains/pallets/collective-content/Cargo.toml | 5 +++++ .../runtimes/collectives/collectives-polkadot/Cargo.toml | 1 + 2 files changed, 6 insertions(+) diff --git a/parachains/pallets/collective-content/Cargo.toml b/parachains/pallets/collective-content/Cargo.toml index 2c6e54b5b93..02ba045b6de 100644 --- a/parachains/pallets/collective-content/Cargo.toml +++ b/parachains/pallets/collective-content/Cargo.toml @@ -38,3 +38,8 @@ std = [ "sp-runtime/std", "sp-std/std", ] + +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index e71f768eb6d..990d868ccc4 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -134,6 +134,7 @@ try-runtime = [ "pallet-preimage/try-runtime", "pallet-referenda/try-runtime", "pallet-ranked-collective/try-runtime", + "pallet-collective-content/try-runtime", ] std = [ "codec/std", From 6104edb883b36ce2268b01c24edf7578d72cb2f9 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 25 Jan 2023 15:39:46 +0100 Subject: [PATCH 14/44] typo fixes, announcement origin, ambassador proxy --- parachains/pallets/collective-content/src/lib.rs | 2 +- .../collectives-polkadot/src/ambassador/mod.rs | 13 +++++++++---- .../collectives/collectives-polkadot/src/impls.rs | 2 +- .../collectives/collectives-polkadot/src/lib.rs | 10 ++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index fadbdc5e573..9807fe08060 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -95,7 +95,7 @@ pub mod pallet { pub enum Event, I: 'static = ()> { /// A new charter has been set. NewCharterSet { cid: Cid }, - /// A new announcement has been proposed. + /// A new announcement has been made. AnnouncementAnnounced { cid: Cid }, /// An on-chain announcement has been removed. AnnouncementRemoved { cid: Cid }, diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 1b586a935be..bb713e7ec02 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -52,10 +52,15 @@ pub type AmbassadorContentInstance = pallet_collective_content::Instance1; impl pallet_collective_content::Config for Runtime { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EnsureAmbassador; - type AnnouncementOrigin = pallet_ranked_collective::EnsureMember< - Runtime, - AmbassadorCollectiveInstance, - { ranks::AMBASSADOR }, + // An announcement can be submitted by a Senior Ambassador member or the [Origin::Ambassador] plurality voice + // taken via referendum on the [tracks::constants::AMBASSADOR] track. + type AnnouncementOrigin = EitherOfDiverse< + pallet_ranked_collective::EnsureMember< + Runtime, + AmbassadorCollectiveInstance, + { ranks::SENIOR_AMBASSADOR }, + >, + EnsureAmbassador, >; type MaxAnnouncementsCount = ConstU32<100>; type WeightInfo = weights::pallet_ambassador_content::WeightInfo; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs index 335bcab5dbe..f2529ac8043 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs @@ -131,7 +131,7 @@ where } } -/// Used the compare the privilege of an origin inside the scheduler. +/// Used to compare the privilege of an origin inside the scheduler. pub struct EqualOrGreatestRootCmp; impl PrivilegeCmp for EqualOrGreatestRootCmp { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 6843a57c1c2..ee43131cdc1 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -285,6 +285,8 @@ pub enum ProxyType { Collator, /// Alliance proxy. Allows calls related to the Alliance. Alliance, + /// Ambassador proxy. Allows calls related to the Ambassador Program. + Ambassador, } impl Default for ProxyType { fn default() -> Self { @@ -321,6 +323,14 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } ), + ProxyType::Ambassador => matches!( + c, + RuntimeCall::AmbassadorCollective { .. } | + RuntimeCall::AmbassadorReferenda { .. } | + RuntimeCall::AmbassadorContent { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } + ), } } fn is_superset(&self, o: &Self) -> bool { From f0c3a60e068b634b687c90e4be9c3511104bba7d Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 25 Jan 2023 20:23:52 +0100 Subject: [PATCH 15/44] announcements with an expiration --- .../collective-content/src/benchmarking.rs | 22 +++++- .../pallets/collective-content/src/lib.rs | 51 +++++++++--- .../pallets/collective-content/src/mock.rs | 2 +- .../pallets/collective-content/src/tests.rs | 79 +++++++++++++++++-- .../pallets/collective-content/src/weights.rs | 4 +- .../src/weights/pallet_ambassador_content.rs | 30 ++++--- 6 files changed, 152 insertions(+), 36 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index fa7afd56212..dc46ffcc261 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -15,7 +15,7 @@ //! The pallet benchmarks. -use super::{Pallet as CollectiveContent, *}; +use super::{DispatchTimeFor, Pallet as CollectiveContent, *}; use frame_benchmarking::benchmarks_instance_pallet; use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; use sp_core::Get; @@ -37,13 +37,27 @@ benchmarks_instance_pallet! { } announce { + let x in 0 .. 1; + + let mut maybe_expire = None; + if x == 1 { + maybe_expire = Some(DispatchTimeFor::::At(10u32.into())); + } + let now = frame_system::Pallet::::block_number(); let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); - let call = Call::::announce { cid: cid.clone() }; + let call = Call::::announce { + cid: cid.clone(), + maybe_expire: maybe_expire.clone(), + }; let origin = T::AnnouncementOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } verify { assert_eq!(CollectiveContent::::announcements().len(), 1); - assert_last_event::(Event::AnnouncementAnnounced { cid }.into()); + assert_eq!(NextAnnouncementExpire::::get().map_or(0, |_| 1), x); + assert_last_event::(Event::AnnouncementAnnounced { + cid, + maybe_expire_at: maybe_expire.map_or(None, |e| Some(e.evaluate(now))), + }.into()); } remove_announcement { @@ -52,7 +66,7 @@ benchmarks_instance_pallet! { let max_count = T::MaxAnnouncementsCount::get() as usize; // fill the announcements vec for the worst case. - let announcements = vec![cid.clone(); max_count]; + let announcements = vec![(cid.clone(), None); max_count]; let announcements: BoundedVec<_, T::MaxAnnouncementsCount> = BoundedVec::try_from(announcements).unwrap(); Announcements::::put(announcements); assert_eq!(CollectiveContent::::announcements().len(), max_count); diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 9807fe08060..687de11f186 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -38,16 +38,22 @@ pub mod weights; pub use pallet::*; pub use weights::WeightInfo; -use frame_support::BoundedVec; +use frame_support::{traits::schedule::DispatchTime, BoundedVec}; use sp_core::ConstU32; /// IPFS compatible CID. // worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. pub type Cid = BoundedVec>; +/// The block number type of [frame_system::Config]. +pub type BlockNumberFor = ::BlockNumber; + +/// [DispatchTime] of [frame_system::Config]. +pub type DispatchTimeFor = DispatchTime>; + #[frame_support::pallet] pub mod pallet { - use super::{Cid, WeightInfo}; + use super::{Cid, DispatchTimeFor, WeightInfo}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -87,6 +93,8 @@ pub mod pallet { MissingAnnouncement, /// Number of announcements exceeds `MaxAnnouncementsCount`. TooManyAnnouncements, + /// Cannot expire in the past. + InvalidExpire, } /// Events emitted by the pallet. @@ -96,7 +104,7 @@ pub mod pallet { /// A new charter has been set. NewCharterSet { cid: Cid }, /// A new announcement has been made. - AnnouncementAnnounced { cid: Cid }, + AnnouncementAnnounced { cid: Cid, maybe_expire_at: Option }, /// An on-chain announcement has been removed. AnnouncementRemoved { cid: Cid }, } @@ -109,8 +117,16 @@ pub mod pallet { /// The collective announcements. #[pallet::storage] #[pallet::getter(fn announcements)] - pub type Announcements, I: 'static = ()> = - StorageValue<_, BoundedVec, ValueQuery>; + pub type Announcements, I: 'static = ()> = StorageValue< + _, + BoundedVec<(Cid, Option), T::MaxAnnouncementsCount>, + ValueQuery, + >; + + /// The closest expiration block number of an announcement. + #[pallet::storage] + pub type NextAnnouncementExpire, I: 'static = ()> = + StorageValue<_, T::BlockNumber, OptionQuery>; #[pallet::call] impl, I: 'static> Pallet { @@ -137,20 +153,35 @@ pub mod pallet { /// Parameters: /// - `origin`: Must be the [Config::CharterOrigin]. /// - `cid`: [CID](super::Cid) of the IPFS document to announce. + /// - `maybe_expire`: expiration block of the announcement. /// /// Weight: `O(1)`. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::announce())] - pub fn announce(origin: OriginFor, cid: Cid) -> DispatchResult { + #[pallet::weight(T::WeightInfo::announce(maybe_expire.map_or(0, |_| 1)))] + pub fn announce( + origin: OriginFor, + cid: Cid, + maybe_expire: Option>, + ) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; + let now = frame_system::Pallet::::block_number(); + let maybe_expire_at = maybe_expire.map(|e| e.evaluate(now)); + ensure!(maybe_expire_at.map_or(true, |e| e > now), Error::::InvalidExpire); + let mut announcements = >::get(); announcements - .try_push(cid.clone()) + .try_push((cid.clone(), maybe_expire_at.clone())) .map_err(|_| Error::::TooManyAnnouncements)?; >::put(announcements); - Self::deposit_event(Event::::AnnouncementAnnounced { cid }); + if let Some(expire_at) = maybe_expire_at { + if NextAnnouncementExpire::::get().map_or(true, |n| n > expire_at) { + NextAnnouncementExpire::::put(expire_at); + } + } + + Self::deposit_event(Event::::AnnouncementAnnounced { cid, maybe_expire_at }); Ok(()) } @@ -168,7 +199,7 @@ pub mod pallet { let mut announcements = >::get(); let pos = announcements - .binary_search(&cid) + .binary_search_by_key(&cid, |(c, _)| c.clone()) .ok() .ok_or(Error::::MissingAnnouncement)?; announcements.remove(pos); diff --git a/parachains/pallets/collective-content/src/mock.rs b/parachains/pallets/collective-content/src/mock.rs index ac13907de45..abc125a3a56 100644 --- a/parachains/pallets/collective-content/src/mock.rs +++ b/parachains/pallets/collective-content/src/mock.rs @@ -50,7 +50,7 @@ impl pallet_collective_content::Config for Test { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EnsureSignedBy; type AnnouncementOrigin = EnsureSignedBy; - type MaxAnnouncementsCount = ConstU32<2>; + type MaxAnnouncementsCount = ConstU32<5>; type WeightInfo = (); } diff --git a/parachains/pallets/collective-content/src/tests.rs b/parachains/pallets/collective-content/src/tests.rs index 0066e775f71..4470a57b9d9 100644 --- a/parachains/pallets/collective-content/src/tests.rs +++ b/parachains/pallets/collective-content/src/tests.rs @@ -48,35 +48,83 @@ fn set_charter_works() { #[test] fn announce_works() { new_test_ext().execute_with(|| { + let now = frame_system::Pallet::::block_number(); // wrong origin. let origin = RuntimeOrigin::signed(OtherAccount::get()); let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); - assert_noop!(CollectiveContent::announce(origin, cid), BadOrigin); + assert_noop!(CollectiveContent::announce(origin, cid, None), BadOrigin); // success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + let maybe_expire_at = None; - assert_ok!(CollectiveContent::announce(origin, cid.clone())); + assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); + assert_eq!(NextAnnouncementExpire::::get(), None); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, + maybe_expire_at: None, })); // one more. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let maybe_expire_at = None; - assert_ok!(CollectiveContent::announce(origin, cid.clone())); + assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); + assert_eq!(NextAnnouncementExpire::::get(), None); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, + maybe_expire_at: None, + })); + + // one more with expire. success. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let maybe_expire_at = DispatchTimeFor::::After(10); + + assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); + assert_eq!(NextAnnouncementExpire::::get(), Some(maybe_expire_at.evaluate(now))); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { + cid, + maybe_expire_at: Some(maybe_expire_at.evaluate(now)), + })); + + // one more with later expire. success. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let prev_maybe_expire_at = DispatchTimeFor::::After(10); + let maybe_expire_at = DispatchTimeFor::::At(now + 20); + + assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); + assert_eq!(NextAnnouncementExpire::::get(), Some(prev_maybe_expire_at.evaluate(now))); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { + cid, + maybe_expire_at: Some(maybe_expire_at.evaluate(now)), + })); + + // one more with earlier expire. success. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let maybe_expire_at = DispatchTimeFor::::At(now + 5); + + assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); + assert_eq!(NextAnnouncementExpire::::get(), Some(maybe_expire_at.evaluate(now))); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { + cid, + maybe_expire_at: Some(maybe_expire_at.evaluate(now)), })); // too many announcements. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let maybe_expire_at = None; - assert_noop!(CollectiveContent::announce(origin, cid), Error::::TooManyAnnouncements); + assert_noop!( + CollectiveContent::announce(origin, cid, maybe_expire_at), + Error::::TooManyAnnouncements + ); }); } @@ -99,17 +147,36 @@ fn remove_announcement_works() { ); // success. + // add announcement. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + assert_ok!(CollectiveContent::announce(origin.clone(), cid.clone(), None)); - assert_ok!(CollectiveContent::announce(origin.clone(), cid.clone())); + // one more announcement. + let cid_2: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let expire_at_2 = DispatchTimeFor::::At(10); + assert_ok!(CollectiveContent::announce(origin.clone(), cid_2.clone(), Some(expire_at_2))); + // two announcements registered. + assert_eq!(>::get().len(), 2); + // remove first announcement and assert. assert_ok!(CollectiveContent::remove_announcement(origin.clone(), cid.clone())); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { cid: cid.clone(), })); assert_noop!( - CollectiveContent::remove_announcement(origin, cid), + CollectiveContent::remove_announcement(origin.clone(), cid), + Error::::MissingAnnouncement + ); + assert_eq!(>::get().len(), 1); + + // remove second announcement and assert. + assert_ok!(CollectiveContent::remove_announcement(origin.clone(), cid_2.clone())); + System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { + cid: cid_2.clone(), + })); + assert_noop!( + CollectiveContent::remove_announcement(origin, cid_2), Error::::MissingAnnouncement ); }); diff --git a/parachains/pallets/collective-content/src/weights.rs b/parachains/pallets/collective-content/src/weights.rs index 363fe8fa328..e489b524e82 100644 --- a/parachains/pallets/collective-content/src/weights.rs +++ b/parachains/pallets/collective-content/src/weights.rs @@ -22,7 +22,7 @@ pub trait WeightInfo { /// Returns the weight of the set_charter extrinsic. fn set_charter() -> Weight; /// Returns the announce of the set_charter extrinsic. - fn announce() -> Weight; + fn announce(_x: u32) -> Weight; /// Returns the remove_announcement of the set_charter extrinsic. fn remove_announcement() -> Weight; } @@ -32,7 +32,7 @@ impl WeightInfo for () { fn set_charter() -> Weight { Weight::zero() } - fn announce() -> Weight { + fn announce(_x: u32) -> Weight { Weight::zero() } fn remove_announcement() -> Weight { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs index dca3ed4d0e8..f622d346269 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_collective_content` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-01-12, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-01-25, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `cob`, CPU: `` //! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 @@ -18,7 +18,7 @@ // --execution=native // --wasm-execution=compiled // --heap-pages=4096 -// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/._pallet_ambassador_content.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -32,24 +32,28 @@ pub struct WeightInfo(PhantomData); impl pallet_collective_content::WeightInfo for WeightInfo { // Storage: AmbassadorContent Charter (r:0 w:1) fn set_charter() -> Weight { - // Minimum execution time: 214_000 nanoseconds. - Weight::from_ref_time(214_000_000) + // Minimum execution time: 218_000 nanoseconds. + Weight::from_ref_time(218_000_000) .saturating_add(T::DbWeight::get().writes(1)) } - // Storage: AmbassadorCollective Members (r:1 w:0) // Storage: AmbassadorContent Announcements (r:1 w:1) - fn announce() -> Weight { - // Minimum execution time: 317_000 nanoseconds. - Weight::from_ref_time(317_000_000) - .saturating_add(T::DbWeight::get().reads(2)) + // Storage: AmbassadorContent NextAnnouncementExpire (r:1 w:1) + /// The range of component `x` is `[0, 1]`. + fn announce(x: u32, ) -> Weight { + // Minimum execution time: 256_000 nanoseconds. + Weight::from_ref_time(264_545_454) + // Standard Error: 2_055_430 + .saturating_add(Weight::from_ref_time(7_454_545).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) } - // Storage: AmbassadorCollective Members (r:1 w:0) // Storage: AmbassadorContent Announcements (r:1 w:1) fn remove_announcement() -> Weight { - // Minimum execution time: 394_000 nanoseconds. - Weight::from_ref_time(394_000_000) - .saturating_add(T::DbWeight::get().reads(2)) + // Minimum execution time: 337_000 nanoseconds. + Weight::from_ref_time(337_000_000) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } } From 514fce90fc53011a4b0c8a8639f689d49ef9261b Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 27 Jan 2023 16:31:08 +0100 Subject: [PATCH 16/44] cleaup announcements on idle --- .../collective-content/src/benchmarking.rs | 24 ++++++- .../pallets/collective-content/src/lib.rs | 68 +++++++++++++++++-- .../pallets/collective-content/src/mock.rs | 28 +++++++- .../pallets/collective-content/src/tests.rs | 68 +++++++++++++++++-- .../pallets/collective-content/src/weights.rs | 9 ++- .../src/weights/pallet_ambassador_content.rs | 26 ++++--- 6 files changed, 196 insertions(+), 27 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index dc46ffcc261..994fe8f9e23 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -19,7 +19,6 @@ use super::{DispatchTimeFor, Pallet as CollectiveContent, *}; use frame_benchmarking::benchmarks_instance_pallet; use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; use sp_core::Get; -use sp_std::vec; fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { frame_system::Pallet::::assert_last_event(generic_event.into()); @@ -53,7 +52,7 @@ benchmarks_instance_pallet! { }: { call.dispatch_bypass_filter(origin)? } verify { assert_eq!(CollectiveContent::::announcements().len(), 1); - assert_eq!(NextAnnouncementExpire::::get().map_or(0, |_| 1), x); + assert_eq!(NextAnnouncementExpireAt::::get().map_or(0, |_| 1), x); assert_last_event::(Event::AnnouncementAnnounced { cid, maybe_expire_at: maybe_expire.map_or(None, |e| Some(e.evaluate(now))), @@ -78,5 +77,26 @@ benchmarks_instance_pallet! { assert_last_event::(Event::AnnouncementRemoved { cid }.into()); } + cleanup_announcements { + let origin = T::AnnouncementOrigin::successful_origin(); + let max_count = T::MaxAnnouncementsCount::get() as usize; + + for i in 0..max_count { + let cid: Cid = i.to_ne_bytes().to_vec().try_into().unwrap(); + CollectiveContent::::announce( + origin.clone(), + cid, + Some(DispatchTimeFor::::At(5u32.into())), + ).expect("could not publish an announcement"); + } + assert_eq!(CollectiveContent::::announcements().len(), max_count); + frame_system::Pallet::::set_block_number(10u32.into()); + }: { + CollectiveContent::::cleanup_announcements(10u32.into()); + } verify { + assert_eq!(CollectiveContent::::announcements().len(), 0); + assert_eq!(frame_system::Pallet::::events().len(), max_count) + } + impl_benchmark_test_suite!(CollectiveContent, super::mock::new_bench_ext(), super::mock::Test); } diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 687de11f186..889aacac8a6 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -40,6 +40,7 @@ pub use weights::WeightInfo; use frame_support::{traits::schedule::DispatchTime, BoundedVec}; use sp_core::ConstU32; +use sp_std::prelude::*; /// IPFS compatible CID. // worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. @@ -53,7 +54,7 @@ pub type DispatchTimeFor = DispatchTime>; #[frame_support::pallet] pub mod pallet { - use super::{Cid, DispatchTimeFor, WeightInfo}; + use super::*; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -79,6 +80,8 @@ pub mod pallet { type CharterOrigin: EnsureOrigin; /// The maximum number of announcements. + /// + /// NOTE: Benchmarks need to be re-run if this changes. #[pallet::constant] type MaxAnnouncementsCount: Get; @@ -125,7 +128,7 @@ pub mod pallet { /// The closest expiration block number of an announcement. #[pallet::storage] - pub type NextAnnouncementExpire, I: 'static = ()> = + pub type NextAnnouncementExpireAt, I: 'static = ()> = StorageValue<_, T::BlockNumber, OptionQuery>; #[pallet::call] @@ -176,8 +179,8 @@ pub mod pallet { >::put(announcements); if let Some(expire_at) = maybe_expire_at { - if NextAnnouncementExpire::::get().map_or(true, |n| n > expire_at) { - NextAnnouncementExpire::::put(expire_at); + if NextAnnouncementExpireAt::::get().map_or(true, |n| n > expire_at) { + NextAnnouncementExpireAt::::put(expire_at); } } @@ -209,4 +212,61 @@ pub mod pallet { Ok(()) } } + + impl, I: 'static> Pallet { + /// Cleanup expired announcements. + pub fn cleanup_announcements(now: T::BlockNumber) { + if NextAnnouncementExpireAt::::get().map_or(true, |next| next > now) { + // no expired announcements expected. + return + } + // find expired announcements. + let announcements = >::get(); + let (live, expired): (Vec<(_, _)>, Vec<(_, _)>) = + announcements.clone().into_iter().partition(|(_, maybe_expire_at)| { + maybe_expire_at.map_or(true, |expire_at| expire_at > now) + }); + if expired.len() == 0 { + // no expired announcements. + return + } + // convert into bounded vec. + let live: BoundedVec<(_, _), T::MaxAnnouncementsCount> = live.try_into().map_or_else( + |err| { + // should never happen. + debug_assert!(false, "failed to convert into bounded vec: {:?}", err); + announcements + }, + |live| live, + ); + // determine the next announcement expire at. + NextAnnouncementExpireAt::::set(live.clone().into_iter().fold( + None, + |next, (_, maybe_expire_at)| match (next, maybe_expire_at) { + (Some(next), Some(expire_at)) if next > expire_at => Some(expire_at), + (None, Some(expire_at)) => Some(expire_at), + _ => next, + }, + )); + // save new list of announcements. + >::put(live); + // publish events for removed announcements. + expired.into_iter().for_each(|(cid, _)| { + Self::deposit_event(Event::::AnnouncementRemoved { cid }) + }); + } + } + + #[pallet::hooks] + impl, I: 'static> Hooks for Pallet { + /// Cleanup expired announcements if there is enough `remaining_weight` weight left. + fn on_idle(now: T::BlockNumber, remaining_weight: Weight) -> Weight { + let weight = T::WeightInfo::cleanup_announcements(); + if remaining_weight.any_lt(weight) { + return Weight::from_ref_time(0) + } + Self::cleanup_announcements(now); + weight + } + } } diff --git a/parachains/pallets/collective-content/src/mock.rs b/parachains/pallets/collective-content/src/mock.rs index abc125a3a56..673dc4de181 100644 --- a/parachains/pallets/collective-content/src/mock.rs +++ b/parachains/pallets/collective-content/src/mock.rs @@ -16,9 +16,11 @@ //! Test utilities. pub use crate as pallet_collective_content; +use crate::WeightInfo; use frame_support::{ - ord_parameter_types, + ord_parameter_types, parameter_types, traits::{ConstU32, ConstU64}, + weights::Weight, }; use frame_system::EnsureSignedBy; use sp_runtime::traits::IdentityLookup; @@ -46,12 +48,16 @@ ord_parameter_types! { pub const OtherAccount: u64 = 3; } +parameter_types! { + pub static MaxAnnouncementsCount: u32 = 5; +} + impl pallet_collective_content::Config for Test { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EnsureSignedBy; type AnnouncementOrigin = EnsureSignedBy; - type MaxAnnouncementsCount = ConstU32<5>; - type WeightInfo = (); + type MaxAnnouncementsCount = MaxAnnouncementsCount; + type WeightInfo = CCWeightInfo; } impl frame_system::Config for Test { @@ -80,6 +86,22 @@ impl frame_system::Config for Test { type OnSetCode = (); type MaxConsumers = ConstU32<16>; } +pub struct CCWeightInfo; +impl WeightInfo for CCWeightInfo { + fn set_charter() -> Weight { + Weight::zero() + } + fn announce(_x: u32) -> Weight { + Weight::zero() + } + fn remove_announcement() -> Weight { + Weight::zero() + } + fn cleanup_announcements() -> Weight { + // used in tests. + Weight::from_ref_time(10) + } +} // Build test environment. pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/parachains/pallets/collective-content/src/tests.rs b/parachains/pallets/collective-content/src/tests.rs index 4470a57b9d9..45fc43acb9b 100644 --- a/parachains/pallets/collective-content/src/tests.rs +++ b/parachains/pallets/collective-content/src/tests.rs @@ -16,7 +16,7 @@ //! Tests. use super::{mock::*, *}; -use frame_support::{assert_noop, assert_ok, error::BadOrigin}; +use frame_support::{assert_noop, assert_ok, error::BadOrigin, traits::Hooks, weights::Weight}; #[test] fn set_charter_works() { @@ -61,7 +61,7 @@ fn announce_works() { let maybe_expire_at = None; assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); - assert_eq!(NextAnnouncementExpire::::get(), None); + assert_eq!(NextAnnouncementExpireAt::::get(), None); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: None, @@ -73,7 +73,7 @@ fn announce_works() { let maybe_expire_at = None; assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); - assert_eq!(NextAnnouncementExpire::::get(), None); + assert_eq!(NextAnnouncementExpireAt::::get(), None); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: None, @@ -85,7 +85,7 @@ fn announce_works() { let maybe_expire_at = DispatchTimeFor::::After(10); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); - assert_eq!(NextAnnouncementExpire::::get(), Some(maybe_expire_at.evaluate(now))); + assert_eq!(NextAnnouncementExpireAt::::get(), Some(maybe_expire_at.evaluate(now))); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: Some(maybe_expire_at.evaluate(now)), @@ -98,7 +98,10 @@ fn announce_works() { let maybe_expire_at = DispatchTimeFor::::At(now + 20); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); - assert_eq!(NextAnnouncementExpire::::get(), Some(prev_maybe_expire_at.evaluate(now))); + assert_eq!( + NextAnnouncementExpireAt::::get(), + Some(prev_maybe_expire_at.evaluate(now)) + ); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: Some(maybe_expire_at.evaluate(now)), @@ -110,7 +113,7 @@ fn announce_works() { let maybe_expire_at = DispatchTimeFor::::At(now + 5); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); - assert_eq!(NextAnnouncementExpire::::get(), Some(maybe_expire_at.evaluate(now))); + assert_eq!(NextAnnouncementExpireAt::::get(), Some(maybe_expire_at.evaluate(now))); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: Some(maybe_expire_at.evaluate(now)), @@ -181,3 +184,56 @@ fn remove_announcement_works() { ); }); } + +#[test] +fn clean_announcements_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + MaxAnnouncementsCount::set(7); + let cleanup_block = 5; + + let announcements: [(Cid, _); 7] = [ + (b"ipfs_1".to_vec().try_into().unwrap(), Some(cleanup_block + 5)), + (b"ipfs_2".to_vec().try_into().unwrap(), Some(cleanup_block - 1)), // expired + (b"ipfs_1".to_vec().try_into().unwrap(), Some(cleanup_block + 2)), + (b"ipfs_3".to_vec().try_into().unwrap(), Some(cleanup_block)), // expired + (b"ipfs_4".to_vec().try_into().unwrap(), None), + (b"ipfs_5".to_vec().try_into().unwrap(), Some(cleanup_block - 2)), // expired + (b"ipfs_1".to_vec().try_into().unwrap(), Some(cleanup_block + 3)), + ]; + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + for (cid, maybe_expire_at) in announcements.into_iter() { + assert_ok!(CollectiveContent::announce( + origin.clone(), + cid, + maybe_expire_at + .map_or(None, |expire_at| Some(DispatchTimeFor::::At(expire_at))) + )); + } + assert_eq!(>::get().len(), 7); + System::set_block_number(cleanup_block); + + // invoke `clean_announcements` through the on_idle hook. + assert_eq!( + >::on_idle(cleanup_block, Weight::from_ref_time(20)), + Weight::from_ref_time(10) + ); + assert_eq!(>::get().len(), 4); + assert_eq!(>::get(), Some(cleanup_block + 2)); + System::assert_has_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { + cid: b"ipfs_2".to_vec().try_into().unwrap(), + })); + System::assert_has_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { + cid: b"ipfs_3".to_vec().try_into().unwrap(), + })); + System::assert_has_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { + cid: b"ipfs_5".to_vec().try_into().unwrap(), + })); + + // on_idle. not enough weight. + assert_eq!( + >::on_idle(cleanup_block, Weight::from_ref_time(9)), + Weight::from_ref_time(0) + ); + }); +} diff --git a/parachains/pallets/collective-content/src/weights.rs b/parachains/pallets/collective-content/src/weights.rs index e489b524e82..e9bf3eadc05 100644 --- a/parachains/pallets/collective-content/src/weights.rs +++ b/parachains/pallets/collective-content/src/weights.rs @@ -21,10 +21,12 @@ use frame_support::weights::Weight; pub trait WeightInfo { /// Returns the weight of the set_charter extrinsic. fn set_charter() -> Weight; - /// Returns the announce of the set_charter extrinsic. + /// Returns the weight of the announce extrinsic. fn announce(_x: u32) -> Weight; - /// Returns the remove_announcement of the set_charter extrinsic. + /// Returns the weight of the remove_announcement extrinsic. fn remove_announcement() -> Weight; + /// Returns the weight of the action. + fn cleanup_announcements() -> Weight; } /// Unit implementation of the [WeightInfo]. @@ -38,4 +40,7 @@ impl WeightInfo for () { fn remove_announcement() -> Weight { Weight::zero() } + fn cleanup_announcements() -> Weight { + Weight::zero() + } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs index f622d346269..ad9d9230526 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_collective_content` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-01-25, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-01-27, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `cob`, CPU: `` //! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 @@ -32,18 +32,16 @@ pub struct WeightInfo(PhantomData); impl pallet_collective_content::WeightInfo for WeightInfo { // Storage: AmbassadorContent Charter (r:0 w:1) fn set_charter() -> Weight { - // Minimum execution time: 218_000 nanoseconds. - Weight::from_ref_time(218_000_000) + // Minimum execution time: 210_000 nanoseconds. + Weight::from_ref_time(210_000_000) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: AmbassadorContent Announcements (r:1 w:1) - // Storage: AmbassadorContent NextAnnouncementExpire (r:1 w:1) + // Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:1) /// The range of component `x` is `[0, 1]`. fn announce(x: u32, ) -> Weight { - // Minimum execution time: 256_000 nanoseconds. - Weight::from_ref_time(264_545_454) - // Standard Error: 2_055_430 - .saturating_add(Weight::from_ref_time(7_454_545).saturating_mul(x.into())) + // Minimum execution time: 253_000 nanoseconds. + Weight::from_ref_time(269_909_090) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(1)) @@ -51,9 +49,17 @@ impl pallet_collective_content::WeightInfo for WeightIn } // Storage: AmbassadorContent Announcements (r:1 w:1) fn remove_announcement() -> Weight { - // Minimum execution time: 337_000 nanoseconds. - Weight::from_ref_time(337_000_000) + // Minimum execution time: 334_000 nanoseconds. + Weight::from_ref_time(334_000_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + // Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:0) + // Storage: AmbassadorContent Announcements (r:1 w:1) + fn cleanup_announcements() -> Weight { + // Minimum execution time: 2_245_000 nanoseconds. + Weight::from_ref_time(2_245_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } } From 1323be309780cdfcaccc244249751b1bb507b154 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Tue, 31 Jan 2023 16:19:25 +0100 Subject: [PATCH 17/44] docs and proxy definition changes --- .../pallets/collective-content/src/lib.rs | 34 +++++++++++-------- .../src/ambassador/mod.rs | 12 ++++--- .../src/ambassador/origins.rs | 6 ++-- .../src/ambassador/tracks.rs | 6 ++-- .../collectives-polkadot/src/lib.rs | 8 +---- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 889aacac8a6..c1532212296 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -13,16 +13,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Managed collective content. +//! Managed Collective Content Pallet //! -//! The pallet provides the functionality to store different types of the content. -//! The content presented as a [Cid] of the IPFS document which might contain any type of data. -//! Every type of the content has its own origin to be manage. The origins are configurable by clients. -//! Storing the content does not require a deposit, the content expected to be managed by a trusted collective. +//! The pallet provides the functionality to store different types of content. This would typically +//! be used by an on-chain collective, such as the Polkadot Alliance or Ambassador Program. +//! +//! The pallet stores content as a [Cid], which should correspond to some off-chain hosting service, +//! such as IPFS, and contain any type of data. Each type of content has its own origin from which +//! it can be managed. The origins are configurable in the runtime. Storing content does not require +//! a deposit, as it is expected to be managed by a trusted collective. //! //! Content types: -//! - the collective [charter](pallet::Charter). A single document managed by [CharterOrigin](pallet::Config::CharterOrigin). -//! - the collective [announcements](pallet::Announcements). A list of announcements managed by [AnnouncementOrigin](pallet::Config::AnnouncementOrigin). +//! +//! - Collective [charter](pallet::Charter): A single document (`Cid`) managed by +//! [CharterOrigin](pallet::Config::CharterOrigin). +//! - Collective [announcements](pallet::Announcements): A list of announcements managed by +//! [AnnouncementOrigin](pallet::Config::AnnouncementOrigin). #![cfg_attr(not(feature = "std"), no_std)] @@ -85,11 +91,10 @@ pub mod pallet { #[pallet::constant] type MaxAnnouncementsCount: Get; - /// Weights information needed for the pallet. + /// Weight information needed for the pallet. type WeightInfo: WeightInfo; } - /// Errors encountered by the pallet (not a full list). #[pallet::error] pub enum Error { /// The announcement is not found. @@ -97,10 +102,9 @@ pub mod pallet { /// Number of announcements exceeds `MaxAnnouncementsCount`. TooManyAnnouncements, /// Cannot expire in the past. - InvalidExpire, + InvalidExpiration, } - /// Events emitted by the pallet. #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event, I: 'static = ()> { @@ -156,7 +160,7 @@ pub mod pallet { /// Parameters: /// - `origin`: Must be the [Config::CharterOrigin]. /// - `cid`: [CID](super::Cid) of the IPFS document to announce. - /// - `maybe_expire`: expiration block of the announcement. + /// - `maybe_expire`: Expiration block of the announcement. /// /// Weight: `O(1)`. #[pallet::call_index(1)] @@ -170,7 +174,7 @@ pub mod pallet { let now = frame_system::Pallet::::block_number(); let maybe_expire_at = maybe_expire.map(|e| e.evaluate(now)); - ensure!(maybe_expire_at.map_or(true, |e| e > now), Error::::InvalidExpire); + ensure!(maybe_expire_at.map_or(true, |e| e > now), Error::::InvalidExpiration); let mut announcements = >::get(); announcements @@ -214,7 +218,7 @@ pub mod pallet { } impl, I: 'static> Pallet { - /// Cleanup expired announcements. + /// Clean up expired announcements. pub fn cleanup_announcements(now: T::BlockNumber) { if NextAnnouncementExpireAt::::get().map_or(true, |next| next > now) { // no expired announcements expected. @@ -259,7 +263,7 @@ pub mod pallet { #[pallet::hooks] impl, I: 'static> Hooks for Pallet { - /// Cleanup expired announcements if there is enough `remaining_weight` weight left. + /// Clean up expired announcements if there is enough `remaining_weight` weight left. fn on_idle(now: T::BlockNumber, remaining_weight: Weight) -> Weight { let weight = T::WeightInfo::cleanup_announcements(); if remaining_weight.any_lt(weight) { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index bb713e7ec02..b9a2bd67ea5 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -16,10 +16,12 @@ //! The Ambassador Program. //! //! The module defines the following on-chain functionality of the Ambassador Program: -//! - managed set of the program members, where every member has a [rank](ranks) (via [pallet_ranked_collective]). -//! - referendum functionality for the program members to propose, vote and execute passed proposals on behalf -//! of the members of a certain [rank](Origin) (via [pallet_referenda]). -//! - managed content (charter, announcements) (via [pallet_collective_content]). +//! +//! - Managed set of program members, where every member has a [rank](ranks) (via +//! [pallet_ranked_collective]). +//! - Referendum functionality for the program members to propose, vote on, and execute proposals on +//! behalf of the members of a certain [rank](Origin) (via [pallet_referenda]). +//! - Managed content (charter, announcements) (via [pallet_collective_content]). pub mod origins; mod tracks; @@ -36,7 +38,7 @@ use sp_runtime::{ traits::{ConstU16, TypedGet}, }; -/// The Ambassador Program members ranks. +/// The Ambassador Program's member ranks. pub mod ranks { use pallet_ranked_collective::Rank; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs index 8c58ba1bc28..40a8a9c28fd 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The Ambassador Program origins. +//! The Ambassador Program's origins. #[frame_support::pallet] pub mod pallet_origins { @@ -77,8 +77,8 @@ pub mod pallet_origins { } } - /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the success result - /// of the corresponding [Rank]. Not implemented for the [Origin::Candidate]. + /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the + /// success result of the corresponding [Rank]. Not implemented for [Origin::Candidate]. pub struct EnsureRankedAmbassador; impl> + From> EnsureOrigin for EnsureRankedAmbassador { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs index 517e40e4cbb..bcc6a64e186 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs @@ -13,16 +13,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The Ambassador Program referendum voting tracks. +//! The Ambassador Program's referenda voting tracks. use super::Origin; use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES, UNITS}; use sp_runtime::Perbill; -/// Referendum TrackId type. +/// Referendum `TrackId` type. pub type TrackId = u16; -/// Referendum tracks ids. +/// Referendum track IDs. pub mod constants { use super::TrackId; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index ee43131cdc1..2e8e9a2c40e 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -297,13 +297,7 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => !matches!( - c, - RuntimeCall::Scheduler { .. } | - RuntimeCall::AmbassadorCollective { .. } | - RuntimeCall::AmbassadorReferenda { .. } | - RuntimeCall::Balances { .. } - ), + ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances { .. }), ProxyType::CancelProxy => matches!( c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | From 1b867de3eb1c3e4f5c4e9246617704d07afb1812 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Tue, 31 Jan 2023 16:51:09 +0100 Subject: [PATCH 18/44] remove unused import --- .../runtimes/collectives/collectives-polkadot/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs index 88b3a45be9b..f57f45a2ba6 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs @@ -23,7 +23,7 @@ use frame_support::{ }; use pallet_alliance::{ProposalIndex, ProposalProvider}; use sp_std::{cmp::Ordering, marker::PhantomData, prelude::*}; -use xcm::latest::{Fungibility, Junction, NetworkId, Parent}; +use xcm::latest::{Fungibility, Junction, Parent}; type AccountIdOf = ::AccountId; From 174a9a8bad9bb7e87c1356a71f8907fbb03e073c Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 6 Feb 2023 08:31:45 +0100 Subject: [PATCH 19/44] review fixes --- .../collective-content/src/benchmarking.rs | 15 +++-- .../pallets/collective-content/src/lib.rs | 30 +++++----- .../pallets/collective-content/src/tests.rs | 60 +++++++++++-------- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index 994fe8f9e23..e9460fd237b 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -24,9 +24,16 @@ fn assert_last_event, I: 'static>(generic_event: >:: frame_system::Pallet::::assert_last_event(generic_event.into()); } +/// returns CID hash of 68 bytes of given `i`. +fn create_cid(i: u8) -> OpaqueCid { + let cid: OpaqueCid = [i; 68].to_vec().try_into().unwrap(); + cid +} + benchmarks_instance_pallet! { set_charter { - let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); + let cid: OpaqueCid = b"bafkreif2mywzuu2b2uwehi6c6fojgd7dhcqngus5gzy23uangvpa2kc5si" + .to_vec().try_into().unwrap(); let call = Call::::set_charter { cid: cid.clone() }; let origin = T::CharterOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } @@ -43,7 +50,7 @@ benchmarks_instance_pallet! { maybe_expire = Some(DispatchTimeFor::::At(10u32.into())); } let now = frame_system::Pallet::::block_number(); - let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); + let cid: OpaqueCid = create_cid(1); let call = Call::::announce { cid: cid.clone(), maybe_expire: maybe_expire.clone(), @@ -60,7 +67,7 @@ benchmarks_instance_pallet! { } remove_announcement { - let cid: Cid = b"ipfs_hash".to_vec().try_into().unwrap(); + let cid: OpaqueCid = create_cid(1); let origin = T::AnnouncementOrigin::successful_origin(); let max_count = T::MaxAnnouncementsCount::get() as usize; @@ -82,7 +89,7 @@ benchmarks_instance_pallet! { let max_count = T::MaxAnnouncementsCount::get() as usize; for i in 0..max_count { - let cid: Cid = i.to_ne_bytes().to_vec().try_into().unwrap(); + let cid: OpaqueCid = create_cid(i as u8); CollectiveContent::::announce( origin.clone(), cid, diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index c1532212296..c0c8c8d4628 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -18,14 +18,14 @@ //! The pallet provides the functionality to store different types of content. This would typically //! be used by an on-chain collective, such as the Polkadot Alliance or Ambassador Program. //! -//! The pallet stores content as a [Cid], which should correspond to some off-chain hosting service, +//! The pallet stores content as a [OpaqueCid], which should correspond to some off-chain hosting service, //! such as IPFS, and contain any type of data. Each type of content has its own origin from which //! it can be managed. The origins are configurable in the runtime. Storing content does not require //! a deposit, as it is expected to be managed by a trusted collective. //! //! Content types: //! -//! - Collective [charter](pallet::Charter): A single document (`Cid`) managed by +//! - Collective [charter](pallet::Charter): A single document (`OpaqueCid`) managed by //! [CharterOrigin](pallet::Config::CharterOrigin). //! - Collective [announcements](pallet::Announcements): A list of announcements managed by //! [AnnouncementOrigin](pallet::Config::AnnouncementOrigin). @@ -50,7 +50,7 @@ use sp_std::prelude::*; /// IPFS compatible CID. // worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. -pub type Cid = BoundedVec>; +pub type OpaqueCid = BoundedVec>; /// The block number type of [frame_system::Config]. pub type BlockNumberFor = ::BlockNumber; @@ -109,24 +109,24 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event, I: 'static = ()> { /// A new charter has been set. - NewCharterSet { cid: Cid }, + NewCharterSet { cid: OpaqueCid }, /// A new announcement has been made. - AnnouncementAnnounced { cid: Cid, maybe_expire_at: Option }, + AnnouncementAnnounced { cid: OpaqueCid, maybe_expire_at: Option }, /// An on-chain announcement has been removed. - AnnouncementRemoved { cid: Cid }, + AnnouncementRemoved { cid: OpaqueCid }, } /// The collective charter. #[pallet::storage] #[pallet::getter(fn charter)] - pub type Charter, I: 'static = ()> = StorageValue<_, Cid, OptionQuery>; + pub type Charter, I: 'static = ()> = StorageValue<_, OpaqueCid, OptionQuery>; /// The collective announcements. #[pallet::storage] #[pallet::getter(fn announcements)] pub type Announcements, I: 'static = ()> = StorageValue< _, - BoundedVec<(Cid, Option), T::MaxAnnouncementsCount>, + BoundedVec<(OpaqueCid, Option), T::MaxAnnouncementsCount>, ValueQuery, >; @@ -141,12 +141,12 @@ pub mod pallet { /// /// Parameters: /// - `origin`: Must be the [Config::CharterOrigin]. - /// - `cid`: [CID](super::Cid) of the IPFS document of the collective charter. + /// - `cid`: [CID](super::OpaqueCid) of the IPFS document of the collective charter. /// /// Weight: `O(1)`. #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::set_charter())] - pub fn set_charter(origin: OriginFor, cid: Cid) -> DispatchResult { + pub fn set_charter(origin: OriginFor, cid: OpaqueCid) -> DispatchResult { T::CharterOrigin::ensure_origin(origin)?; Charter::::put(&cid); @@ -159,7 +159,7 @@ pub mod pallet { /// /// Parameters: /// - `origin`: Must be the [Config::CharterOrigin]. - /// - `cid`: [CID](super::Cid) of the IPFS document to announce. + /// - `cid`: [CID](super::OpaqueCid) of the IPFS document to announce. /// - `maybe_expire`: Expiration block of the announcement. /// /// Weight: `O(1)`. @@ -167,7 +167,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::announce(maybe_expire.map_or(0, |_| 1)))] pub fn announce( origin: OriginFor, - cid: Cid, + cid: OpaqueCid, maybe_expire: Option>, ) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; @@ -196,12 +196,12 @@ pub mod pallet { /// /// Parameters: /// - `origin`: Must be the [Config::CharterOrigin]. - /// - `cid`: [CID](super::Cid) of the IPFS document to remove. + /// - `cid`: [CID](super::OpaqueCid) of the IPFS document to remove. /// /// Weight: `O(1)`, less of the [Config::MaxAnnouncementsCount] is lower. #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::remove_announcement())] - pub fn remove_announcement(origin: OriginFor, cid: Cid) -> DispatchResult { + pub fn remove_announcement(origin: OriginFor, cid: OpaqueCid) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; let mut announcements = >::get(); @@ -230,7 +230,7 @@ pub mod pallet { announcements.clone().into_iter().partition(|(_, maybe_expire_at)| { maybe_expire_at.map_or(true, |expire_at| expire_at > now) }); - if expired.len() == 0 { + if expired.is_empty() { // no expired announcements. return } diff --git a/parachains/pallets/collective-content/src/tests.rs b/parachains/pallets/collective-content/src/tests.rs index 45fc43acb9b..b96b3afad51 100644 --- a/parachains/pallets/collective-content/src/tests.rs +++ b/parachains/pallets/collective-content/src/tests.rs @@ -18,18 +18,23 @@ use super::{mock::*, *}; use frame_support::{assert_noop, assert_ok, error::BadOrigin, traits::Hooks, weights::Weight}; +/// returns CID hash of 68 bytes of given `i`. +fn create_cid(i: u8) -> OpaqueCid { + let cid: OpaqueCid = [i; 68].to_vec().try_into().unwrap(); + cid +} + #[test] fn set_charter_works() { new_test_ext().execute_with(|| { // wrong origin. let origin = RuntimeOrigin::signed(OtherAccount::get()); - let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); - + let cid = create_cid(1); assert_noop!(CollectiveContent::set_charter(origin, cid), BadOrigin); // success. let origin = RuntimeOrigin::signed(CharterManager::get()); - let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + let cid = create_cid(2); assert_ok!(CollectiveContent::set_charter(origin, cid.clone())); assert_eq!(CollectiveContent::charter(), Some(cid.clone())); @@ -37,7 +42,7 @@ fn set_charter_works() { // reset. success. let origin = RuntimeOrigin::signed(CharterManager::get()); - let cid: Cid = b"ipfs_hash_reset_success".to_vec().try_into().unwrap(); + let cid = create_cid(3); assert_ok!(CollectiveContent::set_charter(origin, cid.clone())); assert_eq!(CollectiveContent::charter(), Some(cid.clone())); @@ -51,13 +56,13 @@ fn announce_works() { let now = frame_system::Pallet::::block_number(); // wrong origin. let origin = RuntimeOrigin::signed(OtherAccount::get()); - let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let cid = create_cid(1); assert_noop!(CollectiveContent::announce(origin, cid, None), BadOrigin); // success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + let cid = create_cid(2); let maybe_expire_at = None; assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); @@ -69,7 +74,7 @@ fn announce_works() { // one more. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let cid = create_cid(3); let maybe_expire_at = None; assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); @@ -81,7 +86,7 @@ fn announce_works() { // one more with expire. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let cid = create_cid(4); let maybe_expire_at = DispatchTimeFor::::After(10); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); @@ -93,7 +98,7 @@ fn announce_works() { // one more with later expire. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let cid = create_cid(5); let prev_maybe_expire_at = DispatchTimeFor::::After(10); let maybe_expire_at = DispatchTimeFor::::At(now + 20); @@ -109,7 +114,7 @@ fn announce_works() { // one more with earlier expire. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let cid = create_cid(6); let maybe_expire_at = DispatchTimeFor::::At(now + 5); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); @@ -121,7 +126,7 @@ fn announce_works() { // too many announcements. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let cid = create_cid(7); let maybe_expire_at = None; assert_noop!( @@ -136,13 +141,13 @@ fn remove_announcement_works() { new_test_ext().execute_with(|| { // wrong origin. let origin = RuntimeOrigin::signed(OtherAccount::get()); - let cid: Cid = b"ipfs_hash_fail".to_vec().try_into().unwrap(); + let cid = create_cid(8); assert_noop!(CollectiveContent::remove_announcement(origin, cid), BadOrigin); // missing announcement. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_missing".to_vec().try_into().unwrap(); + let cid = create_cid(9); assert_noop!( CollectiveContent::remove_announcement(origin, cid), @@ -152,11 +157,11 @@ fn remove_announcement_works() { // success. // add announcement. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid: Cid = b"ipfs_hash_success".to_vec().try_into().unwrap(); + let cid = create_cid(10); assert_ok!(CollectiveContent::announce(origin.clone(), cid.clone(), None)); // one more announcement. - let cid_2: Cid = b"ipfs_hash_success_2".to_vec().try_into().unwrap(); + let cid_2 = create_cid(11); let expire_at_2 = DispatchTimeFor::::At(10); assert_ok!(CollectiveContent::announce(origin.clone(), cid_2.clone(), Some(expire_at_2))); // two announcements registered. @@ -192,14 +197,17 @@ fn clean_announcements_works() { MaxAnnouncementsCount::set(7); let cleanup_block = 5; - let announcements: [(Cid, _); 7] = [ - (b"ipfs_1".to_vec().try_into().unwrap(), Some(cleanup_block + 5)), - (b"ipfs_2".to_vec().try_into().unwrap(), Some(cleanup_block - 1)), // expired - (b"ipfs_1".to_vec().try_into().unwrap(), Some(cleanup_block + 2)), - (b"ipfs_3".to_vec().try_into().unwrap(), Some(cleanup_block)), // expired - (b"ipfs_4".to_vec().try_into().unwrap(), None), - (b"ipfs_5".to_vec().try_into().unwrap(), Some(cleanup_block - 2)), // expired - (b"ipfs_1".to_vec().try_into().unwrap(), Some(cleanup_block + 3)), + let announcements: [(_, _); 7] = [ + (create_cid(1), Some(cleanup_block + 5)), + // expired + (create_cid(2), Some(cleanup_block - 1)), + (create_cid(3), Some(cleanup_block + 2)), + // expired + (create_cid(4), Some(cleanup_block)), + (create_cid(5), None), + // expired + (create_cid(6), Some(cleanup_block - 2)), + (create_cid(7), Some(cleanup_block + 3)), ]; let origin = RuntimeOrigin::signed(AnnouncementManager::get()); for (cid, maybe_expire_at) in announcements.into_iter() { @@ -221,13 +229,13 @@ fn clean_announcements_works() { assert_eq!(>::get().len(), 4); assert_eq!(>::get(), Some(cleanup_block + 2)); System::assert_has_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { - cid: b"ipfs_2".to_vec().try_into().unwrap(), + cid: create_cid(2), })); System::assert_has_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { - cid: b"ipfs_3".to_vec().try_into().unwrap(), + cid: create_cid(4), })); System::assert_has_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { - cid: b"ipfs_5".to_vec().try_into().unwrap(), + cid: create_cid(6), })); // on_idle. not enough weight. From 9017a8ba12bcff715151a420308e70cf6d8ca710 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 6 Feb 2023 11:39:00 +0100 Subject: [PATCH 20/44] storage map for the announcements --- .../collective-content/src/benchmarking.rs | 30 +++--- .../pallets/collective-content/src/lib.rs | 102 ++++++++---------- .../pallets/collective-content/src/mock.rs | 9 +- .../pallets/collective-content/src/tests.rs | 38 ++++--- .../pallets/collective-content/src/weights.rs | 4 +- .../src/ambassador/mod.rs | 1 - .../src/weights/pallet_ambassador_content.rs | 75 +++++++++---- 7 files changed, 136 insertions(+), 123 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index e9460fd237b..329eb2a7d75 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -18,7 +18,6 @@ use super::{DispatchTimeFor, Pallet as CollectiveContent, *}; use frame_benchmarking::benchmarks_instance_pallet; use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; -use sp_core::Get; fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { frame_system::Pallet::::assert_last_event(generic_event.into()); @@ -32,8 +31,7 @@ fn create_cid(i: u8) -> OpaqueCid { benchmarks_instance_pallet! { set_charter { - let cid: OpaqueCid = b"bafkreif2mywzuu2b2uwehi6c6fojgd7dhcqngus5gzy23uangvpa2kc5si" - .to_vec().try_into().unwrap(); + let cid: OpaqueCid = create_cid(1); let call = Call::::set_charter { cid: cid.clone() }; let origin = T::CharterOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } @@ -58,7 +56,7 @@ benchmarks_instance_pallet! { let origin = T::AnnouncementOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } verify { - assert_eq!(CollectiveContent::::announcements().len(), 1); + assert_eq!(CollectiveContent::::announcements_count(), 1); assert_eq!(NextAnnouncementExpireAt::::get().map_or(0, |_| 1), x); assert_last_event::(Event::AnnouncementAnnounced { cid, @@ -69,25 +67,25 @@ benchmarks_instance_pallet! { remove_announcement { let cid: OpaqueCid = create_cid(1); let origin = T::AnnouncementOrigin::successful_origin(); - let max_count = T::MaxAnnouncementsCount::get() as usize; - - // fill the announcements vec for the worst case. - let announcements = vec![(cid.clone(), None); max_count]; - let announcements: BoundedVec<_, T::MaxAnnouncementsCount> = BoundedVec::try_from(announcements).unwrap(); - Announcements::::put(announcements); - assert_eq!(CollectiveContent::::announcements().len(), max_count); + CollectiveContent::::announce( + origin.clone(), + cid.clone(), + None, + ).expect("could not publish an announcement"); + assert_eq!(CollectiveContent::::announcements_count(), 1); let call = Call::::remove_announcement { cid: cid.clone() }; }: { call.dispatch_bypass_filter(origin)? } verify { - assert_eq!(CollectiveContent::::announcements().len(), max_count - 1); + assert_eq!(CollectiveContent::::announcements_count(), 0); assert_last_event::(Event::AnnouncementRemoved { cid }.into()); } cleanup_announcements { + let x in 0 .. 100; let origin = T::AnnouncementOrigin::successful_origin(); - let max_count = T::MaxAnnouncementsCount::get() as usize; + let max_count = x; for i in 0..max_count { let cid: OpaqueCid = create_cid(i as u8); CollectiveContent::::announce( @@ -96,13 +94,13 @@ benchmarks_instance_pallet! { Some(DispatchTimeFor::::At(5u32.into())), ).expect("could not publish an announcement"); } - assert_eq!(CollectiveContent::::announcements().len(), max_count); + assert_eq!(CollectiveContent::::announcements_count(), max_count); frame_system::Pallet::::set_block_number(10u32.into()); }: { CollectiveContent::::cleanup_announcements(10u32.into()); } verify { - assert_eq!(CollectiveContent::::announcements().len(), 0); - assert_eq!(frame_system::Pallet::::events().len(), max_count) + assert_eq!(CollectiveContent::::announcements_count(), 0); + assert_eq!(frame_system::Pallet::::events().len() as u32, max_count) } impl_benchmark_test_suite!(CollectiveContent, super::mock::new_bench_ext(), super::mock::Test); diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index c0c8c8d4628..38acdcc4ed0 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -85,12 +85,6 @@ pub mod pallet { /// The origin to control the collective charter. type CharterOrigin: EnsureOrigin; - /// The maximum number of announcements. - /// - /// NOTE: Benchmarks need to be re-run if this changes. - #[pallet::constant] - type MaxAnnouncementsCount: Get; - /// Weight information needed for the pallet. type WeightInfo: WeightInfo; } @@ -124,11 +118,13 @@ pub mod pallet { /// The collective announcements. #[pallet::storage] #[pallet::getter(fn announcements)] - pub type Announcements, I: 'static = ()> = StorageValue< - _, - BoundedVec<(OpaqueCid, Option), T::MaxAnnouncementsCount>, - ValueQuery, - >; + pub type Announcements, I: 'static = ()> = + StorageMap<_, Blake2_128Concat, OpaqueCid, Option, ValueQuery>; + + /// The current count of the announcements. + #[pallet::storage] + #[pallet::getter(fn announcements_count)] + pub type AnnouncementsCount, I: 'static = ()> = StorageValue<_, u32, ValueQuery>; /// The closest expiration block number of an announcement. #[pallet::storage] @@ -176,11 +172,8 @@ pub mod pallet { let maybe_expire_at = maybe_expire.map(|e| e.evaluate(now)); ensure!(maybe_expire_at.map_or(true, |e| e > now), Error::::InvalidExpiration); - let mut announcements = >::get(); - announcements - .try_push((cid.clone(), maybe_expire_at.clone())) - .map_err(|_| Error::::TooManyAnnouncements)?; - >::put(announcements); + >::insert(cid.clone(), maybe_expire_at.clone()); + >::mutate(|count| *count += 1); if let Some(expire_at) = maybe_expire_at { if NextAnnouncementExpireAt::::get().map_or(true, |n| n > expire_at) { @@ -198,19 +191,18 @@ pub mod pallet { /// - `origin`: Must be the [Config::CharterOrigin]. /// - `cid`: [CID](super::OpaqueCid) of the IPFS document to remove. /// - /// Weight: `O(1)`, less of the [Config::MaxAnnouncementsCount] is lower. + /// Weight: `O(1)`. #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::remove_announcement())] pub fn remove_announcement(origin: OriginFor, cid: OpaqueCid) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; + ensure!( + >::contains_key(cid.clone()), + Error::::MissingAnnouncement + ); - let mut announcements = >::get(); - let pos = announcements - .binary_search_by_key(&cid, |(c, _)| c.clone()) - .ok() - .ok_or(Error::::MissingAnnouncement)?; - announcements.remove(pos); - >::put(announcements); + >::remove(cid.clone()); + >::mutate(|count| *count -= 1); Self::deposit_event(Event::::AnnouncementRemoved { cid }); Ok(()) @@ -224,40 +216,32 @@ pub mod pallet { // no expired announcements expected. return } - // find expired announcements. - let announcements = >::get(); - let (live, expired): (Vec<(_, _)>, Vec<(_, _)>) = - announcements.clone().into_iter().partition(|(_, maybe_expire_at)| { - maybe_expire_at.map_or(true, |expire_at| expire_at > now) - }); - if expired.is_empty() { - // no expired announcements. - return - } - // convert into bounded vec. - let live: BoundedVec<(_, _), T::MaxAnnouncementsCount> = live.try_into().map_or_else( - |err| { - // should never happen. - debug_assert!(false, "failed to convert into bounded vec: {:?}", err); - announcements - }, - |live| live, - ); - // determine the next announcement expire at. - NextAnnouncementExpireAt::::set(live.clone().into_iter().fold( - None, - |next, (_, maybe_expire_at)| match (next, maybe_expire_at) { - (Some(next), Some(expire_at)) if next > expire_at => Some(expire_at), - (None, Some(expire_at)) => Some(expire_at), - _ => next, - }, - )); - // save new list of announcements. - >::put(live); - // publish events for removed announcements. - expired.into_iter().for_each(|(cid, _)| { - Self::deposit_event(Event::::AnnouncementRemoved { cid }) + let mut maybe_next: Option = None; + let mut count = 0; + >::translate(|cid, maybe_expire_at: Option| { + match maybe_expire_at { + Some(expire_at) if now >= expire_at => { + Self::deposit_event(Event::::AnnouncementRemoved { cid }); + None + }, + Some(expire_at) => { + // determine `NextAnnouncementExpireAt`. + maybe_next = match maybe_next { + Some(next) if expire_at > next => Some(next), + _ => Some(expire_at), + }; + count += 1; + // return translated `maybe_expire_at`. + Some(maybe_expire_at) + }, + None => { + count += 1; + Some(maybe_expire_at) + }, + } }); + >::set(maybe_next); + >::set(count); } } @@ -265,9 +249,9 @@ pub mod pallet { impl, I: 'static> Hooks for Pallet { /// Clean up expired announcements if there is enough `remaining_weight` weight left. fn on_idle(now: T::BlockNumber, remaining_weight: Weight) -> Weight { - let weight = T::WeightInfo::cleanup_announcements(); + let weight = T::WeightInfo::cleanup_announcements(>::get()); if remaining_weight.any_lt(weight) { - return Weight::from_ref_time(0) + return T::DbWeight::get().reads(1) } Self::cleanup_announcements(now); weight diff --git a/parachains/pallets/collective-content/src/mock.rs b/parachains/pallets/collective-content/src/mock.rs index 673dc4de181..43b9419c95b 100644 --- a/parachains/pallets/collective-content/src/mock.rs +++ b/parachains/pallets/collective-content/src/mock.rs @@ -18,7 +18,7 @@ pub use crate as pallet_collective_content; use crate::WeightInfo; use frame_support::{ - ord_parameter_types, parameter_types, + ord_parameter_types, traits::{ConstU32, ConstU64}, weights::Weight, }; @@ -48,15 +48,10 @@ ord_parameter_types! { pub const OtherAccount: u64 = 3; } -parameter_types! { - pub static MaxAnnouncementsCount: u32 = 5; -} - impl pallet_collective_content::Config for Test { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EnsureSignedBy; type AnnouncementOrigin = EnsureSignedBy; - type MaxAnnouncementsCount = MaxAnnouncementsCount; type WeightInfo = CCWeightInfo; } @@ -97,7 +92,7 @@ impl WeightInfo for CCWeightInfo { fn remove_announcement() -> Weight { Weight::zero() } - fn cleanup_announcements() -> Weight { + fn cleanup_announcements(_x: u32) -> Weight { // used in tests. Weight::from_ref_time(10) } diff --git a/parachains/pallets/collective-content/src/tests.rs b/parachains/pallets/collective-content/src/tests.rs index b96b3afad51..c09bfa15c56 100644 --- a/parachains/pallets/collective-content/src/tests.rs +++ b/parachains/pallets/collective-content/src/tests.rs @@ -59,6 +59,7 @@ fn announce_works() { let cid = create_cid(1); assert_noop!(CollectiveContent::announce(origin, cid, None), BadOrigin); + assert_eq!(AnnouncementsCount::::get(), 0); // success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); @@ -67,6 +68,7 @@ fn announce_works() { assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); assert_eq!(NextAnnouncementExpireAt::::get(), None); + assert_eq!(AnnouncementsCount::::get(), 1); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: None, @@ -79,6 +81,7 @@ fn announce_works() { assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); assert_eq!(NextAnnouncementExpireAt::::get(), None); + assert_eq!(AnnouncementsCount::::get(), 2); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: None, @@ -91,6 +94,7 @@ fn announce_works() { assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); assert_eq!(NextAnnouncementExpireAt::::get(), Some(maybe_expire_at.evaluate(now))); + assert_eq!(AnnouncementsCount::::get(), 3); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: Some(maybe_expire_at.evaluate(now)), @@ -107,6 +111,7 @@ fn announce_works() { NextAnnouncementExpireAt::::get(), Some(prev_maybe_expire_at.evaluate(now)) ); + assert_eq!(AnnouncementsCount::::get(), 4); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: Some(maybe_expire_at.evaluate(now)), @@ -119,26 +124,18 @@ fn announce_works() { assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); assert_eq!(NextAnnouncementExpireAt::::get(), Some(maybe_expire_at.evaluate(now))); + assert_eq!(AnnouncementsCount::::get(), 5); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, maybe_expire_at: Some(maybe_expire_at.evaluate(now)), })); - - // too many announcements. - let origin = RuntimeOrigin::signed(AnnouncementManager::get()); - let cid = create_cid(7); - let maybe_expire_at = None; - - assert_noop!( - CollectiveContent::announce(origin, cid, maybe_expire_at), - Error::::TooManyAnnouncements - ); }); } #[test] fn remove_announcement_works() { new_test_ext().execute_with(|| { + assert_eq!(AnnouncementsCount::::get(), 0); // wrong origin. let origin = RuntimeOrigin::signed(OtherAccount::get()); let cid = create_cid(8); @@ -165,7 +162,9 @@ fn remove_announcement_works() { let expire_at_2 = DispatchTimeFor::::At(10); assert_ok!(CollectiveContent::announce(origin.clone(), cid_2.clone(), Some(expire_at_2))); // two announcements registered. - assert_eq!(>::get().len(), 2); + assert!(>::contains_key(cid.clone())); + assert!(>::contains_key(cid_2.clone())); + assert_eq!(AnnouncementsCount::::get(), 2); // remove first announcement and assert. assert_ok!(CollectiveContent::remove_announcement(origin.clone(), cid.clone())); @@ -173,16 +172,19 @@ fn remove_announcement_works() { cid: cid.clone(), })); assert_noop!( - CollectiveContent::remove_announcement(origin.clone(), cid), + CollectiveContent::remove_announcement(origin.clone(), cid.clone()), Error::::MissingAnnouncement ); - assert_eq!(>::get().len(), 1); + assert!(!>::contains_key(cid)); + assert!(>::contains_key(cid_2.clone())); + assert_eq!(AnnouncementsCount::::get(), 1); // remove second announcement and assert. assert_ok!(CollectiveContent::remove_announcement(origin.clone(), cid_2.clone())); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { cid: cid_2.clone(), })); + assert_eq!(AnnouncementsCount::::get(), 0); assert_noop!( CollectiveContent::remove_announcement(origin, cid_2), Error::::MissingAnnouncement @@ -194,10 +196,9 @@ fn remove_announcement_works() { fn clean_announcements_works() { new_test_ext().execute_with(|| { System::set_block_number(1); - MaxAnnouncementsCount::set(7); let cleanup_block = 5; - let announcements: [(_, _); 7] = [ + let announcements: [(_, _); 8] = [ (create_cid(1), Some(cleanup_block + 5)), // expired (create_cid(2), Some(cleanup_block - 1)), @@ -208,6 +209,7 @@ fn clean_announcements_works() { // expired (create_cid(6), Some(cleanup_block - 2)), (create_cid(7), Some(cleanup_block + 3)), + (create_cid(8), Some(cleanup_block + 4)), ]; let origin = RuntimeOrigin::signed(AnnouncementManager::get()); for (cid, maybe_expire_at) in announcements.into_iter() { @@ -218,7 +220,8 @@ fn clean_announcements_works() { .map_or(None, |expire_at| Some(DispatchTimeFor::::At(expire_at))) )); } - assert_eq!(>::get().len(), 7); + assert_eq!(>::iter_keys().count(), 8); + assert_eq!(AnnouncementsCount::::get(), 8); System::set_block_number(cleanup_block); // invoke `clean_announcements` through the on_idle hook. @@ -226,7 +229,8 @@ fn clean_announcements_works() { >::on_idle(cleanup_block, Weight::from_ref_time(20)), Weight::from_ref_time(10) ); - assert_eq!(>::get().len(), 4); + assert_eq!(>::iter_keys().count(), 5); + assert_eq!(AnnouncementsCount::::get(), 5); assert_eq!(>::get(), Some(cleanup_block + 2)); System::assert_has_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { cid: create_cid(2), diff --git a/parachains/pallets/collective-content/src/weights.rs b/parachains/pallets/collective-content/src/weights.rs index e9bf3eadc05..d004c8858e2 100644 --- a/parachains/pallets/collective-content/src/weights.rs +++ b/parachains/pallets/collective-content/src/weights.rs @@ -26,7 +26,7 @@ pub trait WeightInfo { /// Returns the weight of the remove_announcement extrinsic. fn remove_announcement() -> Weight; /// Returns the weight of the action. - fn cleanup_announcements() -> Weight; + fn cleanup_announcements(x: u32) -> Weight; } /// Unit implementation of the [WeightInfo]. @@ -40,7 +40,7 @@ impl WeightInfo for () { fn remove_announcement() -> Weight { Weight::zero() } - fn cleanup_announcements() -> Weight { + fn cleanup_announcements(_x: u32) -> Weight { Weight::zero() } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index b9a2bd67ea5..007d0e0e252 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -64,7 +64,6 @@ impl pallet_collective_content::Config for Runtime { >, EnsureAmbassador, >; - type MaxAnnouncementsCount = ConstU32<100>; type WeightInfo = weights::pallet_ambassador_content::WeightInfo; } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs index ad9d9230526..e940a82e129 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for `pallet_collective_content` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-01-27, STEPS: `20`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-06, STEPS: `100`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `cob`, CPU: `` //! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 @@ -11,7 +12,7 @@ // benchmark // pallet // --chain=collectives-polkadot-dev -// --steps=20 +// --steps=100 // --repeat=1 // --pallet=pallet_collective_content // --extrinsic=* @@ -30,36 +31,68 @@ use sp_std::marker::PhantomData; /// Weight functions for `pallet_collective_content`. pub struct WeightInfo(PhantomData); impl pallet_collective_content::WeightInfo for WeightInfo { - // Storage: AmbassadorContent Charter (r:0 w:1) + /// Storage: AmbassadorContent Charter (r:0 w:1) + /// Proof: AmbassadorContent Charter (max_values: Some(1), max_size: Some(70), added: 565, mode: MaxEncodedLen) fn set_charter() -> Weight { - // Minimum execution time: 210_000 nanoseconds. - Weight::from_ref_time(210_000_000) + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 45_000 nanoseconds. + Weight::from_ref_time(45_000_000) .saturating_add(T::DbWeight::get().writes(1)) } - // Storage: AmbassadorContent Announcements (r:1 w:1) - // Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:1) + /// Storage: AmbassadorContent AnnouncementsCount (r:1 w:1) + /// Proof: AmbassadorContent AnnouncementsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:1) + /// Proof: AmbassadorContent NextAnnouncementExpireAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: AmbassadorContent Announcements (r:0 w:1) + /// Proof: AmbassadorContent Announcements (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) /// The range of component `x` is `[0, 1]`. fn announce(x: u32, ) -> Weight { - // Minimum execution time: 253_000 nanoseconds. - Weight::from_ref_time(269_909_090) + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `998` + // Minimum execution time: 109_000 nanoseconds. + Weight::from_parts(111_333_333, 998) + // Standard Error: 718_749 + .saturating_add(Weight::from_ref_time(13_666_666).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) } - // Storage: AmbassadorContent Announcements (r:1 w:1) + /// Storage: AmbassadorContent Announcements (r:1 w:1) + /// Proof: AmbassadorContent Announcements (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: AmbassadorContent AnnouncementsCount (r:1 w:1) + /// Proof: AmbassadorContent AnnouncementsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn remove_announcement() -> Weight { - // Minimum execution time: 334_000 nanoseconds. - Weight::from_ref_time(334_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `178` + // Estimated: `3065` + // Minimum execution time: 186_000 nanoseconds. + Weight::from_parts(186_000_000, 3065) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } - // Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:0) - // Storage: AmbassadorContent Announcements (r:1 w:1) - fn cleanup_announcements() -> Weight { - // Minimum execution time: 2_245_000 nanoseconds. - Weight::from_ref_time(2_245_000_000) + /// Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:1) + /// Proof: AmbassadorContent NextAnnouncementExpireAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: AmbassadorContent Announcements (r:100 w:99) + /// Proof: AmbassadorContent Announcements (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: AmbassadorContent AnnouncementsCount (r:0 w:1) + /// Proof: AmbassadorContent AnnouncementsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// The range of component `x` is `[0, 100]`. + fn cleanup_announcements(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `130 + x * (97 ±0)` + // Estimated: `3065 + x * (2566 ±0)` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(103_774_653, 3065) + // Standard Error: 407_952 + .saturating_add(Weight::from_ref_time(102_859_501).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_proof_size(2566).saturating_mul(x.into())) } } From d602443a372d0a785ae7f4ac3ca9ddb02c2b4cbc Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 7 Feb 2023 08:01:27 +0100 Subject: [PATCH 21/44] max scheduler per block for benches --- .../collectives/collectives-polkadot/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 89acfeb105b..256a5d01a05 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -497,7 +497,16 @@ impl pallet_alliance::Config for Runtime { parameter_types! { pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; - pub const MaxScheduledPerBlock: u32 = 200; // TODO replace by 50, after fixing referendum benches +} + +#[cfg(not(feature = "runtime-benchmarks"))] +parameter_types! { + pub const MaxScheduledPerBlock: u32 = 50; +} + +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub const MaxScheduledPerBlock: u32 = 200; } impl pallet_scheduler::Config for Runtime { From 07c7d86b90173476996ba555e5e454170379cda8 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 7 Feb 2023 08:22:59 +0100 Subject: [PATCH 22/44] rename weights files --- .../collectives-polkadot/src/ambassador/mod.rs | 6 +++--- .../collectives-polkadot/src/weights/mod.rs | 6 +++--- ..._content.rs => pallet_collective_content.rs} | 15 +++++++++++++++ .../src/weights/pallet_preimage.rs | 17 ++++++++++++++++- ...ollective.rs => pallet_ranked_collective.rs} | 15 +++++++++++++++ ...assador_referenda.rs => pallet_referenda.rs} | 15 +++++++++++++++ .../src/weights/pallet_scheduler.rs | 15 +++++++++++++++ 7 files changed, 82 insertions(+), 7 deletions(-) rename parachains/runtimes/collectives/collectives-polkadot/src/weights/{pallet_ambassador_content.rs => pallet_collective_content.rs} (86%) rename parachains/runtimes/collectives/collectives-polkadot/src/weights/{pallet_ambassador_collective.rs => pallet_ranked_collective.rs} (86%) rename parachains/runtimes/collectives/collectives-polkadot/src/weights/{pallet_ambassador_referenda.rs => pallet_referenda.rs} (94%) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 007d0e0e252..ed66e1808cd 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -64,7 +64,7 @@ impl pallet_collective_content::Config for Runtime { >, EnsureAmbassador, >; - type WeightInfo = weights::pallet_ambassador_content::WeightInfo; + type WeightInfo = weights::pallet_collective_content::WeightInfo; } impl pallet_ambassador_origins::Config for Runtime {} @@ -78,7 +78,7 @@ parameter_types! { pub type AmbassadorReferendaInstance = pallet_referenda::Instance1; impl pallet_referenda::Config for Runtime { - type WeightInfo = weights::pallet_ambassador_referenda::WeightInfo; + type WeightInfo = weights::pallet_referenda::WeightInfo; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; @@ -119,7 +119,7 @@ morph_types! { pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance1; impl pallet_ranked_collective::Config for Runtime { - type WeightInfo = weights::pallet_ambassador_collective::WeightInfo; + type WeightInfo = weights::pallet_ranked_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; // Promotion is by any of: // - Root can promote arbitrarily. diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs index 172d1bff64e..dad3c2fc822 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs @@ -3,15 +3,15 @@ pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; pub mod pallet_alliance; -pub mod pallet_ambassador_collective; -pub mod pallet_ambassador_content; -pub mod pallet_ambassador_referenda; pub mod pallet_balances; pub mod pallet_collator_selection; pub mod pallet_collective; +pub mod pallet_collective_content; pub mod pallet_multisig; pub mod pallet_preimage; pub mod pallet_proxy; +pub mod pallet_ranked_collective; +pub mod pallet_referenda; pub mod pallet_scheduler; pub mod pallet_session; pub mod pallet_timestamp; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs similarity index 86% rename from parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs rename to parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs index e940a82e129..860adbf4f60 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs @@ -1,3 +1,18 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . //! Autogenerated weights for `pallet_collective_content` //! diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs index dabfe5a02a1..ed889d32b1e 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs @@ -1,4 +1,19 @@ - +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + //! Autogenerated weights for `pallet_preimage` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_collective.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective.rs similarity index 86% rename from parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_collective.rs rename to parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective.rs index 1cd0f6876a1..104a2cd3f89 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_collective.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective.rs @@ -1,3 +1,18 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . //! Autogenerated weights for `pallet_ranked_collective` //! diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_referenda.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda.rs similarity index 94% rename from parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_referenda.rs rename to parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda.rs index 84ccbd1a002..dc8c1157211 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ambassador_referenda.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda.rs @@ -1,3 +1,18 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . //! Autogenerated weights for `pallet_referenda` //! diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs index b22d6682751..0d790a65f01 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_scheduler.rs @@ -1,3 +1,18 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . //! Autogenerated weights for `pallet_scheduler` //! From fe57ff2f870a2e6c94237608b42f3c2551791b20 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 14 Feb 2023 02:47:29 +0100 Subject: [PATCH 23/44] remove todo, update comment --- .../collectives/collectives-polkadot/src/ambassador/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index ed66e1808cd..18c2eaee286 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -103,8 +103,7 @@ impl pallet_referenda::Config for Runtime { } parameter_types! { - // TODO remove "+10", use [ranks::HEAD_AMBASSADOR] instead. To make this possible the benches - // of pallet_ranked_collective should be improved. + // The benches requires max member rank to be at least 10. This rank is available only for root. pub const MaxAmbassadorRank: pallet_ranked_collective::Rank = ranks::HEAD_AMBASSADOR + 10; } From 5f111a2ad7b672286a2a1ff9f5fd71b8f45440ab Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 16 Feb 2023 08:19:42 +0100 Subject: [PATCH 24/44] ToParentTreasury impl --- .../src/ambassador/mod.rs | 4 +- .../collectives-polkadot/src/constants.rs | 9 ++-- .../collectives-polkadot/src/impls.rs | 43 +++++++++---------- .../collectives-polkadot/src/lib.rs | 6 +-- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 18c2eaee286..bd340b96c7f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -73,6 +73,8 @@ parameter_types! { pub const AlarmInterval: BlockNumber = 1; pub const SubmissionDeposit: Balance = 0; pub const UndecidingTimeout: BlockNumber = 7 * DAYS; + // The Ambassador Referenda pallet account, used as a temporarily place to deposit a slashed imbalance before teleport to the treasury. + pub AmbassadorPalletAccId: AccountId = constants::account::AMBASSADOR_REFERENDA_PALLET_ID.into_account_truncating(); } pub type AmbassadorReferendaInstance = pallet_referenda::Instance1; @@ -91,7 +93,7 @@ impl pallet_referenda::Config for Runtime { >; type CancelOrigin = EitherOf, EnsureSeniorAmbassador>; type KillOrigin = EitherOf, EnsureSeniorAmbassador>; - type Slash = ToParentTreasury; + type Slash = ToParentTreasury; type Votes = pallet_ranked_collective::Votes; type Tally = pallet_ranked_collective::TallyOf; type SubmissionDeposit = SubmissionDeposit; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs b/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs index cc41d5c6378..5762a5cf2d8 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/constants.rs @@ -15,12 +15,15 @@ pub mod account { use frame_support::PalletId; - use sp_runtime::AccountId32; /// Relay Chain treasury pallet id, used to convert into AccountId pub const RELAY_TREASURY_PALL_ID: PalletId = PalletId(*b"py/trsry"); - /// account used to temporarily deposit slashed imbalance before teleporting - pub const SLASHED_IMBALANCE_ACC_ID: AccountId32 = AccountId32::new([7u8; 32]); + /// Alliance pallet id. + /// It is used as a temporarily place to deposit a slashed imbalance before teleport to the treasury. + pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia"); + /// Ambassador Referenda pallet id. + /// It is used as a temporarily place to deposit a slashed imbalance before teleport to the treasury. + pub const AMBASSADOR_REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/amref"); } pub mod currency { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs index f57f45a2ba6..b38e86116b2 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs @@ -13,15 +13,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::{AccountId, OriginCaller}; -use crate::{PolkadotXcm, RelayTreasuryAccId, RuntimeOrigin, SlashedImbalanceAccId}; +use crate::OriginCaller; use frame_support::{ dispatch::{DispatchError, DispatchResultWithPostInfo}, log, - traits::{Currency, Imbalance, OnUnbalanced, PrivilegeCmp}, + traits::{Currency, Get, Imbalance, OnUnbalanced, OriginTrait, PrivilegeCmp}, weights::Weight, }; use pallet_alliance::{ProposalIndex, ProposalProvider}; +use parachains_common::impls::NegativeImbalance; use sp_std::{cmp::Ordering, marker::PhantomData, prelude::*}; use xcm::latest::{Fungibility, Junction, Parent}; @@ -31,37 +31,36 @@ type ProposalOf = >::Proposal; type HashOf = ::Hash; -type NegativeImbalanceOf = <>::Currency as Currency< - ::AccountId, ->>::NegativeImbalance; - -type BalanceOf = <>::Currency as Currency< - ::AccountId, ->>::Balance; +/// Type alias to conveniently refer to the `Currency::Balance` associated type. +pub type BalanceOf = + as Currency<::AccountId>>::Balance; /// Implements `OnUnbalanced::on_unbalanced` to teleport slashed assets to relay chain treasury account. -pub struct ToParentTreasury(PhantomData<(T, I)>); +pub struct ToParentTreasury(PhantomData<(TreasuryAcc, PalletAcc, T)>); -impl OnUnbalanced> for ToParentTreasury +impl OnUnbalanced> + for ToParentTreasury where - T: pallet_alliance::Config + frame_system::Config, - [u8; 32]: From, - BalanceOf: Into, - ::AccountId: From, + T: pallet_balances::Config + pallet_xcm::Config + frame_system::Config, + <::RuntimeOrigin as OriginTrait>::AccountId: From>, + [u8; 32]: From<::AccountId>, + TreasuryAcc: Get>, + PalletAcc: Get>, + BalanceOf: Into, { - fn on_unbalanced(amount: NegativeImbalanceOf) { + fn on_unbalanced(amount: NegativeImbalance) { let amount = match amount.drop_zero() { Ok(..) => return, Err(amount) => amount, }; let imbalance = amount.peek(); - let temp_account: AccountId = SlashedImbalanceAccId::get(); - let treasury_acc: AccountId = RelayTreasuryAccId::get(); + let pallet_acc: AccountIdOf = PalletAcc::get(); + let treasury_acc: AccountIdOf = TreasuryAcc::get(); - T::Currency::resolve_creating(&temp_account.clone().into(), amount); + >::resolve_creating(&pallet_acc.clone(), amount); - let result = PolkadotXcm::teleport_assets( - RuntimeOrigin::signed(temp_account.into()), + let result = >::teleport_assets( + <::RuntimeOrigin>::signed(pallet_acc.into()), Box::new(Parent.into()), Box::new( Junction::AccountId32 { network: None, id: treasury_acc.into() } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 256a5d01a05..db2f35d2879 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -463,8 +463,8 @@ pub const MAX_ALLIES: u32 = 100; parameter_types! { pub const AllyDeposit: Balance = 1_000 * UNITS; // 1,000 DOT bond to join as an Ally - // account used to temporarily deposit slashed imbalance before teleporting - pub SlashedImbalanceAccId: AccountId = constants::account::SLASHED_IMBALANCE_ACC_ID.into(); + // The Alliance pallet account, used as a temporarily place to deposit a slashed imbalance before teleport to the treasury. + pub AlliancePalletAccId: AccountId = constants::account::ALLIANCE_PALLET_ID.into_account_truncating(); pub RelayTreasuryAccId: AccountId = constants::account::RELAY_TREASURY_PALL_ID.into_account_truncating(); // The number of blocks a member must wait between giving a retirement notice and retiring. // Supposed to be greater than time required to `kick_member` with alliance motion. @@ -478,7 +478,7 @@ impl pallet_alliance::Config for Runtime { type MembershipManager = RootOrAllianceTwoThirdsMajority; type AnnouncementOrigin = RootOrAllianceTwoThirdsMajority; type Currency = Balances; - type Slashed = ToParentTreasury; + type Slashed = ToParentTreasury; type InitializeMembers = AllianceMotion; type MembershipChanged = AllianceMotion; type RetirementPeriod = AllianceRetirementPeriod; From 48363a7ef2f28c53426fc0ddd0b0d56846f9efb7 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 1 Aug 2023 18:33:18 +0200 Subject: [PATCH 25/44] fixes after mater merge --- Cargo.lock | 16 +++ .../collective-content/src/benchmarking.rs | 16 +-- .../pallets/collective-content/src/lib.rs | 25 ++-- .../pallets/collective-content/src/mock.rs | 20 +--- .../pallets/collective-content/src/tests.rs | 21 ++-- .../collectives-polkadot/Cargo.toml | 4 + .../src/ambassador/mod.rs | 14 +-- .../collectives-polkadot/src/lib.rs | 6 +- .../src/weights/pallet_collective_content.rs | 111 ++++++++++-------- 9 files changed, 123 insertions(+), 110 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4471857131..4ffb42e38d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1868,6 +1868,7 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-collective", + "pallet-collective-content", "pallet-core-fellowship", "pallet-multisig", "pallet-preimage", @@ -7237,6 +7238,21 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-collective-content" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-contracts" version = "4.0.0-dev" diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index 329eb2a7d75..2c74a1f9719 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -15,8 +15,8 @@ //! The pallet benchmarks. -use super::{DispatchTimeFor, Pallet as CollectiveContent, *}; -use frame_benchmarking::benchmarks_instance_pallet; +use super::{Pallet as CollectiveContent, *}; +use frame_benchmarking::v1::{benchmarks_instance_pallet, BenchmarkError}; use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { @@ -33,7 +33,7 @@ benchmarks_instance_pallet! { set_charter { let cid: OpaqueCid = create_cid(1); let call = Call::::set_charter { cid: cid.clone() }; - let origin = T::CharterOrigin::successful_origin(); + let origin = T::CharterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; }: { call.dispatch_bypass_filter(origin)? } verify { assert_eq!(CollectiveContent::::charter(), Some(cid.clone())); @@ -45,7 +45,7 @@ benchmarks_instance_pallet! { let mut maybe_expire = None; if x == 1 { - maybe_expire = Some(DispatchTimeFor::::At(10u32.into())); + maybe_expire = Some(DispatchTime::<_>::At(10u32.into())); } let now = frame_system::Pallet::::block_number(); let cid: OpaqueCid = create_cid(1); @@ -53,7 +53,7 @@ benchmarks_instance_pallet! { cid: cid.clone(), maybe_expire: maybe_expire.clone(), }; - let origin = T::AnnouncementOrigin::successful_origin(); + let origin = T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; }: { call.dispatch_bypass_filter(origin)? } verify { assert_eq!(CollectiveContent::::announcements_count(), 1); @@ -66,7 +66,7 @@ benchmarks_instance_pallet! { remove_announcement { let cid: OpaqueCid = create_cid(1); - let origin = T::AnnouncementOrigin::successful_origin(); + let origin = T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; CollectiveContent::::announce( origin.clone(), cid.clone(), @@ -83,7 +83,7 @@ benchmarks_instance_pallet! { cleanup_announcements { let x in 0 .. 100; - let origin = T::AnnouncementOrigin::successful_origin(); + let origin = T::AnnouncementOrigin::try_successful_origin().unwrap(); let max_count = x; for i in 0..max_count { @@ -91,7 +91,7 @@ benchmarks_instance_pallet! { CollectiveContent::::announce( origin.clone(), cid, - Some(DispatchTimeFor::::At(5u32.into())), + Some(DispatchTime::<_>::At(5u32.into())), ).expect("could not publish an announcement"); } assert_eq!(CollectiveContent::::announcements_count(), max_count); diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 38acdcc4ed0..a36b2d9fc19 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -52,12 +52,6 @@ use sp_std::prelude::*; // worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. pub type OpaqueCid = BoundedVec>; -/// The block number type of [frame_system::Config]. -pub type BlockNumberFor = ::BlockNumber; - -/// [DispatchTime] of [frame_system::Config]. -pub type DispatchTimeFor = DispatchTime>; - #[frame_support::pallet] pub mod pallet { use super::*; @@ -68,7 +62,6 @@ pub mod pallet { const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); #[pallet::pallet] - #[pallet::generate_store(pub (super) trait Store)] #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(PhantomData<(T, I)>); @@ -105,7 +98,7 @@ pub mod pallet { /// A new charter has been set. NewCharterSet { cid: OpaqueCid }, /// A new announcement has been made. - AnnouncementAnnounced { cid: OpaqueCid, maybe_expire_at: Option }, + AnnouncementAnnounced { cid: OpaqueCid, maybe_expire_at: Option> }, /// An on-chain announcement has been removed. AnnouncementRemoved { cid: OpaqueCid }, } @@ -119,7 +112,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn announcements)] pub type Announcements, I: 'static = ()> = - StorageMap<_, Blake2_128Concat, OpaqueCid, Option, ValueQuery>; + StorageMap<_, Blake2_128Concat, OpaqueCid, Option>, ValueQuery>; /// The current count of the announcements. #[pallet::storage] @@ -129,7 +122,7 @@ pub mod pallet { /// The closest expiration block number of an announcement. #[pallet::storage] pub type NextAnnouncementExpireAt, I: 'static = ()> = - StorageValue<_, T::BlockNumber, OptionQuery>; + StorageValue<_, BlockNumberFor, OptionQuery>; #[pallet::call] impl, I: 'static> Pallet { @@ -164,7 +157,7 @@ pub mod pallet { pub fn announce( origin: OriginFor, cid: OpaqueCid, - maybe_expire: Option>, + maybe_expire: Option>>, ) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; @@ -211,14 +204,14 @@ pub mod pallet { impl, I: 'static> Pallet { /// Clean up expired announcements. - pub fn cleanup_announcements(now: T::BlockNumber) { + pub fn cleanup_announcements(now: BlockNumberFor) { if NextAnnouncementExpireAt::::get().map_or(true, |next| next > now) { // no expired announcements expected. return } - let mut maybe_next: Option = None; + let mut maybe_next: Option> = None; let mut count = 0; - >::translate(|cid, maybe_expire_at: Option| { + >::translate(|cid, maybe_expire_at: Option>| { match maybe_expire_at { Some(expire_at) if now >= expire_at => { Self::deposit_event(Event::::AnnouncementRemoved { cid }); @@ -246,9 +239,9 @@ pub mod pallet { } #[pallet::hooks] - impl, I: 'static> Hooks for Pallet { + impl, I: 'static> Hooks> for Pallet { /// Clean up expired announcements if there is enough `remaining_weight` weight left. - fn on_idle(now: T::BlockNumber, remaining_weight: Weight) -> Weight { + fn on_idle(now: BlockNumberFor, remaining_weight: Weight) -> Weight { let weight = T::WeightInfo::cleanup_announcements(>::get()); if remaining_weight.any_lt(weight) { return T::DbWeight::get().reads(1) diff --git a/parachains/pallets/collective-content/src/mock.rs b/parachains/pallets/collective-content/src/mock.rs index 43b9419c95b..b7f90e01597 100644 --- a/parachains/pallets/collective-content/src/mock.rs +++ b/parachains/pallets/collective-content/src/mock.rs @@ -23,23 +23,16 @@ use frame_support::{ weights::Weight, }; use frame_system::EnsureSignedBy; -use sp_runtime::traits::IdentityLookup; +use sp_runtime::{traits::IdentityLookup, BuildStorage}; frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { + pub enum Test { System: frame_system, CollectiveContent: pallet_collective_content, } ); -type BlockNumber = u64; type AccountId = u64; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; ord_parameter_types! { @@ -62,13 +55,12 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; + type Nonce = u64; + type Block = Block; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; - type Header = sp_runtime::testing::Header; type RuntimeEvent = RuntimeEvent; type BlockHashCount = ConstU64<250>; type Version = (); @@ -94,13 +86,13 @@ impl WeightInfo for CCWeightInfo { } fn cleanup_announcements(_x: u32) -> Weight { // used in tests. - Weight::from_ref_time(10) + Weight::from_parts(10, 0) } } // Build test environment. pub fn new_test_ext() -> sp_io::TestExternalities { - let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + let t = RuntimeGenesisConfig::default().build_storage().unwrap().into(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext diff --git a/parachains/pallets/collective-content/src/tests.rs b/parachains/pallets/collective-content/src/tests.rs index c09bfa15c56..21f0960c6df 100644 --- a/parachains/pallets/collective-content/src/tests.rs +++ b/parachains/pallets/collective-content/src/tests.rs @@ -90,7 +90,7 @@ fn announce_works() { // one more with expire. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid = create_cid(4); - let maybe_expire_at = DispatchTimeFor::::After(10); + let maybe_expire_at = DispatchTime::<_>::After(10); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); assert_eq!(NextAnnouncementExpireAt::::get(), Some(maybe_expire_at.evaluate(now))); @@ -103,8 +103,8 @@ fn announce_works() { // one more with later expire. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid = create_cid(5); - let prev_maybe_expire_at = DispatchTimeFor::::After(10); - let maybe_expire_at = DispatchTimeFor::::At(now + 20); + let prev_maybe_expire_at = DispatchTime::<_>::After(10); + let maybe_expire_at = DispatchTime::<_>::At(now + 20); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); assert_eq!( @@ -120,7 +120,7 @@ fn announce_works() { // one more with earlier expire. success. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid = create_cid(6); - let maybe_expire_at = DispatchTimeFor::::At(now + 5); + let maybe_expire_at = DispatchTime::<_>::At(now + 5); assert_ok!(CollectiveContent::announce(origin, cid.clone(), Some(maybe_expire_at))); assert_eq!(NextAnnouncementExpireAt::::get(), Some(maybe_expire_at.evaluate(now))); @@ -159,7 +159,7 @@ fn remove_announcement_works() { // one more announcement. let cid_2 = create_cid(11); - let expire_at_2 = DispatchTimeFor::::At(10); + let expire_at_2 = DispatchTime::<_>::At(10); assert_ok!(CollectiveContent::announce(origin.clone(), cid_2.clone(), Some(expire_at_2))); // two announcements registered. assert!(>::contains_key(cid.clone())); @@ -216,8 +216,7 @@ fn clean_announcements_works() { assert_ok!(CollectiveContent::announce( origin.clone(), cid, - maybe_expire_at - .map_or(None, |expire_at| Some(DispatchTimeFor::::At(expire_at))) + maybe_expire_at.map_or(None, |expire_at| Some(DispatchTime::<_>::At(expire_at))) )); } assert_eq!(>::iter_keys().count(), 8); @@ -226,8 +225,8 @@ fn clean_announcements_works() { // invoke `clean_announcements` through the on_idle hook. assert_eq!( - >::on_idle(cleanup_block, Weight::from_ref_time(20)), - Weight::from_ref_time(10) + >::on_idle(cleanup_block, Weight::from_parts(20, 0)), + Weight::from_parts(10, 0) ); assert_eq!(>::iter_keys().count(), 5); assert_eq!(AnnouncementsCount::::get(), 5); @@ -244,8 +243,8 @@ fn clean_announcements_works() { // on_idle. not enough weight. assert_eq!( - >::on_idle(cleanup_block, Weight::from_ref_time(9)), - Weight::from_ref_time(0) + >::on_idle(cleanup_block, Weight::from_parts(9, 0)), + Weight::from_parts(0, 0) ); }); } diff --git a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index bf3582dde65..9a07512f1b1 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -74,6 +74,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } +pallet-collective-content = { path = "../../../pallets/collective-content", default-features = false } [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } @@ -108,6 +109,7 @@ runtime-benchmarks = [ "pallet-ranked-collective/runtime-benchmarks", "pallet-core-fellowship/runtime-benchmarks", "pallet-salary/runtime-benchmarks", + "pallet-collective-content/runtime-benchmarks", ] try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", @@ -138,6 +140,7 @@ try-runtime = [ "pallet-ranked-collective/try-runtime", "pallet-core-fellowship/try-runtime", "pallet-salary/try-runtime", + "pallet-collective-content/try-runtime", ] std = [ "codec/std", @@ -196,4 +199,5 @@ std = [ "substrate-wasm-builder", "pallet-core-fellowship/std", "pallet-salary/std", + "pallet-collective-content/std", ] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index bd340b96c7f..2cdd8208d1f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -27,7 +27,7 @@ pub mod origins; mod tracks; use super::*; -use frame_support::traits::TryMapSuccess; +use frame_support::traits::{EitherOf, TryMapSuccess}; pub use origins::pallet_origins as pallet_ambassador_origins; use origins::pallet_origins::{ EnsureAmbassador, EnsureRankedAmbassador, EnsureSeniorAmbassador, Origin, @@ -74,13 +74,13 @@ parameter_types! { pub const SubmissionDeposit: Balance = 0; pub const UndecidingTimeout: BlockNumber = 7 * DAYS; // The Ambassador Referenda pallet account, used as a temporarily place to deposit a slashed imbalance before teleport to the treasury. - pub AmbassadorPalletAccId: AccountId = constants::account::AMBASSADOR_REFERENDA_PALLET_ID.into_account_truncating(); + pub AmbassadorPalletAccount: AccountId = constants::account::AMBASSADOR_REFERENDA_PALLET_ID.into_account_truncating(); } -pub type AmbassadorReferendaInstance = pallet_referenda::Instance1; +pub type AmbassadorReferendaInstance = pallet_referenda::Instance2; impl pallet_referenda::Config for Runtime { - type WeightInfo = weights::pallet_referenda::WeightInfo; + type WeightInfo = (); // TODO actual weights type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; @@ -93,7 +93,7 @@ impl pallet_referenda::Config for Runtime { >; type CancelOrigin = EitherOf, EnsureSeniorAmbassador>; type KillOrigin = EitherOf, EnsureSeniorAmbassador>; - type Slash = ToParentTreasury; + type Slash = ToParentTreasury; type Votes = pallet_ranked_collective::Votes; type Tally = pallet_ranked_collective::TallyOf; type SubmissionDeposit = SubmissionDeposit; @@ -117,10 +117,10 @@ morph_types! { } where N::Type: CheckedSub; } -pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance1; +pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance2; impl pallet_ranked_collective::Config for Runtime { - type WeightInfo = weights::pallet_ranked_collective::WeightInfo; + type WeightInfo = (); // TODO actual weights type RuntimeEvent = RuntimeEvent; // Promotion is by any of: // - Root can promote arbitrarily. diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index c11a86d3bf2..1fa503f30d8 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -614,10 +614,10 @@ construct_runtime!( FellowshipSalary: pallet_salary::::{Pallet, Call, Storage, Event} = 64, // Ambassador Program. - AmbassadorCollective: pallet_ranked_collective::::{Pallet, Call, Storage, Event} = 70, - AmbassadorReferenda: pallet_referenda::::{Pallet, Call, Storage, Event} = 71, + AmbassadorCollective: pallet_ranked_collective::::{Pallet, Call, Storage, Event} = 70, + AmbassadorReferenda: pallet_referenda::::{Pallet, Call, Storage, Event} = 71, AmbassadorContent: pallet_collective_content::::{Pallet, Call, Storage, Event} = 72, - AmbassadorOrigins: pallet_ambassador_origins::{Origin} = 63, + AmbassadorOrigins: pallet_ambassador_origins::{Origin} = 73, } ); diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs index 860adbf4f60..97bebe932a1 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs @@ -1,4 +1,4 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. +// Copyright Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify @@ -17,97 +17,106 @@ //! Autogenerated weights for `pallet_collective_content` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-06, STEPS: `100`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-08-01, STEPS: `10`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `cob`, CPU: `` -//! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("collectives-polkadot-dev"), DB CACHE: 1024 +//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/debug/polkadot-parachain +// target/debug/polkadot-parachain // benchmark // pallet // --chain=collectives-polkadot-dev -// --steps=100 -// --repeat=1 +// --wasm-execution=compiled // --pallet=pallet_collective_content // --extrinsic=* -// --execution=native -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/._pallet_ambassador_content.rs +// --steps=10 +// --repeat=2 +// --json +// --header=./file_header.txt +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] +#![allow(missing_docs)] use frame_support::{traits::Get, weights::Weight}; -use sp_std::marker::PhantomData; +use core::marker::PhantomData; /// Weight functions for `pallet_collective_content`. pub struct WeightInfo(PhantomData); impl pallet_collective_content::WeightInfo for WeightInfo { - /// Storage: AmbassadorContent Charter (r:0 w:1) - /// Proof: AmbassadorContent Charter (max_values: Some(1), max_size: Some(70), added: 565, mode: MaxEncodedLen) + /// Storage: `AmbassadorContent::Charter` (r:0 w:1) + /// Proof: `AmbassadorContent::Charter` (`max_values`: Some(1), `max_size`: Some(70), added: 565, mode: `MaxEncodedLen`) fn set_charter() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 45_000 nanoseconds. - Weight::from_ref_time(45_000_000) + // Minimum execution time: 98_000_000 picoseconds. + Weight::from_parts(105_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: AmbassadorContent AnnouncementsCount (r:1 w:1) - /// Proof: AmbassadorContent AnnouncementsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:1) - /// Proof: AmbassadorContent NextAnnouncementExpireAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: AmbassadorContent Announcements (r:0 w:1) - /// Proof: AmbassadorContent Announcements (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorContent::AnnouncementsCount` (r:1 w:1) + /// Proof: `AmbassadorContent::AnnouncementsCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorContent::NextAnnouncementExpireAt` (r:1 w:1) + /// Proof: `AmbassadorContent::NextAnnouncementExpireAt` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorContent::Announcements` (r:0 w:1) + /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) /// The range of component `x` is `[0, 1]`. fn announce(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `42` - // Estimated: `998` - // Minimum execution time: 109_000 nanoseconds. - Weight::from_parts(111_333_333, 998) - // Standard Error: 718_749 - .saturating_add(Weight::from_ref_time(13_666_666).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `285` + // Estimated: `3507` + // Minimum execution time: 241_000_000 picoseconds. + Weight::from_parts(252_900_000, 0) + .saturating_add(Weight::from_parts(0, 3507)) + // Standard Error: 6_181_747 + .saturating_add(Weight::from_parts(45_100_000, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) } - /// Storage: AmbassadorContent Announcements (r:1 w:1) - /// Proof: AmbassadorContent Announcements (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) - /// Storage: AmbassadorContent AnnouncementsCount (r:1 w:1) - /// Proof: AmbassadorContent AnnouncementsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorContent::Announcements` (r:1 w:1) + /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorContent::AnnouncementsCount` (r:1 w:1) + /// Proof: `AmbassadorContent::AnnouncementsCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn remove_announcement() -> Weight { // Proof Size summary in bytes: - // Measured: `178` - // Estimated: `3065` - // Minimum execution time: 186_000 nanoseconds. - Weight::from_parts(186_000_000, 3065) - .saturating_add(T::DbWeight::get().reads(2)) + // Measured: `421` + // Estimated: `3556` + // Minimum execution time: 303_000_000 picoseconds. + Weight::from_parts(309_000_000, 0) + .saturating_add(Weight::from_parts(0, 3556)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: AmbassadorContent NextAnnouncementExpireAt (r:1 w:1) - /// Proof: AmbassadorContent NextAnnouncementExpireAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: AmbassadorContent Announcements (r:100 w:99) - /// Proof: AmbassadorContent Announcements (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen) - /// Storage: AmbassadorContent AnnouncementsCount (r:0 w:1) - /// Proof: AmbassadorContent AnnouncementsCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `AmbassadorContent::NextAnnouncementExpireAt` (r:1 w:1) + /// Proof: `AmbassadorContent::NextAnnouncementExpireAt` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorContent::Announcements` (r:101 w:100) + /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorContent::AnnouncementsCount` (r:0 w:1) + /// Proof: `AmbassadorContent::AnnouncementsCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `x` is `[0, 100]`. fn cleanup_announcements(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `130 + x * (97 ±0)` - // Estimated: `3065 + x * (2566 ±0)` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(103_774_653, 3065) - // Standard Error: 407_952 - .saturating_add(Weight::from_ref_time(102_859_501).saturating_mul(x.into())) + // Measured: `167 + x * (97 ±0)` + // Estimated: `3556 + x * (2566 ±0)` + // Minimum execution time: 38_000_000 picoseconds. + Weight::from_parts(170_764_341, 0) + .saturating_add(Weight::from_parts(0, 3556)) + // Standard Error: 1_031_927 + .saturating_add(Weight::from_parts(139_960_396, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) - .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) - .saturating_add(Weight::from_proof_size(2566).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 2566).saturating_mul(x.into())) } } From a9926fbad485952c5d61282187577f5c1a15ec83 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 9 Aug 2023 19:18:09 +0200 Subject: [PATCH 26/44] more ranks, renames, salary and core pallets --- .../pallets/collective-content/src/lib.rs | 2 +- .../src/ambassador/mod.rs | 215 ++++++++++++++---- .../src/ambassador/origins.rs | 57 +++-- .../src/ambassador/tracks.rs | 198 +++++++++++++--- .../collectives-polkadot/src/lib.rs | 6 +- 5 files changed, 379 insertions(+), 99 deletions(-) diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index a36b2d9fc19..5e28c7175a9 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -165,7 +165,7 @@ pub mod pallet { let maybe_expire_at = maybe_expire.map(|e| e.evaluate(now)); ensure!(maybe_expire_at.map_or(true, |e| e > now), Error::::InvalidExpiration); - >::insert(cid.clone(), maybe_expire_at.clone()); + >::insert(cid.clone(), maybe_expire_at); >::mutate(|count| *count += 1); if let Some(expire_at) = maybe_expire_at { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 2cdd8208d1f..c5a4e29e57f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -15,6 +15,7 @@ //! The Ambassador Program. //! +//! TODO update //! The module defines the following on-chain functionality of the Ambassador Program: //! //! - Managed set of program members, where every member has a [rank](ranks) (via @@ -30,13 +31,12 @@ use super::*; use frame_support::traits::{EitherOf, TryMapSuccess}; pub use origins::pallet_origins as pallet_ambassador_origins; use origins::pallet_origins::{ - EnsureAmbassador, EnsureRankedAmbassador, EnsureSeniorAmbassador, Origin, + EnsureAmbassador, EnsureAmbassadorVoice, EnsureHeadAmbassadorVoice, Origin, }; use sp_arithmetic::traits::CheckedSub; -use sp_runtime::{ - morph_types, - traits::{ConstU16, TypedGet}, -}; +use sp_runtime::traits::{CheckedReduceBy, ConstU16, TypedGet}; +use xcm::prelude::*; +use xcm_builder::{LocatableAssetId, PayOverXcm}; /// The Ambassador Program's member ranks. pub mod ranks { @@ -44,31 +44,57 @@ pub mod ranks { #[allow(dead_code)] pub const CANDIDATE: Rank = 0; - pub const AMBASSADOR: Rank = 1; - pub const SENIOR_AMBASSADOR: Rank = 2; - pub const HEAD_AMBASSADOR: Rank = 3; + pub const AMBASSADOR_TIER_1: Rank = 1; + pub const AMBASSADOR_TIER_2: Rank = 2; + pub const SENIOR_AMBASSADOR_TIER_3: Rank = 3; + pub const SENIOR_AMBASSADOR_TIER_4: Rank = 4; + pub const HEAD_AMBASSADOR_TIER_5: Rank = 5; + pub const HEAD_AMBASSADOR_TIER_6: Rank = 6; + pub const HEAD_AMBASSADOR_TIER_7: Rank = 7; + pub const MASTER_AMBASSADOR_TIER_8: Rank = 8; + pub const MASTER_AMBASSADOR_TIER_9: Rank = 9; } -pub type AmbassadorContentInstance = pallet_collective_content::Instance1; +impl pallet_ambassador_origins::Config for Runtime {} -impl pallet_collective_content::Config for Runtime { +pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance2; + +impl pallet_ranked_collective::Config for Runtime { + type WeightInfo = (); // TODO actual weights type RuntimeEvent = RuntimeEvent; - type CharterOrigin = EnsureAmbassador; - // An announcement can be submitted by a Senior Ambassador member or the [Origin::Ambassador] plurality voice - // taken via referendum on the [tracks::constants::AMBASSADOR] track. - type AnnouncementOrigin = EitherOfDiverse< - pallet_ranked_collective::EnsureMember< - Runtime, - AmbassadorCollectiveInstance, - { ranks::SENIOR_AMBASSADOR }, + // Promotion is by any of: + // - Root can promote arbitrarily. + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote by the rank two above the new rank. + type PromoteOrigin = EitherOf< + frame_system::EnsureRootWithSuccess>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + TryMapSuccess>>, // TODO ensure 3 or higher >, - EnsureAmbassador, >; - type WeightInfo = weights::pallet_collective_content::WeightInfo; + // Demotion is by any of: + // - Root can demote arbitrarily. + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote by the rank two above the current rank. + type DemoteOrigin = EitherOf< + frame_system::EnsureRootWithSuccess>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + TryMapSuccess>>, // TODO ensure 3 or higher + >, + >; + type Polls = AmbassadorReferenda; + type MinRankOfClass = sp_runtime::traits::Identity; + type VoteWeight = pallet_ranked_collective::Linear; } -impl pallet_ambassador_origins::Config for Runtime {} - parameter_types! { pub const AlarmInterval: BlockNumber = 1; pub const SubmissionDeposit: Balance = 0; @@ -85,14 +111,14 @@ impl pallet_referenda::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; type Currency = Balances; - // A proposal can be submitted by a member of the Ambassador Program of [ranks::AMBASSADOR] rank or higher. + // A proposal can be submitted by a member of the Ambassador Program of [ranks::SENIOR_AMBASSADOR_TIER_3] rank or higher. type SubmitOrigin = pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, - { ranks::AMBASSADOR }, + { ranks::SENIOR_AMBASSADOR_TIER_3 }, >; - type CancelOrigin = EitherOf, EnsureSeniorAmbassador>; - type KillOrigin = EitherOf, EnsureSeniorAmbassador>; + type CancelOrigin = EitherOf, EnsureHeadAmbassadorVoice>; + type KillOrigin = EitherOf, EnsureHeadAmbassadorVoice>; type Slash = ToParentTreasury; type Votes = pallet_ranked_collective::Votes; type Tally = pallet_ranked_collective::TallyOf; @@ -104,39 +130,128 @@ impl pallet_referenda::Config for Runtime { type Preimages = Preimage; } -parameter_types! { - // The benches requires max member rank to be at least 10. This rank is available only for root. - pub const MaxAmbassadorRank: pallet_ranked_collective::Rank = ranks::HEAD_AMBASSADOR + 10; -} +pub type AmbassadorContentInstance = pallet_collective_content::Instance1; -morph_types! { - /// A `TryMorph` implementation to reduce a scalar by a particular amount, checking for - /// underflow. - pub type CheckedReduceBy: TryMorph = |r: N::Type| -> Result { - r.checked_sub(&N::get()).ok_or(()) - } where N::Type: CheckedSub; +impl pallet_collective_content::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CharterOrigin = EitherOf, EnsureHeadAmbassadorVoice>; + // An announcement can be submitted by a Senior Ambassador member or the [Origin::AmbassadorTier1] plurality voice + // taken via referendum on the [tracks::constants::AMBASSADOR_TIER_1] track. + type AnnouncementOrigin = EitherOfDiverse< + pallet_ranked_collective::EnsureMember< + Runtime, + AmbassadorCollectiveInstance, + { ranks::SENIOR_AMBASSADOR_TIER_3 }, + >, + EnsureAmbassadorVoice, + >; + type WeightInfo = weights::pallet_collective_content::WeightInfo; } -pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance2; +pub type AmbassadorCoreInstance = pallet_core_fellowship::Instance2; -impl pallet_ranked_collective::Config for Runtime { +impl pallet_core_fellowship::Config for Runtime { type WeightInfo = (); // TODO actual weights type RuntimeEvent = RuntimeEvent; + type Members = pallet_ranked_collective::Pallet; + type Balance = Balance; + // Parameters are set by any of: + // - Root; + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote among all Head Ambassadors. + type ParamsOrigin = EitherOfDiverse< + EnsureXcm>, + EnsureHeadAmbassadorVoice, + >; + // Induction (creating a candidate) is by any of: + // - Root; + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a single Head Ambassador; + // - a vote among all Members. + type InductOrigin = EitherOfDiverse< + EnsureXcm>, + EitherOfDiverse< + pallet_ranked_collective::EnsureMember< + Runtime, + AmbassadorCollectiveInstance, + { ranks::HEAD_AMBASSADOR_TIER_5 }, + >, + EnsureAmbassadorVoice, // TODO ensure 3 or higher + >, + >; + // Approval (rank-retention) of a Member's current rank is by any of: + // - Root; + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote by the rank two above the current rank. + type ApproveOrigin = EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + TryMapSuccess>>, // TODO ensure 3 or higher + >; // Promotion is by any of: // - Root can promote arbitrarily. - // - a vote by the rank above the new rank. + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote by the rank two above the new rank. type PromoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess, - TryMapSuccess>>, + MapSuccess< + EnsureXcm>, + Replace>, + >, + TryMapSuccess>>, // TODO ensure 3 or higher >; - // Demotion is by any of: - // - Root can demote arbitrarily. - // - a vote by the rank above the current rank. - type DemoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess, - TryMapSuccess>>, + type EvidenceSize = ConstU32<65536>; +} + +pub type AmbassadorSalaryInstance = pallet_salary::Instance2; + +parameter_types! { + pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into(); + pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); + pub UsdtAsset: LocatableAssetId = LocatableAssetId { + location: AssetHub::get(), + asset_id: AssetHubUsdtId::get(), + }; + // The interior location on AssetHub for the paying account. This is the Ambassador Salary + // pallet instance (which sits at index 64). This sovereign account will need funding. + pub Interior: InteriorMultiLocation = PalletInstance(74).into(); +} + +const USDT_UNITS: u128 = 1_000_000; + +/// [`PayOverXcm`] setup to pay the Ambassador salary on the AssetHub in USDT. +pub type AmbassadorSalaryPaymaster = PayOverXcm< + Interior, + crate::xcm_config::XcmRouter, + crate::PolkadotXcm, + ConstU32<{ 6 * HOURS }>, + AccountId, + (), + ConvertToValue, + AliasesIntoAccountId32<(), AccountId>, +>; + +impl pallet_salary::Config for Runtime { + type WeightInfo = weights::pallet_salary::WeightInfo; + type RuntimeEvent = RuntimeEvent; + + #[cfg(not(feature = "runtime-benchmarks"))] + type Paymaster = AmbassadorSalaryPaymaster; + #[cfg(feature = "runtime-benchmarks")] + type Paymaster = PayWithEnsure>>; + type Members = pallet_ranked_collective::Pallet; + + #[cfg(not(feature = "runtime-benchmarks"))] + type Salary = pallet_core_fellowship::Pallet; + #[cfg(feature = "runtime-benchmarks")] + type Salary = frame_support::traits::tokens::ConvertRank< + crate::impls::benchmarks::RankToSalary, >; - type Polls = AmbassadorReferenda; - type MinRankOfClass = sp_runtime::traits::Identity; - type VoteWeight = pallet_ranked_collective::Geometric; + // 15 days to register for a salary payment. + type RegistrationPeriod = ConstU32<{ 15 * DAYS }>; + // 15 days to claim the salary payment. + type PayoutPeriod = ConstU32<{ 15 * DAYS }>; + // Total monthly salary budget. + type Budget = ConstU128<{ 100_000 * USDT_UNITS }>; } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs index 40a8a9c28fd..b49f95b284b 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -33,12 +33,24 @@ pub mod pallet_origins { pub enum Origin { /// Plurality voice of the [ranks::CANDIDATE] members or above given via referendum. Candidate, - /// Plurality voice of the [ranks::AMBASSADOR] members or above given via referendum. - Ambassador, - /// Plurality voice of the [ranks::SENIOR_AMBASSADOR] members or above given via referendum. - SeniorAmbassador, - /// Plurality voice of the [ranks::HEAD_AMBASSADOR] members or above given via referendum. - HeadAmbassador, + /// Plurality voice of the [ranks::AMBASSADOR_TIER_1] members or above given via referendum. + AmbassadorTier1, + /// Plurality voice of the [ranks::AMBASSADOR_TIER_2] members or above given via referendum. + AmbassadorTier2, + /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_3] members or above given via referendum. + SeniorAmbassadorTier3, + /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_4] members or above given via referendum. + SeniorAmbassadorTier4, + /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_5] members or above given via referendum. + HeadAmbassadorTier5, + /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_6] members or above given via referendum. + HeadAmbassadorTier6, + /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_7] members or above given via referendum. + HeadAmbassadorTier7, + /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_8] members or above given via referendum. + MasterAmbassadorTier8, + /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_9] members or above given via referendum. + MasterAmbassadorTier9, } /// Implementation of the [EnsureOrigin] trait for the [Origin::Ambassador] origin. @@ -58,43 +70,48 @@ pub mod pallet_origins { } } - /// Implementation of the [EnsureOrigin] trait for the [Origin::SeniorAmbassador] - /// and [Origin::HeadAmbassador] origins. - pub struct EnsureSeniorAmbassador; - impl> + From> EnsureOrigin for EnsureSeniorAmbassador { + /// Implementation of the [EnsureOrigin] trait for the [Origin::HeadAmbassadorTier5] origin. + pub struct EnsureHeadAmbassadorVoice; + impl> + From> EnsureOrigin for EnsureHeadAmbassadorVoice { type Success = (); fn try_origin(o: O) -> Result { o.into().and_then(|o| match o { - Origin::SeniorAmbassador => Ok(()), - Origin::HeadAmbassador => Ok(()), + Origin::HeadAmbassadorTier5 => Ok(()), r => Err(O::from(r)), }) } #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin() -> Result { - Ok(O::from(Origin::HeadAmbassador)) + Ok(O::from(Origin::HeadAmbassadorTier5)) } } + // TODO EnsureAmbassadorVoiceFrom + /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the /// success result of the corresponding [Rank]. Not implemented for [Origin::Candidate]. - pub struct EnsureRankedAmbassador; - - impl> + From> EnsureOrigin for EnsureRankedAmbassador { + pub struct EnsureAmbassadorVoice; + impl> + From> EnsureOrigin for EnsureAmbassadorVoice { type Success = Rank; fn try_origin(o: O) -> Result { o.into().and_then(|o| match o { - Origin::Ambassador => Ok(ranks::AMBASSADOR), - Origin::SeniorAmbassador => Ok(ranks::SENIOR_AMBASSADOR), - Origin::HeadAmbassador => Ok(ranks::HEAD_AMBASSADOR), + Origin::AmbassadorTier1 => Ok(ranks::AMBASSADOR_TIER_1), + Origin::AmbassadorTier2 => Ok(ranks::AMBASSADOR_TIER_2), + Origin::SeniorAmbassadorTier3 => Ok(ranks::SENIOR_AMBASSADOR_TIER_3), + Origin::SeniorAmbassadorTier4 => Ok(ranks::SENIOR_AMBASSADOR_TIER_4), + Origin::HeadAmbassadorTier5 => Ok(ranks::HEAD_AMBASSADOR_TIER_5), + Origin::HeadAmbassadorTier6 => Ok(ranks::HEAD_AMBASSADOR_TIER_6), + Origin::HeadAmbassadorTier7 => Ok(ranks::HEAD_AMBASSADOR_TIER_7), + Origin::MasterAmbassadorTier8 => Ok(ranks::MASTER_AMBASSADOR_TIER_8), + Origin::MasterAmbassadorTier9 => Ok(ranks::MASTER_AMBASSADOR_TIER_9), r => Err(O::from(r)), }) } #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin() -> Result { - Ok(O::from(Origin::HeadAmbassador)) + Ok(O::from(Origin::MasterAmbassadorTier9)) } } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs index bcc6a64e186..7d482aebd7d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs @@ -16,7 +16,9 @@ //! The Ambassador Program's referenda voting tracks. use super::Origin; -use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES, UNITS}; +use crate::{ + constants::currency::DOLLARS, Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES, UNITS, +}; use sp_runtime::Perbill; /// Referendum `TrackId` type. @@ -27,9 +29,15 @@ pub mod constants { use super::TrackId; pub const CANDIDATE: TrackId = 0; - pub const AMBASSADOR: TrackId = 1; - pub const SENIOR_AMBASSADOR: TrackId = 2; - pub const HEAD_AMBASSADOR: TrackId = 3; + pub const AMBASSADOR_TIER_1: TrackId = 1; + pub const AMBASSADOR_TIER_2: TrackId = 2; + pub const SENIOR_AMBASSADOR_TIER_3: TrackId = 3; + pub const SENIOR_AMBASSADOR_TIER_4: TrackId = 4; + pub const HEAD_AMBASSADOR_TIER_5: TrackId = 5; + pub const HEAD_AMBASSADOR_TIER_6: TrackId = 6; + pub const HEAD_AMBASSADOR_TIER_7: TrackId = 7; + pub const MASTER_AMBASSADOR_TIER_8: TrackId = 8; + pub const MASTER_AMBASSADOR_TIER_9: TrackId = 9; } /// The type implementing the [`pallet_referenda::TracksInfo`] trait for referenda pallet. @@ -48,12 +56,12 @@ impl pallet_referenda::TracksInfo for TracksInfo { constants::CANDIDATE, pallet_referenda::TrackInfo { name: "candidate", - max_deciding: 50, - decision_deposit: 10 * UNITS, + max_deciding: 10, + decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 1 * MINUTES, + min_enactment_period: 5 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -67,15 +75,15 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, ), ( - constants::AMBASSADOR, + constants::AMBASSADOR_TIER_1, pallet_referenda::TrackInfo { - name: "ambassador", - max_deciding: 50, - decision_deposit: 10 * UNITS, + name: "ambassador tier 1", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 1 * MINUTES, + min_enactment_period: 5 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -89,15 +97,15 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, ), ( - constants::SENIOR_AMBASSADOR, + constants::AMBASSADOR_TIER_2, pallet_referenda::TrackInfo { - name: "senior ambassador", - max_deciding: 50, - decision_deposit: 10 * UNITS, + name: "ambassador tier 2", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 1 * MINUTES, + min_enactment_period: 5 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -111,15 +119,147 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, ), ( - constants::HEAD_AMBASSADOR, + constants::SENIOR_AMBASSADOR_TIER_3, pallet_referenda::TrackInfo { - name: "head ambassador", - max_deciding: 50, - decision_deposit: 10 * UNITS, + name: "senior ambassador tier 3", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, - min_enactment_period: 1 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + constants::SENIOR_AMBASSADOR_TIER_4, + pallet_referenda::TrackInfo { + name: "senior ambassador tier 4", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + constants::HEAD_AMBASSADOR_TIER_5, + pallet_referenda::TrackInfo { + name: "head ambassador tier 5", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + constants::HEAD_AMBASSADOR_TIER_6, + pallet_referenda::TrackInfo { + name: "head ambassador tier 6", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + constants::HEAD_AMBASSADOR_TIER_7, + pallet_referenda::TrackInfo { + name: "head ambassador tier 7", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + constants::MASTER_AMBASSADOR_TIER_8, + pallet_referenda::TrackInfo { + name: "master ambassador tier 8", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(10), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + constants::MASTER_AMBASSADOR_TIER_9, + pallet_referenda::TrackInfo { + name: "master ambassador tier 9", + max_deciding: 10, + decision_deposit: 5 * DOLLARS, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 5 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -144,15 +284,21 @@ impl pallet_referenda::TracksInfo for TracksInfo { // It is important that this is not available in production! let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into(); if &root == id { - return Ok(constants::HEAD_AMBASSADOR) + return Ok(constants::MASTER_AMBASSADOR_TIER_9) } } match Origin::try_from(id.clone()) { Ok(Origin::Candidate) => Ok(constants::CANDIDATE), - Ok(Origin::Ambassador) => Ok(constants::AMBASSADOR), - Ok(Origin::SeniorAmbassador) => Ok(constants::SENIOR_AMBASSADOR), - Ok(Origin::HeadAmbassador) => Ok(constants::HEAD_AMBASSADOR), + Ok(Origin::AmbassadorTier1) => Ok(constants::AMBASSADOR_TIER_1), + Ok(Origin::AmbassadorTier2) => Ok(constants::AMBASSADOR_TIER_2), + Ok(Origin::SeniorAmbassadorTier3) => Ok(constants::SENIOR_AMBASSADOR_TIER_3), + Ok(Origin::SeniorAmbassadorTier4) => Ok(constants::SENIOR_AMBASSADOR_TIER_4), + Ok(Origin::HeadAmbassadorTier5) => Ok(constants::HEAD_AMBASSADOR_TIER_5), + Ok(Origin::HeadAmbassadorTier6) => Ok(constants::HEAD_AMBASSADOR_TIER_6), + Ok(Origin::HeadAmbassadorTier7) => Ok(constants::HEAD_AMBASSADOR_TIER_7), + Ok(Origin::MasterAmbassadorTier8) => Ok(constants::MASTER_AMBASSADOR_TIER_8), + Ok(Origin::MasterAmbassadorTier9) => Ok(constants::MASTER_AMBASSADOR_TIER_9), _ => Err(()), } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 1fa503f30d8..43944707595 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -616,8 +616,10 @@ construct_runtime!( // Ambassador Program. AmbassadorCollective: pallet_ranked_collective::::{Pallet, Call, Storage, Event} = 70, AmbassadorReferenda: pallet_referenda::::{Pallet, Call, Storage, Event} = 71, - AmbassadorContent: pallet_collective_content::::{Pallet, Call, Storage, Event} = 72, - AmbassadorOrigins: pallet_ambassador_origins::{Origin} = 73, + AmbassadorOrigins: pallet_ambassador_origins::{Origin} = 72, + AmbassadorCore: pallet_core_fellowship::::{Pallet, Call, Storage, Event} = 73, + AmbassadorSalary: pallet_salary::::{Pallet, Call, Storage, Event} = 74, + AmbassadorContent: pallet_collective_content::::{Pallet, Call, Storage, Event} = 75, } ); From 5313c68de7b92be6d642f90d2af3a6eecbe1dbf4 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 10 Aug 2023 12:51:53 +0200 Subject: [PATCH 27/44] ensure origin types, reuse common types --- .../src/ambassador/mod.rs | 97 ++++++------------- .../src/ambassador/origins.rs | 68 +++++++------ .../src/ambassador/tracks.rs | 30 +----- .../src/fellowship/mod.rs | 22 ++--- .../collectives-polkadot/src/xcm_config.rs | 16 ++- 5 files changed, 92 insertions(+), 141 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index c5a4e29e57f..5d0ad8f70cd 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -28,15 +28,16 @@ pub mod origins; mod tracks; use super::*; -use frame_support::traits::{EitherOf, TryMapSuccess}; +use crate::xcm_config::{FellowshipAdminBodyId, UsdtAsset}; +use frame_support::traits::{EitherOf, MapSuccess, TryMapSuccess}; pub use origins::pallet_origins as pallet_ambassador_origins; use origins::pallet_origins::{ - EnsureAmbassador, EnsureAmbassadorVoice, EnsureHeadAmbassadorVoice, Origin, + EnsureAmbassadorVoice, EnsureAmbassadorVoiceFrom, EnsureHeadAmbassadorVoice, Origin, }; -use sp_arithmetic::traits::CheckedSub; -use sp_runtime::traits::{CheckedReduceBy, ConstU16, TypedGet}; +use sp_core::ConstU128; +use sp_runtime::traits::{CheckedReduceBy, ConstU16, ConvertToValue, Replace}; use xcm::prelude::*; -use xcm_builder::{LocatableAssetId, PayOverXcm}; +use xcm_builder::{AliasesIntoAccountId32, PayOverXcm}; /// The Ambassador Program's member ranks. pub mod ranks { @@ -59,37 +60,29 @@ impl pallet_ambassador_origins::Config for Runtime {} pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance2; +// Promotion, demotion and approval (rank-retention) is by any of: +// - Root can promote arbitrarily. +// - the FellowshipAdmin origin (i.e. token holder referendum); +// - a senior members vote by the rank two above the new/current rank. +pub type PromoteOrigin = EitherOf< + frame_system::EnsureRootWithSuccess>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + TryMapSuccess< + EnsureAmbassadorVoiceFrom>, + CheckedReduceBy>, + >, + >, +>; + impl pallet_ranked_collective::Config for Runtime { type WeightInfo = (); // TODO actual weights type RuntimeEvent = RuntimeEvent; - // Promotion is by any of: - // - Root can promote arbitrarily. - // - the FellowshipAdmin origin (i.e. token holder referendum); - // - a vote by the rank two above the new rank. - type PromoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess>, - EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, - >, - TryMapSuccess>>, // TODO ensure 3 or higher - >, - >; - // Demotion is by any of: - // - Root can demote arbitrarily. - // - the FellowshipAdmin origin (i.e. token holder referendum); - // - a vote by the rank two above the current rank. - type DemoteOrigin = EitherOf< - frame_system::EnsureRootWithSuccess>, - EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, - >, - TryMapSuccess>>, // TODO ensure 3 or higher - >, - >; + type PromoteOrigin = PromoteOrigin; + type DemoteOrigin = PromoteOrigin; type Polls = AmbassadorReferenda; type MinRankOfClass = sp_runtime::traits::Identity; type VoteWeight = pallet_ranked_collective::Linear; @@ -135,8 +128,8 @@ pub type AmbassadorContentInstance = pallet_collective_content::Instance1; impl pallet_collective_content::Config for Runtime { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EitherOf, EnsureHeadAmbassadorVoice>; - // An announcement can be submitted by a Senior Ambassador member or the [Origin::AmbassadorTier1] plurality voice - // taken via referendum on the [tracks::constants::AMBASSADOR_TIER_1] track. + // An announcement can be submitted by a Senior Ambassador member or an ambassador plurality voice + // taken via referendum. type AnnouncementOrigin = EitherOfDiverse< pallet_ranked_collective::EnsureMember< Runtime, @@ -167,7 +160,7 @@ impl pallet_core_fellowship::Config for Runtime { // - Root; // - the FellowshipAdmin origin (i.e. token holder referendum); // - a single Head Ambassador; - // - a vote among all Members. + // - a vote among all senior members. type InductOrigin = EitherOfDiverse< EnsureXcm>, EitherOfDiverse< @@ -176,43 +169,17 @@ impl pallet_core_fellowship::Config for Runtime { AmbassadorCollectiveInstance, { ranks::HEAD_AMBASSADOR_TIER_5 }, >, - EnsureAmbassadorVoice, // TODO ensure 3 or higher - >, - >; - // Approval (rank-retention) of a Member's current rank is by any of: - // - Root; - // - the FellowshipAdmin origin (i.e. token holder referendum); - // - a vote by the rank two above the current rank. - type ApproveOrigin = EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, - >, - TryMapSuccess>>, // TODO ensure 3 or higher - >; - // Promotion is by any of: - // - Root can promote arbitrarily. - // - the FellowshipAdmin origin (i.e. token holder referendum); - // - a vote by the rank two above the new rank. - type PromoteOrigin = EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, + EnsureAmbassadorVoiceFrom>, >, - TryMapSuccess>>, // TODO ensure 3 or higher >; + type ApproveOrigin = PromoteOrigin; + type PromoteOrigin = PromoteOrigin; type EvidenceSize = ConstU32<65536>; } pub type AmbassadorSalaryInstance = pallet_salary::Instance2; parameter_types! { - pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into(); - pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); - pub UsdtAsset: LocatableAssetId = LocatableAssetId { - location: AssetHub::get(), - asset_id: AssetHubUsdtId::get(), - }; // The interior location on AssetHub for the paying account. This is the Ambassador Salary // pallet instance (which sits at index 64). This sovereign account will need funding. pub Interior: InteriorMultiLocation = PalletInstance(74).into(); diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs index b49f95b284b..62fc2e37fb6 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -17,7 +17,7 @@ #[frame_support::pallet] pub mod pallet_origins { - use super::super::ranks; + use crate::ambassador::ranks; use frame_support::pallet_prelude::*; use pallet_ranked_collective::Rank; @@ -31,8 +31,6 @@ pub mod pallet_origins { #[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)] #[pallet::origin] pub enum Origin { - /// Plurality voice of the [ranks::CANDIDATE] members or above given via referendum. - Candidate, /// Plurality voice of the [ranks::AMBASSADOR_TIER_1] members or above given via referendum. AmbassadorTier1, /// Plurality voice of the [ranks::AMBASSADOR_TIER_2] members or above given via referendum. @@ -53,21 +51,21 @@ pub mod pallet_origins { MasterAmbassadorTier9, } - /// Implementation of the [EnsureOrigin] trait for the [Origin::Ambassador] origin. - pub struct EnsureAmbassador; - impl> + From> EnsureOrigin for EnsureAmbassador { - type Success = (); - fn try_origin(o: O) -> Result { - o.into().and_then(|o| match o { - Origin::Ambassador => Ok(()), - r => Err(O::from(r)), + impl Origin { + /// Returns the rank that the origin `self` speaks for, or `None` if it doesn't speak for any. + pub fn as_voice(&self) -> Option { + Some(match &self { + Origin::AmbassadorTier1 => ranks::AMBASSADOR_TIER_1, + Origin::AmbassadorTier2 => ranks::AMBASSADOR_TIER_2, + Origin::SeniorAmbassadorTier3 => ranks::SENIOR_AMBASSADOR_TIER_3, + Origin::SeniorAmbassadorTier4 => ranks::SENIOR_AMBASSADOR_TIER_4, + Origin::HeadAmbassadorTier5 => ranks::HEAD_AMBASSADOR_TIER_5, + Origin::HeadAmbassadorTier6 => ranks::HEAD_AMBASSADOR_TIER_6, + Origin::HeadAmbassadorTier7 => ranks::HEAD_AMBASSADOR_TIER_7, + Origin::MasterAmbassadorTier8 => ranks::MASTER_AMBASSADOR_TIER_8, + Origin::MasterAmbassadorTier9 => ranks::MASTER_AMBASSADOR_TIER_9, }) } - - #[cfg(feature = "runtime-benchmarks")] - fn try_successful_origin() -> Result { - Ok(O::from(Origin::Ambassador)) - } } /// Implementation of the [EnsureOrigin] trait for the [Origin::HeadAmbassadorTier5] origin. @@ -87,26 +85,36 @@ pub mod pallet_origins { } } - // TODO EnsureAmbassadorVoiceFrom + /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s + /// from a given rank `R` with the success result of the corresponding [Rank]. + pub struct EnsureAmbassadorVoiceFrom(PhantomData); + impl, O: Into> + From> EnsureOrigin + for EnsureAmbassadorVoiceFrom + { + type Success = Rank; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match Origin::as_voice(&o) { + Some(r) if r >= R::get() => Ok(r), + _ => Err(O::from(o)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + ranks::MASTER_AMBASSADOR_TIER_9 + .ge(&R::get()) + .then(O::from(Origin::MasterAmbassadorTier9)) + .ok_or(Err(())) + } + } /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the - /// success result of the corresponding [Rank]. Not implemented for [Origin::Candidate]. + /// success result of the corresponding [Rank]. pub struct EnsureAmbassadorVoice; impl> + From> EnsureOrigin for EnsureAmbassadorVoice { type Success = Rank; fn try_origin(o: O) -> Result { - o.into().and_then(|o| match o { - Origin::AmbassadorTier1 => Ok(ranks::AMBASSADOR_TIER_1), - Origin::AmbassadorTier2 => Ok(ranks::AMBASSADOR_TIER_2), - Origin::SeniorAmbassadorTier3 => Ok(ranks::SENIOR_AMBASSADOR_TIER_3), - Origin::SeniorAmbassadorTier4 => Ok(ranks::SENIOR_AMBASSADOR_TIER_4), - Origin::HeadAmbassadorTier5 => Ok(ranks::HEAD_AMBASSADOR_TIER_5), - Origin::HeadAmbassadorTier6 => Ok(ranks::HEAD_AMBASSADOR_TIER_6), - Origin::HeadAmbassadorTier7 => Ok(ranks::HEAD_AMBASSADOR_TIER_7), - Origin::MasterAmbassadorTier8 => Ok(ranks::MASTER_AMBASSADOR_TIER_8), - Origin::MasterAmbassadorTier9 => Ok(ranks::MASTER_AMBASSADOR_TIER_9), - r => Err(O::from(r)), - }) + o.into().and_then(|o| Origin::as_voice(&o).ok_or(O::from(o))) } #[cfg(feature = "runtime-benchmarks")] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs index 7d482aebd7d..4c778b44932 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs @@ -16,9 +16,7 @@ //! The Ambassador Program's referenda voting tracks. use super::Origin; -use crate::{ - constants::currency::DOLLARS, Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES, UNITS, -}; +use crate::{constants::currency::DOLLARS, Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES}; use sp_runtime::Perbill; /// Referendum `TrackId` type. @@ -28,7 +26,6 @@ pub type TrackId = u16; pub mod constants { use super::TrackId; - pub const CANDIDATE: TrackId = 0; pub const AMBASSADOR_TIER_1: TrackId = 1; pub const AMBASSADOR_TIER_2: TrackId = 2; pub const SENIOR_AMBASSADOR_TIER_3: TrackId = 3; @@ -51,29 +48,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { /// Return the array of available tracks and their information. fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { - static DATA: [(TrackId, pallet_referenda::TrackInfo); 4] = [ - ( - constants::CANDIDATE, - pallet_referenda::TrackInfo { - name: "candidate", - max_deciding: 10, - decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, - decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: pallet_referenda::Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(50), - ceil: Perbill::from_percent(100), - }, - min_support: pallet_referenda::Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(10), - ceil: Perbill::from_percent(50), - }, - }, - ), + static DATA: [(TrackId, pallet_referenda::TrackInfo); 9] = [ ( constants::AMBASSADOR_TIER_1, pallet_referenda::TrackInfo { @@ -289,7 +264,6 @@ impl pallet_referenda::TracksInfo for TracksInfo { } match Origin::try_from(id.clone()) { - Ok(Origin::Candidate) => Ok(constants::CANDIDATE), Ok(Origin::AmbassadorTier1) => Ok(constants::AMBASSADOR_TIER_1), Ok(Origin::AmbassadorTier2) => Ok(constants::AMBASSADOR_TIER_2), Ok(Origin::SeniorAmbassadorTier3) => Ok(constants::SENIOR_AMBASSADOR_TIER_3), diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs index 99613542a2e..d0d5b9dc3a6 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -20,11 +20,13 @@ pub(crate) mod migration; mod origins; mod tracks; use crate::{ - constants, impls::ToParentTreasury, weights, AccountId, Balance, Balances, FellowshipReferenda, - GovernanceLocation, PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, Scheduler, DAYS, + constants, + impls::ToParentTreasury, + weights, + xcm_config::{FellowshipAdminBodyId, UsdtAsset}, + AccountId, Balance, Balances, FellowshipReferenda, GovernanceLocation, PolkadotTreasuryAccount, + Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, DAYS, }; -use cumulus_primitives_core::Junction::GeneralIndex; use frame_support::{ parameter_types, traits::{EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg}, @@ -36,11 +38,10 @@ pub use origins::{ }; use pallet_ranked_collective::EnsureOfRank; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; -use polkadot_runtime_constants::{time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX}; +use polkadot_runtime_constants::time::HOURS; use sp_core::{ConstU128, ConstU32}; use sp_runtime::traits::{AccountIdConversion, ConstU16, ConvertToValue, Replace, TakeFirst}; -use xcm::latest::BodyId; -use xcm_builder::{AliasesIntoAccountId32, LocatableAssetId, PayOverXcm}; +use xcm_builder::{AliasesIntoAccountId32, PayOverXcm}; #[cfg(feature = "runtime-benchmarks")] use crate::impls::benchmarks::{OpenHrmpChannel, PayWithEnsure}; @@ -63,7 +64,6 @@ pub mod ranks { parameter_types! { // Referenda pallet account, used to temporarily deposit slashed imbalance before teleporting. pub ReferendaPalletAccount: AccountId = constants::account::REFERENDA_PALLET_ID.into_account_truncating(); - pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); } impl pallet_fellowship_origins::Config for Runtime {} @@ -194,12 +194,6 @@ pub type FellowshipSalaryInstance = pallet_salary::Instance1; use xcm::prelude::*; parameter_types! { - pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into(); - pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); - pub UsdtAsset: LocatableAssetId = LocatableAssetId { - location: AssetHub::get(), - asset_id: AssetHubUsdtId::get(), - }; // The interior location on AssetHub for the paying account. This is the Fellowship Salary // pallet instance (which sits at index 64). This sovereign account will need funding. pub Interior: InteriorMultiLocation = PalletInstance(64).into(); diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 3c95da27dd8..07a148ffb8b 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -26,15 +26,16 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; use polkadot_parachain::primitives::Sibling; +use polkadot_runtime_constants::xcm::body::FELLOWSHIP_ADMIN_INDEX; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, IsConcrete, - OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, - WithComputedOrigin, + LocatableAssetId, OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + UsingComponents, WithComputedOrigin, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -46,6 +47,13 @@ parameter_types! { X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub const GovernanceLocation: MultiLocation = MultiLocation::parent(); + pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); + pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into(); + pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); + pub UsdtAsset: LocatableAssetId = LocatableAssetId { + location: AssetHub::get(), + asset_id: AssetHubUsdtId::get(), + }; } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used From cb79c45c0014aadb883c293a41a33160ff09f0e2 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 11 Aug 2023 14:03:06 +0200 Subject: [PATCH 28/44] fixes --- .../src/ambassador/mod.rs | 19 +++++++++++++------ .../src/ambassador/origins.rs | 4 ++-- .../collectives-polkadot/src/lib.rs | 2 ++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 5d0ad8f70cd..86fb4f78410 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -15,14 +15,18 @@ //! The Ambassador Program. //! -//! TODO update //! The module defines the following on-chain functionality of the Ambassador Program: //! -//! - Managed set of program members, where every member has a [rank](ranks) (via -//! [pallet_ranked_collective]). -//! - Referendum functionality for the program members to propose, vote on, and execute proposals on -//! behalf of the members of a certain [rank](Origin) (via [pallet_referenda]). +//! - Managed set of program members, where every member has a [rank](ranks) +//! (via [AmbassadorCollective](pallet_ranked_collective)). +//! - Referendum functionality for the program members to propose, vote on, and execute +//! proposals on behalf of the members of a certain [rank](Origin) +//! (via [AmbassadorReferenda](pallet_referenda)). //! - Managed content (charter, announcements) (via [pallet_collective_content]). +//! - Promotion and demotion periods, register of members' activity, rank based salaries +//! (via [AmbassadorCore](pallet_core_fellowship)). +//! - Members' salaries (via [AmbassadorSalary](pallet_salary), requiring a member to be +//! imported or inducted into [AmbassadorCore](pallet_core_fellowship)). pub mod origins; mod tracks; @@ -206,7 +210,10 @@ impl pallet_salary::Config for Runtime { #[cfg(not(feature = "runtime-benchmarks"))] type Paymaster = AmbassadorSalaryPaymaster; #[cfg(feature = "runtime-benchmarks")] - type Paymaster = PayWithEnsure>>; + type Paymaster = crate::impls::benchmarks::PayWithEnsure< + AmbassadorSalaryPaymaster, + crate::impls::benchmarks::OpenHrmpChannel>, + >; type Members = pallet_ranked_collective::Pallet; #[cfg(not(feature = "runtime-benchmarks"))] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs index 62fc2e37fb6..9391a08ae0d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -103,8 +103,8 @@ pub mod pallet_origins { fn try_successful_origin() -> Result { ranks::MASTER_AMBASSADOR_TIER_9 .ge(&R::get()) - .then(O::from(Origin::MasterAmbassadorTier9)) - .ok_or(Err(())) + .then(|| O::from(Origin::MasterAmbassadorTier9)) + .ok_or(()) } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 43944707595..d775e21005c 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -693,6 +693,8 @@ mod benches { [pallet_referenda, AmbassadorReferenda] [pallet_ranked_collective, AmbassadorCollective] [pallet_collective_content, AmbassadorContent] + [pallet_core_fellowship, AmbassadorCore] + [pallet_salary, AmbassadorSalary] ); } From 35e04176b576b4ca6baf0635eec77d60f057c820 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 11 Aug 2023 14:59:10 +0200 Subject: [PATCH 29/44] benchmark script void output file name --- scripts/benchmarks-ci.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/benchmarks-ci.sh b/scripts/benchmarks-ci.sh index 0456ad4c425..195a455fa56 100755 --- a/scripts/benchmarks-ci.sh +++ b/scripts/benchmarks-ci.sh @@ -31,11 +31,11 @@ fi for pallet in ${pallets[@]} do - output_file="${pallet//::/_}" + output_dir="" extra_args="" # a little hack for pallet_xcm_benchmarks - we want to force custom implementation for XcmWeightInfo if [[ "$pallet" == "pallet_xcm_benchmarks::generic" ]] || [[ "$pallet" == "pallet_xcm_benchmarks::fungible" ]]; then - output_file="xcm/$output_file" + output_dir="xcm/" extra_args="--template=./templates/xcm-bench-template.hbs" fi $artifactsDir/polkadot-parachain benchmark pallet \ @@ -48,5 +48,5 @@ do --repeat=$repeat \ --json \ --header=./file_header.txt \ - --output="${benchmarkOutput}/${output_file}.rs" >> $artifactsDir/${pallet}_benchmark.json + --output="${benchmarkOutput}/${output_dir}" >> $artifactsDir/${pallet}_benchmark.json done From d515363ea642d7c7bbfff561d3330fff6e2b297b Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 11 Aug 2023 16:24:19 +0200 Subject: [PATCH 30/44] weights --- .../src/ambassador/mod.rs | 8 +- .../src/fellowship/mod.rs | 8 +- .../collectives-polkadot/src/weights/mod.rs | 12 +- .../pallet_core_fellowship_ambassador_core.rs | 223 ++++++++ ...pallet_core_fellowship_fellowship_core.rs} | 73 ++- ...ranked_collective_ambassador_collective.rs | 177 ++++++ ...anked_collective_fellowship_collective.rs} | 73 +-- .../pallet_referenda_ambassador_referenda.rs | 536 ++++++++++++++++++ ... pallet_referenda_fellowship_referenda.rs} | 195 ++++--- .../pallet_salary_ambassador_salary.rs | 190 +++++++ ....rs => pallet_salary_fellowship_salary.rs} | 61 +- 11 files changed, 1339 insertions(+), 217 deletions(-) create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship_ambassador_core.rs rename parachains/runtimes/collectives/collectives-polkadot/src/weights/{pallet_core_fellowship.rs => pallet_core_fellowship_fellowship_core.rs} (87%) create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective_ambassador_collective.rs rename parachains/runtimes/collectives/collectives-polkadot/src/weights/{pallet_ranked_collective.rs => pallet_ranked_collective_fellowship_collective.rs} (82%) create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda_ambassador_referenda.rs rename parachains/runtimes/collectives/collectives-polkadot/src/weights/{pallet_referenda.rs => pallet_referenda_fellowship_referenda.rs} (87%) create mode 100644 parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary_ambassador_salary.rs rename parachains/runtimes/collectives/collectives-polkadot/src/weights/{pallet_salary.rs => pallet_salary_fellowship_salary.rs} (86%) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 86fb4f78410..77172d66e6f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -83,7 +83,7 @@ pub type PromoteOrigin = EitherOf< >; impl pallet_ranked_collective::Config for Runtime { - type WeightInfo = (); // TODO actual weights + type WeightInfo = weights::pallet_ranked_collective_ambassador_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; type PromoteOrigin = PromoteOrigin; type DemoteOrigin = PromoteOrigin; @@ -103,7 +103,7 @@ parameter_types! { pub type AmbassadorReferendaInstance = pallet_referenda::Instance2; impl pallet_referenda::Config for Runtime { - type WeightInfo = (); // TODO actual weights + type WeightInfo = weights::pallet_referenda_ambassador_referenda::WeightInfo; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; @@ -148,7 +148,7 @@ impl pallet_collective_content::Config for Runtime { pub type AmbassadorCoreInstance = pallet_core_fellowship::Instance2; impl pallet_core_fellowship::Config for Runtime { - type WeightInfo = (); // TODO actual weights + type WeightInfo = weights::pallet_core_fellowship_ambassador_core::WeightInfo; type RuntimeEvent = RuntimeEvent; type Members = pallet_ranked_collective::Pallet; type Balance = Balance; @@ -204,7 +204,7 @@ pub type AmbassadorSalaryPaymaster = PayOverXcm< >; impl pallet_salary::Config for Runtime { - type WeightInfo = weights::pallet_salary::WeightInfo; + type WeightInfo = weights::pallet_salary_ambassador_salary::WeightInfo; type RuntimeEvent = RuntimeEvent; #[cfg(not(feature = "runtime-benchmarks"))] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs index d0d5b9dc3a6..7aa38b8b8ba 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -71,7 +71,7 @@ impl pallet_fellowship_origins::Config for Runtime {} pub type FellowshipReferendaInstance = pallet_referenda::Instance1; impl pallet_referenda::Config for Runtime { - type WeightInfo = weights::pallet_referenda::WeightInfo; + type WeightInfo = weights::pallet_referenda_fellowship_referenda::WeightInfo; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; @@ -106,7 +106,7 @@ impl pallet_referenda::Config for Runtime { pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1; impl pallet_ranked_collective::Config for Runtime { - type WeightInfo = weights::pallet_ranked_collective::WeightInfo; + type WeightInfo = weights::pallet_ranked_collective_fellowship_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; #[cfg(not(feature = "runtime-benchmarks"))] @@ -136,7 +136,7 @@ impl pallet_ranked_collective::Config for Runtime pub type FellowshipCoreInstance = pallet_core_fellowship::Instance1; impl pallet_core_fellowship::Config for Runtime { - type WeightInfo = weights::pallet_core_fellowship::WeightInfo; + type WeightInfo = weights::pallet_core_fellowship_fellowship_core::WeightInfo; type RuntimeEvent = RuntimeEvent; type Members = pallet_ranked_collective::Pallet; type Balance = Balance; @@ -214,7 +214,7 @@ pub type FellowshipSalaryPaymaster = PayOverXcm< >; impl pallet_salary::Config for Runtime { - type WeightInfo = weights::pallet_salary::WeightInfo; + type WeightInfo = weights::pallet_salary_fellowship_salary::WeightInfo; type RuntimeEvent = RuntimeEvent; #[cfg(not(feature = "runtime-benchmarks"))] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs index 72e8481f166..bd366095e9d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/mod.rs @@ -7,13 +7,17 @@ pub mod pallet_balances; pub mod pallet_collator_selection; pub mod pallet_collective; pub mod pallet_collective_content; -pub mod pallet_core_fellowship; +pub mod pallet_core_fellowship_ambassador_core; +pub mod pallet_core_fellowship_fellowship_core; pub mod pallet_multisig; pub mod pallet_preimage; pub mod pallet_proxy; -pub mod pallet_ranked_collective; -pub mod pallet_referenda; -pub mod pallet_salary; +pub mod pallet_ranked_collective_ambassador_collective; +pub mod pallet_ranked_collective_fellowship_collective; +pub mod pallet_referenda_ambassador_referenda; +pub mod pallet_referenda_fellowship_referenda; +pub mod pallet_salary_ambassador_salary; +pub mod pallet_salary_fellowship_salary; pub mod pallet_scheduler; pub mod pallet_session; pub mod pallet_timestamp; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship_ambassador_core.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship_ambassador_core.rs new file mode 100644 index 00000000000..f40940a8b25 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship_ambassador_core.rs @@ -0,0 +1,223 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_core_fellowship` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/release/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --wasm-execution=compiled +// --pallet=pallet_core_fellowship +// --extrinsic=* +// --steps=2 +// --repeat=2 +// --json +// --header=./file_header.txt +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_core_fellowship`. +pub struct WeightInfo(PhantomData); +impl pallet_core_fellowship::WeightInfo for WeightInfo { + /// Storage: `AmbassadorCore::Params` (r:0 w:1) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + fn set_params() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 11_000_000 picoseconds. + Weight::from_parts(11_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Params` (r:1 w:0) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:1 w:0) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) + /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + fn bump_offboard() -> Weight { + // Proof Size summary in bytes: + // Measured: `66011` + // Estimated: `69046` + // Minimum execution time: 96_000_000 picoseconds. + Weight::from_parts(111_000_000, 0) + .saturating_add(Weight::from_parts(0, 69046)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Params` (r:1 w:0) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:1 w:0) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) + /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + fn bump_demote() -> Weight { + // Proof Size summary in bytes: + // Measured: `66121` + // Estimated: `69046` + // Minimum execution time: 99_000_000 picoseconds. + Weight::from_parts(116_000_000, 0) + .saturating_add(Weight::from_parts(0, 69046)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + fn set_active() -> Weight { + // Proof Size summary in bytes: + // Measured: `360` + // Estimated: `3514` + // Minimum execution time: 21_000_000 picoseconds. + Weight::from_parts(22_000_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:0 w:1) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:0 w:1) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + fn induct() -> Weight { + // Proof Size summary in bytes: + // Measured: `118` + // Estimated: `3514` + // Minimum execution time: 36_000_000 picoseconds. + Weight::from_parts(36_000_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Params` (r:1 w:0) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) + /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:0 w:1) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:0 w:1) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + fn promote() -> Weight { + // Proof Size summary in bytes: + // Measured: `65989` + // Estimated: `69046` + // Minimum execution time: 95_000_000 picoseconds. + Weight::from_parts(110_000_000, 0) + .saturating_add(Weight::from_parts(0, 69046)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(6)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::MemberEvidence` (r:0 w:1) + /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + fn offboard() -> Weight { + // Proof Size summary in bytes: + // Measured: `331` + // Estimated: `3514` + // Minimum execution time: 21_000_000 picoseconds. + Weight::from_parts(22_000_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + fn import() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `3514` + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(21_000_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) + /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + fn approve() -> Weight { + // Proof Size summary in bytes: + // Measured: `65967` + // Estimated: `69046` + // Minimum execution time: 78_000_000 picoseconds. + Weight::from_parts(104_000_000, 0) + .saturating_add(Weight::from_parts(0, 69046)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorCore::Member` (r:1 w:0) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) + /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + fn submit_evidence() -> Weight { + // Proof Size summary in bytes: + // Measured: `151` + // Estimated: `69046` + // Minimum execution time: 43_000_000 picoseconds. + Weight::from_parts(44_000_000, 0) + .saturating_add(Weight::from_parts(0, 69046)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship_fellowship_core.rs similarity index 87% rename from parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship.rs rename to parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship_fellowship_core.rs index 50a8bcea500..51c95003c2f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_core_fellowship_fellowship_core.rs @@ -17,24 +17,21 @@ //! Autogenerated weights for `pallet_core_fellowship` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-ynta1nyy-project-238-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot-parachain +// target/release/polkadot-parachain // benchmark // pallet // --chain=collectives-polkadot-dev // --wasm-execution=compiled // --pallet=pallet_core_fellowship -// --no-storage-info -// --no-median-slopes -// --no-min-squares // --extrinsic=* -// --steps=50 -// --repeat=20 +// --steps=2 +// --repeat=2 // --json // --header=./file_header.txt // --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ @@ -56,8 +53,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_077_000 picoseconds. - Weight::from_parts(9_356_000, 0) + // Minimum execution time: 11_000_000 picoseconds. + Weight::from_parts(12_000_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -75,10 +72,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) fn bump_offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `66111` + // Measured: `66144` // Estimated: `69046` - // Minimum execution time: 128_419_000 picoseconds. - Weight::from_parts(149_318_000, 0) + // Minimum execution time: 109_000_000 picoseconds. + Weight::from_parts(125_000_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(4)) @@ -97,10 +94,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) fn bump_demote() -> Weight { // Proof Size summary in bytes: - // Measured: `66221` + // Measured: `66254` // Estimated: `69046` - // Minimum execution time: 127_629_000 picoseconds. - Weight::from_parts(130_928_000, 0) + // Minimum execution time: 112_000_000 picoseconds. + Weight::from_parts(114_000_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(4)) @@ -111,10 +108,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) fn set_active() -> Weight { // Proof Size summary in bytes: - // Measured: `460` + // Measured: `493` // Estimated: `3514` - // Minimum execution time: 18_655_000 picoseconds. - Weight::from_parts(19_331_000, 0) + // Minimum execution time: 22_000_000 picoseconds. + Weight::from_parts(27_000_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -131,10 +128,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn induct() -> Weight { // Proof Size summary in bytes: - // Measured: `218` + // Measured: `251` // Estimated: `3514` - // Minimum execution time: 28_764_000 picoseconds. - Weight::from_parts(29_385_000, 0) + // Minimum execution time: 35_000_000 picoseconds. + Weight::from_parts(36_000_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(5)) @@ -155,10 +152,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn promote() -> Weight { // Proof Size summary in bytes: - // Measured: `66089` + // Measured: `66122` // Estimated: `69046` - // Minimum execution time: 123_179_000 picoseconds. - Weight::from_parts(125_302_000, 0) + // Minimum execution time: 97_000_000 picoseconds. + Weight::from_parts(129_000_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(6)) @@ -171,10 +168,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) fn offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `431` + // Measured: `464` // Estimated: `3514` - // Minimum execution time: 19_700_000 picoseconds. - Weight::from_parts(20_319_000, 0) + // Minimum execution time: 22_000_000 picoseconds. + Weight::from_parts(22_000_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) @@ -185,10 +182,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) fn import() -> Weight { // Proof Size summary in bytes: - // Measured: `385` + // Measured: `418` // Estimated: `3514` - // Minimum execution time: 18_048_000 picoseconds. - Weight::from_parts(18_345_000, 0) + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(24_000_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -201,10 +198,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) fn approve() -> Weight { // Proof Size summary in bytes: - // Measured: `66067` + // Measured: `66100` // Estimated: `69046` - // Minimum execution time: 108_578_000 picoseconds. - Weight::from_parts(111_311_000, 0) + // Minimum execution time: 89_000_000 picoseconds. + Weight::from_parts(119_000_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -215,10 +212,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) fn submit_evidence() -> Weight { // Proof Size summary in bytes: - // Measured: `151` + // Measured: `184` // Estimated: `69046` - // Minimum execution time: 94_484_000 picoseconds. - Weight::from_parts(97_930_000, 0) + // Minimum execution time: 43_000_000 picoseconds. + Weight::from_parts(52_000_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective_ambassador_collective.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective_ambassador_collective.rs new file mode 100644 index 00000000000..a6372c4b89d --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective_ambassador_collective.rs @@ -0,0 +1,177 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_ranked_collective` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/release/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --wasm-execution=compiled +// --pallet=pallet_ranked_collective +// --extrinsic=* +// --steps=2 +// --repeat=2 +// --json +// --header=./file_header.txt +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_ranked_collective`. +pub struct WeightInfo(PhantomData); +impl pallet_ranked_collective::WeightInfo for WeightInfo { + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:0 w:1) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:0 w:1) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + fn add_member() -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `3507` + // Minimum execution time: 21_000_000 picoseconds. + Weight::from_parts(23_000_000, 0) + .saturating_add(Weight::from_parts(0, 3507)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:11 w:11) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:11 w:11) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:11 w:11) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// The range of component `r` is `[0, 10]`. + /// The range of component `r` is `[0, 10]`. + fn remove_member(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `508 + r * (281 ±0)` + // Estimated: `3519 + r * (2529 ±0)` + // Minimum execution time: 34_000_000 picoseconds. + Weight::from_parts(36_500_000, 0) + .saturating_add(Weight::from_parts(0, 3519)) + // Standard Error: 158_113 + .saturating_add(Weight::from_parts(16_000_000, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(r.into()))) + .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(r.into()))) + .saturating_add(Weight::from_parts(0, 2529).saturating_mul(r.into())) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:0 w:1) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:0 w:1) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// The range of component `r` is `[0, 10]`. + /// The range of component `r` is `[0, 10]`. + fn promote_member(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `210 + r * (17 ±0)` + // Estimated: `3507` + // Minimum execution time: 25_000_000 picoseconds. + Weight::from_parts(26_000_000, 0) + .saturating_add(Weight::from_parts(0, 3507)) + // Standard Error: 180_277 + .saturating_add(Weight::from_parts(650_000, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:1 w:1) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:1 w:1) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// The range of component `r` is `[0, 10]`. + /// The range of component `r` is `[0, 10]`. + fn demote_member(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `508 + r * (71 ±0)` + // Estimated: `3519` + // Minimum execution time: 34_000_000 picoseconds. + Weight::from_parts(36_500_000, 0) + .saturating_add(Weight::from_parts(0, 3519)) + // Standard Error: 335_410 + .saturating_add(Weight::from_parts(550_000, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Voting` (r:1 w:1) + /// Proof: `AmbassadorCollective::Voting` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn vote() -> Weight { + // Proof Size summary in bytes: + // Measured: `566` + // Estimated: `317568` + // Minimum execution time: 57_000_000 picoseconds. + Weight::from_parts(60_000_000, 0) + .saturating_add(Weight::from_parts(0, 317568)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::VotingCleanup` (r:1 w:0) + /// Proof: `AmbassadorCollective::VotingCleanup` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Voting` (r:100 w:100) + /// Proof: `AmbassadorCollective::Voting` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`) + /// The range of component `n` is `[0, 100]`. + /// The range of component `n` is `[0, 100]`. + fn cleanup_poll(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `209 + n * (52 ±0)` + // Estimated: `4365 + n * (2550 ±0)` + // Minimum execution time: 18_000_000 picoseconds. + Weight::from_parts(18_500_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + // Standard Error: 11_180 + .saturating_add(Weight::from_parts(1_335_000, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) + .saturating_add(Weight::from_parts(0, 2550).saturating_mul(n.into())) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective_fellowship_collective.rs similarity index 82% rename from parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective.rs rename to parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective_fellowship_collective.rs index 0ce5de87c8f..724e820dc80 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_ranked_collective_fellowship_collective.rs @@ -17,24 +17,21 @@ //! Autogenerated weights for `pallet_ranked_collective` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-ynta1nyy-project-238-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot-parachain +// target/release/polkadot-parachain // benchmark // pallet // --chain=collectives-polkadot-dev // --wasm-execution=compiled // --pallet=pallet_ranked_collective -// --no-storage-info -// --no-median-slopes -// --no-min-squares // --extrinsic=* -// --steps=50 -// --repeat=20 +// --steps=2 +// --repeat=2 // --json // --header=./file_header.txt // --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ @@ -62,8 +59,8 @@ impl pallet_ranked_collective::WeightInfo for WeightInf // Proof Size summary in bytes: // Measured: `142` // Estimated: `3507` - // Minimum execution time: 16_027_000 picoseconds. - Weight::from_parts(16_501_000, 0) + // Minimum execution time: 21_000_000 picoseconds. + Weight::from_parts(22_000_000, 0) .saturating_add(Weight::from_parts(0, 3507)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(4)) @@ -77,15 +74,16 @@ impl pallet_ranked_collective::WeightInfo for WeightInf /// Storage: `FellowshipCollective::IndexToId` (r:11 w:11) /// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 10]`. + /// The range of component `r` is `[0, 10]`. fn remove_member(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `617 + r * (281 ±0)` + // Measured: `608 + r * (281 ±0)` // Estimated: `3519 + r * (2529 ±0)` - // Minimum execution time: 27_829_000 picoseconds. - Weight::from_parts(30_053_705, 0) + // Minimum execution time: 35_000_000 picoseconds. + Weight::from_parts(36_500_000, 0) .saturating_add(Weight::from_parts(0, 3519)) - // Standard Error: 26_813 - .saturating_add(Weight::from_parts(13_088_861, 0).saturating_mul(r.into())) + // Standard Error: 254_950 + .saturating_add(Weight::from_parts(15_900_000, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(r.into()))) .saturating_add(T::DbWeight::get().writes(4)) @@ -101,15 +99,16 @@ impl pallet_ranked_collective::WeightInfo for WeightInf /// Storage: `FellowshipCollective::IdToIndex` (r:0 w:1) /// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 10]`. + /// The range of component `r` is `[0, 10]`. fn promote_member(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `314 + r * (17 ±0)` + // Measured: `310 + r * (17 ±0)` // Estimated: `3507` - // Minimum execution time: 19_762_000 picoseconds. - Weight::from_parts(20_493_905, 0) + // Minimum execution time: 25_000_000 picoseconds. + Weight::from_parts(25_500_000, 0) .saturating_add(Weight::from_parts(0, 3507)) - // Standard Error: 5_519 - .saturating_add(Weight::from_parts(349_033, 0).saturating_mul(r.into())) + // Standard Error: 70_710 + .saturating_add(Weight::from_parts(400_000, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -122,15 +121,16 @@ impl pallet_ranked_collective::WeightInfo for WeightInf /// Storage: `FellowshipCollective::IndexToId` (r:1 w:1) /// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 10]`. + /// The range of component `r` is `[0, 10]`. fn demote_member(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `632 + r * (72 ±0)` + // Measured: `608 + r * (71 ±0)` // Estimated: `3519` - // Minimum execution time: 28_092_000 picoseconds. - Weight::from_parts(30_800_398, 0) + // Minimum execution time: 35_000_000 picoseconds. + Weight::from_parts(37_500_000, 0) .saturating_add(Weight::from_parts(0, 3519)) - // Standard Error: 17_223 - .saturating_add(Weight::from_parts(615_330, 0).saturating_mul(r.into())) + // Standard Error: 150_000 + .saturating_add(Weight::from_parts(350_000, 0).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -144,10 +144,10 @@ impl pallet_ranked_collective::WeightInfo for WeightInf /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn vote() -> Weight { // Proof Size summary in bytes: - // Measured: `666` + // Measured: `700` // Estimated: `317568` - // Minimum execution time: 46_255_000 picoseconds. - Weight::from_parts(47_590_000, 0) + // Minimum execution time: 57_000_000 picoseconds. + Weight::from_parts(57_000_000, 0) .saturating_add(Weight::from_parts(0, 317568)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) @@ -159,18 +159,19 @@ impl pallet_ranked_collective::WeightInfo for WeightInf /// Storage: `FellowshipCollective::Voting` (r:100 w:100) /// Proof: `FellowshipCollective::Voting` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 100]`. + /// The range of component `n` is `[0, 100]`. fn cleanup_poll(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `500 + n * (50 ±0)` - // Estimated: `4365 + n * (2540 ±0)` - // Minimum execution time: 14_975_000 picoseconds. - Weight::from_parts(17_408_362, 0) + // Measured: `343 + n * (52 ±0)` + // Estimated: `4365 + n * (2550 ±0)` + // Minimum execution time: 18_000_000 picoseconds. + Weight::from_parts(19_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) - // Standard Error: 3_134 - .saturating_add(Weight::from_parts(1_222_024, 0).saturating_mul(n.into())) + // Standard Error: 25_000 + .saturating_add(Weight::from_parts(1_395_000, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) - .saturating_add(Weight::from_parts(0, 2540).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(0, 2550).saturating_mul(n.into())) } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda_ambassador_referenda.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda_ambassador_referenda.rs new file mode 100644 index 00000000000..fdc451c5d31 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda_ambassador_referenda.rs @@ -0,0 +1,536 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_referenda` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/release/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --wasm-execution=compiled +// --pallet=pallet_referenda +// --extrinsic=* +// --steps=2 +// --repeat=2 +// --json +// --header=./file_header.txt +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_referenda`. +pub struct WeightInfo(PhantomData); +impl pallet_referenda::WeightInfo for WeightInfo { + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::ReferendumCount` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:0 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + fn submit() -> Weight { + // Proof Size summary in bytes: + // Measured: `255` + // Estimated: `159279` + // Minimum execution time: 32_000_000 picoseconds. + Weight::from_parts(34_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn place_decision_deposit_preparing() -> Weight { + // Proof Size summary in bytes: + // Measured: `366` + // Estimated: `317568` + // Minimum execution time: 63_000_000 picoseconds. + Weight::from_parts(68_000_000, 0) + .saturating_add(Weight::from_parts(0, 317568)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:0) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn place_decision_deposit_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `1165` + // Estimated: `159279` + // Minimum execution time: 97_000_000 picoseconds. + Weight::from_parts(123_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:0) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn place_decision_deposit_not_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `1173` + // Estimated: `159279` + // Minimum execution time: 104_000_000 picoseconds. + Weight::from_parts(111_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:1) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn place_decision_deposit_passing() -> Weight { + // Proof Size summary in bytes: + // Measured: `702` + // Estimated: `317568` + // Minimum execution time: 140_000_000 picoseconds. + Weight::from_parts(150_000_000, 0) + .saturating_add(Weight::from_parts(0, 317568)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:1) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn place_decision_deposit_failing() -> Weight { + // Proof Size summary in bytes: + // Measured: `601` + // Estimated: `317568` + // Minimum execution time: 81_000_000 picoseconds. + Weight::from_parts(82_000_000, 0) + .saturating_add(Weight::from_parts(0, 317568)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + fn refund_decision_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `317` + // Estimated: `4365` + // Minimum execution time: 38_000_000 picoseconds. + Weight::from_parts(38_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + fn refund_submission_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `167` + // Estimated: `4365` + // Minimum execution time: 17_000_000 picoseconds. + Weight::from_parts(18_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn cancel() -> Weight { + // Proof Size summary in bytes: + // Measured: `311` + // Estimated: `317568` + // Minimum execution time: 44_000_000 picoseconds. + Weight::from_parts(45_000_000, 0) + .saturating_add(Weight::from_parts(0, 317568)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AmbassadorReferenda::MetadataOf` (r:1 w:0) + /// Proof: `AmbassadorReferenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + fn kill() -> Weight { + // Proof Size summary in bytes: + // Measured: `626` + // Estimated: `317568` + // Minimum execution time: 183_000_000 picoseconds. + Weight::from_parts(187_000_000, 0) + .saturating_add(Weight::from_parts(0, 317568)) + .saturating_add(T::DbWeight::get().reads(11)) + .saturating_add(T::DbWeight::get().writes(6)) + } + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:0) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:1) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + fn one_fewer_deciding_queue_empty() -> Weight { + // Proof Size summary in bytes: + // Measured: `140` + // Estimated: `3636` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(12_000_000, 0) + .saturating_add(Weight::from_parts(0, 3636)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn one_fewer_deciding_failing() -> Weight { + // Proof Size summary in bytes: + // Measured: `1412` + // Estimated: `159279` + // Minimum execution time: 88_000_000 picoseconds. + Weight::from_parts(97_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn one_fewer_deciding_passing() -> Weight { + // Proof Size summary in bytes: + // Measured: `1412` + // Estimated: `159279` + // Minimum execution time: 87_000_000 picoseconds. + Weight::from_parts(92_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + fn nudge_referendum_requeued_insertion() -> Weight { + // Proof Size summary in bytes: + // Measured: `935` + // Estimated: `4365` + // Minimum execution time: 43_000_000 picoseconds. + Weight::from_parts(46_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + fn nudge_referendum_requeued_slide() -> Weight { + // Proof Size summary in bytes: + // Measured: `935` + // Estimated: `4365` + // Minimum execution time: 39_000_000 picoseconds. + Weight::from_parts(43_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:0) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + fn nudge_referendum_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `951` + // Estimated: `4365` + // Minimum execution time: 48_000_000 picoseconds. + Weight::from_parts(50_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:0) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::TrackQueue` (r:1 w:1) + /// Proof: `AmbassadorReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(171), added: 2646, mode: `MaxEncodedLen`) + fn nudge_referendum_not_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `959` + // Estimated: `4365` + // Minimum execution time: 42_000_000 picoseconds. + Weight::from_parts(48_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_no_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `263` + // Estimated: `159279` + // Minimum execution time: 28_000_000 picoseconds. + Weight::from_parts(30_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_preparing() -> Weight { + // Proof Size summary in bytes: + // Measured: `311` + // Estimated: `159279` + // Minimum execution time: 26_000_000 picoseconds. + Weight::from_parts(28_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + fn nudge_referendum_timed_out() -> Weight { + // Proof Size summary in bytes: + // Measured: `208` + // Estimated: `4365` + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:1) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_begin_deciding_failing() -> Weight { + // Proof Size summary in bytes: + // Measured: `546` + // Estimated: `159279` + // Minimum execution time: 42_000_000 picoseconds. + Weight::from_parts(46_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::DecidingCount` (r:1 w:1) + /// Proof: `AmbassadorReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_begin_deciding_passing() -> Weight { + // Proof Size summary in bytes: + // Measured: `647` + // Estimated: `159279` + // Minimum execution time: 87_000_000 picoseconds. + Weight::from_parts(93_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_begin_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `700` + // Estimated: `159279` + // Minimum execution time: 100_000_000 picoseconds. + Weight::from_parts(120_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_end_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `683` + // Estimated: `159279` + // Minimum execution time: 90_000_000 picoseconds. + Weight::from_parts(100_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_continue_not_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `700` + // Estimated: `159279` + // Minimum execution time: 77_000_000 picoseconds. + Weight::from_parts(82_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_continue_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `704` + // Estimated: `159279` + // Minimum execution time: 68_000_000 picoseconds. + Weight::from_parts(77_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn nudge_referendum_approved() -> Weight { + // Proof Size summary in bytes: + // Measured: `704` + // Estimated: `317568` + // Minimum execution time: 99_000_000 picoseconds. + Weight::from_parts(104_000_000, 0) + .saturating_add(Weight::from_parts(0, 317568)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:0) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) + fn nudge_referendum_rejected() -> Weight { + // Proof Size summary in bytes: + // Measured: `700` + // Estimated: `159279` + // Minimum execution time: 87_000_000 picoseconds. + Weight::from_parts(100_000_000, 0) + .saturating_add(Weight::from_parts(0, 159279)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::MetadataOf` (r:0 w:1) + /// Proof: `AmbassadorReferenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + fn set_some_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `419` + // Estimated: `4365` + // Minimum execution time: 23_000_000 picoseconds. + Weight::from_parts(25_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorReferenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `AmbassadorReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorReferenda::MetadataOf` (r:1 w:1) + /// Proof: `AmbassadorReferenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + fn clear_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `4365` + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(21_000_000, 0) + .saturating_add(Weight::from_parts(0, 4365)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda_fellowship_referenda.rs similarity index 87% rename from parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda.rs rename to parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda_fellowship_referenda.rs index 1e8b3ecae2e..16459a6bc7f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_referenda_fellowship_referenda.rs @@ -17,24 +17,21 @@ //! Autogenerated weights for `pallet_referenda` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-ynta1nyy-project-238-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot-parachain +// target/release/polkadot-parachain // benchmark // pallet // --chain=collectives-polkadot-dev // --wasm-execution=compiled // --pallet=pallet_referenda -// --no-storage-info -// --no-median-slopes -// --no-min-squares // --extrinsic=* -// --steps=50 -// --repeat=20 +// --steps=2 +// --repeat=2 // --json // --header=./file_header.txt // --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ @@ -60,10 +57,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) fn submit() -> Weight { // Proof Size summary in bytes: - // Measured: `355` + // Measured: `389` // Estimated: `159279` - // Minimum execution time: 29_271_000 picoseconds. - Weight::from_parts(30_285_000, 0) + // Minimum execution time: 34_000_000 picoseconds. + Weight::from_parts(36_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) @@ -74,10 +71,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn place_decision_deposit_preparing() -> Weight { // Proof Size summary in bytes: - // Measured: `366` + // Measured: `400` // Estimated: `317568` - // Minimum execution time: 52_128_000 picoseconds. - Weight::from_parts(53_504_000, 0) + // Minimum execution time: 64_000_000 picoseconds. + Weight::from_parts(67_000_000, 0) .saturating_add(Weight::from_parts(0, 317568)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) @@ -92,10 +89,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn place_decision_deposit_queued() -> Weight { // Proof Size summary in bytes: - // Measured: `2004` + // Measured: `2038` // Estimated: `159279` - // Minimum execution time: 110_018_000 picoseconds. - Weight::from_parts(114_369_000, 0) + // Minimum execution time: 99_000_000 picoseconds. + Weight::from_parts(109_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -110,10 +107,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn place_decision_deposit_not_queued() -> Weight { // Proof Size summary in bytes: - // Measured: `2045` + // Measured: `2079` // Estimated: `159279` - // Minimum execution time: 110_231_000 picoseconds. - Weight::from_parts(114_517_000, 0) + // Minimum execution time: 101_000_000 picoseconds. + Weight::from_parts(111_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -128,10 +125,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn place_decision_deposit_passing() -> Weight { // Proof Size summary in bytes: - // Measured: `802` + // Measured: `836` // Estimated: `317568` - // Minimum execution time: 195_619_000 picoseconds. - Weight::from_parts(207_157_000, 0) + // Minimum execution time: 135_000_000 picoseconds. + Weight::from_parts(153_000_000, 0) .saturating_add(Weight::from_parts(0, 317568)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) @@ -146,10 +143,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn place_decision_deposit_failing() -> Weight { // Proof Size summary in bytes: - // Measured: `701` + // Measured: `735` // Estimated: `317568` - // Minimum execution time: 64_020_000 picoseconds. - Weight::from_parts(65_463_000, 0) + // Minimum execution time: 78_000_000 picoseconds. + Weight::from_parts(82_000_000, 0) .saturating_add(Weight::from_parts(0, 317568)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) @@ -158,10 +155,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) fn refund_decision_deposit() -> Weight { // Proof Size summary in bytes: - // Measured: `317` + // Measured: `351` // Estimated: `4365` - // Minimum execution time: 30_701_000 picoseconds. - Weight::from_parts(31_528_000, 0) + // Minimum execution time: 38_000_000 picoseconds. + Weight::from_parts(39_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -170,10 +167,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) fn refund_submission_deposit() -> Weight { // Proof Size summary in bytes: - // Measured: `167` + // Measured: `201` // Estimated: `4365` - // Minimum execution time: 15_173_000 picoseconds. - Weight::from_parts(15_787_000, 0) + // Minimum execution time: 18_000_000 picoseconds. + Weight::from_parts(19_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -184,10 +181,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn cancel() -> Weight { // Proof Size summary in bytes: - // Measured: `311` + // Measured: `345` // Estimated: `317568` - // Minimum execution time: 37_886_000 picoseconds. - Weight::from_parts(38_679_000, 0) + // Minimum execution time: 45_000_000 picoseconds. + Weight::from_parts(46_000_000, 0) .saturating_add(Weight::from_parts(0, 317568)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) @@ -214,10 +211,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) fn kill() -> Weight { // Proof Size summary in bytes: - // Measured: `517` + // Measured: `587` // Estimated: `317568` - // Minimum execution time: 152_111_000 picoseconds. - Weight::from_parts(155_738_000, 0) + // Minimum execution time: 185_000_000 picoseconds. + Weight::from_parts(196_000_000, 0) .saturating_add(Weight::from_parts(0, 317568)) .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(6)) @@ -228,10 +225,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) fn one_fewer_deciding_queue_empty() -> Weight { // Proof Size summary in bytes: - // Measured: `140` + // Measured: `174` // Estimated: `4277` - // Minimum execution time: 10_712_000 picoseconds. - Weight::from_parts(10_976_000, 0) + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(15_000_000, 0) .saturating_add(Weight::from_parts(0, 4277)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -246,10 +243,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn one_fewer_deciding_failing() -> Weight { // Proof Size summary in bytes: - // Measured: `2418` + // Measured: `2452` // Estimated: `159279` - // Minimum execution time: 97_671_000 picoseconds. - Weight::from_parts(104_911_000, 0) + // Minimum execution time: 82_000_000 picoseconds. + Weight::from_parts(90_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -264,10 +261,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn one_fewer_deciding_passing() -> Weight { // Proof Size summary in bytes: - // Measured: `2418` + // Measured: `2452` // Estimated: `159279` - // Minimum execution time: 104_019_000 picoseconds. - Weight::from_parts(108_208_000, 0) + // Minimum execution time: 91_000_000 picoseconds. + Weight::from_parts(99_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -278,10 +275,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(812), added: 3287, mode: `MaxEncodedLen`) fn nudge_referendum_requeued_insertion() -> Weight { // Proof Size summary in bytes: - // Measured: `1807` + // Measured: `1841` // Estimated: `4365` - // Minimum execution time: 50_199_000 picoseconds. - Weight::from_parts(54_350_000, 0) + // Minimum execution time: 41_000_000 picoseconds. + Weight::from_parts(44_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -292,10 +289,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(812), added: 3287, mode: `MaxEncodedLen`) fn nudge_referendum_requeued_slide() -> Weight { // Proof Size summary in bytes: - // Measured: `1774` + // Measured: `1808` // Estimated: `4365` - // Minimum execution time: 52_459_000 picoseconds. - Weight::from_parts(54_382_000, 0) + // Minimum execution time: 46_000_000 picoseconds. + Weight::from_parts(55_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -308,10 +305,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(812), added: 3287, mode: `MaxEncodedLen`) fn nudge_referendum_queued() -> Weight { // Proof Size summary in bytes: - // Measured: `1790` + // Measured: `1824` // Estimated: `4365` - // Minimum execution time: 57_810_000 picoseconds. - Weight::from_parts(63_690_000, 0) + // Minimum execution time: 49_000_000 picoseconds. + Weight::from_parts(53_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -324,10 +321,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::TrackQueue` (`max_values`: None, `max_size`: Some(812), added: 3287, mode: `MaxEncodedLen`) fn nudge_referendum_not_queued() -> Weight { // Proof Size summary in bytes: - // Measured: `1831` + // Measured: `1865` // Estimated: `4365` - // Minimum execution time: 56_778_000 picoseconds. - Weight::from_parts(59_556_000, 0) + // Minimum execution time: 51_000_000 picoseconds. + Weight::from_parts(54_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -338,10 +335,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_no_deposit() -> Weight { // Proof Size summary in bytes: - // Measured: `263` + // Measured: `297` // Estimated: `159279` - // Minimum execution time: 24_377_000 picoseconds. - Weight::from_parts(27_031_000, 0) + // Minimum execution time: 28_000_000 picoseconds. + Weight::from_parts(30_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) @@ -352,10 +349,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_preparing() -> Weight { // Proof Size summary in bytes: - // Measured: `311` + // Measured: `345` // Estimated: `159279` - // Minimum execution time: 24_717_000 picoseconds. - Weight::from_parts(25_578_000, 0) + // Minimum execution time: 28_000_000 picoseconds. + Weight::from_parts(29_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) @@ -364,10 +361,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(900), added: 3375, mode: `MaxEncodedLen`) fn nudge_referendum_timed_out() -> Weight { // Proof Size summary in bytes: - // Measured: `208` + // Measured: `242` // Estimated: `4365` - // Minimum execution time: 17_280_000 picoseconds. - Weight::from_parts(17_845_000, 0) + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(21_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -382,10 +379,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_begin_deciding_failing() -> Weight { // Proof Size summary in bytes: - // Measured: `646` + // Measured: `680` // Estimated: `159279` - // Minimum execution time: 36_996_000 picoseconds. - Weight::from_parts(37_970_000, 0) + // Minimum execution time: 42_000_000 picoseconds. + Weight::from_parts(47_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -400,10 +397,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_begin_deciding_passing() -> Weight { // Proof Size summary in bytes: - // Measured: `747` + // Measured: `781` // Estimated: `159279` - // Minimum execution time: 91_681_000 picoseconds. - Weight::from_parts(98_640_000, 0) + // Minimum execution time: 90_000_000 picoseconds. + Weight::from_parts(95_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -416,10 +413,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_begin_confirming() -> Weight { // Proof Size summary in bytes: - // Measured: `800` + // Measured: `834` // Estimated: `159279` - // Minimum execution time: 149_940_000 picoseconds. - Weight::from_parts(167_561_000, 0) + // Minimum execution time: 84_000_000 picoseconds. + Weight::from_parts(93_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -432,10 +429,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_end_confirming() -> Weight { // Proof Size summary in bytes: - // Measured: `783` + // Measured: `817` // Estimated: `159279` - // Minimum execution time: 157_443_000 picoseconds. - Weight::from_parts(168_023_000, 0) + // Minimum execution time: 88_000_000 picoseconds. + Weight::from_parts(98_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -448,10 +445,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_continue_not_confirming() -> Weight { // Proof Size summary in bytes: - // Measured: `800` + // Measured: `834` // Estimated: `159279` - // Minimum execution time: 155_539_000 picoseconds. - Weight::from_parts(161_877_000, 0) + // Minimum execution time: 81_000_000 picoseconds. + Weight::from_parts(93_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -464,10 +461,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_continue_confirming() -> Weight { // Proof Size summary in bytes: - // Measured: `804` + // Measured: `838` // Estimated: `159279` - // Minimum execution time: 82_000_000 picoseconds. - Weight::from_parts(87_101_000, 0) + // Minimum execution time: 74_000_000 picoseconds. + Weight::from_parts(77_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -482,10 +479,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) fn nudge_referendum_approved() -> Weight { // Proof Size summary in bytes: - // Measured: `804` + // Measured: `838` // Estimated: `317568` - // Minimum execution time: 154_590_000 picoseconds. - Weight::from_parts(186_418_000, 0) + // Minimum execution time: 105_000_000 picoseconds. + Weight::from_parts(123_000_000, 0) .saturating_add(Weight::from_parts(0, 317568)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) @@ -498,10 +495,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(155814), added: 158289, mode: `MaxEncodedLen`) fn nudge_referendum_rejected() -> Weight { // Proof Size summary in bytes: - // Measured: `800` + // Measured: `834` // Estimated: `159279` - // Minimum execution time: 149_822_000 picoseconds. - Weight::from_parts(164_866_000, 0) + // Minimum execution time: 90_000_000 picoseconds. + Weight::from_parts(100_000_000, 0) .saturating_add(Weight::from_parts(0, 159279)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -514,10 +511,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) fn set_some_metadata() -> Weight { // Proof Size summary in bytes: - // Measured: `386` + // Measured: `453` // Estimated: `4365` - // Minimum execution time: 21_413_000 picoseconds. - Weight::from_parts(21_938_000, 0) + // Minimum execution time: 24_000_000 picoseconds. + Weight::from_parts(24_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -528,10 +525,10 @@ impl pallet_referenda::WeightInfo for WeightInfo { /// Proof: `FellowshipReferenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) fn clear_metadata() -> Weight { // Proof Size summary in bytes: - // Measured: `285` + // Measured: `319` // Estimated: `4365` - // Minimum execution time: 18_927_000 picoseconds. - Weight::from_parts(19_423_000, 0) + // Minimum execution time: 21_000_000 picoseconds. + Weight::from_parts(23_000_000, 0) .saturating_add(Weight::from_parts(0, 4365)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary_ambassador_salary.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary_ambassador_salary.rs new file mode 100644 index 00000000000..0522420f2f5 --- /dev/null +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary_ambassador_salary.rs @@ -0,0 +1,190 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_salary` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/release/polkadot-parachain +// benchmark +// pallet +// --chain=collectives-polkadot-dev +// --wasm-execution=compiled +// --pallet=pallet_salary +// --extrinsic=* +// --steps=2 +// --repeat=2 +// --json +// --header=./file_header.txt +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_salary`. +pub struct WeightInfo(PhantomData); +impl pallet_salary::WeightInfo for WeightInfo { + /// Storage: `AmbassadorSalary::Status` (r:1 w:1) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + fn init() -> Weight { + // Proof Size summary in bytes: + // Measured: `109` + // Estimated: `1541` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(14_000_000, 0) + .saturating_add(Weight::from_parts(0, 1541)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorSalary::Status` (r:1 w:1) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + fn bump() -> Weight { + // Proof Size summary in bytes: + // Measured: `191` + // Estimated: `1541` + // Minimum execution time: 15_000_000 picoseconds. + Weight::from_parts(16_000_000, 0) + .saturating_add(Weight::from_parts(0, 1541)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorSalary::Status` (r:1 w:0) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorSalary::Claimant` (r:1 w:1) + /// Proof: `AmbassadorSalary::Claimant` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) + fn induct() -> Weight { + // Proof Size summary in bytes: + // Measured: `400` + // Estimated: `3551` + // Minimum execution time: 23_000_000 picoseconds. + Weight::from_parts(23_000_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorSalary::Status` (r:1 w:1) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorSalary::Claimant` (r:1 w:1) + /// Proof: `AmbassadorSalary::Claimant` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) + fn register() -> Weight { + // Proof Size summary in bytes: + // Measured: `467` + // Estimated: `3551` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(28_000_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `AmbassadorSalary::Status` (r:1 w:1) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorSalary::Claimant` (r:1 w:1) + /// Proof: `AmbassadorSalary::Claimant` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::QueryCounter` (r:1 w:1) + /// Proof: `PolkadotXcm::QueryCounter` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::RelevantMessagingState` (r:1 w:0) + /// Proof: `ParachainSystem::RelevantMessagingState` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpMessages` (r:0 w:1) + /// Proof: `XcmpQueue::OutboundXcmpMessages` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::Queries` (r:0 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn payout() -> Weight { + // Proof Size summary in bytes: + // Measured: `879` + // Estimated: `4344` + // Minimum execution time: 68_000_000 picoseconds. + Weight::from_parts(72_000_000, 0) + .saturating_add(Weight::from_parts(0, 4344)) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(7)) + } + /// Storage: `AmbassadorSalary::Status` (r:1 w:1) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorSalary::Claimant` (r:1 w:1) + /// Proof: `AmbassadorSalary::Claimant` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::QueryCounter` (r:1 w:1) + /// Proof: `PolkadotXcm::QueryCounter` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::RelevantMessagingState` (r:1 w:0) + /// Proof: `ParachainSystem::RelevantMessagingState` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpMessages` (r:0 w:1) + /// Proof: `XcmpQueue::OutboundXcmpMessages` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::Queries` (r:0 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn payout_other() -> Weight { + // Proof Size summary in bytes: + // Measured: `879` + // Estimated: `4344` + // Minimum execution time: 69_000_000 picoseconds. + Weight::from_parts(70_000_000, 0) + .saturating_add(Weight::from_parts(0, 4344)) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(7)) + } + /// Storage: `AmbassadorSalary::Status` (r:1 w:1) + /// Proof: `AmbassadorSalary::Status` (`max_values`: Some(1), `max_size`: Some(56), added: 551, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorSalary::Claimant` (r:1 w:1) + /// Proof: `AmbassadorSalary::Claimant` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::Queries` (r:1 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn check_payment() -> Weight { + // Proof Size summary in bytes: + // Measured: `479` + // Estimated: `3944` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(28_000_000, 0) + .saturating_add(Weight::from_parts(0, 3944)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary_fellowship_salary.rs similarity index 86% rename from parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary.rs rename to parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary_fellowship_salary.rs index 351834c5e3a..9b43ced54e1 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_salary_fellowship_salary.rs @@ -17,24 +17,21 @@ //! Autogenerated weights for `pallet_salary` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-ynta1nyy-project-238-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 +//! HOSTNAME: `cob`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot-parachain +// target/release/polkadot-parachain // benchmark // pallet // --chain=collectives-polkadot-dev // --wasm-execution=compiled // --pallet=pallet_salary -// --no-storage-info -// --no-median-slopes -// --no-min-squares // --extrinsic=* -// --steps=50 -// --repeat=20 +// --steps=2 +// --repeat=2 // --json // --header=./file_header.txt // --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ @@ -56,8 +53,8 @@ impl pallet_salary::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `142` // Estimated: `1541` - // Minimum execution time: 10_579_000 picoseconds. - Weight::from_parts(10_898_000, 0) + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(17_000_000, 0) .saturating_add(Weight::from_parts(0, 1541)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -68,8 +65,8 @@ impl pallet_salary::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `224` // Estimated: `1541` - // Minimum execution time: 12_723_000 picoseconds. - Weight::from_parts(13_221_000, 0) + // Minimum execution time: 15_000_000 picoseconds. + Weight::from_parts(18_000_000, 0) .saturating_add(Weight::from_parts(0, 1541)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -84,8 +81,8 @@ impl pallet_salary::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `395` // Estimated: `3551` - // Minimum execution time: 18_522_000 picoseconds. - Weight::from_parts(19_120_000, 0) + // Minimum execution time: 22_000_000 picoseconds. + Weight::from_parts(25_000_000, 0) .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -100,8 +97,8 @@ impl pallet_salary::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `462` // Estimated: `3551` - // Minimum execution time: 22_270_000 picoseconds. - Weight::from_parts(23_325_000, 0) + // Minimum execution time: 26_000_000 picoseconds. + Weight::from_parts(29_000_000, 0) .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -132,11 +129,11 @@ impl pallet_salary::WeightInfo for WeightInfo { /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) fn payout() -> Weight { // Proof Size summary in bytes: - // Measured: `703` - // Estimated: `4168` - // Minimum execution time: 54_436_000 picoseconds. - Weight::from_parts(56_347_000, 0) - .saturating_add(Weight::from_parts(0, 4168)) + // Measured: `774` + // Estimated: `4239` + // Minimum execution time: 67_000_000 picoseconds. + Weight::from_parts(74_000_000, 0) + .saturating_add(Weight::from_parts(0, 4239)) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -166,11 +163,11 @@ impl pallet_salary::WeightInfo for WeightInfo { /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) fn payout_other() -> Weight { // Proof Size summary in bytes: - // Measured: `703` - // Estimated: `4168` - // Minimum execution time: 54_140_000 picoseconds. - Weight::from_parts(56_312_000, 0) - .saturating_add(Weight::from_parts(0, 4168)) + // Measured: `774` + // Estimated: `4239` + // Minimum execution time: 66_000_000 picoseconds. + Weight::from_parts(71_000_000, 0) + .saturating_add(Weight::from_parts(0, 4239)) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -182,11 +179,11 @@ impl pallet_salary::WeightInfo for WeightInfo { /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) fn check_payment() -> Weight { // Proof Size summary in bytes: - // Measured: `478` - // Estimated: `3943` - // Minimum execution time: 24_650_000 picoseconds. - Weight::from_parts(25_242_000, 0) - .saturating_add(Weight::from_parts(0, 3943)) + // Measured: `512` + // Estimated: `3977` + // Minimum execution time: 26_000_000 picoseconds. + Weight::from_parts(27_000_000, 0) + .saturating_add(Weight::from_parts(0, 3977)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) } From c238fb26b75569a11abb57437fd14acd26e05f18 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 14 Aug 2023 12:09:32 +0200 Subject: [PATCH 31/44] docs fixes --- parachains/pallets/collective-content/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 5e28c7175a9..4cd76a7ebb4 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -18,7 +18,7 @@ //! The pallet provides the functionality to store different types of content. This would typically //! be used by an on-chain collective, such as the Polkadot Alliance or Ambassador Program. //! -//! The pallet stores content as a [OpaqueCid], which should correspond to some off-chain hosting service, +//! The pallet stores content as an [OpaqueCid], which should correspond to some off-chain hosting service, //! such as IPFS, and contain any type of data. Each type of content has its own origin from which //! it can be managed. The origins are configurable in the runtime. Storing content does not require //! a deposit, as it is expected to be managed by a trusted collective. @@ -49,7 +49,7 @@ use sp_core::ConstU32; use sp_std::prelude::*; /// IPFS compatible CID. -// worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. +// Worst case 2 bytes base and codec, 2 bytes hash type and size, 64 bytes hash digest. pub type OpaqueCid = BoundedVec>; #[frame_support::pallet] From 9ab6aa47063d7e8b67ddc10d9c136037f99c03a3 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 14 Aug 2023 14:56:24 +0200 Subject: [PATCH 32/44] promote origin for rank 0 --- .../src/ambassador/mod.rs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 77172d66e6f..12ae58b1ca6 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -64,11 +64,11 @@ impl pallet_ambassador_origins::Config for Runtime {} pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance2; -// Promotion, demotion and approval (rank-retention) is by any of: -// - Root can promote arbitrarily. -// - the FellowshipAdmin origin (i.e. token holder referendum); -// - a senior members vote by the rank two above the new/current rank. -pub type PromoteOrigin = EitherOf< +/// Demotion is by any of: +/// - Root can promote arbitrarily. +/// - the FellowshipAdmin origin (i.e. token holder referendum); +/// - a senior members vote by the rank two above the current rank. +pub type DemoteOrigin = EitherOf< frame_system::EnsureRootWithSuccess>, EitherOf< MapSuccess< @@ -82,11 +82,28 @@ pub type PromoteOrigin = EitherOf< >, >; +/// Promotion and approval (rank-retention) is by any of: +/// - Root can promote arbitrarily. +/// - the FellowshipAdmin origin (i.e. token holder referendum); +/// - a senior members vote by the rank two above the new/current rank. +/// - a member of rank `5` or above can add a candidate (rank `0`). +pub type PromoteOrigin = EitherOf< + DemoteOrigin, + TryMapSuccess< + pallet_ranked_collective::EnsureMember< + Runtime, + AmbassadorCollectiveInstance, + { ranks::HEAD_AMBASSADOR_TIER_5 }, + >, + Replace>, + >, +>; + impl pallet_ranked_collective::Config for Runtime { type WeightInfo = weights::pallet_ranked_collective_ambassador_collective::WeightInfo; type RuntimeEvent = RuntimeEvent; type PromoteOrigin = PromoteOrigin; - type DemoteOrigin = PromoteOrigin; + type DemoteOrigin = DemoteOrigin; type Polls = AmbassadorReferenda; type MinRankOfClass = sp_runtime::traits::Identity; type VoteWeight = pallet_ranked_collective::Linear; From 67902de4769b312d82a8c1b2325c2d7c967e2776 Mon Sep 17 00:00:00 2001 From: Muharem Ismailov Date: Fri, 18 Aug 2023 12:00:46 +0200 Subject: [PATCH 33/44] Apply suggestions from code review Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../collectives-polkadot/src/ambassador/mod.rs | 2 +- .../collectives-polkadot/src/ambassador/origins.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 12ae58b1ca6..634f016e36d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -23,7 +23,7 @@ //! proposals on behalf of the members of a certain [rank](Origin) //! (via [AmbassadorReferenda](pallet_referenda)). //! - Managed content (charter, announcements) (via [pallet_collective_content]). -//! - Promotion and demotion periods, register of members' activity, rank based salaries +//! - Promotion and demotion periods, register of members' activity, and rank based salaries //! (via [AmbassadorCore](pallet_core_fellowship)). //! - Members' salaries (via [AmbassadorSalary](pallet_salary), requiring a member to be //! imported or inducted into [AmbassadorCore](pallet_core_fellowship)). diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs index 9391a08ae0d..1625401b6fa 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -32,21 +32,21 @@ pub mod pallet_origins { #[pallet::origin] pub enum Origin { /// Plurality voice of the [ranks::AMBASSADOR_TIER_1] members or above given via referendum. - AmbassadorTier1, + Ambassadors, /// Plurality voice of the [ranks::AMBASSADOR_TIER_2] members or above given via referendum. AmbassadorTier2, /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_3] members or above given via referendum. - SeniorAmbassadorTier3, + SeniorAmbassadors, /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_4] members or above given via referendum. SeniorAmbassadorTier4, /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_5] members or above given via referendum. - HeadAmbassadorTier5, + HeadAmbassadors, /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_6] members or above given via referendum. HeadAmbassadorTier6, /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_7] members or above given via referendum. HeadAmbassadorTier7, /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_8] members or above given via referendum. - MasterAmbassadorTier8, + MasterAmbassadors, /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_9] members or above given via referendum. MasterAmbassadorTier9, } From 54bd222c50bc1a8997430278354daf2f931bfb6f Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 18 Aug 2023 12:44:02 +0200 Subject: [PATCH 34/44] renames --- .../src/ambassador/mod.rs | 16 +++--- .../src/ambassador/origins.rs | 50 +++++++++---------- .../src/ambassador/tracks.rs | 18 +++---- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 634f016e36d..ca4bd4fba3a 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -36,7 +36,7 @@ use crate::xcm_config::{FellowshipAdminBodyId, UsdtAsset}; use frame_support::traits::{EitherOf, MapSuccess, TryMapSuccess}; pub use origins::pallet_origins as pallet_ambassador_origins; use origins::pallet_origins::{ - EnsureAmbassadorVoice, EnsureAmbassadorVoiceFrom, EnsureHeadAmbassadorVoice, Origin, + EnsureAmbassadorsVoice, EnsureAmbassadorsVoiceFrom, EnsureHeadAmbassadorsVoice, Origin, }; use sp_core::ConstU128; use sp_runtime::traits::{CheckedReduceBy, ConstU16, ConvertToValue, Replace}; @@ -76,7 +76,7 @@ pub type DemoteOrigin = EitherOf< Replace>, >, TryMapSuccess< - EnsureAmbassadorVoiceFrom>, + EnsureAmbassadorsVoiceFrom>, CheckedReduceBy>, >, >, @@ -131,8 +131,8 @@ impl pallet_referenda::Config for Runtime { AmbassadorCollectiveInstance, { ranks::SENIOR_AMBASSADOR_TIER_3 }, >; - type CancelOrigin = EitherOf, EnsureHeadAmbassadorVoice>; - type KillOrigin = EitherOf, EnsureHeadAmbassadorVoice>; + type CancelOrigin = EitherOf, EnsureHeadAmbassadorsVoice>; + type KillOrigin = EitherOf, EnsureHeadAmbassadorsVoice>; type Slash = ToParentTreasury; type Votes = pallet_ranked_collective::Votes; type Tally = pallet_ranked_collective::TallyOf; @@ -148,7 +148,7 @@ pub type AmbassadorContentInstance = pallet_collective_content::Instance1; impl pallet_collective_content::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type CharterOrigin = EitherOf, EnsureHeadAmbassadorVoice>; + type CharterOrigin = EitherOf, EnsureHeadAmbassadorsVoice>; // An announcement can be submitted by a Senior Ambassador member or an ambassador plurality voice // taken via referendum. type AnnouncementOrigin = EitherOfDiverse< @@ -157,7 +157,7 @@ impl pallet_collective_content::Config for Runtime { AmbassadorCollectiveInstance, { ranks::SENIOR_AMBASSADOR_TIER_3 }, >, - EnsureAmbassadorVoice, + EnsureAmbassadorsVoice, >; type WeightInfo = weights::pallet_collective_content::WeightInfo; } @@ -175,7 +175,7 @@ impl pallet_core_fellowship::Config for Runtime { // - a vote among all Head Ambassadors. type ParamsOrigin = EitherOfDiverse< EnsureXcm>, - EnsureHeadAmbassadorVoice, + EnsureHeadAmbassadorsVoice, >; // Induction (creating a candidate) is by any of: // - Root; @@ -190,7 +190,7 @@ impl pallet_core_fellowship::Config for Runtime { AmbassadorCollectiveInstance, { ranks::HEAD_AMBASSADOR_TIER_5 }, >, - EnsureAmbassadorVoiceFrom>, + EnsureAmbassadorsVoiceFrom>, >, >; type ApproveOrigin = PromoteOrigin; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs index 1625401b6fa..ad95b2e14cf 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -34,62 +34,62 @@ pub mod pallet_origins { /// Plurality voice of the [ranks::AMBASSADOR_TIER_1] members or above given via referendum. Ambassadors, /// Plurality voice of the [ranks::AMBASSADOR_TIER_2] members or above given via referendum. - AmbassadorTier2, + AmbassadorsTier2, /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_3] members or above given via referendum. SeniorAmbassadors, /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_4] members or above given via referendum. - SeniorAmbassadorTier4, + SeniorAmbassadorsTier4, /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_5] members or above given via referendum. HeadAmbassadors, /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_6] members or above given via referendum. - HeadAmbassadorTier6, + HeadAmbassadorsTier6, /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_7] members or above given via referendum. - HeadAmbassadorTier7, + HeadAmbassadorsTier7, /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_8] members or above given via referendum. MasterAmbassadors, /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_9] members or above given via referendum. - MasterAmbassadorTier9, + MasterAmbassadorsTier9, } impl Origin { /// Returns the rank that the origin `self` speaks for, or `None` if it doesn't speak for any. pub fn as_voice(&self) -> Option { Some(match &self { - Origin::AmbassadorTier1 => ranks::AMBASSADOR_TIER_1, - Origin::AmbassadorTier2 => ranks::AMBASSADOR_TIER_2, - Origin::SeniorAmbassadorTier3 => ranks::SENIOR_AMBASSADOR_TIER_3, - Origin::SeniorAmbassadorTier4 => ranks::SENIOR_AMBASSADOR_TIER_4, - Origin::HeadAmbassadorTier5 => ranks::HEAD_AMBASSADOR_TIER_5, - Origin::HeadAmbassadorTier6 => ranks::HEAD_AMBASSADOR_TIER_6, - Origin::HeadAmbassadorTier7 => ranks::HEAD_AMBASSADOR_TIER_7, - Origin::MasterAmbassadorTier8 => ranks::MASTER_AMBASSADOR_TIER_8, - Origin::MasterAmbassadorTier9 => ranks::MASTER_AMBASSADOR_TIER_9, + Origin::Ambassadors => ranks::AMBASSADOR_TIER_1, + Origin::AmbassadorsTier2 => ranks::AMBASSADOR_TIER_2, + Origin::SeniorAmbassadors => ranks::SENIOR_AMBASSADOR_TIER_3, + Origin::SeniorAmbassadorsTier4 => ranks::SENIOR_AMBASSADOR_TIER_4, + Origin::HeadAmbassadors => ranks::HEAD_AMBASSADOR_TIER_5, + Origin::HeadAmbassadorsTier6 => ranks::HEAD_AMBASSADOR_TIER_6, + Origin::HeadAmbassadorsTier7 => ranks::HEAD_AMBASSADOR_TIER_7, + Origin::MasterAmbassadors => ranks::MASTER_AMBASSADOR_TIER_8, + Origin::MasterAmbassadorsTier9 => ranks::MASTER_AMBASSADOR_TIER_9, }) } } - /// Implementation of the [EnsureOrigin] trait for the [Origin::HeadAmbassadorTier5] origin. - pub struct EnsureHeadAmbassadorVoice; - impl> + From> EnsureOrigin for EnsureHeadAmbassadorVoice { + /// Implementation of the [EnsureOrigin] trait for the [Origin::HeadAmbassadors] origin. + pub struct EnsureHeadAmbassadorsVoice; + impl> + From> EnsureOrigin for EnsureHeadAmbassadorsVoice { type Success = (); fn try_origin(o: O) -> Result { o.into().and_then(|o| match o { - Origin::HeadAmbassadorTier5 => Ok(()), + Origin::HeadAmbassadors => Ok(()), r => Err(O::from(r)), }) } #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin() -> Result { - Ok(O::from(Origin::HeadAmbassadorTier5)) + Ok(O::from(Origin::HeadAmbassadors)) } } /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s /// from a given rank `R` with the success result of the corresponding [Rank]. - pub struct EnsureAmbassadorVoiceFrom(PhantomData); + pub struct EnsureAmbassadorsVoiceFrom(PhantomData); impl, O: Into> + From> EnsureOrigin - for EnsureAmbassadorVoiceFrom + for EnsureAmbassadorsVoiceFrom { type Success = Rank; fn try_origin(o: O) -> Result { @@ -103,15 +103,15 @@ pub mod pallet_origins { fn try_successful_origin() -> Result { ranks::MASTER_AMBASSADOR_TIER_9 .ge(&R::get()) - .then(|| O::from(Origin::MasterAmbassadorTier9)) + .then(|| O::from(Origin::MasterAmbassadorsTier9)) .ok_or(()) } } /// Implementation of the [EnsureOrigin] trait for the plurality voice [Origin]s with the /// success result of the corresponding [Rank]. - pub struct EnsureAmbassadorVoice; - impl> + From> EnsureOrigin for EnsureAmbassadorVoice { + pub struct EnsureAmbassadorsVoice; + impl> + From> EnsureOrigin for EnsureAmbassadorsVoice { type Success = Rank; fn try_origin(o: O) -> Result { o.into().and_then(|o| Origin::as_voice(&o).ok_or(O::from(o))) @@ -119,7 +119,7 @@ pub mod pallet_origins { #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin() -> Result { - Ok(O::from(Origin::MasterAmbassadorTier9)) + Ok(O::from(Origin::MasterAmbassadorsTier9)) } } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs index 4c778b44932..e6338fbcb3b 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs @@ -264,15 +264,15 @@ impl pallet_referenda::TracksInfo for TracksInfo { } match Origin::try_from(id.clone()) { - Ok(Origin::AmbassadorTier1) => Ok(constants::AMBASSADOR_TIER_1), - Ok(Origin::AmbassadorTier2) => Ok(constants::AMBASSADOR_TIER_2), - Ok(Origin::SeniorAmbassadorTier3) => Ok(constants::SENIOR_AMBASSADOR_TIER_3), - Ok(Origin::SeniorAmbassadorTier4) => Ok(constants::SENIOR_AMBASSADOR_TIER_4), - Ok(Origin::HeadAmbassadorTier5) => Ok(constants::HEAD_AMBASSADOR_TIER_5), - Ok(Origin::HeadAmbassadorTier6) => Ok(constants::HEAD_AMBASSADOR_TIER_6), - Ok(Origin::HeadAmbassadorTier7) => Ok(constants::HEAD_AMBASSADOR_TIER_7), - Ok(Origin::MasterAmbassadorTier8) => Ok(constants::MASTER_AMBASSADOR_TIER_8), - Ok(Origin::MasterAmbassadorTier9) => Ok(constants::MASTER_AMBASSADOR_TIER_9), + Ok(Origin::Ambassadors) => Ok(constants::AMBASSADOR_TIER_1), + Ok(Origin::AmbassadorsTier2) => Ok(constants::AMBASSADOR_TIER_2), + Ok(Origin::SeniorAmbassadors) => Ok(constants::SENIOR_AMBASSADOR_TIER_3), + Ok(Origin::SeniorAmbassadorsTier4) => Ok(constants::SENIOR_AMBASSADOR_TIER_4), + Ok(Origin::HeadAmbassadors) => Ok(constants::HEAD_AMBASSADOR_TIER_5), + Ok(Origin::HeadAmbassadorsTier6) => Ok(constants::HEAD_AMBASSADOR_TIER_6), + Ok(Origin::HeadAmbassadorsTier7) => Ok(constants::HEAD_AMBASSADOR_TIER_7), + Ok(Origin::MasterAmbassadors) => Ok(constants::MASTER_AMBASSADOR_TIER_8), + Ok(Origin::MasterAmbassadorsTier9) => Ok(constants::MASTER_AMBASSADOR_TIER_9), _ => Err(()), } } From d5118b0c5e0010384132893da8117201f32ef37e Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 18 Aug 2023 12:44:28 +0200 Subject: [PATCH 35/44] benchmarks v2 --- .../collective-content/src/benchmarking.rs | 98 +++++++++++-------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index 2c74a1f9719..e898247f2c2 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -16,8 +16,8 @@ //! The pallet benchmarks. use super::{Pallet as CollectiveContent, *}; -use frame_benchmarking::v1::{benchmarks_instance_pallet, BenchmarkError}; -use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable}; +use frame_benchmarking::{impl_benchmark_test_suite, v2::*}; +use frame_support::traits::EnsureOrigin; fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) { frame_system::Pallet::::assert_last_event(generic_event.into()); @@ -29,60 +29,74 @@ fn create_cid(i: u8) -> OpaqueCid { cid } -benchmarks_instance_pallet! { - set_charter { +// + +// #[instance_benchmarks(where T: Config, I: 'static)] +#[instance_benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn set_charter() -> Result<(), BenchmarkError> { let cid: OpaqueCid = create_cid(1); - let call = Call::::set_charter { cid: cid.clone() }; - let origin = T::CharterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - }: { call.dispatch_bypass_filter(origin)? } - verify { + let origin = + T::CharterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + #[extrinsic_call] + _(origin as T::RuntimeOrigin, cid.clone()); + assert_eq!(CollectiveContent::::charter(), Some(cid.clone())); assert_last_event::(Event::NewCharterSet { cid }.into()); + Ok(()) } - announce { - let x in 0 .. 1; - + #[benchmark] + fn announce(x: Linear<0, 1>) -> Result<(), BenchmarkError> { let mut maybe_expire = None; if x == 1 { maybe_expire = Some(DispatchTime::<_>::At(10u32.into())); } let now = frame_system::Pallet::::block_number(); let cid: OpaqueCid = create_cid(1); - let call = Call::::announce { - cid: cid.clone(), - maybe_expire: maybe_expire.clone(), - }; - let origin = T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - }: { call.dispatch_bypass_filter(origin)? } - verify { + let origin = T::AnnouncementOrigin::try_successful_origin() + .map_err(|_| BenchmarkError::Weightless)?; + + #[extrinsic_call] + _(origin as T::RuntimeOrigin, cid.clone(), maybe_expire.clone()); + assert_eq!(CollectiveContent::::announcements_count(), 1); assert_eq!(NextAnnouncementExpireAt::::get().map_or(0, |_| 1), x); - assert_last_event::(Event::AnnouncementAnnounced { - cid, - maybe_expire_at: maybe_expire.map_or(None, |e| Some(e.evaluate(now))), - }.into()); + assert_last_event::( + Event::AnnouncementAnnounced { + cid, + maybe_expire_at: maybe_expire.map_or(None, |e| Some(e.evaluate(now))), + } + .into(), + ); + + Ok(()) } - remove_announcement { + #[benchmark] + fn remove_announcement() -> Result<(), BenchmarkError> { let cid: OpaqueCid = create_cid(1); - let origin = T::AnnouncementOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - CollectiveContent::::announce( - origin.clone(), - cid.clone(), - None, - ).expect("could not publish an announcement"); + let origin = T::AnnouncementOrigin::try_successful_origin() + .map_err(|_| BenchmarkError::Weightless)?; + CollectiveContent::::announce(origin.clone(), cid.clone(), None) + .expect("could not publish an announcement"); assert_eq!(CollectiveContent::::announcements_count(), 1); - let call = Call::::remove_announcement { cid: cid.clone() }; - }: { call.dispatch_bypass_filter(origin)? } - verify { + #[extrinsic_call] + _(origin as T::RuntimeOrigin, cid.clone()); + assert_eq!(CollectiveContent::::announcements_count(), 0); assert_last_event::(Event::AnnouncementRemoved { cid }.into()); + + Ok(()) } - cleanup_announcements { - let x in 0 .. 100; + #[benchmark] + fn cleanup_announcements(x: Linear<0, 100>) -> Result<(), BenchmarkError> { let origin = T::AnnouncementOrigin::try_successful_origin().unwrap(); let max_count = x; @@ -92,15 +106,21 @@ benchmarks_instance_pallet! { origin.clone(), cid, Some(DispatchTime::<_>::At(5u32.into())), - ).expect("could not publish an announcement"); + ) + .expect("could not publish an announcement"); } assert_eq!(CollectiveContent::::announcements_count(), max_count); frame_system::Pallet::::set_block_number(10u32.into()); - }: { - CollectiveContent::::cleanup_announcements(10u32.into()); - } verify { + + #[block] + { + CollectiveContent::::cleanup_announcements(10u32.into()); + } + assert_eq!(CollectiveContent::::announcements_count(), 0); - assert_eq!(frame_system::Pallet::::events().len() as u32, max_count) + assert_eq!(frame_system::Pallet::::events().len() as u32, max_count); + + Ok(()) } impl_benchmark_test_suite!(CollectiveContent, super::mock::new_bench_ext(), super::mock::Test); From 15ad2f584cbdeb4551da83258c62cb5d32223d5b Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 18 Aug 2023 13:30:11 +0200 Subject: [PATCH 36/44] defensive count inc/dec --- parachains/pallets/collective-content/src/benchmarking.rs | 3 --- parachains/pallets/collective-content/src/lib.rs | 8 ++++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index e898247f2c2..2011230d55c 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -29,9 +29,6 @@ fn create_cid(i: u8) -> OpaqueCid { cid } -// - -// #[instance_benchmarks(where T: Config, I: 'static)] #[instance_benchmarks] mod benchmarks { use super::*; diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 4cd76a7ebb4..aaf8d919a1c 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -57,6 +57,7 @@ pub mod pallet { use super::*; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; + use sp_runtime::{ArithmeticError::Overflow, Saturating}; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); @@ -166,7 +167,10 @@ pub mod pallet { ensure!(maybe_expire_at.map_or(true, |e| e > now), Error::::InvalidExpiration); >::insert(cid.clone(), maybe_expire_at); - >::mutate(|count| *count += 1); + >::try_mutate(|count| -> DispatchResult { + *count = count.checked_add(1).ok_or(Overflow)?; + Ok(()) + })?; if let Some(expire_at) = maybe_expire_at { if NextAnnouncementExpireAt::::get().map_or(true, |n| n > expire_at) { @@ -195,7 +199,7 @@ pub mod pallet { ); >::remove(cid.clone()); - >::mutate(|count| *count -= 1); + >::mutate(|count| count.saturating_dec()); Self::deposit_event(Event::::AnnouncementRemoved { cid }); Ok(()) From 9a562c57dad6c4f73805801e6c1b70cb48a79739 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 18 Aug 2023 15:52:59 +0200 Subject: [PATCH 37/44] default announcement lifetime, fee free expired announcement removal --- .../collective-content/src/benchmarking.rs | 2 +- .../pallets/collective-content/src/lib.rs | 92 ++++++++++--------- .../pallets/collective-content/src/mock.rs | 11 ++- .../pallets/collective-content/src/tests.rs | 87 ++++++++++++------ .../src/ambassador/mod.rs | 5 + 5 files changed, 122 insertions(+), 75 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index 2011230d55c..b1472b612c6 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -66,7 +66,7 @@ mod benchmarks { assert_last_event::( Event::AnnouncementAnnounced { cid, - maybe_expire_at: maybe_expire.map_or(None, |e| Some(e.evaluate(now))), + expire_at: maybe_expire.map_or(now, |e| e.evaluate(now)), } .into(), ); diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index aaf8d919a1c..0c731e91217 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -55,9 +55,9 @@ pub type OpaqueCid = BoundedVec>; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; + use frame_support::{ensure, pallet_prelude::*}; use frame_system::pallet_prelude::*; - use sp_runtime::{ArithmeticError::Overflow, Saturating}; + use sp_runtime::{traits::BadOrigin, ArithmeticError::Overflow, Saturating}; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); @@ -73,6 +73,9 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// Default lifetime for an announcement before it expires. + type AnnouncementLifetime: Get>; + /// The origin to control the collective announcements. type AnnouncementOrigin: EnsureOrigin; @@ -99,7 +102,7 @@ pub mod pallet { /// A new charter has been set. NewCharterSet { cid: OpaqueCid }, /// A new announcement has been made. - AnnouncementAnnounced { cid: OpaqueCid, maybe_expire_at: Option> }, + AnnouncementAnnounced { cid: OpaqueCid, expire_at: BlockNumberFor }, /// An on-chain announcement has been removed. AnnouncementRemoved { cid: OpaqueCid }, } @@ -113,7 +116,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn announcements)] pub type Announcements, I: 'static = ()> = - StorageMap<_, Blake2_128Concat, OpaqueCid, Option>, ValueQuery>; + StorageMap<_, Blake2_128Concat, OpaqueCid, BlockNumberFor, OptionQuery>; /// The current count of the announcements. #[pallet::storage] @@ -148,9 +151,10 @@ pub mod pallet { /// Publish an announcement. /// /// Parameters: - /// - `origin`: Must be the [Config::CharterOrigin]. + /// - `origin`: Must be the [Config::AnnouncementOrigin]. /// - `cid`: [CID](super::OpaqueCid) of the IPFS document to announce. - /// - `maybe_expire`: Expiration block of the announcement. + /// - `maybe_expire`: Expiration block of the announcement. If `None` [`Config::AnnouncementLifetime`] + /// used as a default. /// /// Weight: `O(1)`. #[pallet::call_index(1)] @@ -163,46 +167,57 @@ pub mod pallet { T::AnnouncementOrigin::ensure_origin(origin)?; let now = frame_system::Pallet::::block_number(); - let maybe_expire_at = maybe_expire.map(|e| e.evaluate(now)); - ensure!(maybe_expire_at.map_or(true, |e| e > now), Error::::InvalidExpiration); + let expire_at = maybe_expire + .map_or(now.saturating_add(T::AnnouncementLifetime::get()), |e| e.evaluate(now)); + ensure!(expire_at > now, Error::::InvalidExpiration); - >::insert(cid.clone(), maybe_expire_at); + >::insert(cid.clone(), expire_at); >::try_mutate(|count| -> DispatchResult { *count = count.checked_add(1).ok_or(Overflow)?; Ok(()) })?; - if let Some(expire_at) = maybe_expire_at { - if NextAnnouncementExpireAt::::get().map_or(true, |n| n > expire_at) { - NextAnnouncementExpireAt::::put(expire_at); - } + if NextAnnouncementExpireAt::::get().map_or(true, |n| n > expire_at) { + NextAnnouncementExpireAt::::put(expire_at); } - Self::deposit_event(Event::::AnnouncementAnnounced { cid, maybe_expire_at }); + Self::deposit_event(Event::::AnnouncementAnnounced { cid, expire_at }); Ok(()) } /// Remove an announcement. /// + /// Transaction fee refunded for expired announcements. + /// /// Parameters: - /// - `origin`: Must be the [Config::CharterOrigin]. + /// - `origin`: Must be the [Config::AnnouncementOrigin] or signed for expired announcements. /// - `cid`: [CID](super::OpaqueCid) of the IPFS document to remove. /// /// Weight: `O(1)`. #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::remove_announcement())] - pub fn remove_announcement(origin: OriginFor, cid: OpaqueCid) -> DispatchResult { - T::AnnouncementOrigin::ensure_origin(origin)?; - ensure!( - >::contains_key(cid.clone()), - Error::::MissingAnnouncement - ); + pub fn remove_announcement( + origin: OriginFor, + cid: OpaqueCid, + ) -> DispatchResultWithPostInfo { + let maybe_who = match T::AnnouncementOrigin::try_origin(origin) { + Ok(_) => None, + Err(origin) => Some(ensure_signed(origin)?), + }; + let expire_at = >::get(cid.clone()) + .ok_or(Error::::MissingAnnouncement)?; + let now = frame_system::Pallet::::block_number(); + ensure!(maybe_who.is_none() || now >= expire_at, BadOrigin); >::remove(cid.clone()); >::mutate(|count| count.saturating_dec()); Self::deposit_event(Event::::AnnouncementRemoved { cid }); - Ok(()) + + if now >= expire_at { + return Ok(Pays::No.into()) + } + Ok(Pays::Yes.into()) } } @@ -215,26 +230,19 @@ pub mod pallet { } let mut maybe_next: Option> = None; let mut count = 0; - >::translate(|cid, maybe_expire_at: Option>| { - match maybe_expire_at { - Some(expire_at) if now >= expire_at => { - Self::deposit_event(Event::::AnnouncementRemoved { cid }); - None - }, - Some(expire_at) => { - // determine `NextAnnouncementExpireAt`. - maybe_next = match maybe_next { - Some(next) if expire_at > next => Some(next), - _ => Some(expire_at), - }; - count += 1; - // return translated `maybe_expire_at`. - Some(maybe_expire_at) - }, - None => { - count += 1; - Some(maybe_expire_at) - }, + >::translate(|cid, expire_at: BlockNumberFor| { + if now >= expire_at { + Self::deposit_event(Event::::AnnouncementRemoved { cid }); + None + } else { + // determine `NextAnnouncementExpireAt`. + maybe_next = match maybe_next { + Some(next) if expire_at > next => Some(next), + _ => Some(expire_at), + }; + count += 1; + // return translated `maybe_expire_at`. + Some(expire_at) } }); >::set(maybe_next); diff --git a/parachains/pallets/collective-content/src/mock.rs b/parachains/pallets/collective-content/src/mock.rs index b7f90e01597..02706e82591 100644 --- a/parachains/pallets/collective-content/src/mock.rs +++ b/parachains/pallets/collective-content/src/mock.rs @@ -18,7 +18,7 @@ pub use crate as pallet_collective_content; use crate::WeightInfo; use frame_support::{ - ord_parameter_types, + ord_parameter_types, parameter_types, traits::{ConstU32, ConstU64}, weights::Weight, }; @@ -38,13 +38,18 @@ type Block = frame_system::mocking::MockBlock; ord_parameter_types! { pub const CharterManager: u64 = 1; pub const AnnouncementManager: u64 = 2; - pub const OtherAccount: u64 = 3; + pub const SomeAccount: u64 = 3; +} + +parameter_types! { + pub const AnnouncementLifetime: u64 = 100; } impl pallet_collective_content::Config for Test { type RuntimeEvent = RuntimeEvent; - type CharterOrigin = EnsureSignedBy; + type AnnouncementLifetime = AnnouncementLifetime; type AnnouncementOrigin = EnsureSignedBy; + type CharterOrigin = EnsureSignedBy; type WeightInfo = CCWeightInfo; } diff --git a/parachains/pallets/collective-content/src/tests.rs b/parachains/pallets/collective-content/src/tests.rs index 21f0960c6df..ed110fa8edf 100644 --- a/parachains/pallets/collective-content/src/tests.rs +++ b/parachains/pallets/collective-content/src/tests.rs @@ -16,7 +16,9 @@ //! Tests. use super::{mock::*, *}; -use frame_support::{assert_noop, assert_ok, error::BadOrigin, traits::Hooks, weights::Weight}; +use frame_support::{ + assert_noop, assert_ok, error::BadOrigin, pallet_prelude::Pays, traits::Hooks, weights::Weight, +}; /// returns CID hash of 68 bytes of given `i`. fn create_cid(i: u8) -> OpaqueCid { @@ -28,7 +30,7 @@ fn create_cid(i: u8) -> OpaqueCid { fn set_charter_works() { new_test_ext().execute_with(|| { // wrong origin. - let origin = RuntimeOrigin::signed(OtherAccount::get()); + let origin = RuntimeOrigin::signed(SomeAccount::get()); let cid = create_cid(1); assert_noop!(CollectiveContent::set_charter(origin, cid), BadOrigin); @@ -55,7 +57,7 @@ fn announce_works() { new_test_ext().execute_with(|| { let now = frame_system::Pallet::::block_number(); // wrong origin. - let origin = RuntimeOrigin::signed(OtherAccount::get()); + let origin = RuntimeOrigin::signed(SomeAccount::get()); let cid = create_cid(1); assert_noop!(CollectiveContent::announce(origin, cid, None), BadOrigin); @@ -67,11 +69,14 @@ fn announce_works() { let maybe_expire_at = None; assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); - assert_eq!(NextAnnouncementExpireAt::::get(), None); + assert_eq!( + NextAnnouncementExpireAt::::get(), + Some(now.saturating_add(AnnouncementLifetime::get())) + ); assert_eq!(AnnouncementsCount::::get(), 1); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, - maybe_expire_at: None, + expire_at: now.saturating_add(AnnouncementLifetime::get()), })); // one more. success. @@ -80,11 +85,14 @@ fn announce_works() { let maybe_expire_at = None; assert_ok!(CollectiveContent::announce(origin, cid.clone(), maybe_expire_at)); - assert_eq!(NextAnnouncementExpireAt::::get(), None); + assert_eq!( + NextAnnouncementExpireAt::::get(), + Some(now.saturating_add(AnnouncementLifetime::get())) + ); assert_eq!(AnnouncementsCount::::get(), 2); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, - maybe_expire_at: None, + expire_at: now.saturating_add(AnnouncementLifetime::get()), })); // one more with expire. success. @@ -97,7 +105,7 @@ fn announce_works() { assert_eq!(AnnouncementsCount::::get(), 3); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, - maybe_expire_at: Some(maybe_expire_at.evaluate(now)), + expire_at: maybe_expire_at.evaluate(now), })); // one more with later expire. success. @@ -114,7 +122,7 @@ fn announce_works() { assert_eq!(AnnouncementsCount::::get(), 4); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, - maybe_expire_at: Some(maybe_expire_at.evaluate(now)), + expire_at: maybe_expire_at.evaluate(now), })); // one more with earlier expire. success. @@ -127,7 +135,7 @@ fn announce_works() { assert_eq!(AnnouncementsCount::::get(), 5); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementAnnounced { cid, - maybe_expire_at: Some(maybe_expire_at.evaluate(now)), + expire_at: maybe_expire_at.evaluate(now), })); }); } @@ -137,10 +145,13 @@ fn remove_announcement_works() { new_test_ext().execute_with(|| { assert_eq!(AnnouncementsCount::::get(), 0); // wrong origin. - let origin = RuntimeOrigin::signed(OtherAccount::get()); + let origin = RuntimeOrigin::signed(CharterManager::get()); let cid = create_cid(8); - assert_noop!(CollectiveContent::remove_announcement(origin, cid), BadOrigin); + assert_noop!( + CollectiveContent::remove_announcement(origin, cid), + Error::::MissingAnnouncement + ); // missing announcement. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); @@ -151,42 +162,60 @@ fn remove_announcement_works() { Error::::MissingAnnouncement ); - // success. - // add announcement. + // wrong origin. announcement not yet expired. let origin = RuntimeOrigin::signed(AnnouncementManager::get()); let cid = create_cid(10); assert_ok!(CollectiveContent::announce(origin.clone(), cid.clone(), None)); - - // one more announcement. - let cid_2 = create_cid(11); - let expire_at_2 = DispatchTime::<_>::At(10); - assert_ok!(CollectiveContent::announce(origin.clone(), cid_2.clone(), Some(expire_at_2))); - // two announcements registered. assert!(>::contains_key(cid.clone())); - assert!(>::contains_key(cid_2.clone())); - assert_eq!(AnnouncementsCount::::get(), 2); + assert_eq!(AnnouncementsCount::::get(), 1); + + let origin = RuntimeOrigin::signed(SomeAccount::get()); + assert_noop!(CollectiveContent::remove_announcement(origin, cid.clone()), BadOrigin); + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + assert_ok!(CollectiveContent::remove_announcement(origin, cid)); + + // success. // remove first announcement and assert. - assert_ok!(CollectiveContent::remove_announcement(origin.clone(), cid.clone())); + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid = create_cid(11); + assert_ok!(CollectiveContent::announce(origin.clone(), cid.clone(), None)); + assert!(>::contains_key(cid.clone())); + assert_eq!(AnnouncementsCount::::get(), 1); + + let info = CollectiveContent::remove_announcement(origin.clone(), cid.clone()).unwrap(); + assert_eq!(info.pays_fee, Pays::Yes); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { cid: cid.clone(), })); assert_noop!( - CollectiveContent::remove_announcement(origin.clone(), cid.clone()), + CollectiveContent::remove_announcement(origin, cid.clone()), Error::::MissingAnnouncement ); assert!(!>::contains_key(cid)); - assert!(>::contains_key(cid_2.clone())); + assert_eq!(AnnouncementsCount::::get(), 0); + + // remove expired announcement and assert. + let origin = RuntimeOrigin::signed(AnnouncementManager::get()); + let cid = create_cid(12); + assert_ok!(CollectiveContent::announce( + origin.clone(), + cid.clone(), + Some(DispatchTime::<_>::At(10)) + )); + assert!(>::contains_key(cid.clone())); assert_eq!(AnnouncementsCount::::get(), 1); - // remove second announcement and assert. - assert_ok!(CollectiveContent::remove_announcement(origin.clone(), cid_2.clone())); + System::set_block_number(11); + let origin = RuntimeOrigin::signed(SomeAccount::get()); + let info = CollectiveContent::remove_announcement(origin.clone(), cid.clone()).unwrap(); + assert_eq!(info.pays_fee, Pays::No); System::assert_last_event(RuntimeEvent::CollectiveContent(Event::AnnouncementRemoved { - cid: cid_2.clone(), + cid: cid.clone(), })); assert_eq!(AnnouncementsCount::::get(), 0); assert_noop!( - CollectiveContent::remove_announcement(origin, cid_2), + CollectiveContent::remove_announcement(origin, cid), Error::::MissingAnnouncement ); }); diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index ca4bd4fba3a..d989be99fc4 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -144,11 +144,16 @@ impl pallet_referenda::Config for Runtime { type Preimages = Preimage; } +parameter_types! { + pub const AnnouncementLifetime: BlockNumber = 180 * DAYS; +} + pub type AmbassadorContentInstance = pallet_collective_content::Instance1; impl pallet_collective_content::Config for Runtime { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EitherOf, EnsureHeadAmbassadorsVoice>; + type AnnouncementLifetime = AnnouncementLifetime; // An announcement can be submitted by a Senior Ambassador member or an ambassador plurality voice // taken via referendum. type AnnouncementOrigin = EitherOfDiverse< From 08153e7948cc96fd4d5ef8dea1d167bd665d675b Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 18 Aug 2023 16:11:13 +0200 Subject: [PATCH 38/44] salary in dot --- .../collectives-polkadot/src/ambassador/mod.rs | 10 ++++------ .../collectives-polkadot/src/fellowship/mod.rs | 4 ++-- .../collectives/collectives-polkadot/src/xcm_config.rs | 6 +++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index d989be99fc4..50ba70ff2a0 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -32,7 +32,7 @@ pub mod origins; mod tracks; use super::*; -use crate::xcm_config::{FellowshipAdminBodyId, UsdtAsset}; +use crate::xcm_config::{DotAssetHub, FellowshipAdminBodyId}; use frame_support::traits::{EitherOf, MapSuccess, TryMapSuccess}; pub use origins::pallet_origins as pallet_ambassador_origins; use origins::pallet_origins::{ @@ -211,9 +211,7 @@ parameter_types! { pub Interior: InteriorMultiLocation = PalletInstance(74).into(); } -const USDT_UNITS: u128 = 1_000_000; - -/// [`PayOverXcm`] setup to pay the Ambassador salary on the AssetHub in USDT. +/// [`PayOverXcm`] setup to pay the Ambassador salary on the AssetHub in DOT. pub type AmbassadorSalaryPaymaster = PayOverXcm< Interior, crate::xcm_config::XcmRouter, @@ -221,7 +219,7 @@ pub type AmbassadorSalaryPaymaster = PayOverXcm< ConstU32<{ 6 * HOURS }>, AccountId, (), - ConvertToValue, + ConvertToValue, AliasesIntoAccountId32<(), AccountId>, >; @@ -249,5 +247,5 @@ impl pallet_salary::Config for Runtime { // 15 days to claim the salary payment. type PayoutPeriod = ConstU32<{ 15 * DAYS }>; // Total monthly salary budget. - type Budget = ConstU128<{ 100_000 * USDT_UNITS }>; + type Budget = ConstU128<{ 10_000 * DOLLARS }>; } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs index 7aa38b8b8ba..77eaa06ae73 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -23,7 +23,7 @@ use crate::{ constants, impls::ToParentTreasury, weights, - xcm_config::{FellowshipAdminBodyId, UsdtAsset}, + xcm_config::{FellowshipAdminBodyId, UsdtAssetHub}, AccountId, Balance, Balances, FellowshipReferenda, GovernanceLocation, PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, DAYS, }; @@ -209,7 +209,7 @@ pub type FellowshipSalaryPaymaster = PayOverXcm< ConstU32<{ 6 * HOURS }>, AccountId, (), - ConvertToValue, + ConvertToValue, AliasesIntoAccountId32<(), AccountId>, >; diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index c33fce1ae02..d06b77b14e3 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -50,10 +50,14 @@ parameter_types! { pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into(); pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); - pub UsdtAsset: LocatableAssetId = LocatableAssetId { + pub UsdtAssetHub: LocatableAssetId = LocatableAssetId { location: AssetHub::get(), asset_id: AssetHubUsdtId::get(), }; + pub DotAssetHub: LocatableAssetId = LocatableAssetId { + location: AssetHub::get(), + asset_id: DotLocation::get().into(), + }; } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used From 273e9afccaa71957bec9041b62aff896cb7b9804 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 18 Aug 2023 16:56:12 +0200 Subject: [PATCH 39/44] benchmark fix --- .../collective-content/src/benchmarking.rs | 16 +--- .../pallets/collective-content/src/lib.rs | 16 ++-- .../pallets/collective-content/src/mock.rs | 2 +- .../pallets/collective-content/src/weights.rs | 4 +- .../src/weights/pallet_collective_content.rs | 83 +++++++------------ 5 files changed, 47 insertions(+), 74 deletions(-) diff --git a/parachains/pallets/collective-content/src/benchmarking.rs b/parachains/pallets/collective-content/src/benchmarking.rs index b1472b612c6..72db22d7b1c 100644 --- a/parachains/pallets/collective-content/src/benchmarking.rs +++ b/parachains/pallets/collective-content/src/benchmarking.rs @@ -48,27 +48,19 @@ mod benchmarks { } #[benchmark] - fn announce(x: Linear<0, 1>) -> Result<(), BenchmarkError> { - let mut maybe_expire = None; - if x == 1 { - maybe_expire = Some(DispatchTime::<_>::At(10u32.into())); - } + fn announce() -> Result<(), BenchmarkError> { + let expire_at = DispatchTime::<_>::At(10u32.into()); let now = frame_system::Pallet::::block_number(); let cid: OpaqueCid = create_cid(1); let origin = T::AnnouncementOrigin::try_successful_origin() .map_err(|_| BenchmarkError::Weightless)?; #[extrinsic_call] - _(origin as T::RuntimeOrigin, cid.clone(), maybe_expire.clone()); + _(origin as T::RuntimeOrigin, cid.clone(), Some(expire_at.clone())); assert_eq!(CollectiveContent::::announcements_count(), 1); - assert_eq!(NextAnnouncementExpireAt::::get().map_or(0, |_| 1), x); assert_last_event::( - Event::AnnouncementAnnounced { - cid, - expire_at: maybe_expire.map_or(now, |e| e.evaluate(now)), - } - .into(), + Event::AnnouncementAnnounced { cid, expire_at: expire_at.evaluate(now) }.into(), ); Ok(()) diff --git a/parachains/pallets/collective-content/src/lib.rs b/parachains/pallets/collective-content/src/lib.rs index 0c731e91217..bbbeb62eda2 100644 --- a/parachains/pallets/collective-content/src/lib.rs +++ b/parachains/pallets/collective-content/src/lib.rs @@ -18,10 +18,10 @@ //! The pallet provides the functionality to store different types of content. This would typically //! be used by an on-chain collective, such as the Polkadot Alliance or Ambassador Program. //! -//! The pallet stores content as an [OpaqueCid], which should correspond to some off-chain hosting service, -//! such as IPFS, and contain any type of data. Each type of content has its own origin from which -//! it can be managed. The origins are configurable in the runtime. Storing content does not require -//! a deposit, as it is expected to be managed by a trusted collective. +//! The pallet stores content as an [OpaqueCid], which should correspond to some off-chain hosting +//! service, such as IPFS, and contain any type of data. Each type of content has its own origin +//! from which it can be managed. The origins are configurable in the runtime. Storing content does +//! not require a deposit, as it is expected to be managed by a trusted collective. //! //! Content types: //! @@ -153,12 +153,13 @@ pub mod pallet { /// Parameters: /// - `origin`: Must be the [Config::AnnouncementOrigin]. /// - `cid`: [CID](super::OpaqueCid) of the IPFS document to announce. - /// - `maybe_expire`: Expiration block of the announcement. If `None` [`Config::AnnouncementLifetime`] + /// - `maybe_expire`: Expiration block of the announcement. If `None` + /// [`Config::AnnouncementLifetime`] /// used as a default. /// /// Weight: `O(1)`. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::announce(maybe_expire.map_or(0, |_| 1)))] + #[pallet::weight(T::WeightInfo::announce())] pub fn announce( origin: OriginFor, cid: OpaqueCid, @@ -190,7 +191,8 @@ pub mod pallet { /// Transaction fee refunded for expired announcements. /// /// Parameters: - /// - `origin`: Must be the [Config::AnnouncementOrigin] or signed for expired announcements. + /// - `origin`: Must be the [Config::AnnouncementOrigin] or signed for expired + /// announcements. /// - `cid`: [CID](super::OpaqueCid) of the IPFS document to remove. /// /// Weight: `O(1)`. diff --git a/parachains/pallets/collective-content/src/mock.rs b/parachains/pallets/collective-content/src/mock.rs index 02706e82591..cd5df25ad67 100644 --- a/parachains/pallets/collective-content/src/mock.rs +++ b/parachains/pallets/collective-content/src/mock.rs @@ -83,7 +83,7 @@ impl WeightInfo for CCWeightInfo { fn set_charter() -> Weight { Weight::zero() } - fn announce(_x: u32) -> Weight { + fn announce() -> Weight { Weight::zero() } fn remove_announcement() -> Weight { diff --git a/parachains/pallets/collective-content/src/weights.rs b/parachains/pallets/collective-content/src/weights.rs index d004c8858e2..5715fe0924d 100644 --- a/parachains/pallets/collective-content/src/weights.rs +++ b/parachains/pallets/collective-content/src/weights.rs @@ -22,7 +22,7 @@ pub trait WeightInfo { /// Returns the weight of the set_charter extrinsic. fn set_charter() -> Weight; /// Returns the weight of the announce extrinsic. - fn announce(_x: u32) -> Weight; + fn announce() -> Weight; /// Returns the weight of the remove_announcement extrinsic. fn remove_announcement() -> Weight; /// Returns the weight of the action. @@ -34,7 +34,7 @@ impl WeightInfo for () { fn set_charter() -> Weight { Weight::zero() } - fn announce(_x: u32) -> Weight { + fn announce() -> Weight { Weight::zero() } fn remove_announcement() -> Weight { diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs index 97bebe932a1..9cbf529ca72 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs @@ -1,40 +1,24 @@ -// Copyright Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . //! Autogenerated weights for `pallet_collective_content` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-08-01, STEPS: `10`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-08-18, STEPS: `10`, REPEAT: `3`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `cob`, CPU: `` -//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 // Executed Command: -// target/debug/polkadot-parachain +// ./target/debug/polkadot-parachain // benchmark // pallet // --chain=collectives-polkadot-dev -// --wasm-execution=compiled +// --steps=10 +// --repeat=3 // --pallet=pallet_collective_content // --extrinsic=* -// --steps=10 -// --repeat=2 -// --json -// --header=./file_header.txt -// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_collective_content.rs +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -53,8 +37,8 @@ impl pallet_collective_content::WeightInfo for WeightIn // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 98_000_000 picoseconds. - Weight::from_parts(105_000_000, 0) + // Minimum execution time: 99_000_000 picoseconds. + Weight::from_parts(99_000_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -65,58 +49,53 @@ impl pallet_collective_content::WeightInfo for WeightIn /// Storage: `AmbassadorContent::NextAnnouncementExpireAt` (r:1 w:1) /// Proof: `AmbassadorContent::NextAnnouncementExpireAt` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `AmbassadorContent::Announcements` (r:0 w:1) - /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) - /// The range of component `x` is `[0, 1]`. - fn announce(x: u32, ) -> Weight { + /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + fn announce() -> Weight { // Proof Size summary in bytes: // Measured: `285` // Estimated: `3507` - // Minimum execution time: 241_000_000 picoseconds. - Weight::from_parts(252_900_000, 0) + // Minimum execution time: 273_000_000 picoseconds. + Weight::from_parts(278_000_000, 0) .saturating_add(Weight::from_parts(0, 3507)) - // Standard Error: 6_181_747 - .saturating_add(Weight::from_parts(45_100_000, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `AmbassadorCollective::Members` (r:1 w:0) /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `AmbassadorContent::Announcements` (r:1 w:1) - /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) + /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) /// Storage: `AmbassadorContent::AnnouncementsCount` (r:1 w:1) /// Proof: `AmbassadorContent::AnnouncementsCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn remove_announcement() -> Weight { // Proof Size summary in bytes: - // Measured: `421` - // Estimated: `3556` - // Minimum execution time: 303_000_000 picoseconds. - Weight::from_parts(309_000_000, 0) - .saturating_add(Weight::from_parts(0, 3556)) + // Measured: `450` + // Estimated: `3555` + // Minimum execution time: 326_000_000 picoseconds. + Weight::from_parts(338_000_000, 0) + .saturating_add(Weight::from_parts(0, 3555)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `AmbassadorContent::NextAnnouncementExpireAt` (r:1 w:1) /// Proof: `AmbassadorContent::NextAnnouncementExpireAt` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `AmbassadorContent::Announcements` (r:101 w:100) - /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) + /// Proof: `AmbassadorContent::Announcements` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) /// Storage: `AmbassadorContent::AnnouncementsCount` (r:0 w:1) /// Proof: `AmbassadorContent::AnnouncementsCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `x` is `[0, 100]`. fn cleanup_announcements(x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `167 + x * (97 ±0)` - // Estimated: `3556 + x * (2566 ±0)` - // Minimum execution time: 38_000_000 picoseconds. - Weight::from_parts(170_764_341, 0) - .saturating_add(Weight::from_parts(0, 3556)) - // Standard Error: 1_031_927 - .saturating_add(Weight::from_parts(139_960_396, 0).saturating_mul(x.into())) + // Measured: `167 + x * (96 ±0)` + // Estimated: `3555 + x * (2565 ±0)` + // Minimum execution time: 37_000_000 picoseconds. + Weight::from_parts(144_774_246, 0) + .saturating_add(Weight::from_parts(0, 3555)) + // Standard Error: 329_536 + .saturating_add(Weight::from_parts(138_770_008, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) - .saturating_add(Weight::from_parts(0, 2566).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 2565).saturating_mul(x.into())) } } From 9ae1f6896984e3c122f4c32fc9caf4321b75516a Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 18 Aug 2023 17:10:19 +0200 Subject: [PATCH 40/44] paymaster test --- .../src/tests/ambassador.rs | 66 +++++++++++++++++++ .../collectives-polkadot/src/tests/mod.rs | 1 + .../asset-hub-polkadot/src/xcm_config.rs | 4 ++ 3 files changed, 71 insertions(+) create mode 100644 parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs new file mode 100644 index 00000000000..b1ed8454104 --- /dev/null +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs @@ -0,0 +1,66 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Integration tests concerning the Fellowship. + +use crate::*; +use collectives_polkadot_runtime::ambassador::AmbassadorSalaryPaymaster; +use frame_support::traits::{fungible::Mutate, tokens::Pay}; +use sp_core::crypto::Ss58Codec; +use xcm_emulator::TestExt; + +#[test] +fn pay_salary() { + let pay_from: AccountId = + ::from_string("5DS1Gaf6R9eFAV8QyeZP9P89kTkJMurxv3y3J3TTMu8p8VCX") + .unwrap(); + let pay_to = Polkadot::account_id_of(ALICE); + let pay_amount = 90000000000; + + AssetHubPolkadot::execute_with(|| { + type AssetHubBalances = ::Balances; + + assert_ok!(>::mint_into(&pay_from, pay_amount * 2)); + }); + + Collectives::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_ok!(AmbassadorSalaryPaymaster::pay(&pay_to, (), pay_amount)); + assert_expected_events!( + Collectives, + vec![ + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + ] + ); + }); + + AssetHubPolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + AssetHubPolkadot, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Transfer { from, to, amount }) => { + from: from == &pay_from, + to: to == &pay_to, + amount: amount == &pay_amount, + }, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, + ] + ); + }); +} diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/mod.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/mod.rs index 1ede78b5979..f6d0484feb4 100644 --- a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/mod.rs +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/mod.rs @@ -14,4 +14,5 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +mod ambassador; mod fellowship; diff --git a/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs b/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs index e897fcc6ad4..1fbf2435050 100644 --- a/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs +++ b/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs @@ -186,6 +186,9 @@ match_types! { pub type FellowshipSalaryPallet: impl Contains = { MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(64)) } }; + pub type AmbassadorSalaryPallet: impl Contains = { + MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(74)) } + }; } /// A call filter for the XCM Transact instruction. This is a temporary measure until we properly @@ -370,6 +373,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, FellowsPlurality, FellowshipSalaryPallet, + AmbassadorSalaryPallet, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, From fd88108d5a2be9668e001206bdd53b87aa434979 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 18 Aug 2023 15:12:35 +0000 Subject: [PATCH 41/44] ".git/.scripts/commands/fmt/fmt.sh" --- .../src/ambassador/mod.rs | 7 +++-- .../src/ambassador/origins.rs | 30 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index 50ba70ff2a0..f8ef293e57f 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -125,7 +125,8 @@ impl pallet_referenda::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Scheduler = Scheduler; type Currency = Balances; - // A proposal can be submitted by a member of the Ambassador Program of [ranks::SENIOR_AMBASSADOR_TIER_3] rank or higher. + // A proposal can be submitted by a member of the Ambassador Program of + // [ranks::SENIOR_AMBASSADOR_TIER_3] rank or higher. type SubmitOrigin = pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, @@ -154,8 +155,8 @@ impl pallet_collective_content::Config for Runtime { type RuntimeEvent = RuntimeEvent; type CharterOrigin = EitherOf, EnsureHeadAmbassadorsVoice>; type AnnouncementLifetime = AnnouncementLifetime; - // An announcement can be submitted by a Senior Ambassador member or an ambassador plurality voice - // taken via referendum. + // An announcement can be submitted by a Senior Ambassador member or an ambassador plurality + // voice taken via referendum. type AnnouncementOrigin = EitherOfDiverse< pallet_ranked_collective::EnsureMember< Runtime, diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs index ad95b2e14cf..3ce8a6b9e5d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/origins.rs @@ -31,28 +31,38 @@ pub mod pallet_origins { #[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)] #[pallet::origin] pub enum Origin { - /// Plurality voice of the [ranks::AMBASSADOR_TIER_1] members or above given via referendum. + /// Plurality voice of the [ranks::AMBASSADOR_TIER_1] members or above given via + /// referendum. Ambassadors, - /// Plurality voice of the [ranks::AMBASSADOR_TIER_2] members or above given via referendum. + /// Plurality voice of the [ranks::AMBASSADOR_TIER_2] members or above given via + /// referendum. AmbassadorsTier2, - /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_3] members or above given via referendum. + /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_3] members or above given via + /// referendum. SeniorAmbassadors, - /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_4] members or above given via referendum. + /// Plurality voice of the [ranks::SENIOR_AMBASSADOR_TIER_4] members or above given via + /// referendum. SeniorAmbassadorsTier4, - /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_5] members or above given via referendum. + /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_5] members or above given via + /// referendum. HeadAmbassadors, - /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_6] members or above given via referendum. + /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_6] members or above given via + /// referendum. HeadAmbassadorsTier6, - /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_7] members or above given via referendum. + /// Plurality voice of the [ranks::HEAD_AMBASSADOR_TIER_7] members or above given via + /// referendum. HeadAmbassadorsTier7, - /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_8] members or above given via referendum. + /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_8] members or above given via + /// referendum. MasterAmbassadors, - /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_9] members or above given via referendum. + /// Plurality voice of the [ranks::MASTER_AMBASSADOR_TIER_9] members or above given via + /// referendum. MasterAmbassadorsTier9, } impl Origin { - /// Returns the rank that the origin `self` speaks for, or `None` if it doesn't speak for any. + /// Returns the rank that the origin `self` speaks for, or `None` if it doesn't speak for + /// any. pub fn as_voice(&self) -> Option { Some(match &self { Origin::Ambassadors => ranks::AMBASSADOR_TIER_1, From f9c1c064c33d66ebc3123974b4396cfaa2725135 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 22 Aug 2023 11:07:17 +0200 Subject: [PATCH 42/44] rename and tracks settings --- .../src/ambassador/mod.rs | 6 +- .../src/ambassador/tracks.rs | 56 +++++++++---------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs index f8ef293e57f..4447a7d0451 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -208,13 +208,13 @@ pub type AmbassadorSalaryInstance = pallet_salary::Instance2; parameter_types! { // The interior location on AssetHub for the paying account. This is the Ambassador Salary - // pallet instance (which sits at index 64). This sovereign account will need funding. - pub Interior: InteriorMultiLocation = PalletInstance(74).into(); + // pallet instance (which sits at index 74). This sovereign account will need funding. + pub AmbassadorSalaryLocation: InteriorMultiLocation = PalletInstance(74).into(); } /// [`PayOverXcm`] setup to pay the Ambassador salary on the AssetHub in DOT. pub type AmbassadorSalaryPaymaster = PayOverXcm< - Interior, + AmbassadorSalaryLocation, crate::xcm_config::XcmRouter, crate::PolkadotXcm, ConstU32<{ 6 * HOURS }>, diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs index e6338fbcb3b..3906377d18c 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs @@ -16,7 +16,7 @@ //! The Ambassador Program's referenda voting tracks. use super::Origin; -use crate::{constants::currency::DOLLARS, Balance, BlockNumber, RuntimeOrigin, DAYS, MINUTES}; +use crate::{constants::currency::DOLLARS, Balance, BlockNumber, RuntimeOrigin, DAYS, HOURS}; use sp_runtime::Perbill; /// Referendum `TrackId` type. @@ -55,10 +55,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "ambassador tier 1", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -77,10 +77,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "ambassador tier 2", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -99,10 +99,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "senior ambassador tier 3", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -121,10 +121,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "senior ambassador tier 4", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -143,10 +143,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "head ambassador tier 5", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -165,10 +165,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "head ambassador tier 6", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -187,10 +187,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "head ambassador tier 7", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -209,10 +209,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "master ambassador tier 8", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), @@ -231,10 +231,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "master ambassador tier 9", max_deciding: 10, decision_deposit: 5 * DOLLARS, - prepare_period: 30 * MINUTES, + prepare_period: 24 * HOURS, decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 5 * MINUTES, + confirm_period: 24 * HOURS, + min_enactment_period: 1 * HOURS, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), From 69036ba16c8d48ef0faa369cd846203657398d93 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 22 Aug 2023 17:34:25 +0200 Subject: [PATCH 43/44] ignore test --- .../collectives/collectives-polkadot/src/tests/ambassador.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs index b1ed8454104..00d7a87c350 100644 --- a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs @@ -22,7 +22,9 @@ use frame_support::traits::{fungible::Mutate, tokens::Pay}; use sp_core::crypto::Ss58Codec; use xcm_emulator::TestExt; +// TODO remove ignore https://github.com/paritytech/cumulus/issues/3027 #[test] +#[ignore] fn pay_salary() { let pay_from: AccountId = ::from_string("5DS1Gaf6R9eFAV8QyeZP9P89kTkJMurxv3y3J3TTMu8p8VCX") From 421d3cf24c7b99c8608dcac30e4c0022c9806158 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 22 Aug 2023 18:09:04 +0200 Subject: [PATCH 44/44] comment test --- .../src/tests/ambassador.rs | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs index 00d7a87c350..12ebd70ea5c 100644 --- a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/ambassador.rs @@ -22,47 +22,46 @@ use frame_support::traits::{fungible::Mutate, tokens::Pay}; use sp_core::crypto::Ss58Codec; use xcm_emulator::TestExt; -// TODO remove ignore https://github.com/paritytech/cumulus/issues/3027 #[test] -#[ignore] fn pay_salary() { - let pay_from: AccountId = - ::from_string("5DS1Gaf6R9eFAV8QyeZP9P89kTkJMurxv3y3J3TTMu8p8VCX") - .unwrap(); - let pay_to = Polkadot::account_id_of(ALICE); - let pay_amount = 90000000000; + // TODO remove comments - https://github.com/paritytech/cumulus/issues/3027 + // let pay_from: AccountId = + // ::from_string("5DS1Gaf6R9eFAV8QyeZP9P89kTkJMurxv3y3J3TTMu8p8VCX") + // .unwrap(); + // let pay_to = Polkadot::account_id_of(ALICE); + // let pay_amount = 90000000000; - AssetHubPolkadot::execute_with(|| { - type AssetHubBalances = ::Balances; + // AssetHubPolkadot::execute_with(|| { + // type AssetHubBalances = ::Balances; - assert_ok!(>::mint_into(&pay_from, pay_amount * 2)); - }); + // assert_ok!(>::mint_into(&pay_from, pay_amount * 2)); + // }); - Collectives::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; + // Collectives::execute_with(|| { + // type RuntimeEvent = ::RuntimeEvent; - assert_ok!(AmbassadorSalaryPaymaster::pay(&pay_to, (), pay_amount)); - assert_expected_events!( - Collectives, - vec![ - RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, - ] - ); - }); + // assert_ok!(AmbassadorSalaryPaymaster::pay(&pay_to, (), pay_amount)); + // assert_expected_events!( + // Collectives, + // vec![ + // RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + // ] + // ); + // }); - AssetHubPolkadot::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; + // AssetHubPolkadot::execute_with(|| { + // type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - AssetHubPolkadot, - vec![ - RuntimeEvent::Balances(pallet_balances::Event::Transfer { from, to, amount }) => { - from: from == &pay_from, - to: to == &pay_to, - amount: amount == &pay_amount, - }, - RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, - ] - ); - }); + // assert_expected_events!( + // AssetHubPolkadot, + // vec![ + // RuntimeEvent::Balances(pallet_balances::Event::Transfer { from, to, amount }) => { + // from: from == &pay_from, + // to: to == &pay_to, + // amount: amount == &pay_amount, + // }, + // RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, + // ] + // ); + // }); }