From 2591c7206558676916a5f845a25c16b7d5baa16e Mon Sep 17 00:00:00 2001 From: metricaez Date: Tue, 26 Sep 2023 11:29:26 -0300 Subject: [PATCH 01/19] create benchmarking and mock file --- pallets/withdraw-teleport/Cargo.toml | 1 + pallets/withdraw-teleport/src/benchmarking.rs | 42 +++++++++++++++++++ pallets/withdraw-teleport/src/lib.rs | 5 ++- pallets/withdraw-teleport/src/mock.rs | 0 runtime/trappist/Cargo.toml | 1 + 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 pallets/withdraw-teleport/src/benchmarking.rs create mode 100644 pallets/withdraw-teleport/src/mock.rs diff --git a/pallets/withdraw-teleport/Cargo.toml b/pallets/withdraw-teleport/Cargo.toml index e2152a9d..824b657c 100644 --- a/pallets/withdraw-teleport/Cargo.toml +++ b/pallets/withdraw-teleport/Cargo.toml @@ -34,6 +34,7 @@ sp-runtime = { workspace = true } 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..8ba29cbe --- /dev/null +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -0,0 +1,42 @@ +//! Benchmarking setup for pallet-template +#![cfg(feature = "runtime-benchmarks")] +use super::*; + +#[allow(unused)] +use crate::Pallet as WithdrawAndTeleport; +use frame_benchmarking::{ + impl_benchmark_test_suite, + v2::*, +}; +use frame_system::RawOrigin; + +type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn withdraw_and_teleport() { + // TODO: Create caller & assets + + let fee_asset = Concrete(MultiLocation::parent()); + + // TODO: Fund caller with native + + // TODO: Fund caller with fee asset + + // TODO: Amount of Native to send + + // TODO: Amount of Fee Asset to send + + // TODO: Call create_game extrinsic + #[extrinsic_call] + withdraw_and_teleport(RawOrigin::Signed(caller), bet); + + // TODO: Assert event emited. + } + + impl_benchmark_test_suite!(WithdrawAndTeleport, 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..58d4b035 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -43,8 +43,9 @@ use xcm_executor::traits::WeightBounds; // #[cfg(test)] // mod tests; -// #[cfg(feature = "runtime-benchmarks")] -// mod benchmarking; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + // pub mod weights; // pub use weights::*; diff --git a/pallets/withdraw-teleport/src/mock.rs b/pallets/withdraw-teleport/src/mock.rs new file mode 100644 index 00000000..e69de29b diff --git a/runtime/trappist/Cargo.toml b/runtime/trappist/Cargo.toml index fd2d122c..ce765bd6 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/std", "pallet-xcm/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", From 0e934e1dd5e80eb8ff623ff8e2279e96b8cf38a1 Mon Sep 17 00:00:00 2001 From: metricaez Date: Tue, 26 Sep 2023 14:05:23 -0300 Subject: [PATCH 02/19] add benchmark to runtime and fn --- pallets/withdraw-teleport/src/benchmarking.rs | 38 +++++++++---------- runtime/trappist/Cargo.toml | 2 +- runtime/trappist/src/lib.rs | 1 + 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index 8ba29cbe..5d36a0d0 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -4,36 +4,36 @@ use super::*; #[allow(unused)] use crate::Pallet as WithdrawAndTeleport; -use frame_benchmarking::{ - impl_benchmark_test_suite, - v2::*, -}; +use frame_benchmarking::{impl_benchmark_test_suite, v2::*}; use frame_system::RawOrigin; -type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - #[benchmarks] mod benchmarks { use super::*; #[benchmark] - fn withdraw_and_teleport() { - // TODO: Create caller & assets - - let fee_asset = Concrete(MultiLocation::parent()); - - // TODO: Fund caller with native - - // TODO: Fund caller with fee asset + fn withdraw_and_teleport() -> Result<(), BenchmarkError> { + let asset: MultiAsset = (MultiLocation::new(1, Here), 10).into(); + let caller: T::AccountId = account("caller", 0, 0); - // TODO: Amount of Native to send + let recipient = [0u8; 32]; + let versioned_dest: VersionedMultiLocation = MultiLocation::new(1, X1(Parachain(1))).into(); + let versioned_beneficiary: VersionedMultiLocation = + AccountId32 { network: None, id: recipient.into() }.into(); + let versioned_assets: VersionedMultiAssets = asset.into(); - // TODO: Amount of Fee Asset to send + let amount: u128 = 1_000_000_000; - // TODO: Call create_game extrinsic #[extrinsic_call] - withdraw_and_teleport(RawOrigin::Signed(caller), bet); + withdraw_and_teleport( + RawOrigin::Signed(caller), + Box::new(versioned_dest), + Box::new(versioned_beneficiary), + amount, + Box::new(versioned_assets), + ); + + Ok(()) // TODO: Assert event emited. } diff --git a/runtime/trappist/Cargo.toml b/runtime/trappist/Cargo.toml index ce765bd6..14af75ca 100644 --- a/runtime/trappist/Cargo.toml +++ b/runtime/trappist/Cargo.toml @@ -207,7 +207,7 @@ runtime-benchmarks = [ "pallet-treasury/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", "pallet-utility/runtime-benchmarks", - "pallet-withdraw-teleport/std", + "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..d5b817e9 100644 --- a/runtime/trappist/src/lib.rs +++ b/runtime/trappist/src/lib.rs @@ -774,6 +774,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] From fe847c2ee999c8cf67a9f3fcdb847c2e089e8ea2 Mon Sep 17 00:00:00 2001 From: metricaez Date: Tue, 26 Sep 2023 16:49:16 -0300 Subject: [PATCH 03/19] add assertion --- pallets/withdraw-teleport/Cargo.toml | 1 + pallets/withdraw-teleport/src/benchmarking.rs | 21 ++++++++++++------- pallets/withdraw-teleport/src/lib.rs | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pallets/withdraw-teleport/Cargo.toml b/pallets/withdraw-teleport/Cargo.toml index 824b657c..0f4fd77f 100644 --- a/pallets/withdraw-teleport/Cargo.toml +++ b/pallets/withdraw-teleport/Cargo.toml @@ -29,6 +29,7 @@ sp-io = { workspace = true } sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } +pallet-balances = { workspace = true } [features] default = ["std"] diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index 5d36a0d0..a2448dd6 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -6,6 +6,8 @@ use super::*; use crate::Pallet as WithdrawAndTeleport; use frame_benchmarking::{impl_benchmark_test_suite, v2::*}; use frame_system::RawOrigin; +use frame_support::traits::Currency; +use sp_std::prelude::*; #[benchmarks] mod benchmarks { @@ -15,27 +17,32 @@ mod benchmarks { fn withdraw_and_teleport() -> Result<(), BenchmarkError> { let asset: MultiAsset = (MultiLocation::new(1, Here), 10).into(); let caller: T::AccountId = account("caller", 0, 0); + let initial_balance: u32 = 1_000_000_000; + T::Currency::make_free_balance_be(&caller, initial_balance.into()); let recipient = [0u8; 32]; - let versioned_dest: VersionedMultiLocation = MultiLocation::new(1, X1(Parachain(1))).into(); + 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: u128 = 1_000_000_000; + let amount: u32 = 500_000_000; #[extrinsic_call] withdraw_and_teleport( - RawOrigin::Signed(caller), + RawOrigin::Signed(caller.clone()), Box::new(versioned_dest), Box::new(versioned_beneficiary), - amount, + amount.into(), Box::new(versioned_assets), ); + // TODO: Change to asset check as SetFeesMode might impact the native balance + let remaining_balance = initial_balance - amount; + assert_eq!(T::Currency::free_balance(&caller), remaining_balance.into()); + Ok(()) - Ok(()) - - // TODO: Assert event emited. } impl_benchmark_test_suite!(WithdrawAndTeleport, 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 58d4b035..a07b06ca 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -37,8 +37,8 @@ pub use xcm::{ }; use xcm_executor::traits::WeightBounds; -// #[cfg(test)] -// mod mock; +#[cfg(test)] +mod mock; // #[cfg(test)] // mod tests; From b7709104bb0b889855e5883be0e4acb6d2a70bca Mon Sep 17 00:00:00 2001 From: metricaez Date: Wed, 27 Sep 2023 10:36:00 -0300 Subject: [PATCH 04/19] build mock runtime --- pallets/withdraw-teleport/Cargo.toml | 3 + pallets/withdraw-teleport/src/benchmarking.rs | 17 +- pallets/withdraw-teleport/src/mock.rs | 262 ++++++++++++++++++ 3 files changed, 273 insertions(+), 9 deletions(-) diff --git a/pallets/withdraw-teleport/Cargo.toml b/pallets/withdraw-teleport/Cargo.toml index 0f4fd77f..0edbdfb6 100644 --- a/pallets/withdraw-teleport/Cargo.toml +++ b/pallets/withdraw-teleport/Cargo.toml @@ -30,6 +30,9 @@ 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"] diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index a2448dd6..c6646329 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -3,10 +3,10 @@ use super::*; #[allow(unused)] -use crate::Pallet as WithdrawAndTeleport; +use crate::Pallet as WithdrawTeleport; use frame_benchmarking::{impl_benchmark_test_suite, v2::*}; -use frame_system::RawOrigin; use frame_support::traits::Currency; +use frame_system::RawOrigin; use sp_std::prelude::*; #[benchmarks] @@ -17,8 +17,8 @@ mod benchmarks { fn withdraw_and_teleport() -> Result<(), BenchmarkError> { let asset: MultiAsset = (MultiLocation::new(1, Here), 10).into(); let caller: T::AccountId = account("caller", 0, 0); - let initial_balance: u32 = 1_000_000_000; - T::Currency::make_free_balance_be(&caller, initial_balance.into()); + let initial_balance: u32 = 1_000_000_000; + T::Currency::make_free_balance_be(&caller, initial_balance.into()); let recipient = [0u8; 32]; let versioned_dest: VersionedMultiLocation = T::ReachableDest::get() @@ -38,12 +38,11 @@ mod benchmarks { amount.into(), Box::new(versioned_assets), ); - // TODO: Change to asset check as SetFeesMode might impact the native balance - let remaining_balance = initial_balance - amount; - assert_eq!(T::Currency::free_balance(&caller), remaining_balance.into()); + // TODO: Change to asset check as SetFeesMode might impact the native balance + let remaining_balance = initial_balance - amount; + //assert_eq!(T::Currency::free_balance(&caller), remaining_balance.into()); Ok(()) - } - impl_benchmark_test_suite!(WithdrawAndTeleport, crate::mock::new_test_ext(), crate::mock::Test); + impl_benchmark_test_suite!(WithdrawTeleport, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/pallets/withdraw-teleport/src/mock.rs b/pallets/withdraw-teleport/src/mock.rs index e69de29b..fc5f238d 100644 --- a/pallets/withdraw-teleport/src/mock.rs +++ b/pallets/withdraw-teleport/src/mock.rs @@ -0,0 +1,262 @@ +use crate as pallet_withdraw_teleport; +use frame_benchmarking::account; +use frame_support::{ + construct_runtime, parameter_types, + traits::{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()); +} +pub(crate) fn sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> { + SENT_XCM.with(|q| (*q.borrow()).clone()) +} +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 = u64; + type DustRemoval = (); + type ExistentialDeposit = ConstU64<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; +} + +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", 0, 0), 100)] } + .assimilate_storage(&mut t) + .unwrap(); + pallet_xcm::GenesisConfig:: { safe_xcm_version: Some(2), ..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) +} From 090e74f1307d45f0d8b6af336bf3d423a7e0b502 Mon Sep 17 00:00:00 2001 From: metricaez Date: Wed, 27 Sep 2023 11:07:27 -0300 Subject: [PATCH 05/19] cargot fmt and balance u32 --- Cargo.lock | 4 ++++ pallets/withdraw-teleport/src/benchmarking.rs | 5 +++-- pallets/withdraw-teleport/src/mock.rs | 16 +++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) 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/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index c6646329..04e68ec5 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -16,9 +16,10 @@ mod benchmarks { #[benchmark] fn withdraw_and_teleport() -> Result<(), BenchmarkError> { let asset: MultiAsset = (MultiLocation::new(1, Here), 10).into(); - let caller: T::AccountId = account("caller", 0, 0); + let caller: T::AccountId = account("Alice", 0, 0); let initial_balance: u32 = 1_000_000_000; T::Currency::make_free_balance_be(&caller, initial_balance.into()); + assert_eq!(T::Currency::free_balance(&caller), initial_balance.clone().into()); let recipient = [0u8; 32]; let versioned_dest: VersionedMultiLocation = T::ReachableDest::get() @@ -40,7 +41,7 @@ mod benchmarks { ); // TODO: Change to asset check as SetFeesMode might impact the native balance let remaining_balance = initial_balance - amount; - //assert_eq!(T::Currency::free_balance(&caller), remaining_balance.into()); + assert_eq!(T::Currency::free_balance(&caller), remaining_balance.into()); Ok(()) } diff --git a/pallets/withdraw-teleport/src/mock.rs b/pallets/withdraw-teleport/src/mock.rs index fc5f238d..e5a6b9cb 100644 --- a/pallets/withdraw-teleport/src/mock.rs +++ b/pallets/withdraw-teleport/src/mock.rs @@ -109,7 +109,7 @@ impl frame_system::Config for Test { type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); @@ -121,9 +121,9 @@ impl frame_system::Config for Test { impl pallet_balances::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - type Balance = u64; + type Balance = u32; type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; + type ExistentialDeposit = ConstU32<1>; type AccountStore = System; type ReserveIdentifier = [u8; 8]; type RuntimeHoldReason = (); @@ -245,10 +245,12 @@ 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", 0, 0), 100)] } - .assimilate_storage(&mut t) - .unwrap(); - pallet_xcm::GenesisConfig:: { safe_xcm_version: Some(2), ..Default::default() } + 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(); From 95ce83c37f22c3be60b41d93636bb46e9d5c3971 Mon Sep 17 00:00:00 2001 From: metricaez Date: Wed, 27 Sep 2023 11:32:49 -0300 Subject: [PATCH 06/19] improve pallet error wording --- pallets/withdraw-teleport/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index a07b06ca..59ea33ef 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -66,7 +66,7 @@ pub mod pallet { /// An error ocured during send SendError, /// Failed to execute - FailedToExecute, + FailedToExecuteXcm, } #[pallet::event] @@ -216,7 +216,7 @@ 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(|_| Error::::FailedToExecuteXcm)?; Self::deposit_event(Event::Attempted { outcome }); // Use pallet-xcm send for sending message. From 663b34ed36524fe02448395b92d530220272c369 Mon Sep 17 00:00:00 2001 From: metricaez Date: Wed, 27 Sep 2023 14:39:11 -0300 Subject: [PATCH 07/19] add log and send_origin --- pallets/withdraw-teleport/src/benchmarking.rs | 17 +++++------------ pallets/withdraw-teleport/src/lib.rs | 5 +++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index 04e68ec5..6fd3be93 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -15,12 +15,9 @@ mod benchmarks { #[benchmark] fn withdraw_and_teleport() -> Result<(), BenchmarkError> { - let asset: MultiAsset = (MultiLocation::new(1, Here), 10).into(); - let caller: T::AccountId = account("Alice", 0, 0); - let initial_balance: u32 = 1_000_000_000; - T::Currency::make_free_balance_be(&caller, initial_balance.into()); - assert_eq!(T::Currency::free_balance(&caller), initial_balance.clone().into()); - + let asset: MultiAsset = (MultiLocation::new(0, Here), 10_000).into(); + let send_origin = + T::ExecuteXcmOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let recipient = [0u8; 32]; let versioned_dest: VersionedMultiLocation = T::ReachableDest::get() .ok_or(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))? @@ -28,20 +25,16 @@ mod benchmarks { let versioned_beneficiary: VersionedMultiLocation = AccountId32 { network: None, id: recipient.into() }.into(); let versioned_assets: VersionedMultiAssets = asset.into(); - - let amount: u32 = 500_000_000; + let amount: u32 = 50_000_000; #[extrinsic_call] withdraw_and_teleport( - RawOrigin::Signed(caller.clone()), + send_origin as ::RuntimeOrigin, Box::new(versioned_dest), Box::new(versioned_beneficiary), amount.into(), Box::new(versioned_assets), ); - // TODO: Change to asset check as SetFeesMode might impact the native balance - let remaining_balance = initial_balance - amount; - assert_eq!(T::Currency::free_balance(&caller), remaining_balance.into()); Ok(()) } diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 59ea33ef..2ca25c42 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -24,8 +24,9 @@ type BaseXcm = pallet_xcm::Pallet; use frame_support::{ dispatch::DispatchResult, - ensure, + ensure, log, traits::{Contains, EnsureOrigin, Get}, + LOG_TARGET }; use frame_system::pallet_prelude::OriginFor; pub use pallet::*; @@ -216,7 +217,7 @@ 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::::FailedToExecuteXcm)?; + 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. From ef79ae051adc5fd0df3ae0a79f6d9976515a550b Mon Sep 17 00:00:00 2001 From: metricaez Date: Wed, 27 Sep 2023 16:08:51 -0300 Subject: [PATCH 08/19] add caller and send native as fee --- pallets/withdraw-teleport/src/benchmarking.rs | 10 +++++----- pallets/withdraw-teleport/src/lib.rs | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index 6fd3be93..c58f17af 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -15,9 +15,7 @@ mod benchmarks { #[benchmark] fn withdraw_and_teleport() -> Result<(), BenchmarkError> { - let asset: MultiAsset = (MultiLocation::new(0, Here), 10_000).into(); - let send_origin = - T::ExecuteXcmOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + let asset: MultiAsset = (MultiLocation::new(0, Here), 1_000).into(); let recipient = [0u8; 32]; let versioned_dest: VersionedMultiLocation = T::ReachableDest::get() .ok_or(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))? @@ -25,11 +23,13 @@ mod benchmarks { let versioned_beneficiary: VersionedMultiLocation = AccountId32 { network: None, id: recipient.into() }.into(); let versioned_assets: VersionedMultiAssets = asset.into(); - let amount: u32 = 50_000_000; + let amount: u32 = 1_000; + let caller = whitelisted_caller(); + T::Currency::make_free_balance_be(&caller, 100_000_000u32.into()); #[extrinsic_call] withdraw_and_teleport( - send_origin as ::RuntimeOrigin, + RawOrigin::Signed(caller.clone()), Box::new(versioned_dest), Box::new(versioned_beneficiary), amount.into(), diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 2ca25c42..90b24eb1 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -26,7 +26,6 @@ use frame_support::{ dispatch::DispatchResult, ensure, log, traits::{Contains, EnsureOrigin, Get}, - LOG_TARGET }; use frame_system::pallet_prelude::OriginFor; pub use pallet::*; @@ -217,7 +216,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(|e|{log::debug!("{e:?}"); Error::::FailedToExecuteXcm})?; + 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. From e1145f374e8b48fae78c02c977735701c977a0d3 Mon Sep 17 00:00:00 2001 From: metricaez Date: Wed, 27 Sep 2023 16:49:04 -0300 Subject: [PATCH 09/19] add weights.rs --- pallets/withdraw-teleport/src/weights.rs | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pallets/withdraw-teleport/src/weights.rs diff --git a/pallets/withdraw-teleport/src/weights.rs b/pallets/withdraw-teleport/src/weights.rs new file mode 100644 index 00000000..ccd6e46a --- /dev/null +++ b/pallets/withdraw-teleport/src/weights.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-27, 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=./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}; +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)) + } +} From 6baf10731f5b036aa2986e66eb3fe2e293fb75e9 Mon Sep 17 00:00:00 2001 From: metricaez Date: Wed, 27 Sep 2023 21:04:04 -0300 Subject: [PATCH 10/19] add balance assert to benchmark --- pallets/withdraw-teleport/src/benchmarking.rs | 7 ++++++- pallets/withdraw-teleport/src/mock.rs | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index c58f17af..fbf3a857 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -15,7 +15,8 @@ mod benchmarks { #[benchmark] fn withdraw_and_teleport() -> Result<(), BenchmarkError> { - let asset: MultiAsset = (MultiLocation::new(0, Here), 1_000).into(); + 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)))? @@ -26,6 +27,7 @@ mod benchmarks { 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( @@ -35,6 +37,9 @@ mod benchmarks { amount.into(), Box::new(versioned_assets), ); + + let remaining_balance = initial_balance - amount.into() - (fee_amount as u32).into(); + assert_eq!(T::Currency::free_balance(&caller), remaining_balance); Ok(()) } diff --git a/pallets/withdraw-teleport/src/mock.rs b/pallets/withdraw-teleport/src/mock.rs index e5a6b9cb..eaf86a19 100644 --- a/pallets/withdraw-teleport/src/mock.rs +++ b/pallets/withdraw-teleport/src/mock.rs @@ -2,7 +2,7 @@ use crate as pallet_withdraw_teleport; use frame_benchmarking::account; use frame_support::{ construct_runtime, parameter_types, - traits::{ConstU16, ConstU32, ConstU64, Everything, Nothing}, + traits::{ConstU128, ConstU16, ConstU32, ConstU64, Everything, Nothing}, weights::Weight, }; use frame_system::EnsureRoot; @@ -109,7 +109,7 @@ impl frame_system::Config for Test { type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); @@ -121,9 +121,9 @@ impl frame_system::Config for Test { impl pallet_balances::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - type Balance = u32; + type Balance = Balance; type DustRemoval = (); - type ExistentialDeposit = ConstU32<1>; + type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type ReserveIdentifier = [u8; 8]; type RuntimeHoldReason = (); From 2949e4ad4201f2af58d6cbaeebfe11decabd3ba2 Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 11:19:16 -0300 Subject: [PATCH 11/19] add weight tempalte and weight.rs with template --- pallets/withdraw-teleport/src/weights.rs | 54 +++++++--- templates/frame-weight-template.hbs | 121 +++++++++++++++++++++++ 2 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 templates/frame-weight-template.hbs diff --git a/pallets/withdraw-teleport/src/weights.rs b/pallets/withdraw-teleport/src/weights.rs index ccd6e46a..60a0b4d2 100644 --- a/pallets/withdraw-teleport/src/weights.rs +++ b/pallets/withdraw-teleport/src/weights.rs @@ -1,11 +1,11 @@ -//! Autogenerated weights for `pallet_withdraw_teleport` +//! Autogenerated weights for pallet_withdraw_teleport //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-27, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! 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 +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/trappist-node @@ -17,6 +17,7 @@ // --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)] @@ -24,12 +25,42 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions for `pallet_withdraw_teleport`. -pub struct WeightInfo(PhantomData); -impl pallet_withdraw_teleport::WeightInfo for WeightInfo { +/// 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: 92_000_000 picoseconds. + Weight::from_parts(94_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) @@ -46,10 +77,9 @@ impl pallet_withdraw_teleport::WeightInfo for WeightInf // 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)) + // Minimum execution time: 92_000_000 picoseconds. + Weight::from_parts(94_000_000, 3642) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } } 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}} +} From 06616b79827c531e6f799f348f5f2e42ce0c8a95 Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 11:36:49 -0300 Subject: [PATCH 12/19] add WeightInfo trait --- pallets/withdraw-teleport/src/lib.rs | 8 +-- runtime/trappist/src/lib.rs | 1 + runtime/trappist/src/weights/mod.rs | 1 + .../src/weights/pallet_withdraw_teleport.rs | 55 +++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 runtime/trappist/src/weights/pallet_withdraw_teleport.rs diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 90b24eb1..7eab2631 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -45,9 +45,8 @@ mod mock; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; - -// pub mod weights; -// pub use weights::*; +pub mod weights; +pub use weights::*; #[frame_support::pallet] pub mod pallet { @@ -59,6 +58,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] @@ -102,7 +102,7 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(::teleport_assets())] + #[pallet::weight(::WeightInfo::withdraw_and_teleport())] pub fn withdraw_and_teleport( origin: OriginFor, dest: Box, diff --git a/runtime/trappist/src/lib.rs b/runtime/trappist/src/lib.rs index d5b817e9..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 { diff --git a/runtime/trappist/src/weights/mod.rs b/runtime/trappist/src/weights/mod.rs index cfd98f67..ad6dcf68 100644 --- a/runtime/trappist/src/weights/mod.rs +++ b/runtime/trappist/src/weights/mod.rs @@ -44,6 +44,7 @@ pub mod pallet_treasury; pub mod pallet_uniques; pub mod pallet_utility; pub mod trappist_runtime_benchmarks; +pub mod pallet_withdraw_teleport; pub mod xcm; pub struct TrappistDropAssetsWeigher(); 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)) + } +} From 2097243ecea4212029aa1d3fb38f386e13ac7a82 Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 14:46:06 -0300 Subject: [PATCH 13/19] cargo fmt and rollback stout barrier --- pallets/withdraw-teleport/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 7eab2631..39246e5c 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -58,7 +58,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_xcm::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type WeightInfo: WeightInfo; + type WeightInfo: WeightInfo; } #[pallet::error] @@ -139,6 +139,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 From 605c13114d82ee293dbd1a4f54ddafb810ced568 Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 14:46:56 -0300 Subject: [PATCH 14/19] cargo fmt --- runtime/stout/src/xcm_config.rs | 39 +++++++++++------------------ runtime/trappist/src/weights/mod.rs | 2 +- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/runtime/stout/src/xcm_config.rs b/runtime/stout/src/xcm_config.rs index 856200a9..c3669a39 100644 --- a/runtime/stout/src/xcm_config.rs +++ b/runtime/stout/src/xcm_config.rs @@ -198,30 +198,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 +225,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/src/weights/mod.rs b/runtime/trappist/src/weights/mod.rs index ad6dcf68..e1b153a5 100644 --- a/runtime/trappist/src/weights/mod.rs +++ b/runtime/trappist/src/weights/mod.rs @@ -43,8 +43,8 @@ pub mod pallet_timestamp; pub mod pallet_treasury; pub mod pallet_uniques; pub mod pallet_utility; -pub mod trappist_runtime_benchmarks; pub mod pallet_withdraw_teleport; +pub mod trappist_runtime_benchmarks; pub mod xcm; pub struct TrappistDropAssetsWeigher(); From ab486775ccc8df277a766f25b52b9ed24cd38e0c Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 15:33:07 -0300 Subject: [PATCH 15/19] add Weigher of message to weight --- pallets/withdraw-teleport/src/benchmarking.rs | 1 + pallets/withdraw-teleport/src/lib.rs | 25 ++++++++++++++++++- pallets/withdraw-teleport/src/weights.rs | 8 +++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/pallets/withdraw-teleport/src/benchmarking.rs b/pallets/withdraw-teleport/src/benchmarking.rs index fbf3a857..f84c44fc 100644 --- a/pallets/withdraw-teleport/src/benchmarking.rs +++ b/pallets/withdraw-teleport/src/benchmarking.rs @@ -39,6 +39,7 @@ mod benchmarks { ); 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(()) } diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 39246e5c..9cf8ffdf 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -102,7 +102,30 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::withdraw_and_teleport())] + #[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(); + match maybe_assets { + Ok(assets) => { + use sp_std::vec; + let mut message = Xcm(vec![ + WithdrawAsset(native_assets.clone()), + SetFeesMode { jit_withdraw: true }, + // Burn the native asset. + BurnAsset(native_assets), + // Burn the fee asset derivative. + WithdrawAsset(assets.clone()), + BurnAsset(assets), + ]); + T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| ::WeightInfo::withdraw_and_teleport().saturating_add(w)) + } + _ => Weight::MAX, + } + })] pub fn withdraw_and_teleport( origin: OriginFor, dest: Box, diff --git a/pallets/withdraw-teleport/src/weights.rs b/pallets/withdraw-teleport/src/weights.rs index 60a0b4d2..a70adb36 100644 --- a/pallets/withdraw-teleport/src/weights.rs +++ b/pallets/withdraw-teleport/src/weights.rs @@ -52,8 +52,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `177` // Estimated: `3642` - // Minimum execution time: 92_000_000 picoseconds. - Weight::from_parts(94_000_000, 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)) } @@ -77,8 +77,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `177` // Estimated: `3642` - // Minimum execution time: 92_000_000 picoseconds. - Weight::from_parts(94_000_000, 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)) } From 0089d485564d661f2933e0c0fdf9d6666f3c76e4 Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 15:46:08 -0300 Subject: [PATCH 16/19] code cleanup --- pallets/withdraw-teleport/src/lib.rs | 2 -- runtime/stout/src/xcm_config.rs | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 9cf8ffdf..611b685f 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -115,9 +115,7 @@ pub mod pallet { let mut message = Xcm(vec![ WithdrawAsset(native_assets.clone()), SetFeesMode { jit_withdraw: true }, - // Burn the native asset. BurnAsset(native_assets), - // Burn the fee asset derivative. WithdrawAsset(assets.clone()), BurnAsset(assets), ]); diff --git a/runtime/stout/src/xcm_config.rs b/runtime/stout/src/xcm_config.rs index c3669a39..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; From 939a1082bfa8b93b25b358524c78609efcf69a99 Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 15:57:16 -0300 Subject: [PATCH 17/19] update mock WeightInfo --- pallets/withdraw-teleport/src/mock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/withdraw-teleport/src/mock.rs b/pallets/withdraw-teleport/src/mock.rs index eaf86a19..de27a17c 100644 --- a/pallets/withdraw-teleport/src/mock.rs +++ b/pallets/withdraw-teleport/src/mock.rs @@ -238,6 +238,7 @@ impl pallet_xcm::Config for Test { impl pallet_withdraw_teleport::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_withdraw_teleport::weights::SubstrateWeight; } impl origin::Config for Test {} From e76a63d2ae4bb72628bd0d6674955eee9c55b8e3 Mon Sep 17 00:00:00 2001 From: metricaez Date: Thu, 28 Sep 2023 16:06:49 -0300 Subject: [PATCH 18/19] allow dead code for unused helper fn --- pallets/withdraw-teleport/src/mock.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pallets/withdraw-teleport/src/mock.rs b/pallets/withdraw-teleport/src/mock.rs index de27a17c..98378eef 100644 --- a/pallets/withdraw-teleport/src/mock.rs +++ b/pallets/withdraw-teleport/src/mock.rs @@ -42,9 +42,12 @@ construct_runtime!( 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(); From 6888248e1ea8736e95097de9ed6b12a71134540d Mon Sep 17 00:00:00 2001 From: metricaez Date: Mon, 2 Oct 2023 11:10:22 -0300 Subject: [PATCH 19/19] add send weight to withdraw teleport weight --- pallets/withdraw-teleport/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pallets/withdraw-teleport/src/lib.rs b/pallets/withdraw-teleport/src/lib.rs index 611b685f..d2c0a77c 100644 --- a/pallets/withdraw-teleport/src/lib.rs +++ b/pallets/withdraw-teleport/src/lib.rs @@ -29,6 +29,7 @@ use frame_support::{ }; 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::{ @@ -109,6 +110,7 @@ pub mod pallet { }; 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; @@ -119,7 +121,7 @@ pub mod pallet { WithdrawAsset(assets.clone()), BurnAsset(assets), ]); - T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| ::WeightInfo::withdraw_and_teleport().saturating_add(w)) + T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| ::WeightInfo::withdraw_and_teleport().saturating_add(w).saturating_add(send_weight)) } _ => Weight::MAX, }