Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
dharjeezy committed Dec 25, 2024
1 parent 03a3ad8 commit 213fcd1
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 117 deletions.
9 changes: 2 additions & 7 deletions modules/ismp/clients/parachain/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ sp-inherents = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-consensus-aura = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }

# cumulus
cumulus-pallet-parachain-system = { workspace = true, default-features = false }
Expand Down Expand Up @@ -62,12 +61,7 @@ std = [
"pallet-ismp/std",
"substrate-state-machine/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks"
]

try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
Expand All @@ -79,4 +73,5 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-ismp/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
]
43 changes: 35 additions & 8 deletions modules/ismp/clients/parachain/client/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,60 @@ mod benchmarks {
use super::*;
use ismp::messaging::{ConsensusMessage, Message};

/// Benchmark for add_parachain extrinsic
/// The benchmark creates n parachains and measures the time to add them
/// to the whitelist.
///
/// Parameters:
/// - `n`: Number of parachains to add in a single call
#[benchmark]
fn add_parachain() -> Result<(), BenchmarkError> {
let state_machines: Vec<ParachainData> =
(0..10).map(|i| ParachainData { id: i, slot_duration: 6000 }).collect();
fn add_parachain(n: Linear<1, 100>) -> Result<(), BenchmarkError> {
let parachains: Vec<ParachainData> = (0..n)
.map(|i| {
ParachainData {
id: i,
slot_duration: 6000u64,
}
})
.collect();

#[block]
{
Pallet::<T>::add_parachain(RawOrigin::Root.into(), state_machines)?;
Pallet::<T>::add_parachain(RawOrigin::Root.into(), parachains)?;
}

Ok(())
}

/// Benchmark for remove_parachain extrinsic
/// The benchmark first adds n parachains, then measures the time to remove them
/// from the whitelist.
///
/// Parameters:
/// - `n`: Number of parachains to remove in a single call
#[benchmark]
fn remove_parachain() -> Result<(), BenchmarkError> {
let state_machines: Vec<ParachainData> =
(0..10).map(|i| ParachainData { id: i, slot_duration: 6000 }).collect();
fn remove_parachain(n: Linear<1, 100>) -> Result<(), BenchmarkError> {
let parachains: Vec<ParachainData> = (0..n)
.map(|i| {
ParachainData {
id: i,
slot_duration: 6000u64,
}
})
.collect();

#[block]
{
Pallet::<T>::add_parachain(RawOrigin::Root.into(), state_machines)?;
Pallet::<T>::add_parachain(RawOrigin::Root.into(), parachains)?;
Pallet::<T>::remove_parachain(RawOrigin::Root.into(), vec![0, 1, 2, 3, 4])?;
}

Ok(())
}

/// Benchmark for update_parachain_consensus extrinsic
/// The benchmark first insert a Parachain, then sets the ValidationData,
/// afterward proceed to update the parachain consensus.
#[benchmark]
fn update_parachain_consensus() -> Result<(), BenchmarkError> {
let consensus_message = ConsensusMessage {
Expand Down
5 changes: 3 additions & 2 deletions modules/ismp/clients/parachain/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod migration;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
/// weights trait crate
pub mod weights;

pub use consensus::*;
Expand All @@ -37,7 +38,7 @@ use cumulus_pallet_parachain_system::{
use cumulus_primitives_core::relay_chain;
use ismp::{handlers, messaging::CreateConsensusState};
pub use pallet::*;
pub use weights::WeightInfoTrait;
pub use weights::WeightInfo;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -68,7 +69,7 @@ pub mod pallet {
/// The underlying [`IsmpHost`] implementation
type IsmpHost: IsmpHost + Default;
/// WeightInfo
type WeightInfo: WeightInfoTrait;
type WeightInfo: WeightInfo;
}

/// Mapping of relay chain heights to it's state commitment. The state commitment of the parent
Expand Down
108 changes: 11 additions & 97 deletions modules/ismp/clients/parachain/client/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,102 +13,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Autogenerated weights for `ismp_parachain`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0
//! DATE: 2024-12-15, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Akinloses-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
// Executed Command:
// frame-omni-bencher
// v1
// benchmark
// pallet
// --runtime
// /Users/dharjeezy/Documents/polytope/hyperbridge/target/release/wbuild/gargantua-runtime/gargantua_runtime.compact.wasm
// --pallet
// ismp-parachain
// --all
// --steps
// 2
// --repeat
// 1
// --output
// ismp-parachain-weight.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;

pub trait WeightInfoTrait {
fn add_parachain() -> Weight;
fn remove_parachain() -> Weight;
use frame_support::weights::Weight;
/// The weight information provider trait for dispatchable extrinsics
pub trait WeightInfo {
/// Weight for adding parachains, scaled by the number of machines
/// * n: The number of parachains being added
fn add_parachain(n: u32) -> Weight;
/// Weight for removing parachains, scaled by the number of machines
/// * n: The number of parachains being removed
fn remove_parachain(n: u32) -> Weight;
/// Weight for updating a parachain's consensus
fn update_parachain_consensus() -> Weight;

}
/// Weight functions for `ismp_parachain`.
pub struct WeightInfo<T>(PhantomData<T>);

impl<T: frame_system::Config> WeightInfoTrait for WeightInfo<T> {
/// Storage: `ParachainInfo::ParachainId` (r:1 w:0)
/// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `IsmpParachain::Parachains` (r:0 w:10)
/// Proof: `IsmpParachain::Parachains` (`max_values`: None, `max_size`: Some(12), added: 2487, mode: `MaxEncodedLen`)
/// Storage: `Ismp::ChallengePeriod` (r:0 w:10)
/// Proof: `Ismp::ChallengePeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn add_parachain() -> Weight {
// Proof Size summary in bytes:
// Measured: `103`
// Estimated: `1489`
// Minimum execution time: 48_000_000 picoseconds.
Weight::from_parts(48_000_000, 0)
.saturating_add(Weight::from_parts(0, 1489))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(20))
}
/// Storage: `ParachainInfo::ParachainId` (r:1 w:0)
/// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `IsmpParachain::Parachains` (r:0 w:10)
/// Proof: `IsmpParachain::Parachains` (`max_values`: None, `max_size`: Some(12), added: 2487, mode: `MaxEncodedLen`)
/// Storage: `Ismp::ChallengePeriod` (r:0 w:10)
/// Proof: `Ismp::ChallengePeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_parachain() -> Weight {
// Proof Size summary in bytes:
// Measured: `103`
// Estimated: `1489`
// Minimum execution time: 58_000_000 picoseconds.
Weight::from_parts(58_000_000, 0)
.saturating_add(Weight::from_parts(0, 1489))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(20))
}
/// Storage: `IsmpParachain::ConsensusUpdated` (r:1 w:0)
/// Proof: `IsmpParachain::ConsensusUpdated` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
/// Storage: `Ismp::ConsensusStateClient` (r:1 w:0)
/// Proof: `Ismp::ConsensusStateClient` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Ismp::ConsensusStates` (r:1 w:0)
/// Proof: `Ismp::ConsensusStates` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Ismp::FrozenConsensusClients` (r:1 w:0)
/// Proof: `Ismp::FrozenConsensusClients` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `Ismp::UnbondingPeriod` (r:1 w:0)
/// Proof: `Ismp::UnbondingPeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Ismp::ConsensusClientUpdateTime` (r:1 w:0)
/// Proof: `Ismp::ConsensusClientUpdateTime` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_parachain_consensus() -> Weight {
// Proof Size summary in bytes:
// Measured: `333`
// Estimated: `3798`
// Minimum execution time: 42_000_000 picoseconds.
Weight::from_parts(42_000_000, 0)
.saturating_add(Weight::from_parts(0, 3798))
.saturating_add(T::DbWeight::get().reads(7))
}
}
}
2 changes: 1 addition & 1 deletion parachain/runtimes/gargantua/src/ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl pallet_call_decompressor::Config for Runtime {
impl ismp_parachain::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = Ismp;
type WeightInfo = ismp_parachain::weights::WeightInfo<Runtime>;
type WeightInfo = weights::ismp_parachain::WeightInfo<Runtime>;
}

impl pallet_fishermen::Config for Runtime {
Expand Down
108 changes: 108 additions & 0 deletions parachain/runtimes/gargantua/src/weights/ismp_parachain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (C) Polytope Labs Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Autogenerated weights for `ismp_parachain`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0
//! DATE: 2024-12-15, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Akinloses-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
// Executed Command:
// frame-omni-bencher
// v1
// benchmark
// pallet
// --runtime
// /Users/dharjeezy/Documents/polytope/hyperbridge/target/release/wbuild/gargantua-runtime/gargantua_runtime.compact.wasm
// --pallet
// ismp-parachain
// --all
// --steps
// 2
// --repeat
// 1
// --output
// ismp-parachain-weight.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;

/// Weight functions for `ismp_parachain`.
pub struct WeightInfo<T>(PhantomData<T>);

impl<T: frame_system::Config> ismp_parachain::WeightInfo for WeightInfo<T> {
/// Storage: `ParachainInfo::ParachainId` (r:1 w:0)
/// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `IsmpParachain::Parachains` (r:0 w:10)
/// Proof: `IsmpParachain::Parachains` (`max_values`: None, `max_size`: Some(12), added: 2487, mode: `MaxEncodedLen`)
/// Storage: `Ismp::ChallengePeriod` (r:0 w:10)
/// Proof: `Ismp::ChallengePeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn add_parachain(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `103`
// Estimated: `1489`
// Minimum execution time: 48_000_000 picoseconds.
Weight::from_parts(48_000_000, 0)
.saturating_add(Weight::from_parts(0, 1489))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(20))
}
/// Storage: `ParachainInfo::ParachainId` (r:1 w:0)
/// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `IsmpParachain::Parachains` (r:0 w:10)
/// Proof: `IsmpParachain::Parachains` (`max_values`: None, `max_size`: Some(12), added: 2487, mode: `MaxEncodedLen`)
/// Storage: `Ismp::ChallengePeriod` (r:0 w:10)
/// Proof: `Ismp::ChallengePeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_parachain(n: u32,) -> Weight {
// Proof Size summary in bytes:
// Measured: `103`
// Estimated: `1489`
// Minimum execution time: 58_000_000 picoseconds.
Weight::from_parts(58_000_000, 0)
.saturating_add(Weight::from_parts(0, 1489))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(20))
}
/// Storage: `IsmpParachain::ConsensusUpdated` (r:1 w:0)
/// Proof: `IsmpParachain::ConsensusUpdated` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
/// Storage: `Ismp::ConsensusStateClient` (r:1 w:0)
/// Proof: `Ismp::ConsensusStateClient` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Ismp::ConsensusStates` (r:1 w:0)
/// Proof: `Ismp::ConsensusStates` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Ismp::FrozenConsensusClients` (r:1 w:0)
/// Proof: `Ismp::FrozenConsensusClients` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `Ismp::UnbondingPeriod` (r:1 w:0)
/// Proof: `Ismp::UnbondingPeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Ismp::ConsensusClientUpdateTime` (r:1 w:0)
/// Proof: `Ismp::ConsensusClientUpdateTime` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_parachain_consensus() -> Weight {
// Proof Size summary in bytes:
// Measured: `333`
// Estimated: `3798`
// Minimum execution time: 42_000_000 picoseconds.
Weight::from_parts(42_000_000, 0)
.saturating_add(Weight::from_parts(0, 3798))
.saturating_add(T::DbWeight::get().reads(7))
}
}
1 change: 1 addition & 0 deletions parachain/runtimes/gargantua/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod cumulus_pallet_parachain_system;
pub mod cumulus_pallet_xcmp_queue;
pub mod frame_system;
pub mod ismp_grandpa;
pub mod ismp_parachain;
pub mod pallet_asset_rate;
pub mod pallet_assets;
pub mod pallet_balances;
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/messier/src/ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl pallet_ismp_host_executive::Config for Runtime {
impl ismp_parachain::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = Ismp;
type WeightInfo = ismp_parachain::weights::WeightInfo<Runtime>;
type WeightInfo = weights::ismp_parachain::WeightInfo<Runtime>;
}

impl pallet_call_decompressor::Config for Runtime {
Expand Down
Loading

0 comments on commit 213fcd1

Please sign in to comment.