Skip to content

Commit

Permalink
overhead benchmark comment added
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Dec 2, 2024
1 parent ac5d44b commit 96a0520
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
9 changes: 9 additions & 0 deletions bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostFunctions>;

type FullClient = sc_service::TFullClient<Block, RuntimeApi, ParachainExecutor>;
Expand Down
9 changes: 9 additions & 0 deletions bin/collator/src/parachain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HostFunctions>;

Expand Down
2 changes: 2 additions & 0 deletions runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
82 changes: 82 additions & 0 deletions runtime/shibuya/src/weights/base_extrinsic.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

// 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."
);
}
}
1 change: 1 addition & 0 deletions runtime/shibuya/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

pub mod base_extrinsic;
pub mod orml_oracle;
pub mod pallet_assets;
pub mod pallet_balances;
Expand Down
16 changes: 16 additions & 0 deletions scripts/run_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 96a0520

Please sign in to comment.