Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adjust settings for benchmarking #446

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions runtime/kreivo/src/benchmarking/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
};
use xcm_config::RelayLocation;

impl frame_system_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {
fn setup_set_code_requirements(code: &Vec<u8>) -> Result<(), BenchmarkError> {
ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
Ok(())
}

fn verify_set_code() {
System::assert_last_event(cumulus_pallet_parachain_system::Event::<Runtime>::ValidationFunctionStored.into());
}
}

impl cumulus_pallet_session_benchmarking::Config for Runtime {}

Expand Down Expand Up @@ -43,24 +52,18 @@
let holding_fungibles = holding_non_fungibles.saturating_sub(1);
let fungibles_amount: u128 = 100;
let mut assets = (0..holding_fungibles)
.map(|i| Asset {
id: AssetId(GeneralIndex(i as u128).into()),
fun: Fungible(fungibles_amount * i as u128),
})
.chain(core::iter::once(Asset {
id: AssetId(Here.into()),
fun: Fungible(u128::MAX),
}))
.chain((0..holding_non_fungibles).map(|i| Asset {
id: AssetId(GeneralIndex(i as u128).into()),
fun: NonFungible(asset_instance_from(i)),
.map(|i| (AssetId(GeneralIndex(i as u128).into()), fungibles_amount * i as u128).into())
.chain(core::iter::once((AssetId(Here.into()), u128::MAX).into()))
.chain((0..holding_non_fungibles).map(|i| {
(
AssetId(GeneralIndex(i as u128).into()),
NonFungible(asset_instance_from(i)),
)
.into()
}))
.collect::<Vec<_>>();

assets.push(Asset {
id: AssetId(RelayLocation::get()),
fun: Fungible(1_000_000 * UNITS),
});
assets.push((RelayLocation::get(), 1_000_000 * UNITS).into());
assets.into()
}
}
Expand All @@ -68,7 +71,7 @@
parameter_types! {
pub const TrustedTeleporter: Option<(Location, Asset)> = Some((
RelayLocation::get(),
Asset { fun: Fungible(1 * UNITS), id: AssetId(RelayLocation::get()) },

Check warning on line 74 in runtime/kreivo/src/benchmarking/impls.rs

View workflow job for this annotation

GitHub Actions / clippy

this operation has no effect

warning: this operation has no effect --> runtime/kreivo/src/benchmarking/impls.rs:74:25 | 74 | Asset { fun: Fungible(1 * UNITS), id: AssetId(RelayLocation::get()) }, | ^^^^^^^^^ help: consider reducing it to: `UNITS` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op = note: `#[warn(clippy::identity_op)]` on by default
));
pub const TrustedReserve: Option<(Location, Asset)> = None;
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
Expand All @@ -82,11 +85,7 @@
type TrustedReserve = TrustedReserve;

fn get_asset() -> Asset {
Asset {
id: AssetId(RelayLocation::get()),
fun: Fungible(1 * UNITS),
}
.into()
(RelayLocation::get(), UNITS).into()
}
}

Expand Down Expand Up @@ -120,18 +119,12 @@
fn claimable_asset() -> Result<(Location, Location, XcmAssets), BenchmarkError> {
let origin = RelayLocation::get();
let assets: XcmAssets = (AssetId(RelayLocation::get()), 1_000 * UNITS).into();
let ticket = Location {
parents: 0,
interior: Here,
};
let ticket = Here.into();
Ok((origin, ticket, assets))
}

fn fee_asset() -> Result<Asset, BenchmarkError> {
Ok(Asset {
id: AssetId(RelayLocation::get()),
fun: Fungible(1_000_000 * UNITS),
})
Ok((RelayLocation::get(), 1_000_000 * UNITS).into())
}

fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
Expand Down
19 changes: 0 additions & 19 deletions runtime/kreivo/src/config/communities/kreivo_memberships.rs

This file was deleted.

21 changes: 19 additions & 2 deletions runtime/kreivo/src/config/communities/memberships.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

use fc_traits_memberships::OnMembershipAssigned;
use frame_system::EnsureRootWithSuccess;
use sp_runtime::traits::Verify;

Expand All @@ -14,6 +15,22 @@
pub const DepositPerByte: Balance = 0;
}

const WELL_KNOWN_ATTR_KEYS: [&[u8]; 3] = [b"membership_member_rank", b"membership_gas", b"membership_expiration"];

parameter_types! {
pub CopySystemAttributesOnAssign: Box<dyn OnMembershipAssigned<AccountId, CommunityId, MembershipId>> =
Box::new(|_, group, m| {
use frame_support::traits::nonfungibles_v2::{Inspect as NonFunsInspect, Mutate};
for key in WELL_KNOWN_ATTR_KEYS.into_iter() {
if let Some(value) = CommunityMemberships::system_attribute(&group, Some(&m), key) {
<CommunityMemberships as Mutate<_, _>>::set_attribute(&group, &m, key, &value)?;
}
}

Ok(())
});
}

