Skip to content

Commit

Permalink
[MOON-2531] Generate weights for runtime (#2442)
Browse files Browse the repository at this point in the history
* use generated benchmarks

* use locally generated weights

* use generated weights

* use runtime weights

* use local benchmarked weight

* fix xcm benchmarks

* update substrate

* use benchmark server computed weights

* add BenchmarkHelper to pallet assets mock

* fix TARGET_FILL_AMOUNT const

---------

Co-authored-by: Agusrodri <[email protected]>
  • Loading branch information
nbaztec and Agusrodri authored Aug 29, 2023
1 parent 781669a commit d0ae4a5
Show file tree
Hide file tree
Showing 81 changed files with 8,056 additions and 1,179 deletions.
496 changes: 256 additions & 240 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ fp-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "mo
fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false }
fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false }
pallet-base-fee = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false }
pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false, features = [ "forbid-evm-reentrancy" ] }
pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false, features = [
"forbid-evm-reentrancy",
] }
pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false, features = [
"forbid-evm-reentrancy",
] }
Expand Down Expand Up @@ -351,7 +353,10 @@ parking_lot = "0.12.0"
primitive-types = "0.12.0"
prometheus = { version = "0.13.0", default-features = false }
rand = "0.7.3"
schnorrkel = { version = "0.9.1", default-features = false, features = [ "preaudit_deprecated", "u64_backend" ] }
schnorrkel = { version = "0.9.1", default-features = false, features = [
"preaudit_deprecated",
"u64_backend",
] }
serde_json = { version = "1.0" }
similar-asserts = "1.1.0"
tempfile = "3.2.0"
Expand Down
15 changes: 15 additions & 0 deletions file_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019-2022 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/>.
6 changes: 6 additions & 0 deletions node/service/src/chain_spec/moonbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ pub fn development_chain_spec(mnemonic: Option<String>, num_accounts: Option<u32
"6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b"
)));

// Prefund the benchmark account for frontier, if compiling for benchmarks
#[cfg(feature = "runtime-benchmarks")]
accounts.push(AccountId::from(hex!(
"1000000000000000000000000000000000000001"
)));

ChainSpec::from_genesis(
"Moonbase Development Testnet",
"moonbase_dev",
Expand Down
5 changes: 3 additions & 2 deletions pallets/asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ pub mod mock;
pub mod tests;
pub mod weights;

pub use crate::weights::WeightInfo;

#[pallet]
pub mod pallet {

use crate::weights::WeightInfo;
use super::*;
use frame_support::{
pallet_prelude::*,
traits::{Currency, ReservableCurrency},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub trait WeightInfo {
fn clear_topic() -> Weight;
fn exchange_asset() -> Weight;
fn universal_origin() -> Weight;
fn export_message() -> Weight;
fn set_fees_mode() -> Weight;
fn lock_asset() -> Weight;
fn unlock_asset() -> Weight;
Expand Down Expand Up @@ -395,6 +396,16 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Minimum execution time: 500_000_000_000 picoseconds.
Weight::from_parts(500_000_000_000, 0)
}
/// Storage: Benchmark Override (r:0 w:0)
/// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured)
/// The range of component `x` is `[1, 1000]`.
fn export_message() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 18_446_744_073_709_551_000 picoseconds.
Weight::from_parts(500_000_000_000, 0)
}
fn set_fees_mode() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
Expand Down Expand Up @@ -752,6 +763,16 @@ impl WeightInfo for () {
// Minimum execution time: 500_000_000_000 picoseconds.
Weight::from_parts(500_000_000_000, 0)
}
/// Storage: Benchmark Override (r:0 w:0)
/// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured)
/// The range of component `x` is `[1, 1000]`.
fn export_message() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 18_446_744_073_709_551_000 picoseconds.
Weight::from_parts(500_000_000_000, 0)
}
fn set_fees_mode() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
Expand Down
10 changes: 5 additions & 5 deletions pallets/moonbeam-xcm-benchmarks/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

mod moonbeam_xcm_benchmarks_fungible;
mod moonbeam_xcm_benchmarks_generic;
pub mod fungible;
pub mod generic;

use crate::weights::moonbeam_xcm_benchmarks_generic::WeightInfo;
pub use crate::weights::generic::WeightInfo;
use core::cmp::min;
use frame_support::weights::Weight;
use moonbeam_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use moonbeam_xcm_benchmarks_generic::SubstrateWeight as XcmGeneric;
use fungible::WeightInfo as XcmFungibleWeight;
use generic::SubstrateWeight as XcmGeneric;
use sp_std::prelude::*;
use xcm::{
latest::{prelude::*, Weight as XCMWeight},
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod tests;

use frame_support::pallet;
pub use inflation::{InflationInfo, Range};
use weights::WeightInfo;
pub use weights::WeightInfo;

pub use auto_compound::{AutoCompoundConfig, AutoCompoundDelegations};
pub use delegation_requests::{CancelledScheduledRequest, DelegationAction, ScheduledRequest};
Expand Down
8 changes: 4 additions & 4 deletions pallets/parachain-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8406,7 +8406,7 @@ fn test_on_initialize_weights() {
let weight = ParachainStaking::on_initialize(1);

// TODO: build this with proper db reads/writes
assert_eq!(Weight::from_parts(281952000, 0), weight);
assert_eq!(Weight::from_parts(277027000, 0), weight);

// roll to the end of the round, then run on_init again, we should see round change...
roll_to_round_end(3);
Expand All @@ -8420,8 +8420,8 @@ fn test_on_initialize_weights() {
//
// following this assertion, we add individual weights together to show that we can
// derive this number independently.
let expected_on_init = 2501354773;
assert_eq!(Weight::from_parts(expected_on_init, 187584), weight);
let expected_on_init = 2491581615;
assert_eq!(Weight::from_parts(expected_on_init, 32562), weight);

// assemble weight manually to ensure it is well understood
let mut expected_weight = 0u64;
Expand All @@ -8441,7 +8441,7 @@ fn test_on_initialize_weights() {
// more reads/writes manually accounted for for on_finalize
expected_weight += RocksDbWeight::get().reads_writes(3, 2).ref_time();

assert_eq!(Weight::from_parts(expected_weight, 187584), weight);
assert_eq!(Weight::from_parts(expected_weight, 32562), weight);
assert_eq!(expected_on_init, expected_weight); // magic number == independent accounting
});
}
Expand Down
Loading

0 comments on commit d0ae4a5

Please sign in to comment.