From dbd36680db8311fedd383bc744a0653e721b6741 Mon Sep 17 00:00:00 2001 From: MrishoLukamba Date: Thu, 19 Dec 2024 18:56:05 +0300 Subject: [PATCH] feat(benchmarks) pallet token gateway --- .../pallets/token-gateway/src/benchmarking.rs | 100 +++-- modules/ismp/pallets/token-gateway/src/lib.rs | 24 +- .../ismp/pallets/token-gateway/src/mock.rs | 375 ------------------ .../ismp/pallets/token-gateway/src/weights.rs | 140 +++++++ parachain/runtimes/gargantua/src/lib.rs | 1 + 5 files changed, 216 insertions(+), 424 deletions(-) delete mode 100644 modules/ismp/pallets/token-gateway/src/mock.rs create mode 100644 modules/ismp/pallets/token-gateway/src/weights.rs diff --git a/modules/ismp/pallets/token-gateway/src/benchmarking.rs b/modules/ismp/pallets/token-gateway/src/benchmarking.rs index 6814d5def..5fd591e5b 100644 --- a/modules/ismp/pallets/token-gateway/src/benchmarking.rs +++ b/modules/ismp/pallets/token-gateway/src/benchmarking.rs @@ -2,17 +2,14 @@ use crate::*; use frame_benchmarking::v2::*; -use frame_support::{traits::EnsureOrigin, BoundedVec}; +use frame_support::BoundedVec; use frame_system::RawOrigin; use ismp::host::StateMachine; +use pallet_balances::AdjustmentDirection; use scale_info::prelude::collections::BTreeMap; use sp_runtime::{traits::StaticLookup, AccountId32}; use token_gateway_primitives::{GatewayAssetRegistration, GatewayAssetUpdate}; -fn assert_last_event(generic_event: ::RuntimeEvent) { - frame_system::Pallet::::assert_last_event(generic_event.into()); -} - fn dummy_teleport_asset( ) -> TeleportParams, <::NativeCurrency as Currency>::Balance> where @@ -26,10 +23,10 @@ where ), destination: StateMachine::Evm(100), recepient: H256::from([1u8; 32]), - amount: 2u128.into(), + amount: 1100000000u128.into(), timeout: 10, token_gateway: vec![1, 2, 3, 4, 5], - relayer_fee: 1u128.into(), + relayer_fee: 1000000002u128.into(), } } @@ -39,18 +36,13 @@ fn create_dummy_asset( where <::Assets as fungibles::Inspect>::AssetId: From, { - AssetRegistration { - local_id: <::Assets as fungibles::Inspect>::AssetId::from( - H256::zero(), - ), - reg: asset_details, - } + AssetRegistration { local_id: H256::zero().into(), reg: asset_details } } #[benchmarks( where T: pallet_balances::Config, - T: pallet_assets::Config, + T: pallet_assets::Config, <::Assets as fungibles::Inspect>::AssetId: From, <::NativeCurrency as Currency>::Balance: From, ::AccountId: From<[u8; 32]>, @@ -66,6 +58,8 @@ mod benches { #[benchmark] fn create_erc6160_asset() -> Result<(), BenchmarkError> { + let account: T::AccountId = whitelisted_caller(); + let asset_details = GatewayAssetRegistration { name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(), symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(), @@ -74,14 +68,30 @@ mod benches { }; let asset = create_dummy_asset::(asset_details); + // Set balances + let ed = ::ExistentialDeposit::get(); + + // Adjust total issuance + pallet_balances::Pallet::::force_adjust_total_issuance( + RawOrigin::Root.into(), + AdjustmentDirection::Increase, + ed * 1000, + )?; + + let acc = <::Lookup as StaticLookup>::unlookup(account.clone()); + + pallet_balances::Pallet::::force_set_balance(RawOrigin::Root.into(), acc, ed * 100u128)?; + #[extrinsic_call] - _(RawOrigin::Signed(AccountId32::from([0u8; 32])), asset); + _(RawOrigin::Signed(account), asset); Ok(()) } #[benchmark] fn teleport() -> Result<(), BenchmarkError> { + let account: T::AccountId = whitelisted_caller(); + let asset_details = GatewayAssetRegistration { name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(), symbol: BoundedVec::try_from(b"SPC".to_vec()).unwrap(), @@ -90,15 +100,30 @@ mod benches { }; let asset = create_dummy_asset::(asset_details); - Pallet::::create_erc6160_asset( - RawOrigin::Signed(AccountId32::from([0u8; 32])).into(), - asset, - )?; + Pallet::::create_erc6160_asset(RawOrigin::Signed(account.clone()).into(), asset)?; let dummy_teleport_params = dummy_teleport_asset::(); + // Set balances + let ed = ::ExistentialDeposit::get(); + + // Adjust total issuance + pallet_balances::Pallet::::force_adjust_total_issuance( + RawOrigin::Root.into(), + AdjustmentDirection::Increase, + ed * 1000, + )?; + + let acc = <::Lookup as StaticLookup>::unlookup(account.clone()); + + pallet_balances::Pallet::::force_set_balance( + RawOrigin::Root.into(), + acc.clone(), + ed * 100u128, + )?; + #[extrinsic_call] - teleport(RawOrigin::Signed(AccountId32::from([0u8; 32])), dummy_teleport_params); + teleport(RawOrigin::Signed(account), dummy_teleport_params); Ok(()) } @@ -111,13 +136,13 @@ mod benches { } #[extrinsic_call] - _(RawOrigin::Signed(AccountId32::from([0u8; 32])), addresses); + _(RawOrigin::Root, addresses); Ok(()) } #[benchmark] fn update_erc6160_asset() -> Result<(), BenchmarkError> { - let origin = RawOrigin::Signed(AccountId32::from([0u8; 32])); + let acc_origin: T::AccountId = whitelisted_caller(); let asset_details = GatewayAssetRegistration { name: BoundedVec::try_from(b"Spectre".to_vec()).unwrap(), @@ -126,24 +151,29 @@ mod benches { minimum_balance: None, }; let asset = create_dummy_asset::(asset_details); - let asset_id: H256 = sp_io::hashing::keccak_256(asset.reg.symbol.as_ref()).into(); - let owner = - >::admin(H256::zero().into()); - log::info!("owner: {owner:?}"); - // set balances - let account = T::AccountId::from([0u8; 32]); - let acc = <::Lookup as StaticLookup>::unlookup(account.clone()); - pallet_balances::Pallet::::force_set_balance(RawOrigin::Root.into(), acc, 1000u128)?; - let bal = >::total_balance(&account.clone()); - log::info!("bal: {bal:?}"); + let acc_o = + <::Lookup as StaticLookup>::unlookup(acc_origin.clone()); + let ed = ::ExistentialDeposit::get(); + pallet_balances::Pallet::::force_set_balance( + RawOrigin::Root.into(), + acc_o.clone(), + ed * 100u128, + )?; + // set asset balance + pallet_assets::Pallet::::create( + RawOrigin::Signed(acc_origin.clone()).into(), + H256::zero().into(), + acc_o.clone(), + 1000000000, + )?; Pallet::::create_erc6160_asset( - RawOrigin::Signed(AccountId32::from([0u8; 32])).into(), + RawOrigin::Signed(acc_origin.clone()).into(), asset.clone(), )?; @@ -155,9 +185,7 @@ mod benches { }; #[extrinsic_call] - _(origin, asset_update); + _(RawOrigin::Signed(acc_origin), asset_update); Ok(()) } - - impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ex(), crate::mock::Test); } diff --git a/modules/ismp/pallets/token-gateway/src/lib.rs b/modules/ismp/pallets/token-gateway/src/lib.rs index 790c26e1c..64a1bb75f 100644 --- a/modules/ismp/pallets/token-gateway/src/lib.rs +++ b/modules/ismp/pallets/token-gateway/src/lib.rs @@ -20,9 +20,10 @@ extern crate alloc; mod benchmarking; pub mod impls; -#[cfg(test)] -pub mod mock; + pub mod types; +pub mod weights; +pub use weights::*; use crate::impls::{convert_to_balance, convert_to_erc20}; use alloy_sol_types::SolValue; @@ -30,7 +31,6 @@ use anyhow::anyhow; use codec::Decode; use frame_support::{ ensure, - pallet_prelude::Weight, traits::{ fungibles::{self, Mutate}, tokens::{fungible::Mutate as FungibleMutate, Preservation}, @@ -117,6 +117,9 @@ pub mod pallet { /// The decimals of the native currency #[pallet::constant] type Decimals: Get; + + type WeightInfo: WeightInfo; + } /// Assets supported by this instance of token gateway @@ -222,7 +225,7 @@ pub mod pallet { /// Teleports a registered asset /// locks the asset and dispatches a request to token gateway on the destination #[pallet::call_index(0)] - #[pallet::weight(weight())] + #[pallet::weight(T::WeightInfo::teleport())] pub fn teleport( origin: OriginFor, params: TeleportParams< @@ -305,13 +308,12 @@ pub mod pallet { /// Set the token gateway address for specified chains #[pallet::call_index(1)] - #[pallet::weight(weight())] + #[pallet::weight(T::WeightInfo::set_token_gateway_addresses())] pub fn set_token_gateway_addresses( origin: OriginFor, addresses: BTreeMap>, ) -> DispatchResult { - ensure_signed(origin)?; - //T::AdminOrigin::ensure_origin(origin)?; + T::AdminOrigin::ensure_origin(origin)?; for (chain, address) in addresses { TokenGatewayAddresses::::insert(chain, address.clone()); } @@ -323,7 +325,7 @@ pub mod pallet { /// This works by dispatching a request to the TokenGateway module on each requested chain /// to create the asset. #[pallet::call_index(2)] - #[pallet::weight(weight())] + #[pallet::weight(T::WeightInfo::create_erc6160_asset())] pub fn create_erc6160_asset( origin: OriginFor, asset: AssetRegistration>, @@ -376,7 +378,7 @@ pub mod pallet { /// This works by dispatching a request to the TokenGateway module on each requested chain /// to create the asset. #[pallet::call_index(3)] - #[pallet::weight(weight())] + #[pallet::weight(T::WeightInfo::update_erc6160_asset())] pub fn update_erc6160_asset( origin: OriginFor, asset: GatewayAssetUpdate, @@ -659,10 +661,6 @@ where } } -/// Static weights because benchmarks suck, and we'll be getting PolkaVM soon anyways -fn weight() -> Weight { - Weight::from_parts(300_000_000, 0) -} impl Pallet { /// Ensure the signer is the asset admin diff --git a/modules/ismp/pallets/token-gateway/src/mock.rs b/modules/ismp/pallets/token-gateway/src/mock.rs deleted file mode 100644 index 081ce755a..000000000 --- a/modules/ismp/pallets/token-gateway/src/mock.rs +++ /dev/null @@ -1,375 +0,0 @@ -use crate::*; -use cumulus_pallet_parachain_system::{ - consensus_hook::UnincludedSegmentCapacity, AnyRelayNumber, ConsensusHook, ParachainSetCode, - RelayChainStateProof, -}; -use cumulus_primitives_core::{relay_chain, AggregateMessageOrigin, ParaId, XcmpMessageSource}; -use frame_support::{ - pallet_prelude::ConstU32, - parameter_types, - traits::{ - AsEnsureOriginWithArg, ConstU64, OnTimestampSet, ProcessMessage, ProcessMessageError, - }, - weights::WeightMeter, - BoundedVec, -}; -use frame_system::EnsureRoot; -use ismp::{host::StateMachine, router::IsmpRouter}; -use pallet_assets::AutoIncAssetId; -use pallet_ismp::offchain::Leaf; -use pallet_mmr::primitives::INDEXING_PREFIX; -use polkadot_core_primitives::Moment; -use polkadot_parachain_primitives::primitives::XcmpMessageHandler; -use sp_core::{crypto::AccountId32, ConstU128}; -use sp_runtime::{traits::Keccak256, BuildStorage}; -use std::{cell::RefCell, num::NonZeroU32}; - -use crate as pallet_token_gateway; -type Block = frame_system::mocking::MockBlock; - -frame_support::construct_runtime!( - pub enum Test - { - System: frame_system, - Balances: pallet_balances, - Timestamp: pallet_timestamp, - Ismp: pallet_ismp::{Pallet, Storage, Call, Event}, - Mmr: pallet_mmr, - IsmpParachain: ismp_parachain, - HyperBridge: pallet_hyperbridge, - MessageQueue: pallet_message_queue, - CumulusParachain: cumulus_pallet_parachain_system, - Assets: pallet_assets, - TokenGateway: pallet_token_gateway::{Pallet, Storage, Call, Event} - } -); - -//mock default config implementation -pub struct TestBlockHashCount>(core::marker::PhantomData); -impl, C: Get> Get for TestBlockHashCount { - fn get() -> I { - C::get().into() - } -} - -impl frame_system::Config for Test { - type Nonce = u32; - type Hash = sp_core::hash::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId32; - type Lookup = sp_runtime::traits::IdentityLookup; - type MaxConsumers = frame_support::traits::ConstU32<16>; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type Version = (); - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeEvent = RuntimeEvent; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type PalletInfo = PalletInfo; - type RuntimeTask = RuntimeTask; - type BaseCallFilter = frame_support::traits::Everything; - type BlockHashCount = TestBlockHashCount>; - type OnSetCode = ParachainSetCode; - type SingleBlockMigrations = (); - type MultiBlockMigrator = (); - type PreInherents = (); - type PostInherents = (); - type PostTransactions = (); - type Block = Block; -} - -impl pallet_balances::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeHoldReason = RuntimeHoldReason; - - type RuntimeFreezeReason = RuntimeFreezeReason; - - type AccountStore = System; - - type Balance = u128; - type ExistentialDeposit = ConstU128<1>; - - type ReserveIdentifier = (); - type FreezeIdentifier = Self::RuntimeFreezeReason; - - type DustRemoval = (); - - type MaxLocks = ConstU32<100>; - type MaxReserves = ConstU32<100>; - type MaxFreezes = ConstU32<10>; - - type WeightInfo = (); -} - -std::thread_local! { - pub static HANDLED_DMP_MESSAGES: RefCell>> = RefCell::new(Vec::new()); - pub static HANDLED_XCMP_MESSAGES: RefCell)>> = RefCell::new(Vec::new()); - pub static SENT_MESSAGES: RefCell)>> = RefCell::new(Vec::new()); -} - -pub struct SaveIntoThreadLocal; -impl XcmpMessageHandler for SaveIntoThreadLocal { - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - _max_weight: Weight, - ) -> Weight { - HANDLED_XCMP_MESSAGES.with(|m| { - for (sender, sent_at, message) in iter { - m.borrow_mut().push((sender, sent_at, message.to_vec())); - } - Weight::zero() - }) - } -} - -impl ProcessMessage for SaveIntoThreadLocal { - type Origin = AggregateMessageOrigin; - - fn process_message( - message: &[u8], - origin: Self::Origin, - _meter: &mut WeightMeter, - _id: &mut [u8; 32], - ) -> Result { - assert_eq!(origin, Self::Origin::Parent); - - HANDLED_DMP_MESSAGES.with(|m| { - m.borrow_mut().push(message.to_vec()); - Weight::zero() - }); - Ok(true) - } -} - -pub struct FromThreadLocal; - -impl XcmpMessageSource for FromThreadLocal { - fn take_outbound_messages(_maximum_channels: usize) -> Vec<(ParaId, Vec)> { - let id = ParaId::new(1000); - let result = vec![(id, vec![])]; - result - } -} - -std::thread_local! { - pub static CONSENSUS_HOOK: RefCell (Weight, UnincludedSegmentCapacity)>> - = RefCell::new(Box::new(|_| (Weight::zero(), NonZeroU32::new(1).unwrap().into()))); -} - -pub struct TestConsensusHook; - -impl ConsensusHook for TestConsensusHook { - fn on_state_proof(s: &RelayChainStateProof) -> (Weight, UnincludedSegmentCapacity) { - CONSENSUS_HOOK.with(|f| f.borrow_mut()(s)) - } -} - -impl cumulus_pallet_parachain_system::Config for Test { - type RuntimeEvent = RuntimeEvent; - type OnSystemEvent = (); - type SelfParaId = ParachainId; - type OutboundXcmpMessageSource = FromThreadLocal; - type DmpQueue = frame_support::traits::EnqueueWithOrigin; - type ReservedDmpWeight = ReservedDmpWeight; - type XcmpMessageHandler = SaveIntoThreadLocal; - type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = AnyRelayNumber; - type ConsensusHook = TestConsensusHook; - type WeightInfo = (); -} - -impl pallet_message_queue::Config for Test { - type RuntimeEvent = RuntimeEvent; - // NOTE that normally for benchmarking we should use the No-OP message processor, but in this - // case its a mocked runtime and will only be used to generate insecure default weights. - type MessageProcessor = SaveIntoThreadLocal; - type Size = u32; - type QueueChangeHandler = (); - type QueuePausedQuery = (); - type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>; - type MaxStale = sp_core::ConstU32<8>; - type ServiceWeight = MaxWeight; - type IdleMaxServiceWeight = (); - type WeightInfo = (); -} - -pub struct MockOnTimestampSet; -impl OnTimestampSet for MockOnTimestampSet { - fn on_timestamp_set(moment: Moment) { - CapturedMoment::mutate(|x| *x = Some(moment)); - } -} - -pub(crate) fn clear_captured_moment() { - CapturedMoment::mutate(|x| *x = None); -} - -pub(crate) fn get_captured_moment() -> Option { - CapturedMoment::get() -} - -impl pallet_timestamp::Config for Test { - type Moment = Moment; - type OnTimestampSet = MockOnTimestampSet; - type MinimumPeriod = ConstU64<5>; - type WeightInfo = (); -} - -impl pallet_hyperbridge::Config for Test { - type RuntimeEvent = RuntimeEvent; - type IsmpHost = Ismp; -} - -impl ismp_parachain::Config for Test { - type RuntimeEvent = RuntimeEvent; - type IsmpHost = Ismp; -} - -parameter_types! { - // The hyperbridge parachain on Polkadot - pub const Coprocessor: Option = Some(StateMachine::Polkadot(3367)); - // The host state machine of this pallet - pub const HostStateMachine: StateMachine = StateMachine::Polkadot(1000); // your paraId here - - pub const ParachainId: ParaId = ParaId::new(1000); - pub const ReservedXcmpWeight: Weight = Weight::zero(); - pub const ReservedDmpWeight: Weight = Weight::zero(); - pub const MaxWeight: Weight = Weight::MAX; - pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; - pub static CapturedMoment: Option = None; - -} - -impl pallet_mmr::Config for Test { - const INDEXING_PREFIX: &'static [u8] = INDEXING_PREFIX; - type Hashing = Keccak256; - type Leaf = Leaf; - type ForkIdentifierProvider = Ismp; -} - -impl pallet_ismp::Config for Test { - // configure the runtime event - type RuntimeEvent = RuntimeEvent; - // Permissioned origin who can create or update consensus clients - type AdminOrigin = EnsureRoot; - // The state machine identifier for this state machine - type HostStateMachine = HostStateMachine; - // The pallet_timestamp pallet - type TimestampProvider = Timestamp; - // The currency implementation that is offered to relayers - type Currency = Balances; - // The balance type for the currency implementation - type Balance = u128; - // Router implementation for routing requests/responses to their respective modules - type Router = Router; - // Optional coprocessor for incoming requests/responses - type Coprocessor = Coprocessor; - // Supported consensus clients - type ConsensusClients = ( - // as an example, the parachain consensus client - ismp_parachain::ParachainConsensusClient, - ); - // Offchain database implementation. Outgoing requests and responses are - // inserted in this database, while their commitments are stored onchain. - type OffchainDB = Mmr; - // Weight provider for local modules - type WeightProvider = (); -} - -#[derive(Default)] -pub struct Router; -impl IsmpRouter for Router { - fn module_for_id(&self, _id: Vec) -> Result, anyhow::Error> { - // let module = match id.as_slice() { - // YOUR_MODULE_ID => Box::new(()), - // _ => Err(ismp::Error::ModuleNotFound(id))? - // }; - // Ok(module) - todo!() - } -} - -impl Config for Test { - type RuntimeEvent = RuntimeEvent; - - type Dispatcher = Ismp; - - type NativeCurrency = Balances; - - type AssetAdmin = AssetAdmin; - - type Assets = Assets; - - type NativeAssetId = NativeAssetId; - - type AssetIdFactory = (); - - type Decimals = Decimals; -} - -parameter_types! { - pub const AssetAdmin: AccountId32 = AccountId32::new([0u8;32]); - // A constant that should represent the native asset id - pub const NativeAssetId: H256 = H256::zero(); - // Set the correct precision for the native currency - pub const Decimals: u8 = 12; -} - -impl pallet_assets::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Balance = u128; - type RemoveItemsLimit = ConstU32<5>; - type AssetId = H256; - type AssetIdParameter = H256; - type AssetDeposit = ConstU128<1>; - type AssetAccountDeposit = ConstU128<10>; - type MetadataDepositBase = ConstU128<1>; - type MetadataDepositPerByte = ConstU128<1>; - type ApprovalDeposit = ConstU128<1>; - type StringLimit = ConstU32<50>; - type Extra = (); - type CallbackHandle = AutoIncAssetId; - type WeightInfo = (); - type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; - type ForceOrigin = EnsureRoot; - type Freezer = (); -} - -pub fn new_test_ext() -> sp_io::TestExternalities { - let asset_id: H256 = H256::zero(); - - let t = RuntimeGenesisConfig { - system: Default::default(), - balances: pallet_balances::GenesisConfig { - balances: vec![(AccountId32::from([0u8; 32]), 10000)], - }, - assets: pallet_assets::GenesisConfig { - assets: vec![ - // id, owner, is_sufficient, min_balance - (asset_id, AccountId32::from([0u8; 32]), true, 0), - ], - metadata: vec![ - // id, name, symbol, decimals - (asset_id, "Spectre".into(), "SPC".into(), 10), - ], - accounts: vec![ - // id, account_id, balance - (asset_id, AccountId32::from([0u8; 32]), 1000), - ], - next_asset_id: None, - }, - } - .build_storage() - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} diff --git a/modules/ismp/pallets/token-gateway/src/weights.rs b/modules/ismp/pallets/token-gateway/src/weights.rs new file mode 100644 index 000000000..c383dffc1 --- /dev/null +++ b/modules/ismp/pallets/token-gateway/src/weights.rs @@ -0,0 +1,140 @@ + +//! Autogenerated weights for `pallet_token_gateway` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0 +//! DATE: 2024-12-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Mac`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 + +// Executed Command: +// ./target/release/hyperbridge +// benchmark +// pallet +// --runtime=target/release/wbuild/gargantua-runtime/gargantua_runtime.compact.wasm +// --genesis-builder=runtime +// --pallet=pallet-token-gateway +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --output=modules/ismp/pallets/token-gateway/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 needed for `pallet_token_gateway. +pub trait WeightInfo { + fn create_erc6160_asset() -> Weight; + fn teleport() -> Weight; + fn set_token_gateway_addresses() -> Weight; + fn update_erc6160_asset() -> Weight; +} + +/// Weight functions for `pallet_token_gateway`. +pub struct TokenGatewayWeightInfo(PhantomData); +impl WeightInfo for TokenGatewayWeightInfo { + /// Storage: `HyperBridge::HostParams` (r:1 w:0) + /// Proof: `HyperBridge::HostParams` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Ismp::Nonce` (r:1 w:1) + /// Proof: `Ismp::Nonce` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Mmr::CounterForIntermediateLeaves` (r:1 w:1) + /// Proof: `Mmr::CounterForIntermediateLeaves` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Mmr::NumberOfLeaves` (r:1 w:0) + /// Proof: `Mmr::NumberOfLeaves` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Mmr::IntermediateLeaves` (r:1 w:1) + /// Proof: `Mmr::IntermediateLeaves` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `TokenGateway::Decimals` (r:0 w:1) + /// Proof: `TokenGateway::Decimals` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `TokenGateway::LocalAssets` (r:0 w:1) + /// Proof: `TokenGateway::LocalAssets` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `TokenGateway::SupportedAssets` (r:0 w:1) + /// Proof: `TokenGateway::SupportedAssets` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: UNKNOWN KEY `0x52657175657374436f6d6d69746d656e7473f69464d93c5ef13116a0e1aec2dd` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x52657175657374436f6d6d69746d656e7473f69464d93c5ef13116a0e1aec2dd` (r:1 w:1) + fn create_erc6160_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3465` + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 0) + .saturating_add(Weight::from_parts(0, 3465)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(7)) + } + /// Storage: `TokenGateway::SupportedAssets` (r:1 w:0) + /// Proof: `TokenGateway::SupportedAssets` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `TokenGateway::Decimals` (r:1 w:0) + /// Proof: `TokenGateway::Decimals` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Ismp::Nonce` (r:1 w:1) + /// Proof: `Ismp::Nonce` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Mmr::CounterForIntermediateLeaves` (r:1 w:1) + /// Proof: `Mmr::CounterForIntermediateLeaves` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Mmr::NumberOfLeaves` (r:1 w:0) + /// Proof: `Mmr::NumberOfLeaves` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Mmr::IntermediateLeaves` (r:1 w:1) + /// Proof: `Mmr::IntermediateLeaves` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: UNKNOWN KEY `0x52657175657374436f6d6d69746d656e747366379cd08ce2b1618974e688611a` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x52657175657374436f6d6d69746d656e747366379cd08ce2b1618974e688611a` (r:1 w:1) + fn teleport() -> Weight { + // Proof Size summary in bytes: + // Measured: `362` + // Estimated: `6196` + // Minimum execution time: 95_000_000 picoseconds. + Weight::from_parts(96_000_000, 0) + .saturating_add(Weight::from_parts(0, 6196)) + .saturating_add(T::DbWeight::get().reads(11)) + .saturating_add(T::DbWeight::get().writes(6)) + } + /// Storage: `TokenGateway::TokenGatewayAddresses` (r:0 w:1) + /// Proof: `TokenGateway::TokenGatewayAddresses` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn set_token_gateway_addresses() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(4_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `TokenGateway::LocalAssets` (r:1 w:0) + /// Proof: `TokenGateway::LocalAssets` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(238), added: 2713, mode: `MaxEncodedLen`) + /// Storage: `HyperBridge::HostParams` (r:1 w:0) + /// Proof: `HyperBridge::HostParams` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Ismp::Nonce` (r:1 w:1) + /// Proof: `Ismp::Nonce` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Mmr::CounterForIntermediateLeaves` (r:1 w:1) + /// Proof: `Mmr::CounterForIntermediateLeaves` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Mmr::NumberOfLeaves` (r:1 w:0) + /// Proof: `Mmr::NumberOfLeaves` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Mmr::IntermediateLeaves` (r:1 w:1) + /// Proof: `Mmr::IntermediateLeaves` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: UNKNOWN KEY `0x52657175657374436f6d6d69746d656e7473536a84a5a5e4654066eda0b5daf7` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x52657175657374436f6d6d69746d656e7473536a84a5a5e4654066eda0b5daf7` (r:1 w:1) + fn update_erc6160_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `555` + // Estimated: `4020` + // Minimum execution time: 25_000_000 picoseconds. + Weight::from_parts(26_000_000, 0) + .saturating_add(Weight::from_parts(0, 4020)) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(4)) + } +} diff --git a/parachain/runtimes/gargantua/src/lib.rs b/parachain/runtimes/gargantua/src/lib.rs index 40a1a1e52..cb742973b 100644 --- a/parachain/runtimes/gargantua/src/lib.rs +++ b/parachain/runtimes/gargantua/src/lib.rs @@ -592,6 +592,7 @@ impl pallet_token_gateway::Config for Runtime { type AssetIdFactory = (); type Decimals = Decimals; + type WeightInfo = pallet_token_gateway::TokenGatewayWeightInfo; } parameter_types! {