diff --git a/Cargo.lock b/Cargo.lock index ad0bec08..959b515f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6998,14 +6998,18 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "pallet-balances", "pallet-xcm", "parity-scale-codec", + "polkadot-parachain", + "polkadot-runtime-parachains", "scale-info", "sp-core", "sp-io", "sp-runtime", "sp-std", "xcm", + "xcm-builder", "xcm-executor", ] diff --git a/pallets/withdraw-teleport/Cargo.toml b/pallets/withdraw-teleport/Cargo.toml index e2152a9d..0edbdfb6 100644 --- a/pallets/withdraw-teleport/Cargo.toml +++ b/pallets/withdraw-teleport/Cargo.toml @@ -29,11 +29,16 @@ sp-io = { workspace = true } sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } +pallet-balances = { workspace = true } +xcm-builder = { workspace = true } +polkadot-parachain = { workspace = true } +polkadot-runtime-parachains = { workspace = true } [features] default = ["std"] std = [ "parity-scale-codec/std", + "frame-benchmarking/std", "frame-support/std", "frame-system/std", "scale-info/std", diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs new file mode 100644 index 00000000..f84c44fc --- /dev/null +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -0,0 +1,48 @@ +//! Benchmarking setup for pallet-template +#![cfg(feature = "runtime-benchmarks")] +use super::*; + +#[allow(unused)] +use crate::Pallet as WithdrawTeleport; +use frame_benchmarking::{impl_benchmark_test_suite, v2::*}; +use frame_support::traits::Currency; +use frame_system::RawOrigin; +use sp_std::prelude::*; + +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn withdraw_and_teleport() -> Result<(), BenchmarkError> { + let fee_amount = 1_000; + let asset: MultiAsset = (MultiLocation::new(0, Here), fee_amount.clone()).into(); + let recipient = [0u8; 32]; + let versioned_dest: VersionedMultiLocation = T::ReachableDest::get() + .ok_or(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))? + .into(); + let versioned_beneficiary: VersionedMultiLocation = + AccountId32 { network: None, id: recipient.into() }.into(); + let versioned_assets: VersionedMultiAssets = asset.into(); + let amount: u32 = 1_000; + let caller = whitelisted_caller(); + T::Currency::make_free_balance_be(&caller, 100_000_000u32.into()); + let initial_balance = T::Currency::free_balance(&caller); + + #[extrinsic_call] + withdraw_and_teleport( + RawOrigin::Signed(caller.clone()), + Box::new(versioned_dest), + Box::new(versioned_beneficiary), + amount.into(), + Box::new(versioned_assets), + ); + + let remaining_balance = initial_balance - amount.into() - (fee_amount as u32).into(); + // Send or execution error would derive on balances amounts not being deducted from caller. + assert_eq!(T::Currency::free_balance(&caller), remaining_balance); + Ok(()) + } + + impl_benchmark_test_suite!(WithdrawTeleport, crate::mock::new_test_ext(), crate::mock::Test); +} diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 09b75205..d2c0a77c 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -24,11 +24,12 @@ type BaseXcm = pallet_xcm::Pallet; use frame_support::{ dispatch::DispatchResult, - ensure, + ensure, log, traits::{Contains, EnsureOrigin, Get}, }; use frame_system::pallet_prelude::OriginFor; pub use pallet::*; +use pallet_xcm::WeightInfo as XcmWeightInfo; use parity_scale_codec::Encode; use sp_std::{boxed::Box, vec}; pub use xcm::{ @@ -37,16 +38,16 @@ pub use xcm::{ }; use xcm_executor::traits::WeightBounds; -// #[cfg(test)] -// mod mock; +#[cfg(test)] +mod mock; // #[cfg(test)] // mod tests; -// #[cfg(feature = "runtime-benchmarks")] -// mod benchmarking; -// pub mod weights; -// pub use weights::*; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +pub mod weights; +pub use weights::*; #[frame_support::pallet] pub mod pallet { @@ -58,6 +59,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_xcm::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type WeightInfo: WeightInfo; } #[pallet::error] @@ -65,7 +67,7 @@ pub mod pallet { /// An error ocured during send SendError, /// Failed to execute - FailedToExecute, + FailedToExecuteXcm, } #[pallet::event] @@ -101,7 +103,29 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(::teleport_assets())] + #[pallet::weight({ + let native_asset = MultiAsset { + id: AssetId::Concrete(MultiLocation::here()), + fun: Fungibility::Fungible(*native_asset_amount), + }; + let native_assets = MultiAssets::from(vec![native_asset.clone()]); + let maybe_assets: Result = (*fee_asset.clone()).try_into(); + let send_weight = ::WeightInfo::send(); + match maybe_assets { + Ok(assets) => { + use sp_std::vec; + let mut message = Xcm(vec![ + WithdrawAsset(native_assets.clone()), + SetFeesMode { jit_withdraw: true }, + BurnAsset(native_assets), + WithdrawAsset(assets.clone()), + BurnAsset(assets), + ]); + T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| ::WeightInfo::withdraw_and_teleport().saturating_add(w).saturating_add(send_weight)) + } + _ => Weight::MAX, + } + })] pub fn withdraw_and_teleport( origin: OriginFor, dest: Box, @@ -138,6 +162,10 @@ impl Pallet { let fee_asset: MultiAssets = (*fee_asset).try_into().map_err(|()| pallet_xcm::Error::::BadVersion)?; + // Limit the number of fee assets to 1. + ensure!(fee_asset.len() > 0, pallet_xcm::Error::::Empty); + ensure!(fee_asset.len() < 2, pallet_xcm::Error::::TooManyAssets); + //Create assets // Native from local perspective @@ -215,7 +243,10 @@ impl Pallet { let hash = message.using_encoded(sp_io::hashing::blake2_256); let outcome = T::XcmExecutor::execute_xcm_in_credit(origin_location, message, hash, weight, weight); - outcome.clone().ensure_complete().map_err(|_| Error::::FailedToExecute)?; + outcome.clone().ensure_complete().map_err(|e| { + log::debug!("{e:?}"); + Error::::FailedToExecuteXcm + })?; Self::deposit_event(Event::Attempted { outcome }); // Use pallet-xcm send for sending message. diff --git a/pallets/withdraw-teleport/src/mock.rs b/pallets/withdraw-teleport/src/mock.rs new file mode 100644 index 00000000..98378eef --- /dev/null +++ b/pallets/withdraw-teleport/src/mock.rs @@ -0,0 +1,268 @@ +use crate as pallet_withdraw_teleport; +use frame_benchmarking::account; +use frame_support::{ + construct_runtime, parameter_types, + traits::{ConstU128, ConstU16, ConstU32, ConstU64, Everything, Nothing}, + weights::Weight, +}; +use frame_system::EnsureRoot; +use pallet_xcm::*; +use parity_scale_codec::Encode; +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_runtime_parachains::origin; +use sp_core::H256; +use sp_runtime::{traits::IdentityLookup, AccountId32, BuildStorage}; +pub use sp_std::{cell::RefCell, fmt::Debug, marker::PhantomData}; +use xcm::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, Case, ChildParachainAsNative, ChildParachainConvertsVia, + ChildSystemParachainAsSuperuser, CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, + FixedWeightBounds, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, +}; +use xcm_executor::XcmExecutor; + +pub type AccountId = AccountId32; +pub type Balance = u128; +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Test + { + System: frame_system::{Pallet, Call, Storage, Config, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + ParasOrigin: origin::{Pallet, Origin}, + XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config}, + //TestNotifier: pallet_test_notifier::{Pallet, Call, Event}, + WithdrawTeleport: pallet_withdraw_teleport::{Pallet, Call, Event}, + } +); + +thread_local! { + pub static SENT_XCM: RefCell)>> = RefCell::new(Vec::new()); +} + +#[allow(dead_code)] +pub(crate) fn sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> { + SENT_XCM.with(|q| (*q.borrow()).clone()) +} +#[allow(dead_code)] +pub(crate) fn take_sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> { + SENT_XCM.with(|q| { + let mut r = Vec::new(); + std::mem::swap(&mut r, &mut *q.borrow_mut()); + r + }) +} + +/// Sender that never returns error, always sends +pub struct TestSendXcm; +impl SendXcm for TestSendXcm { + type Ticket = (MultiLocation, Xcm<()>); + fn validate( + dest: &mut Option, + msg: &mut Option>, + ) -> SendResult<(MultiLocation, Xcm<()>)> { + let pair = (dest.take().unwrap(), msg.take().unwrap()); + Ok((pair, MultiAssets::new())) + } + fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result { + let hash = fake_message_hash(&pair.1); + SENT_XCM.with(|q| q.borrow_mut().push(pair)); + Ok(hash) + } +} +/// Sender that returns error if `X8` junction and stops routing +pub struct TestSendXcmErrX8; +impl SendXcm for TestSendXcmErrX8 { + type Ticket = (MultiLocation, Xcm<()>); + fn validate( + dest: &mut Option, + msg: &mut Option>, + ) -> SendResult<(MultiLocation, Xcm<()>)> { + let (dest, msg) = (dest.take().unwrap(), msg.take().unwrap()); + if dest.len() == 8 { + Err(SendError::Transport("Destination location full")) + } else { + Ok(((dest, msg), MultiAssets::new())) + } + } + fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result { + let hash = fake_message_hash(&pair.1); + SENT_XCM.with(|q| q.borrow_mut().push(pair)); + Ok(hash) + } +} + +impl frame_system::Config for Test { + type RuntimeEvent = RuntimeEvent; + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = (); + type BlockLength = (); + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type BlockHashCount = ConstU64<250>; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = ConstU16<42>; + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl pallet_balances::Config for Test { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); + type Balance = Balance; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<1>; + type AccountStore = System; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxLocks = (); + type MaxReserves = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; +} + +parameter_types! { + pub const RelayLocation: MultiLocation = Here.into_location(); + pub const AnyNetwork: Option = None; + pub UniversalLocation: InteriorMultiLocation = Here; + pub UnitWeightCost: u64 = 1_000; +} + +pub type SovereignAccountOf = + (ChildParachainConvertsVia, AccountId32Aliases); + +pub type LocalAssetTransactor = + XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(1_000, 1_000); + pub CurrencyPerSecondPerByte: (AssetId, u128, u128) = (Concrete(RelayLocation::get()), 1, 1); + pub TrustedAssets: (MultiAssetFilter, MultiLocation) = (All.into(), Here.into()); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub type Barrier = ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + AllowKnownQueryResponses, + AllowSubscriptionsFrom, +); + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = TestSendXcm; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = Case; + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetLocker = (); + type AssetExchanger = (); + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +parameter_types! { + pub static AdvertisedXcmVersion: XcmVersion = 3; +} + +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parachain(1000).into()); +} + +impl pallet_xcm::Config for Test { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = (TestSendXcmErrX8, TestSendXcm); + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmExecuteFilter = Everything; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = AdvertisedXcmVersion; + type TrustedLockers = (); + type SovereignAccountOf = AccountId32Aliases<(), AccountId32>; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type MaxLockers = frame_support::traits::ConstU32<8>; + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type WeightInfo = TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; +} + +impl pallet_withdraw_teleport::Config for Test { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_withdraw_teleport::weights::SubstrateWeight; +} + +impl origin::Config for Test {} + +// Build genesis storage according to the mock runtime. +pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![(account("Alice", 1, 1), 100_000_000)], + } + .assimilate_storage(&mut t) + .unwrap(); + pallet_xcm::GenesisConfig:: { safe_xcm_version: Some(3), ..Default::default() } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} + +pub(crate) fn fake_message_hash(message: &Xcm) -> XcmHash { + message.using_encoded(sp_io::hashing::blake2_256) +} diff --git a/pallets/withdraw-teleport/src/weights.rs b/pallets/withdraw-teleport/src/weights.rs new file mode 100644 index 00000000..a70adb36 --- /dev/null +++ b/pallets/withdraw-teleport/src/weights.rs @@ -0,0 +1,85 @@ + +//! Autogenerated weights for pallet_withdraw_teleport +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-09-28, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Emilianos-MacBook-Pro.local`, CPU: `` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/trappist-node +// benchmark +// pallet +// --chain=dev +// --steps=20 +// --repeat=10 +// --pallet=pallet_withdraw_teleport +// --extrinsic=* +// --wasm-execution=compiled +// --template=./templates/frame-weight-template.hbs +// --output=./pallets/withdraw-teleport/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for pallet_withdraw_teleport. +pub trait WeightInfo { + fn withdraw_and_teleport() -> Weight; +} + +/// Weights for pallet_withdraw_teleport using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// 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`) + fn withdraw_and_teleport() -> Weight { + // Proof Size summary in bytes: + // Measured: `177` + // Estimated: `3642` + // Minimum execution time: 87_000_000 picoseconds. + Weight::from_parts(88_000_000, 3642) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + /// 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`) + fn withdraw_and_teleport() -> Weight { + // Proof Size summary in bytes: + // Measured: `177` + // Estimated: `3642` + // Minimum execution time: 87_000_000 picoseconds. + Weight::from_parts(88_000_000, 3642) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } +} diff --git a/runtime/stout/src/xcm_config.rs b/runtime/stout/src/xcm_config.rs index 856200a9..b8e6b2bd 100644 --- a/runtime/stout/src/xcm_config.rs +++ b/runtime/stout/src/xcm_config.rs @@ -46,8 +46,7 @@ use xcm_builder::{ EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::XcmExecutor; @@ -198,30 +197,19 @@ match_types! { }; } -pub type Barrier = TrailingSetTopicAsId< - DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - // Expected responses are OK. - AllowKnownQueryResponses, - // Allow XCMs with some computed origins to pass through. - WithComputedOrigin< - ( - // If the message is one that immediately attemps to pay for execution, then - // allow it. - AllowTopLevelPaidExecutionFrom, - // Parent, its pluralities (i.e. governance bodies), and the Fellows plurality - // get free execution. - AllowUnpaidExecutionFrom, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, - ), - UniversalLocation, - ConstU32<8>, - >, - ), - >, +pub type Barrier = DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + // Parent and its exec plurality get free execution + AllowUnpaidExecutionFrom, + AllowUnpaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), >; parameter_types! { @@ -236,7 +224,7 @@ parameter_types! { 0u128 ); /// Roc = 7 RUSD - pub RocPerSecond: (xcm::v3::AssetId, u128,u128) = (MultiLocation::new(1,Here).into(), default_fee_per_second() * 70, 0u128); + pub RocPerSecond: (xcm::v3::AssetId, u128,u128) = (MultiLocation::parent().into(), default_fee_per_second() * 70, 0u128); pub HopPerSecond: (xcm::v3::AssetId, u128, u128) = (MultiLocation::new(1, X1(Parachain(1836))).into(), default_fee_per_second() * 10, 0u128); } diff --git a/runtime/trappist/Cargo.toml b/runtime/trappist/Cargo.toml index fd2d122c..14af75ca 100644 --- a/runtime/trappist/Cargo.toml +++ b/runtime/trappist/Cargo.toml @@ -207,6 +207,7 @@ runtime-benchmarks = [ "pallet-treasury/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", "pallet-utility/runtime-benchmarks", + "pallet-withdraw-teleport/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", diff --git a/runtime/trappist/src/lib.rs b/runtime/trappist/src/lib.rs index d47fb673..ddbb1d67 100644 --- a/runtime/trappist/src/lib.rs +++ b/runtime/trappist/src/lib.rs @@ -651,6 +651,7 @@ impl pallet_treasury::Config for Runtime { impl pallet_withdraw_teleport::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_withdraw_teleport::WeightInfo; } impl pallet_lockdown_mode::Config for Runtime { @@ -774,6 +775,7 @@ mod benches { [pallet_scheduler, Scheduler] [pallet_utility, Utility] [cumulus_pallet_xcmp_queue, XcmpQueue] + [pallet_withdraw_teleport, WithdrawTeleport] // XCM // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] diff --git a/runtime/trappist/src/weights/mod.rs b/runtime/trappist/src/weights/mod.rs index cfd98f67..e1b153a5 100644 --- a/runtime/trappist/src/weights/mod.rs +++ b/runtime/trappist/src/weights/mod.rs @@ -43,6 +43,7 @@ pub mod pallet_timestamp; pub mod pallet_treasury; pub mod pallet_uniques; pub mod pallet_utility; +pub mod pallet_withdraw_teleport; pub mod trappist_runtime_benchmarks; pub mod xcm; diff --git a/runtime/trappist/src/weights/pallet_withdraw_teleport.rs b/runtime/trappist/src/weights/pallet_withdraw_teleport.rs new file mode 100644 index 00000000..a9943728 --- /dev/null +++ b/runtime/trappist/src/weights/pallet_withdraw_teleport.rs @@ -0,0 +1,55 @@ + +//! Autogenerated weights for `pallet_withdraw_teleport` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-09-28, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Emilianos-MacBook-Pro.local`, CPU: `` +//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 + +// Executed Command: +// ./target/release/trappist-node +// benchmark +// pallet +// --chain=dev +// --steps=20 +// --repeat=10 +// --pallet=pallet_withdraw_teleport +// --extrinsic=* +// --wasm-execution=compiled +// --output=./runtime/trappist/src/weights/pallet_withdraw_teleport.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_withdraw_teleport`. +pub struct WeightInfo(PhantomData); +impl pallet_withdraw_teleport::WeightInfo for WeightInfo { + /// 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`) + fn withdraw_and_teleport() -> Weight { + // Proof Size summary in bytes: + // Measured: `177` + // Estimated: `3642` + // Minimum execution time: 85_000_000 picoseconds. + Weight::from_parts(86_000_000, 0) + .saturating_add(Weight::from_parts(0, 3642)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/templates/frame-weight-template.hbs b/templates/frame-weight-template.hbs new file mode 100644 index 00000000..38bb4de2 --- /dev/null +++ b/templates/frame-weight-template.hbs @@ -0,0 +1,121 @@ +{{header}} +//! Autogenerated weights for {{pallet}} +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}` +//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` +//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} + +// Executed Command: +{{#each args as |arg|}} +// {{arg}} +{{/each}} + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for {{pallet}}. +pub trait WeightInfo { + {{#each benchmarks as |benchmark|}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{c.name}}: u32, {{/each~}} + ) -> Weight; + {{/each}} +} + +/// Weights for {{pallet}} using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +{{#if (eq pallet "frame_system")}} +impl WeightInfo for SubstrateWeight { +{{else}} +impl WeightInfo for SubstrateWeight { +{{/if}} + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + /// {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}}) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} + } + {{/each}} +} + +// For backwards compatibility and tests +impl WeightInfo for () { + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + /// {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}}) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} + } + {{/each}} +}