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: benchmarking for pallet-data-preservers and pallet-registrar on Dancelight #783

Merged
merged 25 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1210454
chore: added dancelight to dev-benchmark-pallet.sh script
Dec 11, 2024
0ea8ab6
feat: added pallet_data_preservers to dancelight's benchmarks runtime…
Dec 11, 2024
11fe9a6
fix: disable InnerRegistrar for benchmarking so all pallet_data_prese…
Dec 16, 2024
2703217
feat: added weights for pallet_data_preservers on Dancelight
Dec 16, 2024
84843a6
Merge branch 'master' into aleks-fix-data-preservers-benchmarking
chexware Dec 16, 2024
f0c48c3
feat: using weights::runtime_common_paras_registrar for InnerDancelig…
Dec 17, 2024
979fc76
chore: added tmp folder and raw.json to .gitignore
Dec 19, 2024
a010dc8
feat: added benchmark helper for pallet_data_preservers
Dec 20, 2024
85b2b88
feat: added initial implementation of benchmark helper for pallet_dat…
Dec 20, 2024
075b3f7
feat: added reserving of para_id to DataPreserversBenchmarkHelper
Dec 21, 2024
955f90f
fix: pallet_data_preservers benchmarking for Dancelight works correctly
Dec 21, 2024
623b7db
style: fixed formatting
Dec 21, 2024
55c37fd
Merge branch 'master' into aleks-fix-data-preservers-benchmarking
chexware Dec 21, 2024
9f1e349
chore: moved DataPreserversBenchmarkHelper-related imports inside the…
Dec 21, 2024
ae6d3b8
Merge branch 'master' into aleks-fix-data-preservers-benchmarking
chexware Dec 30, 2024
6ab88e0
Merge branch 'master' into aleks-fix-data-preservers-benchmarking
chexware Jan 3, 2025
6741692
refactor: moved reserving ParaId for benchmarking to InnerDancelightR…
Jan 6, 2025
cbc5f2b
Merge branch 'master' into aleks-fix-data-preservers-benchmarking
Jan 6, 2025
1ef85d3
chore: updated dev-benchmark-pallet.sh output folders
Jan 6, 2025
0a86309
chore: removed unused imports
Jan 6, 2025
846fb7d
fix: cargo-clippy errors
Jan 6, 2025
1b709ba
fix: fixed pallet-registrar benchmarking for Dancelight
Jan 7, 2025
73b2878
chore: remove unused ArgumentFactory
Jan 7, 2025
3116c52
chore: removed unused imports
Jan 7, 2025
ab4a8c9
Merge branch 'master' into aleks-fix-data-preservers-benchmarking
chexware Jan 8, 2025
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
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# Spec/Wasm build directory
/build/


# RustRover - related
**/.idea
**/.idea

# Temporary files
**/tmp
raw.json
27 changes: 25 additions & 2 deletions pallets/data-preservers/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ use {
tp_traits::{ParaId, StorageDeposit},
};

/// Trait describing factory function for para_id.
pub trait ArgumentFactory<AcocuntId> {
/// Factory function reserving parachain
fn reserve_para_id(para_id: ParaId);
chexware marked this conversation as resolved.
Show resolved Hide resolved
}

/// Dummy implementation for when the factory is not needed.
impl<AccountId> ArgumentFactory<AccountId> for () {
fn reserve_para_id(_para_id: ParaId) {}
}

