From 7d6c168aba8b4e1946ceb28ab58aa83bf1d23054 Mon Sep 17 00:00:00 2001 From: Alexandru Gheorghe Date: Fri, 5 Dec 2025 00:59:42 +0200 Subject: [PATCH 1/4] asset-hub-polkadot: use inmemorydb weights Signed-off-by: Alexandru Gheorghe --- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 4 +- .../src/weights/inmemorydb_weights.rs | 108 ++++++++++++++++++ .../asset-hub-polkadot/src/weights/mod.rs | 3 +- 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 system-parachains/asset-hubs/asset-hub-polkadot/src/weights/inmemorydb_weights.rs diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index b385abcad2..cccc77e29f 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -176,7 +176,7 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::{ claims as pallet_claims, prod_or_fast, BlockHashCount, SlowAdjustingFeeUpdate, }; -use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; +use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, InMemoryDbWeight}; impl_opaque_keys! { pub struct SessionKeys { @@ -246,7 +246,7 @@ impl frame_system::Config for Runtime { type RuntimeTask = RuntimeTask; type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; - type DbWeight = RocksDbWeight; + type DbWeight = InMemoryDbWeight; type Version = Version; type PalletInfo = PalletInfo; type OnNewAccount = (); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/inmemorydb_weights.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/inmemorydb_weights.rs new file mode 100644 index 0000000000..abc9dcf6ee --- /dev/null +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/inmemorydb_weights.rs @@ -0,0 +1,108 @@ +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 49.1.0 +//! DATE: 2025-09-10 (Y/M/D) +//! HOSTNAME: `versi-developer-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! +//! DATABASE: `InMemoryDb`, RUNTIME: `Polkadot Asset Hub` +//! BLOCK-NUM: `BlockId::Number(9640792)` +//! SKIP-WRITE: `false`, SKIP-READ: `false`, WARMUPS: `1` +//! STATE-VERSION: `V1`, STATE-CACHE-SIZE: `` +//! WEIGHT-PATH: `` +//! METRIC: `Average`, WEIGHT-MUL: `1.0`, WEIGHT-ADD: `0` + +// Executed Command: +// ./target/production/polkadot-parachain +// benchmark +// storage +// --warmups +// 1 +// --state-version +// 1 +// --base-path +// /opt/local-ssd/polkadot-asset-hub/ +// --chain +// cumulus/polkadot-parachain/chain-specs/asset-hub-polkadot.json +// --detailed-log-output +// --enable-trie-cache +// --trie-cache-size +// 10737418240 +// --batch-size +// 10000 +// --mode +// validate-block +// --validate-block-rounds +// 100 + +/// Storage DB weights for the `Polkadot Asset Hub` runtime and `InMemoryDb`. +pub mod constants { + use frame_support::weights::constants; + use sp_core::parameter_types; + use sp_weights::RuntimeDbWeight; + + parameter_types! { + /// `InMemoryDb` weights are measured in the context of the validation functions. + /// To avoid submitting overweight blocks to the relay chain this is the configuration + /// parachains should use. + pub const InMemoryDbWeight: RuntimeDbWeight = RuntimeDbWeight { + // Time to read one storage item. + // Calculated by multiplying the *Average* of all values with `1.0` and adding `0`. + // + // Stats nanoseconds: + // Min, Max: 13_036, 14_636 + // Average: 13_701 + // Median: 13_739 + // Std-Dev: 327.35 + // + // Percentiles nanoseconds: + // 99th: 14_322 + // 95th: 14_185 + // 75th: 13_962 + read: 13_701 * constants::WEIGHT_REF_TIME_PER_NANOS, + + // Time to write one storage item. + // Calculated by multiplying the *Average* of all values with `1.0` and adding `0`. + // + // Stats nanoseconds: + // Min, Max: 31_957, 34_238 + // Average: 33_060 + // Median: 33_048 + // Std-Dev: 230.45 + // + // Percentiles nanoseconds: + // 99th: 33_927 + // 95th: 33_440 + // 75th: 33_157 + write: 33_060 * constants::WEIGHT_REF_TIME_PER_NANOS, + }; + } + + #[cfg(test)] + mod test_db_weights { + use super::InMemoryDbWeight as W; + use sp_weights::constants; + + /// Checks that all weights exist and have sane values. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn bound() { + // At least 1 µs. + assert!( + W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Read weight should be at least 1 µs." + ); + assert!( + W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Write weight should be at least 1 µs." + ); + // At most 1 ms. + assert!( + W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Read weight should be at most 1 ms." + ); + assert!( + W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Write weight should be at most 1 ms." + ); + } + } +} diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/mod.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/mod.rs index 00518d202f..217ed280d4 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/mod.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/mod.rs @@ -20,6 +20,7 @@ pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; pub mod frame_system_extensions; +pub mod inmemorydb_weights; pub mod pallet_ah_migrator; pub mod pallet_ah_ops; pub mod pallet_asset_conversion; @@ -67,4 +68,4 @@ pub mod xcm; pub use block_weights::constants::BlockExecutionWeight; pub use extrinsic_weights::constants::ExtrinsicBaseWeight; -pub use rocksdb_weights::constants::RocksDbWeight; +pub use inmemorydb_weights::constants::InMemoryDbWeight; From d120102a4585f07ad84a59f6ac0af0f2679dfc6e Mon Sep 17 00:00:00 2001 From: Alexandru Gheorghe Date: Fri, 5 Dec 2025 01:06:29 +0200 Subject: [PATCH 2/4] update changelog Signed-off-by: Alexandru Gheorghe --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 769731a555..9c4e7315bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add `cumulus-pallet-weight-reclaim` to all Kusama system parachains for storage weight reclaim functionality ([#941](https://github.com/polkadot-fellows/runtimes/pull/941)) - asset-hub-kusama: use inmemorydb weights([polkadot-fellows/runtimes/pull/918](https://github.com/polkadot-fellows/runtimes/pull/918)) +- asset-hub-polkadot: use inmemorydb weights([polkadot-fellows/runtimes/pull/918](https://github.com/polkadot-fellows/runtimes/pull/918)) ## [2.0.3] 21.11.2025 From 419716f3d4e076d25e663e327e69b1423e0d08b3 Mon Sep 17 00:00:00 2001 From: Alexandru Gheorghe Date: Tue, 9 Dec 2025 10:57:27 +0200 Subject: [PATCH 3/4] update changelog Signed-off-by: Alexandru Gheorghe --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c4e7315bc..2278831959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add `cumulus-pallet-weight-reclaim` to all Kusama system parachains for storage weight reclaim functionality ([#941](https://github.com/polkadot-fellows/runtimes/pull/941)) - asset-hub-kusama: use inmemorydb weights([polkadot-fellows/runtimes/pull/918](https://github.com/polkadot-fellows/runtimes/pull/918)) -- asset-hub-polkadot: use inmemorydb weights([polkadot-fellows/runtimes/pull/918](https://github.com/polkadot-fellows/runtimes/pull/918)) +- asset-hub-polkadot: use inmemorydb weights([polkadot-fellows/runtimes/pull/918](https://github.com/polkadot-fellows/runtimes/pull/1025)) ## [2.0.3] 21.11.2025 From e2c5830f2684c73cec374b9003737824d54b1cea Mon Sep 17 00:00:00 2001 From: Alexandru Gheorghe Date: Wed, 10 Dec 2025 13:17:03 +0200 Subject: [PATCH 4/4] keep weights for snowbridge_pallet_system_backend unchanged Signed-off-by: Alexandru Gheorghe --- .../snowbridge_pallet_system_backend.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/snowbridge_pallet_system_backend.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/snowbridge_pallet_system_backend.rs index cb9a44c1a5..ea1ea610b8 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/snowbridge_pallet_system_backend.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/snowbridge_pallet_system_backend.rs @@ -18,48 +18,53 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; /// Weight functions for `snowbridge_pallet_system_frontend::BackendWeightInfo`. pub struct WeightInfo(PhantomData); impl snowbridge_pallet_system_frontend::BackendWeightInfo for WeightInfo { /// Copy the weight generated for `fn register_token() -> Weight` from ../../../../bridge-hubs/bridge-hub-polkadot/src/weights/snowbridge_pallet_system_v2.rs + /// Use `RocksDbWeight::get()` to get the weight of reads and writes, in order to keep the weights the same as in Bridge Hub. fn transact_register_token() -> Weight { Weight::from_parts(53_009_000, 0) .saturating_add(Weight::from_parts(0, 4115)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(4)) } /// Copy the weight generated for `fn add_tip() -> Weight` from ../../../../bridge-hubs/bridge-hub-polkadot/src/weights/snowbridge_pallet_system_v2.rs + /// Use `RocksDbWeight::get()` to get the weight of reads and writes, in order to keep the weights the same as in Bridge Hub. fn transact_add_tip() -> Weight { Weight::from_parts(12_440_000, 0) .saturating_add(Weight::from_parts(0, 3505)) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) } /// Copy the weight generated for `fn do_process_message() -> Weight` from ../../../../bridge-hubs/bridge-hub-polkadot/src/weights/snowbridge_pallet_outbound_queue_v2.rs + /// Use `RocksDbWeight::get()` to get the weight of reads and writes, in order to keep the weights the same as in Bridge Hub. fn do_process_message() -> Weight { Weight::from_parts(29_560_000, 0) .saturating_add(Weight::from_parts(0, 1527)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(4)) } /// Copy the weight generated for `fn commit_single() -> Weight` from ../../../../bridge-hubs/bridge-hub-polkadot/src/weights/snowbridge_pallet_outbound_queue_v2.rs + /// Use `RocksDbWeight::get()` to get the weight of reads and writes, in order to keep the weights the same as in Bridge Hub. fn commit_single() -> Weight { Weight::from_parts(11_960_000, 0) .saturating_add(Weight::from_parts(0, 1620)) - .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().reads(1)) } /// Copy the weight generated for `fn submit_delivery_receipt() -> Weight` from ../../../../bridge-hubs/bridge-hub-polkadot/src/weights/snowbridge_pallet_outbound_queue_v2.rs + /// Use `RocksDbWeight::get()` to get the weight of reads and writes, in order to keep the weights the same as in Bridge Hub. fn submit_delivery_receipt() -> Weight { Weight::from_parts(142_070_000, 0) .saturating_add(Weight::from_parts(0, 3762)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(1)) } }