diff --git a/Cargo.lock b/Cargo.lock index 44c6b56787..1630f73395 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14466,6 +14466,7 @@ dependencies = [ "sp-std", "sp-transaction-pool", "sp-version", + "sp-weights", "staging-parachain-info", "staging-xcm", "staging-xcm-builder", diff --git a/Cargo.toml b/Cargo.toml index 6d207a4814..857e8a929e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -114,6 +114,7 @@ sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk", branch = " sp-staking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false } sp-externalities = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false } sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false } +sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false } # (native) sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } diff --git a/bin/collator/src/local/service.rs b/bin/collator/src/local/service.rs index 7c3c210441..039a943ab5 100644 --- a/bin/collator/src/local/service.rs +++ b/bin/collator/src/local/service.rs @@ -47,11 +47,20 @@ use astar_primitives::*; const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; /// Parachain host functions +#[cfg(not(feature = "runtime-benchmarks"))] pub type HostFunctions = ( cumulus_client_service::ParachainHostFunctions, moonbeam_primitives_ext::moonbeam_ext::HostFunctions, ); +/// Host functions required for kitchensink runtime and Substrate node. +#[cfg(feature = "runtime-benchmarks")] +pub type HostFunctions = ( + frame_benchmarking::benchmarking::HostFunctions, + cumulus_client_service::ParachainHostFunctions, + moonbeam_primitives_ext::moonbeam_ext::HostFunctions, +); + type ParachainExecutor = WasmExecutor; type FullClient = sc_service::TFullClient; diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index 64566c934e..b8c6fcb9f0 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -62,11 +62,20 @@ use crate::{ }; /// Parachain host functions +#[cfg(not(feature = "runtime-benchmarks"))] pub type HostFunctions = ( cumulus_client_service::ParachainHostFunctions, moonbeam_primitives_ext::moonbeam_ext::HostFunctions, ); +/// Host functions required for kitchensink runtime and Substrate node. +#[cfg(feature = "runtime-benchmarks")] +pub type HostFunctions = ( + frame_benchmarking::benchmarking::HostFunctions, + cumulus_client_service::ParachainHostFunctions, + moonbeam_primitives_ext::moonbeam_ext::HostFunctions, +); + /// Parachain executor pub type ParachainExecutor = WasmExecutor; diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 4f06299215..4dce8933a5 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -36,6 +36,7 @@ sp-session = { workspace = true } sp-std = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } +sp-weights = { workspace = true } # frame dependencies frame-executive = { workspace = true } @@ -264,6 +265,7 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", + "sp-weights/std", "substrate-wasm-builder", "vesting-mbm/std", "xcm-builder/std", diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 3463018ce8..bd54f01d69 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -249,9 +249,7 @@ parameter_types! { pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() .base_block(BlockExecutionWeight::get()) .for_class(DispatchClass::all(), |weights| { - // Adjusting the base extrinsic weight to account for the additional database - // read introduced by the `tx-pause` pallet during extrinsic filtering. - weights.base_extrinsic = ExtrinsicBaseWeight::get().saturating_add(RocksDbWeight::get().reads(1)); + weights.base_extrinsic = weights::base_extrinsic::ExtrinsicBaseWeight::get(); }) .for_class(DispatchClass::Normal, |weights| { weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); diff --git a/runtime/shibuya/src/weights/base_extrinsic.rs b/runtime/shibuya/src/weights/base_extrinsic.rs new file mode 100644 index 0000000000..f94c16cc62 --- /dev/null +++ b/runtime/shibuya/src/weights/base_extrinsic.rs @@ -0,0 +1,82 @@ +// This file is part of Astar. + +// Copyright (C) Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +// This is just a dummy file. + +use sp_core::parameter_types; +use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight}; + +// parameter_types! { +// /// Time to execute a NO-OP extrinsic, for example `System::remark`. +// /// Calculated by multiplying the *Average* with `1.0` and adding `0`. +// /// +// /// Stats nanoseconds: +// /// Min, Max: 106_559, 107_788 +// /// Average: 107_074 +// /// Median: 107_067 +// /// Std-Dev: 242.67 +// /// +// /// Percentiles nanoseconds: +// /// 99th: 107_675 +// /// 95th: 107_513 +// /// 75th: 107_225 +// pub const ExtrinsicBaseWeight: Weight = +// Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(107_074), 0); +// } + +parameter_types! { + /// Time to execute a NO-OP extrinsic, for example `System::remark`. + /// Calculated by multiplying the *Average* with `1.0` and adding `0`. + /// + /// Stats nanoseconds: + /// Min, Max: 87_894, 99_268 + /// Average: 90_705 + /// Median: 90_325 + /// Std-Dev: 2344.95 + /// + /// Percentiles nanoseconds: + /// 99th: 99_232 + /// 95th: 96_405 + /// 75th: 91_204 + pub const ExtrinsicBaseWeight: Weight = + Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(90_705), 0); +} + +#[cfg(test)] +mod test_weights { + use sp_weights::constants; + + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::ExtrinsicBaseWeight::get(); + + // At least 10 µs. + assert!( + w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS, + "Weight should be at least 10 µs." + ); + // At most 1 ms. + assert!( + w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Weight should be at most 1 ms." + ); + } +} diff --git a/runtime/shibuya/src/weights/mod.rs b/runtime/shibuya/src/weights/mod.rs index 93a7d79b6f..f4d73f8812 100644 --- a/runtime/shibuya/src/weights/mod.rs +++ b/runtime/shibuya/src/weights/mod.rs @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with Astar. If not, see . +pub mod base_extrinsic; pub mod orml_oracle; pub mod pallet_assets; pub mod pallet_balances; diff --git a/scripts/run_benchmarks.sh b/scripts/run_benchmarks.sh index c739e4762d..dc90465601 100755 --- a/scripts/run_benchmarks.sh +++ b/scripts/run_benchmarks.sh @@ -137,6 +137,22 @@ for chain in ${chains//,/ }; do fi done + # Update the block and extrinsic overhead weights. + echo "[+] Benchmarking block and extrinsic overheads..." + OUTPUT=$( + ./target/production/polkadot benchmark overhead \ + --chain=$chain \ + --wasm-execution=compiled \ + --weight-path="$output_path/$chain/" \ + --warmup=10 \ + --repeat=100 \ + --header=./.github/license-check/headers/HEADER-GNUv3 + ) + if [ $? -ne 0 ]; then + echo "$OUTPUT" >> "$ERR_FILE" + echo "[-] Failed to benchmark the block and extrinsic overheads. Error written to $ERR_FILE; continuing..." + fi + echo "[+] Benchmarking the machine..." OUTPUT=$( $ASTAR_COLLATOR benchmark machine --chain=$chain 2>&1