Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Drop Asset Benchmarks
  • Loading branch information
Valentin Fernandez committed May 18, 2023
commit e24e6f2c1a9915e29fddb33b318448a918ff0a06
35 changes: 35 additions & 0 deletions pallets/benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "trappist-runtime-benchmarks"
version = "0.1.0"
edition = "2021"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", ] }
scale-info = { version = "2.3.1", default-features = false, features = ["derive"] }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }

xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }

[dev-dependencies]
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
"xcm-executor/std"
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
33 changes: 33 additions & 0 deletions pallets/benchmarks/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use frame_benchmarking::benchmarks;
use sp_runtime::SaturatedConversion;
use xcm::prelude::AssetId as XcmAssetId;

use crate::*;

benchmarks! {
drop_assets_fungible {
let origin = MultiLocation::default();
let asset_id = 1;
let location = Parachain(asset_id).into();
T::register_asset(asset_id.into(), location.clone());
let asset = MultiAsset { id: XcmAssetId::Concrete(location), fun: Fungibility::Fungible(100) };
} : {
T::DropAssets::drop_assets(&origin, asset.into());
}

drop_assets_native {
let origin = MultiLocation::default();
let location = MultiLocation { parents: 0, interior: Here };
let amount = T::ExistentialDeposit::get().saturated_into();
let asset = MultiAsset { id: XcmAssetId::Concrete(location), fun: Fungibility::Fungible(amount) };
} : {
T::DropAssets::drop_assets(&origin, asset.into());
}

drop_assets_default {
let origin = MultiLocation::default();
let asset = MultiAsset { id: XcmAssetId::Abstract(Default::default()), fun: Fungibility::Fungible(0) };
} : {
T::DropAssets::drop_assets(&origin, asset.into());
}
}
43 changes: 43 additions & 0 deletions pallets/benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Pallet for benchmarking.

#![cfg_attr(not(feature = "std"), no_std)]

use codec::Codec;
use frame_support::{pallet_prelude::*, traits::tokens::AssetId};
use sp_runtime::traits::AtLeast32BitUnsigned;
use xcm::prelude::*;
use xcm_executor::traits::DropAssets;

pub use pallet::*;
pub use weights::*;

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod weights;

#[frame_support::pallet]
pub mod pallet {
use super::*;

#[pallet::config]
pub trait Config: frame_system::Config {
/// Identifier for the class of asset.
type AssetId: AssetId + From<u32>;

/// The balance of an account.
type Balance: Parameter + Member + AtLeast32BitUnsigned + Codec + TypeInfo;

/// The minimum amount required to keep an account open.
#[pallet::constant]
type ExistentialDeposit: Get<Self::Balance>;

/// Handler for when some non-empty `Assets` value should be dropped.
type DropAssets: DropAssets;

/// Handler to register an asset.
fn register_asset(asset_id: Self::AssetId, location: MultiLocation);
}

#[pallet::pallet]
pub struct Pallet<T>(_);
}
7 changes: 7 additions & 0 deletions pallets/benchmarks/src/weights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::Weight;

pub trait WeightInfo {
fn drop_assets_fungible() -> Weight;
fn drop_assets_native() -> Weight;
fn drop_assets_default() -> Weight;
}
21 changes: 21 additions & 0 deletions runtime/trappist/src/weights/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use ::trappist_runtime_benchmarks::WeightInfo;
use xcm_primitives::DropAssetsWeigher;

use crate::{Runtime, Weight};

mod trappist_runtime_benchmarks;

pub struct TrappistDropAssetsWeigher();
impl DropAssetsWeigher for TrappistDropAssetsWeigher {
fn fungible() -> Weight {
trappist_runtime_benchmarks::WeightInfo::<Runtime>::drop_assets_fungible()
}

fn native() -> Weight {
trappist_runtime_benchmarks::WeightInfo::<Runtime>::drop_assets_native()
}

fn default() -> Weight {
trappist_runtime_benchmarks::WeightInfo::<Runtime>::drop_assets_default()
}
}
53 changes: 53 additions & 0 deletions runtime/trappist/src/weights/trappist_runtime_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

//! Autogenerated weights for `trappist_runtime_benchmarks`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-05-08, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `kalan-x1x`, CPU: `12th Gen Intel(R) Core(TM) i7-12800H`
//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
// target/release/trappist-collator
// benchmark
// pallet
// --chain
// dev
// --pallet
// trappist_runtime_benchmarks
// --extrinsic
// *
// --steps
// 20
// --repeat
// 10
// --output
// runtime/trappist/src/weights/trappist_runtime_benchmarks.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for `trappist_runtime_benchmarks`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> trappist_runtime_benchmarks::WeightInfo for WeightInfo<T> {
// Storage: AssetRegistry AssetMultiLocationId (r:1 w:0)
// Storage: Assets Asset (r:1 w:0)
fn drop_assets_fungible() -> Weight {
// Minimum execution time: 4_589 nanoseconds.
Weight::from_parts(4_898_000, 0)
.saturating_add(T::DbWeight::get().reads(2))
}
// Storage: AssetRegistry AssetMultiLocationId (r:1 w:0)
fn drop_assets_native() -> Weight {
// Minimum execution time: 2_157 nanoseconds.
Weight::from_parts(2_314_000, 0)
.saturating_add(T::DbWeight::get().reads(1))
}
fn drop_assets_default() -> Weight {
// Minimum execution time: 130 nanoseconds.
Weight::from_parts(154_000, 0)
}
}