From 5e61a2d8a6ddeaf0258c664d11205494227a4273 Mon Sep 17 00:00:00 2001 From: Nikita Khateev Date: Thu, 25 Jul 2024 17:24:14 +0400 Subject: [PATCH] Fix for treasury config and benchmark (#240) * Fix treasury config * fix build * Updated benchmarks * fix generic fmt * fix clippy * fix comments --------- Co-authored-by: Amar Singh --- evm-template/runtime/src/configs/mod.rs | 36 +--- evm-template/runtime/src/types.rs | 29 ++- .../runtime/src/weights/pallet_treasury.rs | 65 +++--- generic-template/runtime/src/benchmark.rs | 66 ++++++ generic-template/runtime/src/configs/mod.rs | 64 +++--- generic-template/runtime/src/types.rs | 26 +++ generic-template/runtime/src/weights/mod.rs | 1 + .../runtime/src/weights/pallet_treasury.rs | 197 ++++++++++++++++++ 8 files changed, 388 insertions(+), 96 deletions(-) create mode 100644 generic-template/runtime/src/weights/pallet_treasury.rs diff --git a/evm-template/runtime/src/configs/mod.rs b/evm-template/runtime/src/configs/mod.rs index a23be05..f2e318f 100644 --- a/evm-template/runtime/src/configs/mod.rs +++ b/evm-template/runtime/src/configs/mod.rs @@ -28,10 +28,7 @@ use pallet_ethereum::PostLogContent; use pallet_evm::{EVMCurrencyAdapter, EnsureAccountId20, IdentityAddressMapping}; use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; -use polkadot_runtime_common::{ - impls::{LocatableAssetConverter, VersionedLocatableAsset, VersionedLocationConverter}, - BlockHashCount, SlowAdjustingFeeUpdate, -}; +use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use scale_info::TypeInfo; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{H160, U256}; @@ -42,11 +39,7 @@ use sp_runtime::{ use sp_std::marker::PhantomData; use sp_version::RuntimeVersion; // XCM Imports -use xcm::{ - latest::{prelude::BodyId, InteriorLocation, Junction::PalletInstance}, - VersionedLocation, -}; -use xcm_builder::PayOverXcm; +use xcm::latest::{prelude::BodyId, InteriorLocation, Junction::PalletInstance}; #[cfg(not(feature = "runtime-benchmarks"))] use xcm_builder::ProcessXcmMessage; use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; @@ -55,14 +48,15 @@ use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; use crate::benchmark::{OpenHrmpChannel, PayWithEnsure}; use crate::{ constants::{ - currency::{deposit, CENTS, EXISTENTIAL_DEPOSIT, MICROCENTS}, + currency::{deposit, CENTS, EXISTENTIAL_DEPOSIT, GRAND, MICROCENTS}, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MAX_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO, SLOT_DURATION, VERSION, WEIGHT_PER_GAS, }, opaque, types::{ - AccountId, Balance, Block, BlockNumber, CollatorSelectionUpdateOrigin, ConsensusHook, Hash, - Nonce, PriceForSiblingParachainDelivery, + AccountId, AssetKind, Balance, Beneficiary, Block, BlockNumber, + CollatorSelectionUpdateOrigin, ConsensusHook, Hash, Nonce, + PriceForSiblingParachainDelivery, TreasuryPaymaster, }, weights::{self, BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, Aura, Balances, BaseFee, CollatorSelection, EVMChainId, MessageQueue, OpenZeppelinPrecompiles, @@ -514,8 +508,8 @@ impl pallet_utility::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = 2000; // * CENTS - pub const ProposalBondMaximum: Balance = 1;// * GRAND; + pub const ProposalBondMinimum: Balance = 2 * GRAND; + pub const ProposalBondMaximum: Balance = GRAND; pub const SpendPeriod: BlockNumber = 6 * DAYS; pub const Burn: Permill = Permill::from_perthousand(2); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); @@ -533,20 +527,6 @@ parameter_types! { pub BenchmarkParaId: u8 = 0; } -type Beneficiary = VersionedLocation; -type AssetKind = VersionedLocatableAsset; - -pub type TreasuryPaymaster = PayOverXcm< - TreasuryInteriorLocation, - xcm_config::XcmRouter, - crate::PolkadotXcm, - ConstU32<{ 6 * HOURS }>, - Beneficiary, - AssetKind, - LocatableAssetConverter, - VersionedLocationConverter, ->; - impl pallet_treasury::Config for Runtime { type ApproveOrigin = EitherOfDiverse, Treasurer>; type AssetKind = AssetKind; diff --git a/evm-template/runtime/src/types.rs b/evm-template/runtime/src/types.rs index 9eb9bae..63ece02 100644 --- a/evm-template/runtime/src/types.rs +++ b/evm-template/runtime/src/types.rs @@ -2,15 +2,25 @@ use fp_account::EthereumSignature; use frame_support::traits::EitherOfDiverse; use frame_system::EnsureRoot; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; +use polkadot_runtime_common::impls::{ + LocatableAssetConverter, VersionedLocatableAsset, VersionedLocationConverter, +}; +use sp_core::ConstU32; use sp_runtime::{ generic, traits::{BlakeTwo256, IdentifyAccount, Verify}, MultiAddress, }; -use xcm_builder::ConvertedConcreteId; +use xcm::VersionedLocation; +use xcm_builder::{ConvertedConcreteId, PayOverXcm}; use xcm_executor::traits::JustTry; use xcm_primitives::AsAssetType; +use crate::{ + configs::{xcm_config, TreasuryInteriorLocation}, + constants::HOURS, + AssetManager, Assets, +}; pub use crate::{ configs::{ xcm_config::RelayLocation, AssetType, FeeAssetId, StakingAdminBodyId, @@ -21,7 +31,6 @@ pub use crate::{ }, AllPalletsWithSystem, Runtime, RuntimeCall, XcmpQueue, }; -use crate::{AssetManager, Assets}; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -118,3 +127,19 @@ pub type XcmFeesToAccount = xcm_primitives::XcmFeesToAccount< AccountId, TreasuryAccount, >; + +/// These aliases are describing the Beneficiary and AssetKind for the Treasury pallet +pub type Beneficiary = VersionedLocation; +pub type AssetKind = VersionedLocatableAsset; + +/// This is a type that describes how we should transfer bounties from treasury pallet +pub type TreasuryPaymaster = PayOverXcm< + TreasuryInteriorLocation, + xcm_config::XcmRouter, + crate::PolkadotXcm, + ConstU32<{ 6 * HOURS }>, + Beneficiary, + AssetKind, + LocatableAssetConverter, + VersionedLocationConverter, +>; diff --git a/evm-template/runtime/src/weights/pallet_treasury.rs b/evm-template/runtime/src/weights/pallet_treasury.rs index fbb7dd5..3cc3801 100644 --- a/evm-template/runtime/src/weights/pallet_treasury.rs +++ b/evm-template/runtime/src/weights/pallet_treasury.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_treasury` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-06-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `ip-172-31-15-118`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -42,8 +42,8 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `6` // Estimated: `1887` - // Minimum execution time: 13_831_000 picoseconds. - Weight::from_parts(14_113_000, 0) + // Minimum execution time: 13_456_000 picoseconds. + Weight::from_parts(13_880_000, 0) .saturating_add(Weight::from_parts(0, 1887)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(3)) @@ -56,8 +56,8 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `134` // Estimated: `1489` - // Minimum execution time: 32_187_000 picoseconds. - Weight::from_parts(32_905_000, 0) + // Minimum execution time: 32_043_000 picoseconds. + Weight::from_parts(32_512_000, 0) .saturating_add(Weight::from_parts(0, 1489)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) @@ -70,8 +70,8 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `430` // Estimated: `6172` - // Minimum execution time: 50_832_000 picoseconds. - Weight::from_parts(51_309_000, 0) + // Minimum execution time: 50_210_000 picoseconds. + Weight::from_parts(51_711_000, 0) .saturating_add(Weight::from_parts(0, 6172)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) @@ -85,11 +85,11 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `433 + p * (8 ±0)` // Estimated: `3549` - // Minimum execution time: 10_700_000 picoseconds. - Weight::from_parts(13_306_602, 0) + // Minimum execution time: 10_613_000 picoseconds. + Weight::from_parts(13_553_733, 0) .saturating_add(Weight::from_parts(0, 3549)) - // Standard Error: 1_333 - .saturating_add(Weight::from_parts(106_841, 0).saturating_mul(p.into())) + // Standard Error: 1_221 + .saturating_add(Weight::from_parts(95_485, 0).saturating_mul(p.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -99,35 +99,34 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `90` // Estimated: `1887` - // Minimum execution time: 6_999_000 picoseconds. - Weight::from_parts(7_248_000, 0) + // Minimum execution time: 6_900_000 picoseconds. + Weight::from_parts(7_133_000, 0) .saturating_add(Weight::from_parts(0, 1887)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `System::Account` (r:199 w:199) + /// Storage: `System::Account` (r:1 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) /// Storage: `Treasury::Deactivated` (r:1 w:1) /// Proof: `Treasury::Deactivated` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// Storage: `Treasury::Approvals` (r:1 w:1) /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) - /// Storage: `Treasury::Proposals` (r:99 w:99) + /// Storage: `Treasury::Proposals` (r:99 w:0) /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) /// The range of component `p` is `[0, 99]`. fn on_initialize_proposals(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `351 + p * (220 ±0)` - // Estimated: `3581 + p * (5182 ±0)` - // Minimum execution time: 25_230_000 picoseconds. - Weight::from_parts(37_320_091, 0) + // Measured: `215 + p * (96 ±0)` + // Estimated: `3581 + p * (2559 ±0)` + // Minimum execution time: 25_132_000 picoseconds. + Weight::from_parts(24_004_402, 0) .saturating_add(Weight::from_parts(0, 3581)) - // Standard Error: 14_026 - .saturating_add(Weight::from_parts(44_075_078, 0).saturating_mul(p.into())) + // Standard Error: 5_817 + .saturating_add(Weight::from_parts(3_490_607, 0).saturating_mul(p.into())) .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(p.into()))) - .saturating_add(T::DbWeight::get().writes(3)) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_parts(0, 5182).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(Weight::from_parts(0, 2559).saturating_mul(p.into())) } /// Storage: `Treasury::SpendCount` (r:1 w:1) /// Proof: `Treasury::SpendCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -137,8 +136,8 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `6` // Estimated: `1489` - // Minimum execution time: 16_410_000 picoseconds. - Weight::from_parts(16_859_000, 0) + // Minimum execution time: 16_286_000 picoseconds. + Weight::from_parts(16_758_000, 0) .saturating_add(Weight::from_parts(0, 1489)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) @@ -163,8 +162,8 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `491` // Estimated: `5318` - // Minimum execution time: 61_669_000 picoseconds. - Weight::from_parts(62_804_000, 0) + // Minimum execution time: 61_116_000 picoseconds. + Weight::from_parts(62_281_000, 0) .saturating_add(Weight::from_parts(0, 5318)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(5)) @@ -177,8 +176,8 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `170` // Estimated: `5318` - // Minimum execution time: 28_555_000 picoseconds. - Weight::from_parts(29_396_000, 0) + // Minimum execution time: 28_673_000 picoseconds. + Weight::from_parts(29_031_000, 0) .saturating_add(Weight::from_parts(0, 5318)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) @@ -189,8 +188,8 @@ impl pallet_treasury::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `142` // Estimated: `5318` - // Minimum execution time: 16_360_000 picoseconds. - Weight::from_parts(16_699_000, 0) + // Minimum execution time: 16_349_000 picoseconds. + Weight::from_parts(16_835_000, 0) .saturating_add(Weight::from_parts(0, 5318)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/generic-template/runtime/src/benchmark.rs b/generic-template/runtime/src/benchmark.rs index bc1197a..308dd46 100644 --- a/generic-template/runtime/src/benchmark.rs +++ b/generic-template/runtime/src/benchmark.rs @@ -20,3 +20,69 @@ frame_benchmarking::define_benchmarks!( [pallet_conviction_voting, ConvictionVoting] [pallet_whitelist, Whitelist] ); + +use cumulus_primitives_core::{ChannelStatus, GetChannelInfo}; +use frame_support::traits::{ + tokens::{Pay, PaymentStatus}, + Get, +}; +use sp_std::marker::PhantomData; + +use crate::ParachainSystem; + +/// Trait for setting up any prerequisites for successful execution of benchmarks. +pub trait EnsureSuccessful { + fn ensure_successful(); +} + +/// Implementation of the [`EnsureSuccessful`] trait which opens an HRMP channel between +/// the Collectives and a parachain with a given ID. +pub struct OpenHrmpChannel(PhantomData); +impl> EnsureSuccessful for OpenHrmpChannel { + fn ensure_successful() { + if let ChannelStatus::Closed = ParachainSystem::get_channel_status(I::get().into()) { + ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(I::get().into()) + } + } +} + +/// Type that wraps a type implementing the [`Pay`] trait to decorate its +/// [`Pay::ensure_successful`] function with a provided implementation of the +/// [`EnsureSuccessful`] trait. +pub struct PayWithEnsure(PhantomData<(O, E)>); +impl Pay for PayWithEnsure +where + O: Pay, + E: EnsureSuccessful, +{ + type AssetKind = O::AssetKind; + type Balance = O::Balance; + type Beneficiary = O::Beneficiary; + type Error = O::Error; + type Id = O::Id; + + fn pay( + who: &Self::Beneficiary, + asset_kind: Self::AssetKind, + amount: Self::Balance, + ) -> Result { + O::pay(who, asset_kind, amount) + } + + fn check_payment(id: Self::Id) -> PaymentStatus { + O::check_payment(id) + } + + fn ensure_successful( + who: &Self::Beneficiary, + asset_kind: Self::AssetKind, + amount: Self::Balance, + ) { + E::ensure_successful(); + O::ensure_successful(who, asset_kind, amount) + } + + fn ensure_concluded(id: Self::Id) { + O::ensure_concluded(id) + } +} diff --git a/generic-template/runtime/src/configs/mod.rs b/generic-template/runtime/src/configs/mod.rs index 2fb2c4e..b887cbc 100644 --- a/generic-template/runtime/src/configs/mod.rs +++ b/generic-template/runtime/src/configs/mod.rs @@ -25,10 +25,7 @@ pub use governance::origins::pallet_custom_origins; use governance::{origins::Treasurer, TreasurySpender}; use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; -use polkadot_runtime_common::{ - impls::{LocatableAssetConverter, VersionedLocatableAsset, VersionedLocationConverter}, - BlockHashCount, SlowAdjustingFeeUpdate, -}; +use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use scale_info::TypeInfo; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_runtime::{ @@ -36,31 +33,29 @@ use sp_runtime::{ Perbill, Permill, RuntimeDebug, }; use sp_version::RuntimeVersion; -use xcm::{ - latest::{ - prelude::{AssetId, BodyId}, - InteriorLocation, - Junction::PalletInstance, - }, - VersionedLocation, +use xcm::latest::{ + prelude::{AssetId, BodyId}, + InteriorLocation, + Junction::PalletInstance, }; -use xcm_builder::PayOverXcm; #[cfg(not(feature = "runtime-benchmarks"))] use xcm_builder::ProcessXcmMessage; use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; +#[cfg(feature = "runtime-benchmarks")] +use crate::benchmark::{OpenHrmpChannel, PayWithEnsure}; use crate::{ constants::{ - currency::{deposit, CENTS, EXISTENTIAL_DEPOSIT, MICROCENTS}, + currency::{deposit, CENTS, EXISTENTIAL_DEPOSIT, GRAND, MICROCENTS}, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MAX_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO, SLOT_DURATION, VERSION, }, types::{ - AccountId, Balance, Block, BlockNumber, CollatorSelectionUpdateOrigin, ConsensusHook, Hash, - Nonce, PriceForSiblingParachainDelivery, + AccountId, AssetKind, Balance, Beneficiary, Block, BlockNumber, + CollatorSelectionUpdateOrigin, ConsensusHook, Hash, Nonce, + PriceForSiblingParachainDelivery, TreasuryPaymaster, }, - weights, - weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, + weights::{self, BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, Aura, Balances, CollatorSelection, MessageQueue, OriginCaller, PalletInfo, ParachainSystem, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Session, SessionKeys, System, Treasury, WeightToFee, XcmpQueue, @@ -537,10 +532,16 @@ impl pallet_utility::Config for Runtime { type WeightInfo = weights::pallet_utility::WeightInfo; } +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub LocationParents: u8 = 1; + pub BenchmarkParaId: u8 = 0; +} + parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = 2000; // * CENTS - pub const ProposalBondMaximum: Balance = 1;// * GRAND; + pub const ProposalBondMinimum: Balance = 2 * GRAND; + pub const ProposalBondMaximum: Balance = GRAND; pub const SpendPeriod: BlockNumber = 6 * DAYS; pub const Burn: Permill = Permill::from_perthousand(2); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); @@ -554,11 +555,14 @@ parameter_types! { impl pallet_treasury::Config for Runtime { type ApproveOrigin = EitherOfDiverse, Treasurer>; - type AssetKind = VersionedLocatableAsset; + type AssetKind = AssetKind; type BalanceConverter = frame_support::traits::tokens::UnityAssetBalanceConversion; #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::TreasuryArguments; - type Beneficiary = VersionedLocation; + type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::TreasuryArguments< + LocationParents, + BenchmarkParaId, + >; + type Beneficiary = Beneficiary; type BeneficiaryLookup = IdentityLookup; type Burn = (); type BurnDestination = (); @@ -566,16 +570,10 @@ impl pallet_treasury::Config for Runtime { type MaxApprovals = MaxApprovals; type OnSlash = Treasury; type PalletId = TreasuryPalletId; - type Paymaster = PayOverXcm< - TreasuryInteriorLocation, - xcm_config::XcmRouter, - crate::PolkadotXcm, - ConstU32<{ 6 * HOURS }>, - Self::Beneficiary, - Self::AssetKind, - LocatableAssetConverter, - VersionedLocationConverter, - >; + #[cfg(feature = "runtime-benchmarks")] + type Paymaster = PayWithEnsure>; + #[cfg(not(feature = "runtime-benchmarks"))] + type Paymaster = TreasuryPaymaster; type PayoutPeriod = PayoutSpendPeriod; type ProposalBond = ProposalBond; type ProposalBondMaximum = ProposalBondMaximum; @@ -585,5 +583,5 @@ impl pallet_treasury::Config for Runtime { type SpendFunds = (); type SpendOrigin = TreasurySpender; type SpendPeriod = SpendPeriod; - type WeightInfo = pallet_treasury::weights::SubstrateWeight; + type WeightInfo = weights::pallet_treasury::WeightInfo; } diff --git a/generic-template/runtime/src/types.rs b/generic-template/runtime/src/types.rs index f14ede8..c3474e2 100644 --- a/generic-template/runtime/src/types.rs +++ b/generic-template/runtime/src/types.rs @@ -1,12 +1,22 @@ use frame_support::traits::EitherOfDiverse; use frame_system::EnsureRoot; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; +use polkadot_runtime_common::impls::{ + LocatableAssetConverter, VersionedLocatableAsset, VersionedLocationConverter, +}; +use sp_core::ConstU32; use sp_runtime::{ generic, traits::{BlakeTwo256, IdentifyAccount, Verify}, MultiAddress, MultiSignature, }; +use xcm::VersionedLocation; +use xcm_builder::PayOverXcm; +use crate::{ + configs::{xcm_config, TreasuryInteriorLocation}, + constants::HOURS, +}; pub use crate::{ configs::{ xcm_config::RelayLocation, FeeAssetId, StakingAdminBodyId, ToSiblingBaseDeliveryFee, @@ -95,3 +105,19 @@ pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< BLOCK_PROCESSING_VELOCITY, UNINCLUDED_SEGMENT_CAPACITY, >; + +/// These aliases are describing the Beneficiary and AssetKind for the Treasury pallet +pub type Beneficiary = VersionedLocation; +pub type AssetKind = VersionedLocatableAsset; + +/// This is a type that describes how we should transfer bounties from treasury pallet +pub type TreasuryPaymaster = PayOverXcm< + TreasuryInteriorLocation, + xcm_config::XcmRouter, + crate::PolkadotXcm, + ConstU32<{ 6 * HOURS }>, + Beneficiary, + AssetKind, + LocatableAssetConverter, + VersionedLocationConverter, +>; diff --git a/generic-template/runtime/src/weights/mod.rs b/generic-template/runtime/src/weights/mod.rs index 2f076c0..e5e6bd8 100644 --- a/generic-template/runtime/src/weights/mod.rs +++ b/generic-template/runtime/src/weights/mod.rs @@ -34,6 +34,7 @@ pub mod pallet_scheduler; pub mod pallet_session; pub mod pallet_sudo; pub mod pallet_timestamp; +pub mod pallet_treasury; pub mod pallet_utility; pub mod pallet_whitelist; pub mod pallet_xcm; diff --git a/generic-template/runtime/src/weights/pallet_treasury.rs b/generic-template/runtime/src/weights/pallet_treasury.rs new file mode 100644 index 0000000..62bd6ea --- /dev/null +++ b/generic-template/runtime/src/weights/pallet_treasury.rs @@ -0,0 +1,197 @@ + +//! Autogenerated weights for `pallet_treasury` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-07-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-172-31-15-118`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 + +// Executed Command: +// target/release/parachain-template-node +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=benchmarking/results/results-pallet_treasury.json +// --pallet=pallet_treasury +// --chain=dev +// --output=benchmarking/new-benchmarks/pallet_treasury.rs + +#![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_treasury`. +pub struct WeightInfo(PhantomData); +impl pallet_treasury::WeightInfo for WeightInfo { + /// Storage: `Treasury::ProposalCount` (r:1 w:1) + /// Proof: `Treasury::ProposalCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Proposals` (r:0 w:1) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + fn spend_local() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `1887` + // Minimum execution time: 13_617_000 picoseconds. + Weight::from_parts(14_006_000, 0) + .saturating_add(Weight::from_parts(0, 1887)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `Treasury::ProposalCount` (r:1 w:1) + /// Proof: `Treasury::ProposalCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Proposals` (r:0 w:1) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + fn propose_spend() -> Weight { + // Proof Size summary in bytes: + // Measured: `107` + // Estimated: `1489` + // Minimum execution time: 30_109_000 picoseconds. + Weight::from_parts(30_762_000, 0) + .saturating_add(Weight::from_parts(0, 1489)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `Treasury::Proposals` (r:1 w:1) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn reject_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `368` + // Estimated: `6196` + // Minimum execution time: 46_753_000 picoseconds. + Weight::from_parts(47_536_000, 0) + .saturating_add(Weight::from_parts(0, 6196)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `Treasury::Proposals` (r:1 w:0) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + /// The range of component `p` is `[0, 99]`. + fn approve_proposal(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `433 + p * (8 ±0)` + // Estimated: `3573` + // Minimum execution time: 9_469_000 picoseconds. + Weight::from_parts(13_272_306, 0) + .saturating_add(Weight::from_parts(0, 3573)) + // Standard Error: 1_480 + .saturating_add(Weight::from_parts(104_034, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + fn remove_approval() -> Weight { + // Proof Size summary in bytes: + // Measured: `90` + // Estimated: `1887` + // Minimum execution time: 7_149_000 picoseconds. + Weight::from_parts(7_250_000, 0) + .saturating_add(Weight::from_parts(0, 1887)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `System::Account` (r:9 w:9) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Deactivated` (r:1 w:1) + /// Proof: `Treasury::Deactivated` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Proposals` (r:99 w:4) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// The range of component `p` is `[0, 99]`. + fn on_initialize_proposals(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `666 + p * (133 ±0)` + // Estimated: `22019 + p * (2583 ±4)` + // Minimum execution time: 25_010_000 picoseconds. + Weight::from_parts(178_002_629, 0) + .saturating_add(Weight::from_parts(0, 22019)) + // Standard Error: 39_227 + .saturating_add(Weight::from_parts(4_022_516, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(T::DbWeight::get().writes(14)) + .saturating_add(Weight::from_parts(0, 2583).saturating_mul(p.into())) + } + /// Storage: `Treasury::SpendCount` (r:1 w:1) + /// Proof: `Treasury::SpendCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Spends` (r:0 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(1853), added: 4328, mode: `MaxEncodedLen`) + fn spend() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `1489` + // Minimum execution time: 16_508_000 picoseconds. + Weight::from_parts(16_698_000, 0) + .saturating_add(Weight::from_parts(0, 1489)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `Treasury::Spends` (r:1 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(1853), added: 4328, 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: `XcmpQueue::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `XcmpQueue::DeliveryFeeFactor` (`max_values`: None, `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: `457` + // Estimated: `5318` + // Minimum execution time: 60_626_000 picoseconds. + Weight::from_parts(62_416_000, 0) + .saturating_add(Weight::from_parts(0, 5318)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: `Treasury::Spends` (r:1 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(1853), added: 4328, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::Queries` (r:1 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn check_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `170` + // Estimated: `5318` + // Minimum execution time: 28_319_000 picoseconds. + Weight::from_parts(28_882_000, 0) + .saturating_add(Weight::from_parts(0, 5318)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `Treasury::Spends` (r:1 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(1853), added: 4328, mode: `MaxEncodedLen`) + fn void_spend() -> Weight { + // Proof Size summary in bytes: + // Measured: `142` + // Estimated: `5318` + // Minimum execution time: 16_333_000 picoseconds. + Weight::from_parts(16_801_000, 0) + .saturating_add(Weight::from_parts(0, 5318)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } +}