Skip to content
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

Fix benchmark #970

Merged
merged 19 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 32 additions & 16 deletions frame-weight-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
//! 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}}`
//! 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}}

Expand All @@ -37,9 +38,10 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

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

/// Weight functions needed for {{pallet}}.
pub trait WeightInfo {
Expand All @@ -61,7 +63,7 @@ impl<T: frame_system::Config> WeightInfo for BifrostWeight<T> {
{{/if}}
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
// {{comment}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
Expand All @@ -71,22 +73,29 @@ impl<T: frame_system::Config> WeightInfo for BifrostWeight<T> {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
({{underscore benchmark.base_weight}} as 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(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
.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}} as Weight))
.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}} as Weight).saturating_mul({{cr.name}} as Weight)))
.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}} as Weight))
.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}} as Weight).saturating_mul({{cw.name}} as Weight)))
.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}}
Expand All @@ -96,7 +105,7 @@ impl<T: frame_system::Config> WeightInfo for BifrostWeight<T> {
impl WeightInfo for () {
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
// {{comment}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
Expand All @@ -106,22 +115,29 @@ impl WeightInfo for () {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
({{underscore benchmark.base_weight}} as 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(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
.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}} as Weight))
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
.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}} as Weight))
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
.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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub const KUSAMA_ALICE_STASH_ACCOUNT: [u8; 32] =
hex_literal::hex!["be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f"];
pub const KUSAMA_BOB_STASH_ACCOUNT: [u8; 32] =
hex_literal::hex!["fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e"];
pub const CATHI: [u8; 32] = [2u8; 32];
// pub const CATHI: [u8; 32] = [2u8; 32];

pub const KSM_DECIMALS: u128 = 1000_000_000_000;
pub const BNC_DECIMALS: u128 = 1000_000_000_000;
Expand Down
2 changes: 2 additions & 0 deletions pallets/asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ std = [
"sp-std/std",
"frame-support/std",
"frame-system/std",
"frame-benchmarking?/std",
"primitives/std",
"xcm/std",
"xcm-builder/std",
Expand All @@ -46,4 +47,5 @@ runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
53 changes: 25 additions & 28 deletions pallets/asset-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@

#![cfg(feature = "runtime-benchmarks")]

use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use super::*;
use crate::Pallet as AssetRegistry;
use frame_benchmarking::{benchmarks, v1::BenchmarkError};
use frame_support::{assert_ok, dispatch::UnfilteredDispatchable};
use primitives::{CurrencyId, TokenSymbol};
use sp_runtime::traits::UniqueSaturatedFrom;

use super::*;
#[allow(unused_imports)]
use crate::Pallet as AssetRegistry;
use xcm::v3::prelude::*;

benchmarks! {
register_native_asset {
let origin = T::RegisterOrigin::successful_origin();
let v0_location = VersionedMultiLocation::V0(xcm::v0::MultiLocation::X1(
xcm::v0::Junction::Parachain(1000),
));
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let v3_location = VersionedMultiLocation::V3(MultiLocation::from(X1(Junction::Parachain(1000))));

let call = Call::<T>::register_native_asset {
currency_id: CurrencyId::Token(TokenSymbol::DOT),
location: Box::new(v0_location.clone()),
location: Box::new(v3_location.clone()),
metadata: Box::new(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
Expand All @@ -60,15 +57,13 @@ benchmarks! {
}

update_native_asset {
let origin = T::RegisterOrigin::successful_origin();
let v0_location = VersionedMultiLocation::V0(xcm::v0::MultiLocation::X1(
xcm::v0::Junction::Parachain(1000),
));
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let v3_location = VersionedMultiLocation::V3(MultiLocation::from(X1(Junction::Parachain(1000))));

assert_ok!(AssetRegistry::<T>::register_native_asset(
origin.clone(),
CurrencyId::Token(TokenSymbol::DOT),
Box::new(v0_location.clone()),
Box::new(v3_location.clone()),
Box::new(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
Expand All @@ -79,7 +74,7 @@ benchmarks! {

let call = Call::<T>::update_native_asset {
currency_id: CurrencyId::Token(TokenSymbol::DOT),
location: Box::new(v0_location.clone()),
location: Box::new(v3_location.clone()),
metadata: Box::new(AssetMetadata {
name: b"Token Name".to_vec(),
symbol: b"TN".to_vec(),
Expand All @@ -103,7 +98,7 @@ benchmarks! {
}

register_token_metadata {
let origin = T::RegisterOrigin::successful_origin();
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
name: b"Bifrost Native Coin".to_vec(),
symbol: b"BNC".to_vec(),
Expand All @@ -120,7 +115,7 @@ benchmarks! {
}

register_vtoken_metadata {
let origin = T::RegisterOrigin::successful_origin();
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
name: b"Bifrost Native Coin".to_vec(),
symbol: b"BNC".to_vec(),
Expand Down Expand Up @@ -150,7 +145,7 @@ benchmarks! {
}

register_vstoken_metadata {
let origin = T::RegisterOrigin::successful_origin();
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
name: b"KSM Native Token".to_vec(),
symbol: b"KSM".to_vec(),
Expand Down Expand Up @@ -180,7 +175,7 @@ benchmarks! {
}

register_vsbond_metadata {
let origin = T::RegisterOrigin::successful_origin();
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
name: b"KSM Native Token".to_vec(),
symbol: b"KSM".to_vec(),
Expand Down Expand Up @@ -214,18 +209,19 @@ benchmarks! {
}

register_multilocation {
let origin = T::RegisterOrigin::successful_origin();
let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let metadata = AssetMetadata {
name: b"Bifrost Native Coin".to_vec(),
symbol: b"BNC".to_vec(),
decimals: 12,
minimal_balance: BalanceOf::<T>::unique_saturated_from(0u128),
};
// v1
let location = VersionedMultiLocation::V1(MultiLocation {
// v3
let location = VersionedMultiLocation::V3(MultiLocation {
parents: 1,
interior: xcm::v1::Junctions::X1(xcm::v1::Junction::Parachain(2001)),
interior: Junctions::X1(Parachain(2001)),
});

let multi_location: MultiLocation = location.clone().try_into().unwrap();

assert_ok!(AssetRegistry::<T>::register_token_metadata(
Expand All @@ -236,7 +232,7 @@ benchmarks! {
let call = Call::<T>::register_multilocation {
currency_id: CurrencyId::Token2(0),
location:Box::new(location.clone()),
weight:2000_000_000,
weight:Weight::from_parts(2000_000_000, u64::MAX),
};
}: {call.dispatch_bypass_filter(origin)?}
verify {
Expand All @@ -248,12 +244,13 @@ benchmarks! {
CurrencyIdToLocations::<T>::get(CurrencyId::Token2(0)),
Some(multi_location.clone())
);
assert_eq!(CurrencyIdToWeights::<T>::get(CurrencyId::Token2(0)), Some(2000_000_000));
assert_eq!(CurrencyIdToWeights::<T>::get(CurrencyId::Token2(0)), Some(Weight::from_parts(2000_000_000, u64::MAX)));
}
}

impl_benchmark_test_suite!(
impl_benchmark_test_suite!(
AssetRegistry,
crate::mock::ExtBuilder::default().build(),
crate::mock::Runtime
);

}
Loading