diff --git a/runtime/kreivo/src/benchmarking/impls.rs b/runtime/kreivo/src/benchmarking/impls.rs index ee44858b..77d1b784 100644 --- a/runtime/kreivo/src/benchmarking/impls.rs +++ b/runtime/kreivo/src/benchmarking/impls.rs @@ -14,7 +14,16 @@ use xcm::latest::prelude::{ }; 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) -> 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::::ValidationFunctionStored.into()); + } +} impl cumulus_pallet_session_benchmarking::Config for Runtime {} @@ -43,24 +52,18 @@ impl pallet_xcm_benchmarks::Config for Runtime { 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::>(); - assets.push(Asset { - id: AssetId(RelayLocation::get()), - fun: Fungible(1_000_000 * UNITS), - }); + assets.push((RelayLocation::get(), 1_000_000 * UNITS).into()); assets.into() } } @@ -82,11 +85,7 @@ impl pallet_xcm_benchmarks::fungible::Config for Runtime { type TrustedReserve = TrustedReserve; fn get_asset() -> Asset { - Asset { - id: AssetId(RelayLocation::get()), - fun: Fungible(1 * UNITS), - } - .into() + (RelayLocation::get(), UNITS).into() } } @@ -120,18 +119,12 @@ impl pallet_xcm_benchmarks::generic::Config for Runtime { 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 { - 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> { diff --git a/runtime/kreivo/src/config/communities/kreivo_memberships.rs b/runtime/kreivo/src/config/communities/kreivo_memberships.rs deleted file mode 100644 index 91697f00..00000000 --- a/runtime/kreivo/src/config/communities/kreivo_memberships.rs +++ /dev/null @@ -1,19 +0,0 @@ -use super::*; - -use fc_traits_memberships::OnMembershipAssigned; -use frame_support::traits::nonfungibles_v2::{Inspect as NonFunsInspect, Mutate}; - -const WELL_KNOWN_ATTR_KEYS: [&[u8]; 3] = [b"membership_member_rank", b"membership_gas", b"membership_expiration"]; - -parameter_types! { - pub CopySystemAttributesOnAssign: Box> = - Box::new(|_, group, m| { - for key in WELL_KNOWN_ATTR_KEYS.into_iter() { - if let Some(value) = CommunityMemberships::system_attribute(&group, Some(&m), key) { - >::set_attribute(&group, &m, key, &value)?; - } - } - - Ok(()) - }); -} diff --git a/runtime/kreivo/src/config/communities/memberships.rs b/runtime/kreivo/src/config/communities/memberships.rs index 91a213a7..7789b599 100644 --- a/runtime/kreivo/src/config/communities/memberships.rs +++ b/runtime/kreivo/src/config/communities/memberships.rs @@ -1,5 +1,6 @@ use super::*; +use fc_traits_memberships::OnMembershipAssigned; use frame_system::EnsureRootWithSuccess; use sp_runtime::traits::Verify; @@ -14,6 +15,22 @@ parameter_types! { 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> = + 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) { + >::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 @@ -63,8 +80,8 @@ use sp_runtime::traits::IdentifyAccount; impl pallet_nfts::BenchmarkHelper::Signer, AccountId, Signature> for NftsBenchmarksHelper { - fn collection(_: u16) -> CommunityId { - ::BenchmarkHelper::community_id() + fn collection(id: u16) -> CommunityId { + id.into() } fn item(i: u16) -> MembershipId { i.into() diff --git a/runtime/kreivo/src/config/communities/mod.rs b/runtime/kreivo/src/config/communities/mod.rs index ce37ac3b..abffc800 100644 --- a/runtime/kreivo/src/config/communities/mod.rs +++ b/runtime/kreivo/src/config/communities/mod.rs @@ -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")] @@ -65,7 +64,7 @@ impl pallet_communities::Config for Runtime { type AdminOrigin = EitherOf, EnsureCommunityAccount>; type MemberMgmtOrigin = EitherOf, EnsureCommunityAccount>; type MemberMgmt = - WithHooks, kreivo_memberships::CopySystemAttributesOnAssign>; + WithHooks, memberships::CopySystemAttributesOnAssign>; type MembershipId = MembershipId; type Polls = CommunityReferenda; diff --git a/runtime/kreivo/src/config/contracts/mod.rs b/runtime/kreivo/src/config/contracts/mod.rs index 5585c919..e6aeac0c 100644 --- a/runtime/kreivo/src/config/contracts/mod.rs +++ b/runtime/kreivo/src/config/contracts/mod.rs @@ -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 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(_) + ) } } @@ -95,7 +102,11 @@ impl pallet_contracts::Config for Runtime { type MaxDelegateDependencies = ConstU32<32>; type UnsafeUnstableInterface = ConstBool; type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>; + #[cfg(not(feature = "runtime-benchmarks"))] type UploadOrigin = EnsureRootWithSuccess; + #[cfg(feature = "runtime-benchmarks")] + type UploadOrigin = EnsureSigned; + #[cfg(not(feature = "runtime-benchmarks"))] type InstantiateOrigin = EitherOf< EnsureRootWithSuccess, EitherOf< @@ -103,7 +114,15 @@ impl pallet_contracts::Config for Runtime { AsSignedByStaticCommunity>, // Kippu >, >; + #[cfg(feature = "runtime-benchmarks")] + type InstantiateOrigin = EnsureSigned; + #[cfg(not(feature = "runtime-benchmarks"))] type Migrations = (); + #[cfg(feature = "runtime-benchmarks")] + type Migrations = ( + pallet_contracts::migration::v15::Migration, + pallet_contracts::migration::v16::Migration, + ); type Debug = (); type Environment = (); diff --git a/runtime/kreivo/src/config/system.rs b/runtime/kreivo/src/config/system.rs index 1114264e..e433dcb4 100644 --- a/runtime/kreivo/src/config/system.rs +++ b/runtime/kreivo/src/config/system.rs @@ -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; @@ -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; }