pub type CommunityMembershipsInstance = pallet_nfts::Instance2;

// From https://github.com/polkadot-fellows/runtimes/blob/main/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs#L810
Expand Down Expand Up @@ -63,8 +80,8 @@
impl pallet_nfts::BenchmarkHelper<CommunityId, MembershipId, <Signature as Verify>::Signer, AccountId, Signature>
for NftsBenchmarksHelper
{
fn collection(_: u16) -> CommunityId {
<Runtime as pallet_communities::Config>::BenchmarkHelper::community_id()
fn collection(id: u16) -> CommunityId {
id.into()

Check warning on line 84 in runtime/kreivo/src/config/communities/memberships.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `u16`

warning: useless conversion to the same type: `u16` --> runtime/kreivo/src/config/communities/memberships.rs:84:3 | 84 | id.into() | ^^^^^^^^^ help: consider removing `.into()`: `id` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
}
fn item(i: u16) -> MembershipId {
i.into()
Expand Down
3 changes: 1 addition & 2 deletions runtime/kreivo/src/config/communities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use virto_common::{CommunityId, MembershipId};

use fc_traits_memberships::{NonFungiblesMemberships, WithHooks};
pub mod governance;
mod kreivo_memberships;
pub mod memberships;

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -65,7 +64,7 @@ impl pallet_communities::Config for Runtime {
type AdminOrigin = EitherOf<EnsureCommunity<Self>, EnsureCommunityAccount>;
type MemberMgmtOrigin = EitherOf<EnsureCommunity<Self>, EnsureCommunityAccount>;
type MemberMgmt =
WithHooks<NonFungiblesMemberships<CommunityMemberships>, kreivo_memberships::CopySystemAttributesOnAssign>;
WithHooks<NonFungiblesMemberships<CommunityMemberships>, memberships::CopySystemAttributesOnAssign>;
type MembershipId = MembershipId;

type Polls = CommunityReferenda;
Expand Down
35 changes: 27 additions & 8 deletions runtime/kreivo/src/config/contracts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
use super::*;
use frame_support::{
parameter_types,
traits::{ConstBool, ConstU32, EitherOf, Randomness},
traits::{ConstBool, ConstU32, Randomness},
};
use frame_system::{pallet_prelude::BlockNumberFor, EnsureRootWithSuccess};
use frame_system::pallet_prelude::BlockNumberFor;
use kreivo_apis::KreivoChainExtensions;
use pallet_balances::Call as BalancesCall;
use pallet_communities::origin::AsSignedByStaticCommunity;
use sp_core::ConstU16;

#[cfg(not(feature = "runtime-benchmarks"))]
use {
frame_support::traits::EitherOf, frame_system::EnsureRootWithSuccess,
pallet_communities::origin::AsSignedByStaticCommunity, sp_core::ConstU16,
};

#[cfg(feature = "runtime-benchmarks")]
use frame_system::EnsureSigned;

pub enum CallFilter {}

impl frame_support::traits::Contains<RuntimeCall> for CallFilter {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }) | RuntimeCall::Assets(_) => true,
_ => false,
}
matches!(
call,
RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }) | RuntimeCall::Assets(_)
)
}
}

Expand Down Expand Up @@ -95,15 +102,27 @@ impl pallet_contracts::Config for Runtime {
type MaxDelegateDependencies = ConstU32<32>;
type UnsafeUnstableInterface = ConstBool<true>;
type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
#[cfg(not(feature = "runtime-benchmarks"))]
type UploadOrigin = EnsureRootWithSuccess<AccountId, TreasuryAccount>;
#[cfg(feature = "runtime-benchmarks")]
type UploadOrigin = EnsureSigned<AccountId>;
#[cfg(not(feature = "runtime-benchmarks"))]
type InstantiateOrigin = EitherOf<
EnsureRootWithSuccess<AccountId, TreasuryAccount>,
EitherOf<
AsSignedByStaticCommunity<Runtime, ConstU16<1>>, // Virto
AsSignedByStaticCommunity<Runtime, ConstU16<2>>, // Kippu
>,
>;
#[cfg(feature = "runtime-benchmarks")]
type InstantiateOrigin = EnsureSigned<AccountId>;
#[cfg(not(feature = "runtime-benchmarks"))]
type Migrations = ();
#[cfg(feature = "runtime-benchmarks")]
type Migrations = (
pallet_contracts::migration::v15::Migration<Self>,
pallet_contracts::migration::v16::Migration<Self>,
);

type Debug = ();
type Environment = ();
Expand Down
2 changes: 1 addition & 1 deletion runtime/kreivo/src/config/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ parameter_types! {
}

impl cumulus_pallet_parachain_system::Config for Runtime {
type WeightInfo = ();
type RuntimeEvent = RuntimeEvent;
type OnSystemEvent = ();
type SelfParaId = parachain_info::Pallet<Runtime>;
Expand All @@ -115,6 +114,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type WeightInfo = ();
type ConsensusHook = ConsensusHook;
}

Expand Down
Loading