Skip to content

Commit

Permalink
regenerate weights
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Dec 18, 2024
1 parent 7896cc6 commit 3111704
Show file tree
Hide file tree
Showing 38 changed files with 1,289 additions and 1,268 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion docs/pages/developers/network/relayer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ You can obtain the required etherscan API key by following [this guide](https://

### Contract addresses

You can find the addresses for the `IsmpHost` contracts for [mainnet](developers/evm/contracts/mainnet) and [testnet](developers/evm/contracts/testnet)
You can find the addresses for the `IsmpHost` contracts for [mainnet](/developers/evm/contracts/mainnet) and [testnet](/developers/evm/contracts/testnet)

## Withdrawing Fees

Expand Down
22 changes: 11 additions & 11 deletions modules/consensus/sync-committee/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ impl<C: Config, const ETH1_DATA_VOTES_BOUND: usize> SyncCommitteeProver<C, ETH1_
finality_checkpoint: Checkpoint,
latest_block_id: Option<&str>,
) -> Result<Option<VerifierStateUpdate>, anyhow::Error> {
if finality_checkpoint.root == Node::default()
|| client_state.latest_finalized_epoch >= finality_checkpoint.epoch
if finality_checkpoint.root == Node::default() ||
client_state.latest_finalized_epoch >= finality_checkpoint.epoch
{
trace!(target: "sync-committee-prover", "No new epoch finalized yet {}", finality_checkpoint.epoch);
return Ok(None);
Expand Down Expand Up @@ -287,9 +287,9 @@ impl<C: Config, const ETH1_DATA_VOTES_BOUND: usize> SyncCommitteeProver<C, ETH1_

let signature_period = compute_sync_committee_period_at_slot::<C>(block.slot);

if num_signatures >= min_signatures
&& (state_period..=state_period + 1).contains(&signature_period)
&& parent_block_finality_checkpoint.epoch > client_state.latest_finalized_epoch
if num_signatures >= min_signatures &&
(state_period..=state_period + 1).contains(&signature_period) &&
parent_block_finality_checkpoint.epoch > client_state.latest_finalized_epoch
{
break;
}
Expand Down Expand Up @@ -354,10 +354,10 @@ impl<C: Config, const ETH1_DATA_VOTES_BOUND: usize> SyncCommitteeProver<C, ETH1_
period: u64,
) -> Result<VerifierStateUpdate, anyhow::Error> {
trace!(target: "sync-committee-prover", "latest_update_for_period {period}");
let mut higest_slot_in_epoch = ((period * C::EPOCHS_PER_SYNC_COMMITTEE_PERIOD)
* C::SLOTS_PER_EPOCH)
+ (C::EPOCHS_PER_SYNC_COMMITTEE_PERIOD * C::SLOTS_PER_EPOCH)
- 1;
let mut higest_slot_in_epoch = ((period * C::EPOCHS_PER_SYNC_COMMITTEE_PERIOD) *
C::SLOTS_PER_EPOCH) +
(C::EPOCHS_PER_SYNC_COMMITTEE_PERIOD * C::SLOTS_PER_EPOCH) -
1;
let mut count = 0;
// Some slots are empty so we'll use a loop to fetch the highest available slot in an epoch
let mut block = loop {
Expand Down Expand Up @@ -494,8 +494,8 @@ pub fn prove_block_roots_proof<C: Config, const ETH1_DATA_VOTES_BOUND: usize>(
let epoch_for_header = compute_epoch_at_slot::<C>(header.slot) as usize;
let epoch_for_state = compute_epoch_at_slot::<C>(state.slot) as usize;

if epoch_for_state.saturating_sub(epoch_for_header)
>= SLOTS_PER_HISTORICAL_ROOT / C::SLOTS_PER_EPOCH as usize
if epoch_for_state.saturating_sub(epoch_for_header) >=
SLOTS_PER_HISTORICAL_ROOT / C::SLOTS_PER_EPOCH as usize
{
// todo: Historical root proofs
unimplemented!()
Expand Down
4 changes: 2 additions & 2 deletions modules/ismp/clients/grandpa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-grandpa"
version = "1.15.3"
version = "1.15.4"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand Down Expand Up @@ -70,4 +70,4 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-ismp/runtime-benchmarks",
]
]
137 changes: 71 additions & 66 deletions modules/ismp/clients/grandpa/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,83 +1,88 @@
#![cfg(feature = "runtime-benchmarks")]
// Copyright (c) 2024 Polytope Labs.
// 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 lang

//! Benchmarks for the ISMP GRANDPA pallet operations
use super::*;
use frame_benchmarking::v2::*;
use frame_support::pallet_prelude::Weight;
use frame_system::RawOrigin;
use sp_std::prelude::*;

/// Benchmarks for the ISMP GRANDPA pallet operations
#[benchmarks]
mod benchmarks {
use super::*;
use super::*;

/// Benchmark for add_state_machines extrinsic
/// The benchmark creates n state machines and measures the time to add them
/// to the whitelist.
///
/// Parameters:
/// - `n`: Number of state machines to add in a single call
#[benchmark]
fn add_state_machines(n: Linear<1, 100>) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();

let state_machines: Vec<AddStateMachine> = (0..n)
.map(|i| {
let id = [i as u8, 0, 0, 0]; // Create unique 4-byte identifier
AddStateMachine {
state_machine: StateMachine::Substrate(id),
slot_duration: 6000u64,
}
})
.collect();
/// Benchmark for add_state_machines extrinsic
/// The benchmark creates n state machines and measures the time to add them
/// to the whitelist.
///
/// Parameters:
/// - `n`: Number of state machines to add in a single call
#[benchmark]
fn add_state_machines(n: Linear<1, 100>) -> Result<(), BenchmarkError> {
let state_machines: Vec<AddStateMachine> = (0..n)
.map(|i| {
let id = [i as u8, 0, 0, 0]; // Create unique 4-byte identifier
AddStateMachine {
state_machine: StateMachine::Substrate(id),
slot_duration: 6000u64,
}
})
.collect();

#[extrinsic_call]
_(RawOrigin::Root, state_machines);
#[extrinsic_call]
_(RawOrigin::Root, state_machines);

// Verify operation was successful
assert!(SupportedStateMachines::<T>::iter().count() == n as usize);
Ok(())
}
// Verify operation was successful
assert!(SupportedStateMachines::<T>::iter().count() == n as usize);
Ok(())
}

/// Benchmark for remove_state_machines extrinsic
/// The benchmark first adds n state machines, then measures the time to remove them
/// from the whitelist.
///
/// Parameters:
/// - `n`: Number of state machines to remove in a single call
#[benchmark]
fn remove_state_machines(n: Linear<1, 100>) -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();

// Setup: First add state machines that we'll remove
let setup_machines: Vec<AddStateMachine> = (0..n)
.map(|i| {
let id = [i as u8, 0, 0, 0]; // Create unique 4-byte identifier
AddStateMachine {
state_machine: StateMachine::Substrate(id),
slot_duration: 6000u64,
}
})
.collect();
/// Benchmark for remove_state_machines extrinsic
/// The benchmark first adds n state machines, then measures the time to remove them
/// from the whitelist.
///
/// Parameters:
/// - `n`: Number of state machines to remove in a single call
#[benchmark]
fn remove_state_machines(n: Linear<1, 100>) -> Result<(), BenchmarkError> {
// Setup: First add state machines that we'll remove
let setup_machines: Vec<AddStateMachine> = (0..n)
.map(|i| {
let id = [i as u8, 0, 0, 0]; // Create unique 4-byte identifier
AddStateMachine {
state_machine: StateMachine::Substrate(id),
slot_duration: 6000u64,
}
})
.collect();

// Add the machines using root origin
Pallet::<T>::add_state_machines(
RawOrigin::Root.into(),
setup_machines.clone(),
)?;
// Add the machines using root origin
Pallet::<T>::add_state_machines(RawOrigin::Root.into(), setup_machines.clone())?;

// Create removal list
let remove_machines: Vec<StateMachine> =
setup_machines.into_iter().map(|m| m.state_machine).collect();
// Create removal list
let remove_machines: Vec<StateMachine> =
setup_machines.into_iter().map(|m| m.state_machine).collect();

// Verify initial state
assert!(SupportedStateMachines::<T>::iter().count() == n as usize);
// Verify initial state
assert!(SupportedStateMachines::<T>::iter().count() == n as usize);

#[extrinsic_call]
_(RawOrigin::Root, remove_machines);
#[extrinsic_call]
_(RawOrigin::Root, remove_machines);

// Verify all machines were removed
assert!(SupportedStateMachines::<T>::iter().count() == 0);
Ok(())
}
// Verify all machines were removed
assert!(SupportedStateMachines::<T>::iter().count() == 0);
Ok(())
}
}

33 changes: 13 additions & 20 deletions modules/ismp/clients/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ pub mod benchmarking;

pub mod consensus;
pub mod messages;
pub mod weights;

use alloc::vec::Vec;
use frame_support::pallet_prelude::Weight;
use ismp::host::StateMachine;
pub use pallet::*;
pub trait WeightInfo {
/// Weight for adding state machines, scaled by the number of machines
/// * n: The number of machines being added
fn add_state_machines(n: u32) -> Weight;

/// Weight for removing state machines, scaled by the number of machines
/// * n: The number of machines being removed
fn remove_state_machines(n: u32) -> Weight;
pub use weights::WeightInfo;

/// Update the state machine whitelist
#[derive(Clone, codec::Encode, codec::Decode, scale_info::TypeInfo, Debug, PartialEq, Eq)]
pub struct AddStateMachine {
/// State machine to add
pub state_machine: StateMachine,
/// It's slot duration
pub slot_duration: u64,
}

pub mod weights;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use alloc::vec::Vec;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use ismp::host::IsmpHost;
Expand All @@ -55,6 +55,8 @@ pub mod pallet {

/// IsmpHost implementation
type IsmpHost: IsmpHost + Default;

/// Weight information for dispatchable extrinsics
type WeightInfo: WeightInfo;
}

Expand Down Expand Up @@ -121,12 +123,3 @@ pub mod pallet {
}
}
}

