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

Generate weights per runtime #2939

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
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.

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
1 change: 0 additions & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod impl_self_contained_call;
mod impl_xcm_evm_runner;
pub mod migrations;
pub mod timestamp;
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 @@ -136,6 +133,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
File renamed without changes.
2 changes: 1 addition & 1 deletion runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
//! XCM configuration for Moonbase.
//!

use super::moonbase_weights;
use super::{
governance, AccountId, AssetId, AssetManager, Balance, Balances, DealWithFees,
EmergencyParaXcm, Erc20XcmBridge, EvmForeignAssets, MaintenanceMode, MessageQueue,
ParachainInfo, ParachainSystem, Perbill, PolkadotXcm, Runtime, RuntimeBlockWeights,
RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury, XcmpQueue,
};
use crate::OpenTechCommitteeInstance;
use moonbeam_runtime_common::weights as moonbase_weights;
use moonkit_xcm_primitives::AccountIdAssetIdConversion;
use sp_runtime::{
traits::{Hash as THash, MaybeEquivalence, PostDispatchInfoOf},
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/asset_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use super::{
FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX,
};

use super::moonbeam_weights;
use frame_support::{
dispatch::GetDispatchInfo,
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, EitherOfDiverse},
weights::Weight,
};
use moonbeam_runtime_common::weights as moonbeam_weights;
use moonkit_xcm_primitives::AccountIdAssetIdConversion;

use frame_system::{EnsureNever, EnsureRoot};
Expand Down
8 changes: 4 additions & 4 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ pub use moonbeam_core_primitives::{
Index, Signature,
};
use moonbeam_rpc_primitives_txpool::TxPoolResponse;
use moonbeam_runtime_common::{
timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp},
weights as moonbeam_weights,
};
use moonbeam_runtime_common::timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp};
use pallet_ethereum::Call::transact;
use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction};
use pallet_evm::{
Expand Down Expand Up @@ -125,8 +122,11 @@ pub type Precompiles = MoonbeamPrecompiles<Runtime>;

pub mod asset_config;
pub mod governance;
mod weights;
pub mod xcm_config;

use governance::councils::*;
pub(crate) use weights as moonbeam_weights;

/// GLMR, the native token, uses 18 decimals of precision.
pub mod currency {
Expand Down
7 changes: 5 additions & 2 deletions runtime/moonbeam/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
// 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::moonbeam_weights;
use crate::{
asset_config::ForeignAssetInstance, xcm_config::XcmExecutorConfig, OpenTechCommitteeInstance,
Runtime, TreasuryCouncilInstance,
};
use crate::{AssetId, H160};
use frame_support::parameter_types;
use moonbeam_runtime_common::weights as moonbeam_weights;
use moonkit_xcm_primitives::AccountIdAssetIdConversion;
use pallet_evm_precompile_author_mapping::AuthorMappingPrecompile;
use pallet_evm_precompile_balances_erc20::{Erc20BalancesPrecompile, Erc20Metadata};
Expand Down Expand Up @@ -246,7 +246,10 @@ type MoonbeamPrecompilesAt<R> = (
>,
PrecompileAt<
AddressU64<2073>,
RelayDataVerifierPrecompile<R>,
RelayDataVerifierPrecompile<
R,
moonbeam_weights::pallet_precompile_benchmarks::WeightInfo<Runtime>,
>,
(CallableByContract, CallableByPrecompile),
>,
);
Expand Down
72 changes: 72 additions & 0 deletions runtime/moonbeam/src/weights/cumulus_pallet_parachain_system.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2024 Moonbeam foundation
// 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 `cumulus_pallet_parachain_system`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-08-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `MacBook-Pro-de-romarq.local`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024

// Executed Command:
// ./target/release/moonbeam
// benchmark
// pallet
// --chain=moonbase-dev
// --steps=50
// --repeat=20
// --pallet=cumulus_pallet_parachain_system
// --extrinsic=*
// --wasm-execution=compiled
// --header=./file_header.txt
// --template=./benchmarking/frame-weight-template.hbs
// --output=./runtime/common/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

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

/// Weights for `cumulus_pallet_parachain_system`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> cumulus_pallet_parachain_system::WeightInfo for WeightInfo<T> {
/// Storage: `ParachainSystem::LastDmqMqcHead` (r:1 w:1)
/// Proof: `ParachainSystem::LastDmqMqcHead` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `MessageQueue::BookStateFor` (r:1 w:1)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::ServiceHead` (r:1 w:1)
/// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`)
/// Storage: `ParachainSystem::ProcessedDownwardMessages` (r:0 w:1)
/// Proof: `ParachainSystem::ProcessedDownwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `MessageQueue::Pages` (r:0 w:1000)
/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(107993), added: 110468, mode: `MaxEncodedLen`)
/// The range of component `n` is `[0, 1000]`.
fn enqueue_inbound_downward_messages(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `82`
// Estimated: `3517`
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(2_000_000, 3517)
// Standard Error: 914_274
.saturating_add(Weight::from_parts(213_425_397, 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())))
}
}
Loading
Loading