Skip to content

Commit 69cdc6c

Browse files
authored
Benchmarking and more cleanup (#42)
* Benchmark nits * bench bot + script * Update polkadot-sdk master because of benchmarking bug (at the end we should change it to the unstable2507) * Setup benchmarking
1 parent ee7dec4 commit 69cdc6c

File tree

18 files changed

+1212
-472
lines changed

18 files changed

+1212
-472
lines changed

Cargo.lock

Lines changed: 267 additions & 267 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 79 additions & 79 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ Controls the validator set. Currently set in genesis and validators can be added
4848

4949
#### polkadot-bulletin-chain/pallets/transaction-storage
5050
Stores arbitrary data on IPFS via the `store` extrinsic, provided that either the signer or the preimage of the data are pre-authorized. Stored data can be retrieved from IPFS or directly from the node via the transaction index or hash.
51+
52+
### Fresh benchmarks
53+
54+
Run on the dedicated machine from the root directory:
55+
```
56+
python3 scripts/cmd/cmd.py bench bulletin-polkadot
57+
```

runtimes/bulletin-polkadot/src/bridge-primitives/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
extern crate alloc;
2323

2424
// TODO: move here the stuff from
25-
// bp-polkadot-bulletin = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "db5e645422ccf952018a3c466a33fef477858602", default-features = false }
25+
// bp-polkadot-bulletin = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false }

runtimes/bulletin-polkadot/src/lib.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl frame_system::Config for Runtime {
256256

257257
impl pallet_validator_set::Config for Runtime {
258258
type RuntimeEvent = RuntimeEvent;
259-
type WeightInfo = pallet_validator_set::weights::SubstrateWeight<Runtime>;
259+
type WeightInfo = weights::pallet_validator_set::WeightInfo<Runtime>;
260260
type AddRemoveOrigin = EnsureRoot<AccountId>;
261261
type MaxAuthorities = MaxAuthorities;
262262
type SetKeysCooldownBlocks = SetKeysCooldownBlocks;
@@ -289,7 +289,7 @@ impl pallet_babe::Config for Runtime {
289289
type ExpectedBlockTime = ConstU64<MILLISECS_PER_BLOCK>;
290290
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
291291
type DisabledValidators = Session;
292-
// TODO: weights
292+
293293
type WeightInfo = ();
294294
type MaxAuthorities = MaxAuthorities;
295295
type MaxNominators = ConstU32<0>;
@@ -305,7 +305,7 @@ impl pallet_babe::Config for Runtime {
305305

306306
impl pallet_grandpa::Config for Runtime {
307307
type RuntimeEvent = RuntimeEvent;
308-
// TODO: weights
308+
309309
type WeightInfo = ();
310310
type MaxAuthorities = MaxAuthorities;
311311
type MaxNominators = ConstU32<0>;
@@ -336,14 +336,14 @@ impl pallet_timestamp::Config for Runtime {
336336
type Moment = u64;
337337
type OnTimestampSet = Babe;
338338
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
339-
// TODO: weights
340-
type WeightInfo = ();
339+
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
341340
}
342341

343342
impl pallet_transaction_storage::Config for Runtime {
344343
type RuntimeEvent = RuntimeEvent;
345-
type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight<Runtime>;
344+
type WeightInfo = weights::pallet_transaction_storage::WeightInfo<Runtime>;
346345
type MaxBlockTransactions = ConstU32<512>;
346+
// TODO: add here comment
347347
type MaxTransactionSize = ConstU32<{ 8 * 1024 * 1024 }>;
348348
type StoragePeriod = StoragePeriod;
349349
type AuthorizationPeriod = AuthorizationPeriod;
@@ -356,7 +356,7 @@ impl pallet_transaction_storage::Config for Runtime {
356356

357357
impl pallet_relayer_set::Config for Runtime {
358358
type RuntimeEvent = RuntimeEvent;
359-
type WeightInfo = pallet_relayer_set::weights::SubstrateWeight<Runtime>;
359+
type WeightInfo = weights::pallet_relayer_set::WeightInfo<Runtime>;
360360
type AddRemoveOrigin = EnsureRoot<AccountId>;
361361
type BridgeTxFailCooldownBlocks = BridgeTxFailCooldownBlocks;
362362
}
@@ -631,8 +631,10 @@ pub type Executive = frame_executive::Executive<
631631

632632
#[cfg(feature = "runtime-benchmarks")]
633633
mod benches {
634+
use super::*;
635+
634636
frame_benchmarking::define_benchmarks!(
635-
[frame_benchmarking, BaselineBench::<Runtime>]
637+
[frame_benchmarking::baseline, Baseline::<Runtime>]
636638
[frame_system, SystemBench::<Runtime>]
637639
[pallet_timestamp, Timestamp]
638640
[pallet_transaction_storage, TransactionStorage]
@@ -643,8 +645,22 @@ mod benches {
643645
// [pallet_bridge_parachains, BridgeParachainsBench::<Runtime, bridge_config::WithPolkadotBridgeParachainsInstance>]
644646
// [pallet_bridge_messages, BridgeMessagesBench::<Runtime, bridge_config::WithPeoplePolkadotMessagesInstance>]
645647
);
648+
649+
pub use frame_benchmarking::{baseline::Pallet as Baseline, BenchmarkBatch, BenchmarkList};
650+
pub use frame_system_benchmarking::Pallet as SystemBench;
651+
652+
pub use frame_support::traits::{StorageInfoTrait, WhitelistedStorageKeys};
653+
pub use pallet_bridge_messages::benchmarking::Pallet as BridgeMessagesBench;
654+
pub use pallet_bridge_parachains::benchmarking::Pallet as BridgeParachainsBench;
655+
pub use sp_storage::TrackedStorageKey;
656+
657+
impl frame_system_benchmarking::Config for Runtime {}
658+
impl frame_benchmarking::baseline::Config for Runtime {}
646659
}
647660

661+
#[cfg(feature = "runtime-benchmarks")]
662+
use benches::*;
663+
648664
impl_runtime_apis! {
649665
impl sp_api::Core<Block> for Runtime {
650666
fn version() -> RuntimeVersion {
@@ -883,41 +899,18 @@ impl_runtime_apis! {
883899
Vec<frame_benchmarking::BenchmarkList>,
884900
Vec<frame_support::traits::StorageInfo>,
885901
) {
886-
use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
887-
use frame_support::traits::StorageInfoTrait;
888-
use frame_system_benchmarking::Pallet as SystemBench;
889-
use baseline::Pallet as BaselineBench;
890-
891-
use pallet_bridge_parachains::benchmarking::Pallet as BridgeParachainsBench;
892-
use pallet_bridge_messages::benchmarking::Pallet as BridgeMessagesBench;
893-
894902
let mut list = Vec::<BenchmarkList>::new();
895903
list_benchmarks!(list, extra);
896904

897905
let storage_info = AllPalletsWithSystem::storage_info();
898-
899906
(list, storage_info)
900907
}
901908

902909
#[allow(non_local_definitions)]
903910
fn dispatch_benchmark(
904911
config: frame_benchmarking::BenchmarkConfig
905912
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
906-
use sp_storage::TrackedStorageKey;
907-
use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch};
908-
909-
use frame_system_benchmarking::Pallet as SystemBench;
910-
use baseline::Pallet as BaselineBench;
911-
912-
use pallet_bridge_parachains::benchmarking::Pallet as BridgeParachainsBench;
913-
use pallet_bridge_messages::benchmarking::Pallet as BridgeMessagesBench;
914-
915-
impl frame_system_benchmarking::Config for Runtime {}
916-
impl baseline::Config for Runtime {}
917-
918-
use frame_support::traits::WhitelistedStorageKeys;
919913
let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
920-
921914
let mut batches = Vec::<BenchmarkBatch>::new();
922915
let params = (&config, &whitelist);
923916
add_benchmarks!(params, batches);

runtimes/bulletin-polkadot/src/polkadot_bridge_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ parameter_types! {
201201
pub type WithPolkadotBridgeGrandpaInstance = ();
202202
impl pallet_bridge_grandpa::Config<WithPolkadotBridgeGrandpaInstance> for Runtime {
203203
type RuntimeEvent = RuntimeEvent;
204-
type WeightInfo = crate::weights::bridge_polkadot_grandpa::WeightInfo<Runtime>;
204+
type WeightInfo = crate::weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
205205

206206
type BridgedChain = bp_polkadot::Polkadot;
207207
type MaxFreeHeadersPerBlock = MaxFreePolkadotHeadersPerBlock;

runtimes/bulletin-polkadot/src/weights/bridge_polkadot_grandpa.rs

Lines changed: 0 additions & 84 deletions
This file was deleted.

runtimes/bulletin-polkadot/src/weights/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
//! Expose the auto generated weight files.
22
3+
use ::pallet_bridge_grandpa::WeightInfoExt as GrandpaWeightInfoExt;
4+
use ::pallet_bridge_messages::WeightInfoExt as MessagesWeightInfoExt;
5+
use ::pallet_bridge_parachains::WeightInfoExt as ParachainsWeightInfoExt;
6+
use ::pallet_bridge_relayers::WeightInfo as _;
37
use frame_support::weights::Weight;
4-
use pallet_bridge_relayers::WeightInfo;
58

6-
pub mod bridge_polkadot_grandpa;
79
pub mod bridge_polkadot_messages;
810
pub mod bridge_polkadot_parachains;
911
pub mod bridge_polkadot_relayers;
12+
pub mod pallet_bridge_grandpa;
13+
pub mod pallet_relayer_set;
14+
pub mod pallet_timestamp;
15+
pub mod pallet_transaction_storage;
16+
pub mod pallet_validator_set;
1017

11-
impl pallet_bridge_grandpa::WeightInfoExt for bridge_polkadot_grandpa::WeightInfo<crate::Runtime> {
18+
impl GrandpaWeightInfoExt for pallet_bridge_grandpa::WeightInfo<crate::Runtime> {
1219
fn submit_finality_proof_overhead_from_runtime() -> Weight {
1320
// our signed extension:
1421
// 1) checks whether relayer registration is active from validate/pre_dispatch;
@@ -18,9 +25,7 @@ impl pallet_bridge_grandpa::WeightInfoExt for bridge_polkadot_grandpa::WeightInf
1825
}
1926
}
2027

21-
impl pallet_bridge_parachains::WeightInfoExt
22-
for bridge_polkadot_parachains::WeightInfo<crate::Runtime>
23-
{
28+
impl ParachainsWeightInfoExt for bridge_polkadot_parachains::WeightInfo<crate::Runtime> {
2429
fn expected_extra_storage_proof_size() -> u32 {
2530
crate::bp_people_polkadot::EXTRA_STORAGE_PROOF_SIZE
2631
}
@@ -34,9 +39,7 @@ impl pallet_bridge_parachains::WeightInfoExt
3439
}
3540
}
3641

37-
impl pallet_bridge_messages::WeightInfoExt
38-
for bridge_polkadot_messages::WeightInfo<crate::Runtime>
39-
{
42+
impl MessagesWeightInfoExt for bridge_polkadot_messages::WeightInfo<crate::Runtime> {
4043
fn expected_extra_storage_proof_size() -> u32 {
4144
crate::bp_people_polkadot::EXTRA_STORAGE_PROOF_SIZE
4245
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md
2+
// for a list of specific contributors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
//! Autogenerated weights for `pallet_bridge_grandpa`
18+
//!
19+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
20+
//! DATE: 2025-08-28, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
21+
//! WORST CASE MAP SIZE: `1000000`
22+
//! HOSTNAME: `toaster1`, CPU: `AMD Ryzen Threadripper 7980X 64-Cores`
23+
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
24+
25+
// Executed Command:
26+
// frame-omni-bencher
27+
// v1
28+
// benchmark
29+
// pallet
30+
// --extrinsic=*
31+
// --runtime=target/production/wbuild/bulletin-polkadot-runtime/bulletin_polkadot_runtime.wasm
32+
// --pallet=pallet_bridge_grandpa
33+
// --header=/home/bkontur/cargo-remote-builds-bulletin/9907520327012243881/scripts/cmd/file_header.txt
34+
// --output=./runtimes/bulletin-polkadot/src/weights
35+
// --wasm-execution=compiled
36+
// --steps=2
37+
// --repeat=1
38+
// --heap-pages=4096
39+
40+
#![cfg_attr(rustfmt, rustfmt_skip)]
41+
#![allow(unused_parens)]
42+
#![allow(unused_imports)]
43+
#![allow(missing_docs)]
44+
45+
use frame_support::{traits::Get, weights::Weight};
46+
use core::marker::PhantomData;
47+
48+
/// Weight functions for `pallet_bridge_grandpa`.
49+
pub struct WeightInfo<T>(PhantomData<T>);
50+
impl<T: frame_system::Config> pallet_bridge_grandpa::WeightInfo for WeightInfo<T> {
51+
/// Storage: `BridgePolkadotGrandpa::CurrentAuthoritySet` (r:1 w:0)
52+
/// Proof: `BridgePolkadotGrandpa::CurrentAuthoritySet` (`max_values`: Some(1), `max_size`: Some(50250), added: 50745, mode: `MaxEncodedLen`)
53+
/// Storage: `BridgePolkadotGrandpa::PalletOperatingMode` (r:1 w:0)
54+
/// Proof: `BridgePolkadotGrandpa::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
55+
/// Storage: `BridgePolkadotGrandpa::BestFinalized` (r:1 w:1)
56+
/// Proof: `BridgePolkadotGrandpa::BestFinalized` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`)
57+
/// Storage: `BridgePolkadotGrandpa::ImportedHashesPointer` (r:1 w:1)
58+
/// Proof: `BridgePolkadotGrandpa::ImportedHashesPointer` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
59+
/// Storage: `BridgePolkadotGrandpa::ImportedHashes` (r:1 w:1)
60+
/// Proof: `BridgePolkadotGrandpa::ImportedHashes` (`max_values`: Some(1200), `max_size`: Some(36), added: 1521, mode: `MaxEncodedLen`)
61+
/// Storage: `BridgePolkadotGrandpa::ImportedHeaders` (r:0 w:2)
62+
/// Proof: `BridgePolkadotGrandpa::ImportedHeaders` (`max_values`: Some(1200), `max_size`: Some(68), added: 1553, mode: `MaxEncodedLen`)
63+
/// The range of component `p` is `[1, 168]`.
64+
/// The range of component `v` is `[50, 100]`.
65+
fn submit_finality_proof(p: u32, v: u32, ) -> Weight {
66+
// Proof Size summary in bytes:
67+
// Measured: `49 + p * (59 ±0)`
68+
// Estimated: `51735`
69+
// Minimum execution time: 258_153_000 picoseconds.
70+
Weight::from_parts(40_939_721, 0)
71+
.saturating_add(Weight::from_parts(0, 51735))
72+
// Standard Error: 148_691
73+
.saturating_add(Weight::from_parts(25_170_278, 0).saturating_mul(p.into()))
74+
// Standard Error: 496_630
75+
.saturating_add(Weight::from_parts(1_920_430, 0).saturating_mul(v.into()))
76+
.saturating_add(T::DbWeight::get().reads(5))
77+
.saturating_add(T::DbWeight::get().writes(5))
78+
}
79+
/// Storage: `BridgePolkadotGrandpa::CurrentAuthoritySet` (r:1 w:1)
80+
/// Proof: `BridgePolkadotGrandpa::CurrentAuthoritySet` (`max_values`: Some(1), `max_size`: Some(50250), added: 50745, mode: `MaxEncodedLen`)
81+
/// Storage: `BridgePolkadotGrandpa::ImportedHashesPointer` (r:1 w:1)
82+
/// Proof: `BridgePolkadotGrandpa::ImportedHashesPointer` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
83+
/// Storage: `BridgePolkadotGrandpa::ImportedHashes` (r:1 w:1)
84+
/// Proof: `BridgePolkadotGrandpa::ImportedHashes` (`max_values`: Some(1200), `max_size`: Some(36), added: 1521, mode: `MaxEncodedLen`)
85+
/// Storage: `BridgePolkadotGrandpa::BestFinalized` (r:0 w:1)
86+
/// Proof: `BridgePolkadotGrandpa::BestFinalized` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`)
87+
/// Storage: `BridgePolkadotGrandpa::ImportedHeaders` (r:0 w:2)
88+
/// Proof: `BridgePolkadotGrandpa::ImportedHeaders` (`max_values`: Some(1200), `max_size`: Some(68), added: 1553, mode: `MaxEncodedLen`)
89+
fn force_set_pallet_state() -> Weight {
90+
// Proof Size summary in bytes:
91+
// Measured: `84`
92+
// Estimated: `51735`
93+
// Minimum execution time: 92_470_000 picoseconds.
94+
Weight::from_parts(92_470_000, 0)
95+
.saturating_add(Weight::from_parts(0, 51735))
96+
.saturating_add(T::DbWeight::get().reads(3))
97+
.saturating_add(T::DbWeight::get().writes(6))
98+
}
99+
}

0 commit comments

Comments
 (0)