diff --git a/Cargo.lock b/Cargo.lock index 3cb498b657..b984e532fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,6 +194,7 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", + "frame-benchmarking", "frame-executive", "frame-support", "frame-system", @@ -749,6 +750,7 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", + "frame-benchmarking", "frame-executive", "frame-support", "frame-system", @@ -844,12 +846,14 @@ name = "bifrost-salp" version = "0.8.0" dependencies = [ "bifrost-bancor", + "frame-benchmarking", "frame-support", "frame-system", "log", "node-primitives", "orml-tokens", "orml-traits", + "pallet-xcm", "parity-scale-codec", "polkadot-parachain", "sp-arithmetic", @@ -4940,6 +4944,7 @@ dependencies = [ "cumulus-client-service", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", + "frame-benchmarking", "frame-system-rpc-runtime-api", "hex-literal 0.2.1", "jsonrpc-core", @@ -5343,6 +5348,7 @@ name = "pallet-collective" version = "3.0.0" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.8#1b758b2a8d151d97d2242260c465b6df9cb8a7a4" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", diff --git a/Makefile b/Makefile index d1ec8e28db..17d2413b55 100644 --- a/Makefile +++ b/Makefile @@ -76,4 +76,12 @@ copy-genesis-config-release: .PHONY: format format: rustup component add rustfmt - cargo +nightly fmt --all -- --check \ No newline at end of file + cargo +nightly fmt --all -- --check + +.PHONY: test-benchmarking +test-benchmarking: + cargo test --features runtime-benchmarks --features with-all-runtime --features --all benchmarking + +.PHONY: run-benchmarking +run-benchmarking: + ./scripts/run_all_benches.sh diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index d0b829930b..a8980f1986 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -62,9 +62,7 @@ cli = [ "structopt", "substrate-build-script-utils", ] -runtime-benchmarks = [ - "frame-benchmarking-cli", -] +runtime-benchmarks = [ "node-service/runtime-benchmarks" ] with-asgard-runtime = [ "node-service/with-asgard-runtime", ] diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 1c2e65fc83..a92210ce7f 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -15,6 +15,7 @@ sc-telemetry = { version = "3.0.0" } sc-transaction-pool = { version = "3.0.0" } sc-tracing = { version = "3.0.0" } sc-service = { version = "0.9.0", default-features = false } +frame-benchmarking = { version = "3.0.0", default-features = false } # Substrate Primitives sp-consensus-aura = { version = "0.9.0" } @@ -76,6 +77,10 @@ bifrost-charge-transaction-fee-rpc-runtime-api = { path = "../../pallets/charge- [features] default = [ "std" ] std = [] +runtime-benchmarks = [ + "asgard-runtime/runtime-benchmarks", + "bifrost-runtime/runtime-benchmarks", +] with-asgard-runtime = [ "asgard-runtime", ] diff --git a/node/service/src/collator.rs b/node/service/src/collator.rs index f4ab6e7c0d..da713695b1 100644 --- a/node/service/src/collator.rs +++ b/node/service/src/collator.rs @@ -58,6 +58,7 @@ native_executor_instance!( pub AsgardExecutor, asgard_runtime::api::dispatch, asgard_runtime::native_version, + frame_benchmarking::benchmarking::HostFunctions, ); #[cfg(feature = "with-bifrost-runtime")] @@ -65,6 +66,7 @@ native_executor_instance!( pub BifrostExecutor, bifrost_runtime::api::dispatch, bifrost_runtime::native_version, + frame_benchmarking::benchmarking::HostFunctions, ); /// Starts a `ServiceBuilder` for a full service. diff --git a/pallets/salp/Cargo.toml b/pallets/salp/Cargo.toml index bcc6434799..3c15c5a1ea 100644 --- a/pallets/salp/Cargo.toml +++ b/pallets/salp/Cargo.toml @@ -10,11 +10,14 @@ log = { version = "0.4.14", default-features = false } node-primitives = { path = "../../node/primitives", default-features = false } frame-support = { version = "3.0.0", default-features = false } frame-system = { version = "3.0.0", default-features = false } +frame-benchmarking = { version = "3.0.0", default-features = false, optional = true } sp-std = { version = "3.0.0", default-features = false } sp-runtime = { version = "3.0.0", default-features = false } sp-arithmetic = { version = "3.0.0", default-features = false } xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", default-features = false } xcm-support = { path = "../../xcm-support", default-features = false } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8",default-features = false } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8",default-features = false } orml-traits = { version = "0.4.1-dev", default-features = false } polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } @@ -23,8 +26,6 @@ sp-io = "3.0.0" sp-core = "3.0.0" orml-tokens = "0.4.1-dev" bifrost-bancor = { path = "../../pallets/bancor" } -xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" } [features] default = ["std"] @@ -39,8 +40,15 @@ std = [ "sp-arithmetic/std", "orml-traits/std", "xcm/std", + "xcm-builder/std", "xcm-support/std", "polkadot-parachain/std", ] -with-asgard-runtime = ["std"] -with-bifrost-runtime = ["std"] + +runtime-benchmarks = [ + "frame-benchmarking", + "sp-runtime/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", +] diff --git a/pallets/salp/src/benchmarking.rs b/pallets/salp/src/benchmarking.rs new file mode 100644 index 0000000000..ea2aed6543 --- /dev/null +++ b/pallets/salp/src/benchmarking.rs @@ -0,0 +1,111 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +// Ensure we're `no_std` when compiling for Wasm. +#[cfg(feature = "runtime-benchmarks")] +use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_support::assert_ok; +use frame_system::RawOrigin; +use sp_runtime::traits::Bounded; +use sp_std::prelude::*; + +pub use crate::{Pallet as Salp, *}; + +fn assert_last_event(generic_event: ::Event) { + let events = frame_system::Pallet::::events(); + let system_event: ::Event = generic_event.into(); + // compare to the last event record + let frame_system::EventRecord { event, .. } = &events[events.len() - 1]; + assert_eq!(event, &system_event); +} + +fn create_fund(id: u32) -> ParaId { + let cap = BalanceOf::::max_value(); + let first_period = (0 as u32).into(); + let last_period = (7 as u32).into(); + let para_id = id; + + let caller = account("fund_creator", id, 0); + + assert_ok!(CurrencyOf::::deposit(Salp::::token(), &caller, T::SubmissionDeposit::get())); + + assert_ok!(Salp::::create( + RawOrigin::Signed(caller).into(), + para_id, + cap, + first_period, + last_period, + )); + + para_id +} + +#[allow(dead_code)] +fn contribute_fund(who: &T::AccountId, index: ParaId) { + let value = T::SubmissionDeposit::get(); + + assert_ok!(Salp::::contribute(RawOrigin::Signed(who.clone()).into(), index, value)); +} + +benchmarks! { + create { + let para_id = 1 as u32; + let cap = BalanceOf::::max_value(); + let first_period = 0u32.into(); + let last_period = 3u32.into(); + + let caller: T::AccountId = whitelisted_caller(); + + CurrencyOf::::deposit( + Salp::::token(), + &caller, + T::SubmissionDeposit::get(), + )?; + + }: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period) + verify { + assert_last_event::(Event::::Created(para_id).into()) + } + + contribute { + let fund_index = create_fund::(1); + let caller: T::AccountId = whitelisted_caller(); + let contribution = T::MinContribution::get(); + + }: _(RawOrigin::Signed(caller.clone()), fund_index, contribution) + verify { + assert_last_event::(Event::::Contributing(caller, fund_index, contribution).into()); + } + + on_finalize { + let end_block: T::BlockNumber = T::ReleaseCycle::get(); + let n in 2 .. 100; + + for i in 0 .. n { + let fund_index = create_fund::(i); + let contributor: T::AccountId = account("contributor", i, 0); + let contribution = T::MinContribution::get() * (i + 1).into(); + + Salp::::contribute(RawOrigin::Signed(contributor).into(), fund_index, contribution)?; + } + }: { + Salp::::on_finalize(end_block); + } +} + +impl_benchmark_test_suite!(Salp, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index 59784c72ac..71e7e609fb 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -19,7 +19,11 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; +#[cfg(test)] mod mock; +#[cfg(test)] mod tests; // Re-export pallet items so that they can be accessed from the crate namespace. @@ -30,11 +34,35 @@ pub use pallet::*; type TrieIndex = u32; +pub trait WeightInfo { + fn create() -> Weight; + fn contribute() -> Weight; + fn on_finalize(n: u32) -> Weight; +} + +pub struct TestWeightInfo; +impl WeightInfo for TestWeightInfo { + fn create() -> Weight { + 0 + } + + fn contribute() -> Weight { + 0 + } + + fn on_finalize(_n: u32) -> Weight { + 0 + } +} + +#[allow(type_alias_bounds)] +pub type AccountIdOf = ::AccountId; + #[allow(type_alias_bounds)] -type AccountIdOf = ::AccountId; +pub type CurrencyOf = ::MultiCurrency; #[allow(type_alias_bounds)] -type BalanceOf = <::MultiCurrency as MultiCurrency>>::Balance; +pub type BalanceOf = <::MultiCurrency as MultiCurrency>>::Balance; #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)] pub enum FundStatus { @@ -142,7 +170,7 @@ pub mod pallet { PalletId, }; use frame_system::pallet_prelude::*; - use node_primitives::{traits::BancorHandler, CurrencyId, LeasePeriod, ParaId, TokenSymbol}; + use node_primitives::{traits::BancorHandler, CurrencyId, LeasePeriod, ParaId}; use orml_traits::{ currency::TransferAll, LockIdentifier, MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency, MultiReservableCurrency, @@ -178,6 +206,9 @@ pub mod pallet { #[pallet::constant] type RelyChainToken: Get; + #[pallet::constant] + type DepositToken: Get; + /// The number of blocks over which a single period lasts. #[pallet::constant] type LeasePeriod: Get>; @@ -215,6 +246,9 @@ pub mod pallet { #[pallet::constant] type SlotLength: Get; + + /// Weight information for the extrinsics in this module. + type WeightInfo: WeightInfo; } #[pallet::pallet] @@ -392,7 +426,7 @@ pub mod pallet { } /// Create a new crowdloaning campaign for a parachain slot deposit for the current auction. - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -438,7 +472,7 @@ pub mod pallet { /// Contribute to a crowd sale. This will transfer some balance over to fund a parachain /// slot. It will be withdrawable in two instances: the parachain becomes retired; or the /// slot is unable to be purchased and the timeout expires. - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::contribute())] pub fn contribute( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -849,11 +883,8 @@ pub mod pallet { Ok(()) } - fn token() -> CurrencyId { - #[cfg(feature = "with-asgard-runtime")] - return CurrencyId::Token(TokenSymbol::ASG); - #[cfg(not(feature = "with-asgard-runtime"))] - return CurrencyId::Token(TokenSymbol::BNC); + pub fn token() -> CurrencyId { + T::DepositToken::get() } pub fn vstoken() -> CurrencyId { diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index 8135c76039..71330ecb8a 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -18,8 +18,6 @@ // Ensure we're `no_std` when compiling for Wasm. -#![cfg(test)] - use frame_support::{construct_runtime, parameter_types, traits::GenesisBuild, PalletId}; use node_primitives::{Amount, Balance, CurrencyId, TokenSymbol}; use sp_arithmetic::Percent; @@ -133,6 +131,7 @@ parameter_types! { pub const LeasePeriod: BlockNumber = 6 * WEEKS; pub const ReleaseRatio: Percent = Percent::from_percent(50); pub const SlotLength: BlockNumber = 8u32 as BlockNumber; + pub const DepositTokenType: CurrencyId = CurrencyId::Token(TokenSymbol::ASG); } parameter_types! { @@ -144,6 +143,7 @@ type LocalOriginToLocation = (SignedToAccountId32 impl salp::Config for Test { type BancorPool = Bancor; type BifrostXcmExecutor = MockXcmExecutor; + type DepositToken = DepositTokenType; type Event = Event; type ExecuteXcmOrigin = EnsureXcmOrigin; type LeasePeriod = LeasePeriod; @@ -157,6 +157,7 @@ impl salp::Config for Test { type SlotLength = SlotLength; type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; + type WeightInfo = salp::TestWeightInfo; } // To control the result returned by `MockXcmExecutor` diff --git a/pallets/salp/src/tests.rs b/pallets/salp/src/tests.rs index edba30a975..c8dbc1249f 100644 --- a/pallets/salp/src/tests.rs +++ b/pallets/salp/src/tests.rs @@ -18,8 +18,6 @@ // Ensure we're `no_std` when compiling for Wasm. -#![cfg(test)] - use frame_support::{assert_noop, assert_ok, dispatch::DispatchError}; use crate::{mock::*, ContributionStatus, Error, FundStatus}; diff --git a/runtime/asgard/Cargo.toml b/runtime/asgard/Cargo.toml index c8de5588ed..a264c345be 100644 --- a/runtime/asgard/Cargo.toml +++ b/runtime/asgard/Cargo.toml @@ -11,7 +11,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = log = { version = "0.4.14", default-features = false } serde = { version = "1.0.124", optional = true } static_assertions = "1.1.0" -hex-literal = { version = "0.3.1", optional = true } +hex-literal = { version = "0.3.1"} # primitives node-primitives = { default-features = false, path = "../../node/primitives" } @@ -29,6 +29,7 @@ sp-consensus-aura = { version = "0.9.0", default-features = false } sp-arithmetic = { version = "3.0.0", default-features = false } # frame dependencies +frame-benchmarking = { version = "3.0.0", default-features = false, optional = true } frame-executive = { version = "3.0.0", default-features = false } frame-support = { version = "3.0.0", default-features = false } frame-system = { version = "3.0.0", default-features = false } @@ -106,6 +107,7 @@ with-tracing = [ "frame-executive/with-tracing" ] std = [ "codec/std", "log/std", + "frame-benchmarking/std", "frame-executive/std", "frame-support/std", "frame-system-rpc-runtime-api/std", @@ -173,3 +175,14 @@ std = [ "zenlink-protocol/std", "zenlink-protocol-runtime-api/std", ] + +runtime-benchmarks = [ + "frame-benchmarking", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "bifrost-salp/runtime-benchmarks", +] diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index b36f82031e..3052e36706 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -53,6 +53,8 @@ use sp_core::{ }; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; +#[cfg(feature = "runtime-benchmarks")] +use sp_runtime::RuntimeString; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto, Zero}, @@ -940,11 +942,13 @@ parameter_types! { pub const LeasePeriod: BlockNumber = KUSAMA_LEASE_PERIOD; pub const ReleaseRatio: Percent = Percent::from_percent(50); pub const SlotLength: BlockNumber = 8u32 as BlockNumber; + pub const DepositTokenType: CurrencyId = CurrencyId::Token(TokenSymbol::ASG); } impl bifrost_salp::Config for Runtime { type BancorPool = Bancor; type BifrostXcmExecutor = BifrostXcmAdaptor; + type DepositToken = DepositTokenType; type Event = Event; type ExecuteXcmOrigin = EnsureXcmOrigin; type LeasePeriod = LeasePeriod; @@ -958,6 +962,7 @@ impl bifrost_salp::Config for Runtime { type SlotLength = SlotLength; type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; + type WeightInfo = weights::pallet_salp::WeightInfo; // bifrost_salp::TestWeightInfo; } parameter_types! { @@ -1452,6 +1457,40 @@ impl_runtime_apis! { ) } } + + // benchmarks for asgard modules + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig + ) -> Result, RuntimeString> { + use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey}; + + let whitelist: Vec = vec![ + // Block Number + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), + // Total Issuance + hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), + // Execution Phase + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), + // Event Count + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), + // System Events + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + // Caller 0 Account + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da946c154ffd9992e395af90b5b13cc6f295c77033fce8a9045824a6690bbf99c6db269502f0a8d1d2a008542d5690a0749").to_vec().into(), + // Treasury Account + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(), + ]; + + let mut batches = Vec::::new(); + let params = (&config, &whitelist); + add_benchmark!(params, batches, bifrost_salp, Salp); + + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } } struct CheckInherents; diff --git a/runtime/asgard/src/weights/mod.rs b/runtime/asgard/src/weights/mod.rs index e32fc9bd4e..ca54404001 100644 --- a/runtime/asgard/src/weights/mod.rs +++ b/runtime/asgard/src/weights/mod.rs @@ -20,5 +20,6 @@ //! A list of the different weight modules for our runtime. +pub mod pallet_salp; pub mod pallet_vesting; pub mod pallet_vtoken_mint; diff --git a/runtime/asgard/src/weights/pallet_salp.rs b/runtime/asgard/src/weights/pallet_salp.rs new file mode 100644 index 0000000000..5b82ba2d59 --- /dev/null +++ b/runtime/asgard/src/weights/pallet_salp.rs @@ -0,0 +1,69 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +//! Autogenerated weights for bifrost_salp +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-07-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 + +// Executed Command: +// target/debug/bifrost +// benchmark +// --chain +// asgard-dev +// --steps=50 +// --repeat=20 +// --pallet=bifrost-salp +// --extrinsic +// * +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/salp.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_salp. +pub struct WeightInfo(PhantomData); +impl bifrost_salp::WeightInfo for WeightInfo { + fn create() -> Weight { + (2_345_291_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + + fn contribute() -> Weight { + (1_251_633_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + + fn on_finalize(n: u32) -> Weight { + (290_825_000 as Weight) + // Standard Error: 5_000 + .saturating_add((399_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/runtime/bifrost/Cargo.toml b/runtime/bifrost/Cargo.toml index f85ce80bd6..9aba38d97e 100644 --- a/runtime/bifrost/Cargo.toml +++ b/runtime/bifrost/Cargo.toml @@ -24,6 +24,7 @@ sp-version = { version = "3.0.0", default-features = false } sp-consensus-aura = { version = "0.9.0", default-features = false } # frame dependencies +frame-benchmarking = { version = "3.0.0", default-features = false, optional = true } frame-executive = { version = "3.0.0", default-features = false } frame-support = { version = "3.0.0", default-features = false } frame-system = { version = "3.0.0", default-features = false } @@ -114,3 +115,13 @@ std = [ "pallet-session/std", "pallet-vesting/std", ] + +runtime-benchmarks = [ + "frame-benchmarking", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", +] diff --git a/scripts/run_all_benches.sh b/scripts/run_all_benches.sh new file mode 100755 index 0000000000..f07313254f --- /dev/null +++ b/scripts/run_all_benches.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Runs all benchmarks for all pallets, for each of the runtimes specified below +# Should be run on a reference machine to gain accurate benchmarks(currently run on bifrost builder) + +runtimes=( + asgard +) + +# cargo build --locked --release +for runtime in "${runtimes[@]}"; do + cargo run --release --features="runtime-benchmarks,with-${runtime}-runtime" --locked benchmark --chain "${runtime}-dev" --execution=wasm --wasm-execution=compiled --pallet "*" --extrinsic "*" --repeat 0 | sed -r -e 's/Pallet: "([a-z_:]+)".*/\1/' | uniq | grep -v frame_system > "${runtime}_pallets" + while read -r line; do + pallet="$(echo "$line" | cut -d' ' -f1)"; + echo "Runtime: $runtime. Pallet: $pallet"; + cargo run --release --features="runtime-benchmarks,with-${runtime}-runtime" -- benchmark --chain="${runtime}-dev" --steps=50 --repeat=20 --pallet="$pallet" --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./HEADER-GPL3 --output="./runtime/${runtime}/src/weights/${pallet/::/_}.rs" + done < "${runtime}_pallets" + rm "${runtime}_pallets" +done \ No newline at end of file