/// Update the state machine whitelist
#[derive(Clone, codec::Encode, codec::Decode, scale_info::TypeInfo, Debug, PartialEq, Eq)]
pub struct AddStateMachine {
/// State machine to add
pub state_machine: StateMachine,
/// It's slot duration
pub slot_duration: u64,
}
1 change: 1 addition & 0 deletions modules/ismp/clients/grandpa/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// 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 lang

use alloc::collections::BTreeMap;
use codec::{Decode, Encode};
use grandpa_verifier_primitives::{FinalityProof, ParachainHeaderProofs};
Expand Down
46 changes: 12 additions & 34 deletions modules/ismp/clients/grandpa/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,15 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

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

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

/// Weights for ismp_grandpa
pub struct WeightInfo<T>(PhantomData<T>);

/// Weight functions for ismp-parachain pallet extrinsics.
impl<T: frame_system::Config> crate::WeightInfo for WeightInfo<T> {
/// Weight for adding state machines, scaled by the number of machines.
/// Values based on measured benchmarks:
/// - Base Weight: 5.525 µs
/// - Additional Weight per item: 1.458 µs
/// - DB Weight: n writes
fn add_state_machines(n: u32) -> Weight {
Weight::from_parts(5_525, 0)
.saturating_add(Weight::from_parts(1_458, 0).saturating_mul(n as u64))
.saturating_add(T::DbWeight::get().writes(n as u64))
}

/// Weight for removing state machines, scaled by the number of machines.
/// Values based on measured benchmarks:
/// - Base Weight: 4.914 µs
/// - Additional Weight per item: 1.419 µs
/// - DB Weight: n writes
fn remove_state_machines(n: u32) -> Weight {
Weight::from_parts(4_914, 0)
.saturating_add(Weight::from_parts(1_419, 0).saturating_mul(n as u64))
.saturating_add(T::DbWeight::get().writes(n as u64))
}
}
use frame_support::weights::Weight;

/// The weight information provider trait for dispatchable extrinsics
pub trait WeightInfo {
/// Weight for adding state machines, scaled by the number of machines
/// * n: The number of machines being added
fn add_state_machines(n: u32) -> Weight;

/// Weight for removing state machines, scaled by the number of machines
/// * n: The number of machines being removed
fn remove_state_machines(n: u32) -> Weight;
}
7 changes: 3 additions & 4 deletions parachain/runtimes/gargantua/src/ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ impl pallet_state_coprocessor::Config for Runtime {
type Mmr = Mmr;
}


pub struct Coprocessor;

impl Get<Option<StateMachine>> for Coprocessor {
Expand Down Expand Up @@ -108,9 +107,9 @@ impl pallet_ismp::Config for Runtime {
}

impl ismp_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = pallet_ismp::Pallet<Runtime>;
type WeightInfo = ismp_grandpa::weights::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type IsmpHost = pallet_ismp::Pallet<Runtime>;
type WeightInfo = weights::ismp_grandpa::WeightInfo<Runtime>;
}

impl pallet_token_governor::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions parachain/runtimes/gargantua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![allow(non_local_definitions)]
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
Expand Down
Loading

0 comments on commit 3111704

Please sign in to comment.