This repository was archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
[#113] Benchmark drop_assets() of TrappistDropAssets
#165
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| [package] | ||
| name = "pallet-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"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>(_); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| use frame_support::weights::Weight; | ||
|
|
||
| pub trait WeightInfo { | ||
| fn drop_assets_fungible() -> Weight; | ||
| fn drop_assets_native() -> Weight; | ||
| fn drop_assets_default() -> Weight; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.