Skip to content

Commit 7a0675a

Browse files
authored
Merge pull request #3543 from autonomys/fix-broken-benchmark
Fix broken `pallet-domains` benchmarks
2 parents 247c266 + c2293f3 commit 7a0675a

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pallet-domains/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ frame-system.workspace = true
2020
hexlit.workspace = true
2121
log.workspace = true
2222
pallet-balances.workspace = true
23+
pallet-subspace = { workspace = true, optional = true }
2324
scale-info = { workspace = true, features = ["derive"] }
2425
sp-consensus-slots.workspace = true
2526
sp-consensus-subspace.workspace = true
@@ -37,6 +38,7 @@ subspace-runtime-primitives.workspace = true
3738
[dev-dependencies]
3839
domain-pallet-executive.workspace = true
3940
hex-literal.workspace = true
41+
pallet-subspace.workspace = true
4042
pallet-timestamp.workspace = true
4143
pallet-block-fees.workspace = true
4244
sp-externalities.workspace = true
@@ -51,6 +53,7 @@ std = [
5153
"frame-system/std",
5254
"log/std",
5355
"pallet-balances/std",
56+
"pallet-subspace/std",
5457
"scale-info/std",
5558
"sp-consensus-slots/std",
5659
"sp-consensus-subspace/std",
@@ -70,6 +73,7 @@ runtime-benchmarks = [
7073
"frame-system/runtime-benchmarks",
7174
"frame-benchmarking",
7275
"frame-benchmarking/runtime-benchmarks",
76+
"pallet-subspace/runtime-benchmarks",
7377
"sp-domains/runtime-benchmarks",
7478
"sp-domains-fraud-proof/runtime-benchmarks",
7579
"sp-runtime/runtime-benchmarks",

crates/pallet-domains/src/benchmarking.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use frame_support::assert_ok;
2626
use frame_support::traits::fungible::{Inspect, Mutate};
2727
use frame_support::traits::Hooks;
2828
use frame_system::{Pallet as System, RawOrigin};
29+
use pallet_subspace::BlockRandomness;
2930
use sp_core::crypto::{Ss58Codec, UncheckedFrom};
3031
use sp_domains::{
3132
dummy_opaque_bundle, DomainId, ExecutionReceipt, OperatorAllowList, OperatorId,
@@ -35,11 +36,16 @@ use sp_domains::{
3536
use sp_domains_fraud_proof::fraud_proof::FraudProof;
3637
use sp_runtime::traits::{CheckedAdd, One, Zero};
3738
use sp_std::collections::btree_set::BTreeSet;
39+
use subspace_core_primitives::Randomness;
3840

3941
const SEED: u32 = 0;
4042
const MAX_NOMINATORS_TO_SLASH_WITHOUT_OPERATOR: u32 = MAX_NOMINATORS_TO_SLASH - 1;
4143

42-
#[benchmarks(where <RuntimeCallFor<T> as sp_runtime::traits::Dispatchable>::RuntimeOrigin: From<DomainOrigin>)]
44+
#[allow(clippy::multiple_bound_locations)]
45+
#[benchmarks(where
46+
T: pallet_subspace::Config,
47+
<RuntimeCallFor<T> as sp_runtime::traits::Dispatchable>::RuntimeOrigin: From<DomainOrigin>,
48+
)]
4349
mod benchmarks {
4450
use super::*;
4551
use sp_std::vec;
@@ -850,8 +856,8 @@ mod benchmarks {
850856
#[benchmark]
851857
fn transfer_treasury_funds() {
852858
// Ensure the treasury account has balance
853-
let treasury_amount = 5000u32.into();
854-
let transfer_amount = 500u32.into();
859+
let transfer_amount = T::Currency::minimum_balance();
860+
let treasury_amount = T::Currency::minimum_balance() + transfer_amount;
855861
let account = account("slashed_account", 1, SEED);
856862
assert_eq!(T::Currency::balance(&account), 0u32.into());
857863
T::Currency::set_balance(&T::TreasuryAccount::get(), treasury_amount);
@@ -995,12 +1001,16 @@ mod benchmarks {
9951001
(operator_account, operator_id)
9961002
}
9971003

998-
fn run_to_block<T: Config>(block_number: BlockNumberFor<T>, parent_hash: T::Hash) {
1004+
fn run_to_block<T: Config + pallet_subspace::Config>(
1005+
block_number: BlockNumberFor<T>,
1006+
parent_hash: T::Hash,
1007+
) {
9991008
if let Some(parent_block_number) = block_number.checked_sub(&One::one()) {
10001009
Domains::<T>::on_finalize(parent_block_number);
10011010
}
10021011
System::<T>::set_block_number(block_number);
10031012
System::<T>::initialize(&block_number, &parent_hash, &Default::default());
1013+
BlockRandomness::<T>::put(Randomness::default());
10041014
Domains::<T>::on_initialize(block_number);
10051015
System::<T>::finalize();
10061016
}

crates/pallet-domains/src/tests.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use frame_support::weights::{IdentityFee, Weight};
2020
use frame_support::{assert_err, assert_ok, derive_impl, parameter_types, PalletId};
2121
use frame_system::mocking::MockUncheckedExtrinsic;
2222
use frame_system::pallet_prelude::*;
23+
use pallet_subspace::NormalEraChange;
2324
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
2425
use scale_info::TypeInfo;
2526
use sp_core::crypto::Pair;
@@ -34,14 +35,18 @@ use sp_domains::{
3435
use sp_domains_fraud_proof::fraud_proof::FraudProof;
3536
use sp_runtime::generic::{Preamble, EXTRINSIC_FORMAT_VERSION};
3637
use sp_runtime::traits::{
37-
AccountIdConversion, BlakeTwo256, BlockNumberProvider, Bounded, Hash as HashT, IdentityLookup,
38-
One, Zero,
38+
AccountIdConversion, BlakeTwo256, BlockNumberProvider, Bounded, ConstU16, Hash as HashT,
39+
IdentityLookup, One, Zero,
3940
};
4041
use sp_runtime::transaction_validity::TransactionValidityError;
4142
use sp_runtime::type_with_default::TypeWithDefault;
4243
use sp_runtime::{BuildStorage, OpaqueExtrinsic};
4344
use sp_version::RuntimeVersion;
44-
use subspace_core_primitives::U256 as P256;
45+
use std::num::NonZeroU64;
46+
use subspace_core_primitives::pieces::Piece;
47+
use subspace_core_primitives::segments::HistorySize;
48+
use subspace_core_primitives::solutions::SolutionRange;
49+
use subspace_core_primitives::{SlotNumber, U256 as P256};
4550
use subspace_runtime_primitives::{
4651
ConsensusEventSegmentSize, HoldIdentifier, Moment, Nonce, StorageFee, SSC,
4752
};
@@ -61,6 +66,7 @@ frame_support::construct_runtime!(
6166
System: frame_system,
6267
Timestamp: pallet_timestamp,
6368
Balances: pallet_balances,
69+
Subspace: pallet_subspace,
6470
Domains: pallet_domains,
6571
DomainExecutive: domain_pallet_executive,
6672
BlockFees: pallet_block_fees,
@@ -313,6 +319,54 @@ impl pallet_block_fees::Config for Test {
313319
type DomainChainByteFee = DomainChainByteFee;
314320
}
315321

322+
pub const INITIAL_SOLUTION_RANGE: SolutionRange =
323+
u64::MAX / (1024 * 1024 * 1024 / Piece::SIZE as u64) * 3 / 10;
324+
325+
parameter_types! {
326+
pub const BlockAuthoringDelay: SlotNumber = 2;
327+
pub const PotEntropyInjectionInterval: BlockNumber = 5;
328+
pub const PotEntropyInjectionLookbackDepth: u8 = 2;
329+
pub const PotEntropyInjectionDelay: SlotNumber = 4;
330+
pub const EraDuration: u32 = 4;
331+
// 1GB
332+
pub const InitialSolutionRange: SolutionRange = INITIAL_SOLUTION_RANGE;
333+
pub const RecentSegments: HistorySize = HistorySize::new(NonZeroU64::new(5).unwrap());
334+
pub const RecentHistoryFraction: (HistorySize, HistorySize) = (
335+
HistorySize::new(NonZeroU64::new(1).unwrap()),
336+
HistorySize::new(NonZeroU64::new(10).unwrap()),
337+
);
338+
pub const MinSectorLifetime: HistorySize = HistorySize::new(NonZeroU64::new(4).unwrap());
339+
pub const RecordSize: u32 = 3840;
340+
pub const ExpectedVotesPerBlock: u32 = 9;
341+
pub const ReplicationFactor: u16 = 1;
342+
pub const ReportLongevity: u64 = 34;
343+
pub const ShouldAdjustSolutionRange: bool = false;
344+
pub const BlockSlotCount: u32 = 6;
345+
}
346+
347+
impl pallet_subspace::Config for Test {
348+
type RuntimeEvent = RuntimeEvent;
349+
type SubspaceOrigin = pallet_subspace::EnsureSubspaceOrigin;
350+
type BlockAuthoringDelay = BlockAuthoringDelay;
351+
type PotEntropyInjectionInterval = PotEntropyInjectionInterval;
352+
type PotEntropyInjectionLookbackDepth = PotEntropyInjectionLookbackDepth;
353+
type PotEntropyInjectionDelay = PotEntropyInjectionDelay;
354+
type EraDuration = EraDuration;
355+
type InitialSolutionRange = InitialSolutionRange;
356+
type SlotProbability = SlotProbability;
357+
type ConfirmationDepthK = ConfirmationDepthK;
358+
type RecentSegments = RecentSegments;
359+
type RecentHistoryFraction = RecentHistoryFraction;
360+
type MinSectorLifetime = MinSectorLifetime;
361+
type ExpectedVotesPerBlock = ExpectedVotesPerBlock;
362+
type MaxPiecesInSector = ConstU16<1>;
363+
type ShouldAdjustSolutionRange = ShouldAdjustSolutionRange;
364+
type EraChangeTrigger = NormalEraChange;
365+
type WeightInfo = ();
366+
type BlockSlotCount = BlockSlotCount;
367+
type ExtensionWeightInfo = pallet_subspace::extensions::weights::SubstrateWeight<Self>;
368+
}
369+
316370
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
317371
let t = frame_system::GenesisConfig::<Test>::default()
318372
.build_storage()

0 commit comments

Comments
 (0)