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

Weights per runtime #3019

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e55b0d2
fix test
TarekkMA Sep 11, 2024
a7c7eda
Merge remote-tracking branch 'origin/master' into tarekkma/weights-pe…
gonzamontiel Oct 18, 2024
44008c4
fix parachain staking pallet per runtime (WIP)
gonzamontiel Oct 18, 2024
aaaca99
regenerate asset manager benchmarks per runtime
gonzamontiel Oct 21, 2024
9ad2268
fix parachain staking benchmarks
gonzamontiel Oct 21, 2024
809b8f4
regenerate weights locally in pallet asset manager
gonzamontiel Oct 21, 2024
4f97d73
re run all benchmarks for moonbeam
gonzamontiel Oct 24, 2024
ff30ba5
re run all benchmarks for moonriver
gonzamontiel Oct 25, 2024
7473c14
re run all benchmarks for moonbase
gonzamontiel Oct 25, 2024
10ce9ab
fix pallet asset manager weights per runtime
gonzamontiel Oct 28, 2024
cf9a5ba
Merge branch 'master' into gonza/weights-per-runtime
gonzamontiel Oct 30, 2024
5f88ea4
cargo fmt
gonzamontiel Oct 30, 2024
7b8ab7d
fix gas in integration tests
gonzamontiel Nov 1, 2024
12bac22
Merge branch 'master' into gonza/weights-per-runtime
gonzamontiel Nov 4, 2024
85200b2
Merge remote-tracking branch 'origin/master' into gonza/weights-per-r…
gonzamontiel Nov 6, 2024
819b1fb
Fix runtime integration tests
gonzamontiel Nov 7, 2024
3e43444
Merge branch 'master' into gonza/weights-per-runtime
gonzamontiel Nov 7, 2024
10c39e0
take +1 different due to existential deposit
gonzamontiel Nov 8, 2024
7f4f7c6
fix pallet parameters
gonzamontiel Nov 10, 2024
0929a46
simplify
gonzamontiel Nov 10, 2024
27f3d1b
Merge remote-tracking branch 'origin/master' into gonza/weights-per-r…
gonzamontiel Nov 10, 2024
80ff518
Merge branch 'gonza/weights-per-runtime' of github.com:moonbeam-found…
gonzamontiel Nov 10, 2024
d9d6189
fmt
gonzamontiel Nov 11, 2024
8967e0c
revert to correct wights
gonzamontiel Nov 11, 2024
ea4af8b
Update scripts/run-benches-for-runtime.sh
gonzamontiel Nov 11, 2024
21b6804
add strategy for running for the 3 different runtimes
gonzamontiel Nov 11, 2024
eca0630
prettier
gonzamontiel Nov 11, 2024
62079dd
Re generated weights per runtime
gonzamontiel Nov 12, 2024
819ee11
fix weights
gonzamontiel Nov 13, 2024
f81ab3f
rollback adjustment for rewards percentage discrepancy
gonzamontiel Nov 13, 2024
41eadb6
Merge remote-tracking branch 'origin/master' into gonza/weights-per-r…
gonzamontiel Nov 13, 2024
09de778
prettier
gonzamontiel Nov 13, 2024
5b03853
Merge branch 'master' into gonza/weights-per-runtime
gonzamontiel Nov 13, 2024
9e8b6d6
update pallet crowdloan weights for moonbase
gonzamontiel Nov 14, 2024
3f92f27
Merge branch 'master' into gonza/weights-per-runtime
gonzamontiel Nov 15, 2024
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
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-11, 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_128_000 picoseconds.
Weight::from_parts(91_853_295, 3517)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge increase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird, I don't see a big difference in the final weights comparison: 393.97ms to 393.71ms using subweight.

// Standard Error: 63_404
.saturating_add(Weight::from_parts(293_145_862, 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
Loading