macro_rules! bset {
( $($value:expr),* $(,)? ) => {
{
Expand Down Expand Up @@ -319,7 +330,11 @@ mod benchmarks {
#[benchmark]
fn start_assignment() {
let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap();
let para_id = ParaId::from(42);
// !!! (Applicable for Dancelight only)
// The specified ParaId needs to be larger than LOWEST_PUBLIC_ID value in Polkadot SDK.
// Currently, this value is 2000. We should also avoid setting the value to one of
// the container chains reserved by root
let para_id = ParaId::from(2042);

let profile = Profile {
url,
Expand All @@ -333,6 +348,8 @@ mod benchmarks {
Pallet::<T>::create_profile(RawOrigin::Signed(caller.clone()).into(), profile)
.expect("to create profile");

T::BenchmarkHelper::reserve_para_id(para_id);

let origin = T::AssignmentOrigin::try_successful_origin(&para_id).unwrap();

#[extrinsic_call]
Expand All @@ -352,7 +369,11 @@ mod benchmarks {
#[benchmark]
fn stop_assignment() {
let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap();
let para_id = ParaId::from(42);
// !!! (Applicable for Dancelight only)
// The specified ParaId needs to be larger than LOWEST_PUBLIC_ID value in Polkadot SDK.
// Currently, this value is 2000. We should also avoid setting the value to one of
// the container chains reserved by root
let para_id = ParaId::from(2042);

let profile = Profile {
url,
Expand All @@ -366,6 +387,8 @@ mod benchmarks {
Pallet::<T>::create_profile(RawOrigin::Signed(caller.clone()).into(), profile)
.expect("to create profile");

T::BenchmarkHelper::reserve_para_id(para_id);

let origin = T::AssignmentOrigin::try_successful_origin(&para_id).unwrap();

Pallet::<T>::start_assignment(
Expand Down
7 changes: 7 additions & 0 deletions pallets/data-preservers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ mod tests;
#[cfg(any(test, feature = "runtime-benchmarks"))]
mod benchmarks;

#[cfg(feature = "runtime-benchmarks")]
pub use benchmarks::ArgumentFactory;

pub mod weights;
pub use weights::WeightInfo;

Expand Down Expand Up @@ -172,6 +175,10 @@ pub mod pallet {
type AssignmentPayment: AssignmentPayment<Self::AccountId>;

type WeightInfo: WeightInfo;

/// Helper type for benchmarks.
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper: ArgumentFactory<Self::AccountId>;
}

#[pallet::event]
Expand Down
3 changes: 3 additions & 0 deletions pallets/data-preservers/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ impl pallet_data_preservers::Config for Test {
type MaxParaIdsVecLen = ConstU32<20>;
type ProfileDeposit = tp_traits::BytesDeposit<ConstU128<1000>, ConstU128<51>>;
type WeightInfo = ();

#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

#[derive(Default)]
Expand Down
2 changes: 2 additions & 0 deletions runtime/dancebox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@ impl pallet_data_preservers::Config for Runtime {
type MaxAssignmentsPerParaId = MaxAssignmentsPerParaId;
type MaxNodeUrlLen = MaxNodeUrlLen;
type MaxParaIdsVecLen = MaxLengthParaIds;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

impl pallet_author_noting::Config for Runtime {
Expand Down
3 changes: 3 additions & 0 deletions runtime/flashbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,9 @@ impl pallet_data_preservers::Config for Runtime {
type MaxAssignmentsPerParaId = MaxAssignmentsPerParaId;
type MaxNodeUrlLen = MaxNodeUrlLen;
type MaxParaIdsVecLen = MaxLengthParaIds;

#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

impl pallet_author_noting::Config for Runtime {
Expand Down
62 changes: 58 additions & 4 deletions solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,8 @@ impl pallet_beefy_mmr::Config for Runtime {

impl paras_sudo_wrapper::Config for Runtime {}

#[cfg(feature = "runtime-benchmarks")]
use pallet_data_preservers::ArgumentFactory;
use pallet_pooled_staking::traits::{IsCandidateEligible, Timer};
use pallet_staking::SessionInterface;

Expand Down Expand Up @@ -1558,7 +1560,7 @@ impl pallet_data_preservers::AssignmentPayment<AccountId> for PreserversAssignme
type ProviderRequest = PreserversAssignmentPaymentRequest;
/// Extra parameter the assigner provides.
type AssignerParameter = PreserversAssignmentPaymentExtra;
/// Represents the succesful outcome of the assignment.
/// Represents the successful outcome of the assignment.
type AssignmentWitness = PreserversAssignmentPaymentWitness;

fn try_start_assignment(
Expand Down Expand Up @@ -1618,11 +1620,54 @@ impl pallet_data_preservers::AssignmentPayment<AccountId> for PreserversAssignme
}
}

pub struct DataPreserversBenchmarkHelper<T>(PhantomData<T>);

#[cfg(feature = "runtime-benchmarks")]
impl<T> ArgumentFactory<T::AccountId> for DataPreserversBenchmarkHelper<T>
where
T: pallet_registrar::Config + pallet_balances::Config + paras_registrar::Config,
{
fn reserve_para_id(para_id: ParaId) {
use frame_support::{assert_ok, dispatch::RawOrigin, traits::fungible::Mutate};

let account: T::AccountId = frame_benchmarking::account("para_manager", 0, 1);
assert_ok!(<T as pallet_registrar::Config>::Currency::mint_into(
chexware marked this conversation as resolved.
Show resolved Hide resolved
&account,
<T as pallet_registrar::Config>::Currency::minimum_balance() * 10_000_000u32.into()
+ T::DepositAmount::get(),
));

paras_registrar::NextFreeParaId::<T>::put(para_id);
assert_eq!(paras_registrar::NextFreeParaId::<T>::get(), para_id);
assert_ok!(paras_registrar::Pallet::<T>::reserve(
RawOrigin::Signed(account.clone()).into()
));

let mut storage = vec![];
storage.push((b":code".to_vec(), vec![1; 10]).into());
let genesis_data = ContainerChainGenesisData {
storage,
name: Default::default(),
id: Default::default(),
fork_id: Default::default(),
extensions: Default::default(),
properties: Default::default(),
};

assert_ok!(pallet_registrar::Pallet::<T>::register(
chexware marked this conversation as resolved.
Show resolved Hide resolved
RawOrigin::Signed(account).into(),
para_id,
genesis_data,
T::InnerRegistrar::bench_head_data()
));
}
}

impl pallet_data_preservers::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Currency = Balances;
type WeightInfo = ();
type WeightInfo = weights::pallet_data_preservers::SubstrateWeight<Runtime>;

type ProfileId = u64;
type ProfileDeposit = tp_traits::BytesDeposit<ProfileDepositBaseFee, ProfileDepositByteFee>;
Expand All @@ -1634,6 +1679,8 @@ impl pallet_data_preservers::Config for Runtime {
type MaxAssignmentsPerParaId = MaxAssignmentsPerParaId;
type MaxNodeUrlLen = MaxNodeUrlLen;
type MaxParaIdsVecLen = MaxLengthParaIds;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = DataPreserversBenchmarkHelper<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -2053,8 +2100,13 @@ impl pallet_registrar::Config for Runtime {
type DepositAmount = DepositAmount;
type RegistrarHooks = DancelightRegistrarHooks;
type RuntimeHoldReason = RuntimeHoldReason;
type InnerRegistrar =
InnerDancelightRegistrar<Runtime, AccountId, Registrar, paras_registrar::TestWeightInfo>;

type InnerRegistrar = InnerDancelightRegistrar<
Runtime,
AccountId,
Registrar,
weights::runtime_common_paras_registrar::SubstrateWeight<Runtime>,
>;
type WeightInfo = weights::pallet_registrar::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -2206,7 +2258,9 @@ mod benches {
[pallet_external_validators_rewards, ExternalValidatorsRewards]
[pallet_external_validator_slashes, ExternalValidatorSlashes]
[pallet_invulnerables, TanssiInvulnerables]
[pallet_data_preservers, DataPreservers]
[pallet_pooled_staking, PooledStaking]

// XCM
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
Expand Down
1 change: 1 addition & 0 deletions solo-chains/runtime/dancelight/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod pallet_author_noting;
pub mod pallet_balances;
pub mod pallet_collator_assignment;
pub mod pallet_conviction_voting;
pub mod pallet_data_preservers;
pub mod pallet_external_validator_slashes;
pub mod pallet_external_validators;
pub mod pallet_external_validators_rewards;
Expand Down
Loading
Loading