Skip to content

Commit

Permalink
Weights per runtime (#3019)
Browse files Browse the repository at this point in the history
* fix test

* Merge remote-tracking branch 'origin/master' into tarekkma/weights-per-runtime

# Conflicts:
#	runtime/common/src/lib.rs
#	runtime/moonbase/src/weights/pallet_xcm_weight_trader.rs
#	runtime/moonbeam/src/lib.rs
#	runtime/moonbeam/src/precompiles.rs
#	runtime/moonriver/src/precompiles.rs

* fix parachain staking pallet per runtime (WIP)

* regenerate asset manager benchmarks per runtime

* fix parachain staking benchmarks

* regenerate weights locally in pallet asset manager

* re run all benchmarks for moonbeam

* re run all benchmarks for moonriver

* re run all benchmarks for moonbase

* fix pallet asset manager weights per runtime

* cargo fmt

* fix gas in integration tests

* Fix runtime integration tests

* take +1 different due to existential deposit

* fix pallet parameters

* simplify

* fmt

* revert to correct wights

* Update scripts/run-benches-for-runtime.sh

* add strategy for running for the 3 different runtimes

* prettier

* Re generated weights per runtime

* fix weights

* rollback adjustment for rewards percentage discrepancy

* prettier

* update pallet crowdloan weights for moonbase

* remove benchmarks for clear_suicided_storage (removed)

* revert unwanted changes in specs

* add pallet_xcm_weight_trader weights

* add pallets to define_benchmarks!

* regenerate pallet xcm weight trader from ubuntu machine

* re execute weights from cumulus_pallet_parachain_system

* Execute moonbeam/moonriver weights for pallet parameters

---------

Co-authored-by: Tarek Mohamed Abdalla <[email protected]>
  • Loading branch information
gonzamontiel and TarekkMA authored Nov 21, 2024
1 parent 8d67538 commit 5b3642d
Show file tree
Hide file tree
Showing 141 changed files with 14,764 additions and 961 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/check-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
needs: ["set-tags"]
runs-on:
labels: bare-metal
strategy:
matrix:
runtime: [moonbeam, moonbase, moonriver]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -58,7 +61,7 @@ jobs:
- name: Run benchmarks
shell: bash
run: |
./scripts/run-benches-for-runtime.sh moonbase release
./scripts/run-benches-for-runtime.sh ${{ matrix.runtime }} release
if test -f "benchmarking_errors.txt"; then
cat benchmarking_errors.txt
false
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

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

8 changes: 6 additions & 2 deletions pallets/parachain-staking/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,14 +963,16 @@ benchmarks! {
verify {
let state = Pallet::<T>::delegator_state(&last_top_delegator)
.expect("delegator must exist");
let current_round = Pallet::<T>::round().current;
let delegator_delay = <<T as Config>::LeaveDelegatorsDelay>::get();
assert_eq!(
Pallet::<T>::delegation_scheduled_requests(&collator)
.iter()
.find(|r| r.delegator == last_top_delegator)
.cloned(),
Some(ScheduledRequest {
delegator: last_top_delegator,
when_executable: 3,
when_executable: current_round + delegator_delay,
action: DelegationAction::Revoke(last_top_delegator_bond),
}),
);
Expand Down Expand Up @@ -1185,14 +1187,16 @@ benchmarks! {
verify {
let state = Pallet::<T>::delegator_state(&last_top_delegator)
.expect("just request bonded less so exists");
let current_round = Pallet::<T>::round().current;
let delegator_delay = <<T as Config>::DelegationBondLessDelay>::get();
assert_eq!(
Pallet::<T>::delegation_scheduled_requests(&collator)
.iter()
.find(|r| r.delegator == last_top_delegator)
.cloned(),
Some(ScheduledRequest {
delegator: last_top_delegator,
when_executable: 3,
when_executable: current_round + delegator_delay,
action: DelegationAction::Decrease(bond_less),
}),
);
Expand Down
2 changes: 0 additions & 2 deletions precompiles/relay-data-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version = "0.1.0"
# Moonbeam
storage-proof-primitives = { workspace = true }
pallet-precompile-benchmarks = { workspace = true }
moonbeam-runtime-common = { workspace = true }

# Substrate
cumulus-primitives-core = { workspace = true }
Expand Down Expand Up @@ -46,7 +45,6 @@ std = [
"frame-support/std",
"frame-system/std",
"fp-evm/std",
"moonbeam-runtime-common/std",
"parity-scale-codec/std",
"precompile-utils/std",
"pallet-evm/std",
Expand Down
12 changes: 6 additions & 6 deletions precompiles/relay-data-verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use core::marker::PhantomData;
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use fp_evm::{PrecompileFailure, PrecompileHandle};
use frame_support::{ensure, traits::ConstU32};
use moonbeam_runtime_common::weights::pallet_precompile_benchmarks::WeightInfo;
use pallet_precompile_benchmarks::WeightInfo as TWeightInfo;
use precompile_utils::prelude::*;
use sp_core::H256;
Expand All @@ -45,15 +44,16 @@ pub type GetArrayLimit = ConstU32<ARRAY_LIMIT>;
pub type RawKey = BoundedBytes<GetKeyLengthLimit>;

/// Relay Data Verifier precompile.
pub struct RelayDataVerifierPrecompile<Runtime>(PhantomData<Runtime>);
pub struct RelayDataVerifierPrecompile<Runtime, WeightInfo>(PhantomData<(Runtime, WeightInfo)>);

#[precompile_utils::precompile]
impl<Runtime> RelayDataVerifierPrecompile<Runtime>
impl<Runtime, WeightInfo> RelayDataVerifierPrecompile<Runtime, WeightInfo>
where
Runtime: frame_system::Config
+ pallet_relay_storage_roots::Config
+ pallet_evm::Config
+ pallet_precompile_benchmarks::Config,
WeightInfo: TWeightInfo,
{
/// Verify the storage entry using the provided relay block number and proof. Return the value
/// of the storage entry if the proof is valid and the entry exists.
Expand All @@ -66,7 +66,7 @@ where
key: RawKey,
) -> EvmResult<UnboundedBytes> {
// Charge gas for storage proof verification
let weight = WeightInfo::<Runtime>::verify_entry(proof.proof.len() as u32);
let weight = WeightInfo::verify_entry(proof.proof.len() as u32);
handle.record_external_cost(Some(weight.ref_time()), Some(0), Some(0))?;

// Get the storage root of the relay block
Expand Down Expand Up @@ -95,7 +95,7 @@ where
ensure!(keys.len() > 0, revert("Keys must not be empty"));

// Charge gas for storage proof verification
let weight = WeightInfo::<Runtime>::verify_entry(proof.proof.len() as u32);
let weight = WeightInfo::verify_entry(proof.proof.len() as u32);
handle.record_external_cost(Some(weight.ref_time()), Some(0), Some(0))?;

// Get the storage root of the relay block
Expand All @@ -119,7 +119,7 @@ where
#[precompile::public("latest_relay_block_number()")]
#[precompile::view]
fn latest_relay_block(handle: &mut impl PrecompileHandle) -> EvmResult<RelayBlockNumber> {
let weight = WeightInfo::<Runtime>::latest_relay_block();
let weight = WeightInfo::latest_relay_block();
handle.record_external_cost(Some(weight.ref_time()), Some(weight.proof_size()), Some(0))?;

pallet_relay_storage_roots::RelayStorageRootKeys::<Runtime>::get()
Expand Down
32 changes: 26 additions & 6 deletions precompiles/relay-data-verifier/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
use super::*;
use cumulus_pallet_parachain_system::{RelayChainState, RelaychainStateProvider};
use frame_support::{
construct_runtime, parameter_types, sp_runtime::traits::IdentityLookup, traits::Everything,
weights::Weight,
construct_runtime, parameter_types,
sp_runtime::traits::IdentityLookup,
traits::Everything,
weights::{RuntimeDbWeight, Weight},
};
use pallet_evm::{EnsureAddressNever, EnsureAddressRoot, SubstrateBlockHashMapping};
use parity_scale_codec::Decode;
Expand Down Expand Up @@ -146,10 +148,28 @@ impl pallet_relay_storage_roots::Config for Runtime {
type WeightInfo = ();
}

pub type Precompiles<R> =
PrecompileSetBuilder<R, PrecompileAt<AddressU64<1>, RelayDataVerifierPrecompile<R>>>;
pub struct MockWeightInfo;

pub type PCall = RelayDataVerifierPrecompileCall<Runtime>;
impl pallet_precompile_benchmarks::WeightInfo for MockWeightInfo {
fn verify_entry(x: u32) -> Weight {
Weight::from_parts(76_430_000, 0)
.saturating_add(Weight::from_parts(678_469, 0).saturating_mul(x.into()))
}
fn latest_relay_block() -> Weight {
Weight::from_parts(4_641_000, 1606)
.saturating_add(<() as Get<RuntimeDbWeight>>::get().reads(1_u64))
}
fn p256_verify() -> Weight {
Weight::from_parts(1_580_914_000, 0).saturating_mul(1u64)
}
}

pub type Precompiles<R> = PrecompileSetBuilder<
R,
PrecompileAt<AddressU64<1>, RelayDataVerifierPrecompile<R, MockWeightInfo>>,
>;

pub type PCall = RelayDataVerifierPrecompileCall<Runtime, MockWeightInfo>;

const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
/// Block storage limit in bytes. Set to 40 KB.
Expand Down Expand Up @@ -195,7 +215,7 @@ impl pallet_evm::Config for Runtime {
}

impl pallet_precompile_benchmarks::Config for Runtime {
type WeightInfo = WeightInfo<Runtime>;
type WeightInfo = MockWeightInfo;
}

pub(crate) struct ExtBuilder {
Expand Down
6 changes: 2 additions & 4 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod apis;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
mod impl_moonbeam_xcm_call;
mod impl_moonbeam_xcm_call_tracing;
mod impl_on_charge_evm_transaction;
Expand All @@ -25,7 +27,3 @@ mod impl_xcm_evm_runner;
pub mod migrations;
pub mod timestamp;
pub mod types;
pub mod weights;

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
2 changes: 1 addition & 1 deletion runtime/moonbase/src/asset_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use super::{
RuntimeCall, RuntimeEvent, RuntimeOrigin, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX,
};

use moonbeam_runtime_common::weights as moonbase_weights;
use super::moonbase_weights;
use moonkit_xcm_primitives::AccountIdAssetIdConversion;

use frame_support::{
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/src/governance/councils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

//! Councils for Gov1 and Gov2
use super::moonbase_weights;
use super::*;
use moonbeam_runtime_common::weights as moonbase_weights;

pub type TreasuryCouncilInstance = pallet_collective::Instance3;
pub type OpenTechCommitteeInstance = pallet_collective::Instance4;
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/src/governance/referenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
//! 2. pallet-whitelist
//! 3. pallet-referenda
use super::moonbase_weights;
use super::*;
use crate::currency::*;
use frame_support::traits::{EitherOf, MapSuccess};
use frame_system::EnsureRootWithSuccess;
use moonbeam_runtime_common::weights as moonbase_weights;
use sp_runtime::traits::Replace;

parameter_types! {
Expand Down
8 changes: 4 additions & 4 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ use frame_support::{
use frame_system::{EnsureRoot, EnsureSigned};
use governance::councils::*;
use moonbeam_rpc_primitives_txpool::TxPoolResponse;
use moonbeam_runtime_common::{
timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp},
weights as moonbase_weights,
};
use moonbeam_runtime_common::timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp};
use nimbus_primitives::CanAuthor;
use pallet_ethereum::Call::transact;
use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction};
Expand Down Expand Up @@ -133,6 +130,9 @@ pub use sp_runtime::BuildStorage;

pub type Precompiles = MoonbasePrecompiles<Runtime>;

mod weights;
pub(crate) use weights as moonbase_weights;

/// UNIT, the native token, uses 18 decimals of precision.
pub mod currency {
use super::Balance;
Expand Down
7 changes: 5 additions & 2 deletions runtime/moonbase/src/precompiles.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/>.

use super::moonbase_weights;
use crate::{
asset_config::ForeignAssetInstance,
xcm_config::{AssetType, XcmExecutorConfig},
OpenTechCommitteeInstance, TreasuryCouncilInstance,
};
use crate::{AccountId, AssetId, AssetManager, Balances, Erc20XcmBridge, Runtime, H160};
use frame_support::parameter_types;
use moonbeam_runtime_common::weights as moonbase_weights;
use moonkit_xcm_primitives::{
location_matcher::{Erc20PalletMatcher, ForeignAssetMatcher, SingleAddressMatcher},
AccountIdAssetIdConversion,
Expand Down Expand Up @@ -271,7 +271,10 @@ type MoonbasePrecompilesAt<R> = (
>,
PrecompileAt<
AddressU64<2073>,
RelayDataVerifierPrecompile<R>,
RelayDataVerifierPrecompile<
R,
moonbase_weights::pallet_precompile_benchmarks::WeightInfo<Runtime>,
>,
(CallableByContract, CallableByPrecompile),
>,
PrecompileAt<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Autogenerated weights for `cumulus_pallet_parachain_system`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0
//! DATE: 2024-10-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-11-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024
Expand All @@ -34,7 +34,7 @@
// --wasm-execution=compiled
// --header=./file_header.txt
// --template=./benchmarking/frame-weight-template.hbs
// --output=./runtime/common/src/weights/
// --output=./runtime/moonbase/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
Expand All @@ -61,10 +61,10 @@ impl<T: frame_system::Config> cumulus_pallet_parachain_system::WeightInfo for We
// Proof Size summary in bytes:
// Measured: `82`
// Estimated: `3517`
// Minimum execution time: 2_264_000 picoseconds.
Weight::from_parts(2_385_000, 3517)
// Standard Error: 22_805
.saturating_add(Weight::from_parts(293_496_971, 0).saturating_mul(n.into()))
// Minimum execution time: 2_153_000 picoseconds.
Weight::from_parts(2_247_000, 3517)
// Standard Error: 37_208
.saturating_add(Weight::from_parts(295_984_445, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
Expand Down
Loading

0 comments on commit 5b3642d

Please sign in to comment.