-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
benchmark pallet asset manager #991
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c8c7a7a
wip
girazoki 356eea2
Merge remote-tracking branch 'upstream/master' into benchmark_pallet_…
girazoki 5177f59
Adapt to latest
girazoki e7becfa
Introduce moonbase-runtime-benchmarks
girazoki 6c865ae
Add moonbase-benchmarks to cargo config
girazoki 63047c5
remove print
girazoki 5433a69
Remove more prints
girazoki 48e0e43
Remove even more prints
girazoki ea4224e
Add weights generated by target hardware
girazoki e23a218
Comment from benchmarkscript
girazoki 727d2a0
actually add weights
girazoki c3ab3fe
FMT, copyright and weightinfo
girazoki c45b0e6
Fix tests
girazoki 5dd7903
Merge remote-tracking branch 'upstream/master' into girazoki-benchmar…
girazoki 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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,67 @@ | ||
// Copyright 2019-2021 PureStake Inc. | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Moonbeam is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use crate::{Call, Config, Pallet}; | ||
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; | ||
use frame_system::RawOrigin; | ||
|
||
benchmarks! { | ||
register_asset { | ||
// does not really matter what we register | ||
let asset_type = T::AssetType::default(); | ||
let metadata = T::AssetRegistrarMetadata::default(); | ||
let amount = 1u32.into(); | ||
let asset_id: T::AssetId = asset_type.clone().into(); | ||
|
||
}: _(RawOrigin::Root, asset_type.clone(), metadata, amount) | ||
verify { | ||
assert_eq!(Pallet::<T>::asset_id_type(asset_id), Some(asset_type)); | ||
} | ||
|
||
set_asset_units_per_second { | ||
// does not really matter what we register | ||
let asset_type = T::AssetType::default(); | ||
let metadata = T::AssetRegistrarMetadata::default(); | ||
let amount = 1u32.into(); | ||
let asset_id: T::AssetId = asset_type.clone().into(); | ||
Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount)?; | ||
|
||
}: _(RawOrigin::Root, asset_id, 1) | ||
verify { | ||
assert_eq!(Pallet::<T>::asset_id_units_per_second(asset_id), Some(1)); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::mock::Test; | ||
use sp_io::TestExternalities; | ||
|
||
pub fn new_test_ext() -> TestExternalities { | ||
let t = frame_system::GenesisConfig::default() | ||
.build_storage::<Test>() | ||
.unwrap(); | ||
TestExternalities::new(t) | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::benchmarks::tests::new_test_ext(), | ||
crate::mock::Test | ||
); |
This file contains 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 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 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,86 @@ | ||
// Copyright 2019-2021 PureStake Inc. | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Moonbeam is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Autogenerated weights for pallet_asset_manager | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
//! DATE: 2021-11-15, STEPS: `32`, REPEAT: 64, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 | ||
|
||
// Executed Command: | ||
// ./target/release/moonbeam | ||
// benchmark | ||
// --chain | ||
// dev | ||
// --execution=wasm | ||
// --wasm-execution=compiled | ||
// --pallet | ||
// pallet_asset_manager | ||
// --extrinsic | ||
// * | ||
// --steps | ||
// 32 | ||
// --repeat | ||
// 64 | ||
// --raw | ||
// --template=./benchmarking/frame-weight-template.hbs | ||
// --output | ||
// /tmp/ | ||
// --record-proof | ||
|
||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
|
||
use frame_support::{ | ||
traits::Get, | ||
weights::{constants::RocksDbWeight, Weight}, | ||
}; | ||
use sp_std::marker::PhantomData; | ||
|
||
/// Weight functions needed for pallet_asset_manager. | ||
pub trait WeightInfo { | ||
fn register_asset() -> Weight; | ||
fn set_asset_units_per_second() -> Weight; | ||
} | ||
|
||
/// Weights for pallet_asset_manager using the Substrate node and recommended hardware. | ||
pub struct SubstrateWeight<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { | ||
fn register_asset() -> Weight { | ||
(52_572_000 as Weight) | ||
.saturating_add(T::DbWeight::get().reads(7 as Weight)) | ||
.saturating_add(T::DbWeight::get().writes(5 as Weight)) | ||
} | ||
fn set_asset_units_per_second() -> Weight { | ||
(22_860_000 as Weight) | ||
.saturating_add(T::DbWeight::get().reads(5 as Weight)) | ||
.saturating_add(T::DbWeight::get().writes(3 as Weight)) | ||
} | ||
} | ||
|
||
// For backwards compatibility and tests | ||
impl WeightInfo for () { | ||
fn register_asset() -> Weight { | ||
(52_572_000 as Weight) | ||
.saturating_add(RocksDbWeight::get().reads(7 as Weight)) | ||
.saturating_add(RocksDbWeight::get().writes(5 as Weight)) | ||
} | ||
fn set_asset_units_per_second() -> Weight { | ||
(22_860_000 as Weight) | ||
.saturating_add(RocksDbWeight::get().reads(5 as Weight)) | ||
.saturating_add(RocksDbWeight::get().writes(3 as Weight)) | ||
} | ||
} |
This file contains 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this imply
runtime-benchmarks
so you don't need multiple feature flags to use it? You would probably need to do that in a lot of pallets or create an alias in.cargo/config.toml
, so maybe not...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue here is that I need to propagate the flag at least till runtime-common, which is the common place where we put our benchmark apis. And since runtime-common is common for all runtimes, I need to have a special flag to incorportate the benchmarks for pallets belonging to moonbase only.
The way I designed it currently is that if you build with moonbase-runtime-bechmarks, it will build with runtime-benchmarks & moonbase-runtime-benchmarks just the moonbase runtime. From here there are two possibilities:
Quite honestly I'd rather not be too invasive with this PR, and not change much how things worked. I think this approach is the lesser invasive as things worked as before, but we have a new flag with which we can run the just moonbase benchmarks