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

short-term fix for para inherent weight overestimation #5082

Merged
merged 32 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b0fbeec
temp fix for para inherent weight overestimation
ordian Jul 19, 2024
940c02e
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Jul 22, 2024
67c295d
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jul 22, 2024
08dc2cc
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jul 22, 2024
f920d3b
fixup
ordian Jul 23, 2024
9c7d1b5
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Jul 23, 2024
42d0302
another fixup
ordian Jul 23, 2024
f4d2eee
fixup
ordian Jul 25, 2024
b235de4
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Jul 25, 2024
be07fcb
fix a typo
ordian Jul 26, 2024
9fe7a6b
polkadot bench: make bitfields full in builder
ordian Jul 26, 2024
ce6d0ac
rename some weight files
ordian Jul 26, 2024
64b367c
some more weight renames
ordian Jul 26, 2024
d305a1a
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 6, 2024
c8b2c30
fmt
ordian Aug 6, 2024
e9258b7
rename rococo weights too
ordian Aug 6, 2024
6133e83
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Aug 7, 2024
c9f313c
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2024
ea9abce
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2024
254c11c
prdoc
ordian Aug 7, 2024
ca5ee10
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 7, 2024
c4e0989
restore the comment
ordian Aug 7, 2024
cbe0b3f
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 14, 2024
277f40a
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 16, 2024
90e4eaf
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 22, 2024
b5873d4
adjust some of the runtime builder params
ordian Aug 22, 2024
05d90cb
adjust backing bench
ordian Aug 22, 2024
bb75fb5
rename validaty to backing votes
ordian Aug 22, 2024
73d3e6e
fix a typo
ordian Aug 22, 2024
1ca7b53
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Aug 22, 2024
18c3e03
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 23, 2024
46c7965
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 23, 2024
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
15 changes: 8 additions & 7 deletions polkadot/runtime/parachains/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
.expect("self.block_number is u32")
}

/// Maximum number of validators that may be part of a validator group.
/// Fallback for the maximum number of validators participating in parachains consensus (a.k.a.
/// active validators).
pub(crate) fn fallback_max_validators() -> u32 {
configuration::ActiveConfig::<T>::get().max_validators.unwrap_or(200)
configuration::ActiveConfig::<T>::get().max_validators.unwrap_or(1024)
}

/// Maximum number of validators participating in parachains consensus (a.k.a. active
Expand Down Expand Up @@ -285,8 +286,8 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {

/// Get the minimum number of validity votes in order for a backed candidate to be included.
#[cfg(feature = "runtime-benchmarks")]
pub(crate) fn fallback_min_validity_votes() -> u32 {
(Self::fallback_max_validators() / 2) + 1
pub(crate) fn fallback_min_backing_votes() -> u32 {
2
}

fn mock_head_data() -> HeadData {
Expand Down Expand Up @@ -356,11 +357,11 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
availability_votes,
commitments,
);
inclusion::PendingAvailability::<T>::mutate(para_id, |maybe_andidates| {
if let Some(candidates) = maybe_andidates {
inclusion::PendingAvailability::<T>::mutate(para_id, |maybe_candidates| {
if let Some(candidates) = maybe_candidates {
candidates.push_back(candidate_availability);
} else {
*maybe_andidates =
*maybe_candidates =
Some([candidate_availability].into_iter().collect::<VecDeque<_>>());
}
});
Expand Down
37 changes: 21 additions & 16 deletions polkadot/runtime/parachains/src/paras_inherent/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ use polkadot_primitives::v7::GroupIndex;
use crate::builder::BenchBuilder;

benchmarks! {
enter_empty {
let scenario = BenchBuilder::<T>::new()
alexggh marked this conversation as resolved.
Show resolved Hide resolved
.build();

let mut benchmark = scenario.data.clone();

benchmark.bitfields.clear();
benchmark.backed_candidates.clear();
benchmark.disputes.clear();
Comment on lines +35 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these really needed if we just called build() on a default BenchBuilder instance?

}: enter(RawOrigin::None, benchmark)
verify {
// Assert that the block was not discarded
assert!(Included::<T>::get().is_some());
}
// Variant over `v`, the number of dispute statements in a dispute statement set. This gives the
// weight of a single dispute statement set.
enter_variable_disputes {
Expand Down Expand Up @@ -92,18 +106,8 @@ benchmarks! {
// Variant over `v`, the amount of validity votes for a backed candidate. This gives the weight
// of a single backed candidate.
enter_backed_candidates_variable {
// NOTE: the starting value must be over half of the max validators per group so the backed
// candidate is not rejected. Also, we cannot have more validity votes than validators in
// the group.

// Do not use this range for Rococo because it only has 1 validator per backing group,
// which causes issues when trying to create slopes with the benchmarking analysis. Instead
// use v = 1 for running Rococo benchmarks
let v in (BenchBuilder::<T>::fallback_min_validity_votes())
..(BenchBuilder::<T>::fallback_max_validators());

// Comment in for running rococo benchmarks
// let v = 1;
let v in (BenchBuilder::<T>::fallback_min_backing_votes())
..(BenchBuilder::<T>::fallback_max_validators_per_core());

let cores_with_backed: BTreeMap<_, _>
= vec![(0, v)] // The backed candidate will have `v` validity votes.
Expand All @@ -119,7 +123,6 @@ benchmarks! {
// There is 1 backed,
assert_eq!(benchmark.backed_candidates.len(), 1);
// with `v` validity votes.
// let votes = v as usize;
let votes = min(scheduler::Pallet::<T>::group_validators(GroupIndex::from(0)).unwrap().len(), v as usize);
assert_eq!(benchmark.backed_candidates.get(0).unwrap().validity_votes().len(), votes);

Expand Down Expand Up @@ -157,7 +160,7 @@ benchmarks! {
let v = crate::configuration::ActiveConfig::<T>::get().max_code_size;

let cores_with_backed: BTreeMap<_, _>
= vec![(0, BenchBuilder::<T>::fallback_min_validity_votes())]
= vec![(0, BenchBuilder::<T>::fallback_min_backing_votes())]
.into_iter()
.collect();

Expand All @@ -168,8 +171,10 @@ benchmarks! {

let mut benchmark = scenario.data.clone();

// let votes = BenchBuilder::<T>::fallback_min_validity_votes() as usize;
let votes = min(scheduler::Pallet::<T>::group_validators(GroupIndex::from(0)).unwrap().len(), BenchBuilder::<T>::fallback_min_validity_votes() as usize);
let votes = min(
scheduler::Pallet::<T>::group_validators(GroupIndex::from(0)).unwrap().len(),
BenchBuilder::<T>::fallback_min_backing_votes() as usize
);

// There is 1 backed
assert_eq!(benchmark.backed_candidates.len(), 1);
Expand Down
18 changes: 15 additions & 3 deletions polkadot/runtime/parachains/src/paras_inherent/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use polkadot_primitives::{
use super::{BackedCandidate, Config, DisputeStatementSet, Weight};

pub trait WeightInfo {
/// The weight of processing an empty parachain inherent.
fn enter_empty() -> Weight;
/// Variant over `v`, the count of dispute statements in a dispute statement set. This gives the
/// weight of a single dispute statement set.
fn enter_variable_disputes(v: u32) -> Weight;
Expand All @@ -45,6 +47,9 @@ pub struct TestWeightInfo;
// mock.
#[cfg(not(feature = "runtime-benchmarks"))]
impl WeightInfo for TestWeightInfo {
fn enter_empty() -> Weight {
Weight::zero()
}
fn enter_variable_disputes(v: u32) -> Weight {
// MAX Block Weight should fit 4 disputes
Weight::from_parts(80_000 * v as u64 + 80_000, 0)
Expand All @@ -66,6 +71,9 @@ impl WeightInfo for TestWeightInfo {
// running as a test.
#[cfg(feature = "runtime-benchmarks")]
impl WeightInfo for TestWeightInfo {
fn enter_empty() -> Weight {
Weight::zero()
}
fn enter_variable_disputes(_v: u32) -> Weight {
Weight::zero()
}
Expand Down Expand Up @@ -123,7 +131,8 @@ where
set_proof_size_to_tx_size(
<<T as Config>::WeightInfo as WeightInfo>::enter_variable_disputes(
statement_set.as_ref().statements.len() as u32,
),
)
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty()),
sandreim marked this conversation as resolved.
Show resolved Hide resolved
statement_set,
)
}
Expand All @@ -133,14 +142,16 @@ pub fn signed_bitfields_weight<T: Config>(
) -> Weight {
set_proof_size_to_tx_size(
<<T as Config>::WeightInfo as WeightInfo>::enter_bitfields()
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty())
.saturating_mul(bitfields.len() as u64),
bitfields,
)
}

pub fn signed_bitfield_weight<T: Config>(bitfield: &UncheckedSignedAvailabilityBitfield) -> Weight {
set_proof_size_to_tx_size(
<<T as Config>::WeightInfo as WeightInfo>::enter_bitfields(),
<<T as Config>::WeightInfo as WeightInfo>::enter_bitfields()
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty()),
bitfield,
)
}
Expand All @@ -155,7 +166,8 @@ pub fn backed_candidate_weight<T: frame_system::Config + Config>(
<<T as Config>::WeightInfo as WeightInfo>::enter_backed_candidates_variable(
candidate.validity_votes().len() as u32,
)
},
}
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty()),
alexggh marked this conversation as resolved.
Show resolved Hide resolved
candidate,
)
}
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/rococo/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ where
fn on_reap_identity(who: &AccountId, fields: u32, subs: u32) -> DispatchResult {
use crate::{
impls::IdentityMigratorCalls::PokeDeposit,
weights::runtime_common_identity_migrator::WeightInfo as MigratorWeights,
weights::polkadot_runtime_common_identity_migrator::WeightInfo as MigratorWeights,
};

let total_to_send = Self::calculate_remote_deposit(fields, subs);
Expand Down
32 changes: 16 additions & 16 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ impl claims::Config for Runtime {
type VestingSchedule = Vesting;
type Prefix = Prefix;
type MoveClaimOrigin = EnsureRoot<AccountId>;
type WeightInfo = weights::runtime_common_claims::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_common_claims::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -940,7 +940,7 @@ impl pallet_proxy::Config for Runtime {
impl parachains_origin::Config for Runtime {}

impl parachains_configuration::Config for Runtime {
type WeightInfo = weights::runtime_parachains_configuration::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_configuration::WeightInfo<Runtime>;
}

impl parachains_shared::Config for Runtime {
Expand All @@ -963,7 +963,7 @@ impl parachains_inclusion::Config for Runtime {
type DisputesHandler = ParasDisputes;
type RewardValidators = RewardValidators;
type MessageQueue = MessageQueue;
type WeightInfo = weights::runtime_parachains_inclusion::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_inclusion::WeightInfo<Runtime>;
}

parameter_types! {
Expand All @@ -972,7 +972,7 @@ parameter_types! {

impl parachains_paras::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::runtime_parachains_paras::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_paras::WeightInfo<Runtime>;
type UnsignedPriority = ParasUnsignedPriority;
type QueueFootprinter = ParaInclusion;
type NextSessionRotation = Babe;
Expand Down Expand Up @@ -1046,11 +1046,11 @@ impl parachains_hrmp::Config for Runtime {
HrmpChannelSizeAndCapacityWithSystemRatio,
>;
type VersionWrapper = crate::XcmPallet;
type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_hrmp::WeightInfo<Runtime>;
}

impl parachains_paras_inherent::Config for Runtime {
type WeightInfo = weights::runtime_parachains_paras_inherent::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_paras_inherent::WeightInfo<Runtime>;
}

impl parachains_scheduler::Config for Runtime {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ impl coretime::Config for Runtime {
type Currency = Balances;
type BrokerId = BrokerId;
type BrokerPotLocation = BrokerPot;
type WeightInfo = weights::runtime_parachains_coretime::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_coretime::WeightInfo<Runtime>;
type SendXcm = crate::xcm_config::XcmRouter;
type AssetTransactor = crate::xcm_config::LocalAssetTransactor;
type AccountToLocation = xcm_builder::AliasesIntoAccountId32<
Expand All @@ -1100,7 +1100,7 @@ impl parachains_on_demand::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type TrafficDefaultValue = OnDemandTrafficDefaultValue;
type WeightInfo = weights::runtime_parachains_on_demand::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_on_demand::WeightInfo<Runtime>;
type MaxHistoricalRevenue = MaxHistoricalRevenue;
type PalletId = OnDemandPalletId;
}
Expand All @@ -1110,15 +1110,15 @@ impl parachains_assigner_coretime::Config for Runtime {}
impl parachains_initializer::Config for Runtime {
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
type ForceOrigin = EnsureRoot<AccountId>;
type WeightInfo = weights::runtime_parachains_initializer::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_initializer::WeightInfo<Runtime>;
type CoretimeOnNewSession = Coretime;
}

impl parachains_disputes::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RewardValidators = ();
type SlashingHandler = parachains_slashing::SlashValidatorsForDisputes<ParasSlashing>;
type WeightInfo = weights::runtime_parachains_disputes::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_parachains_disputes::WeightInfo<Runtime>;
}

impl parachains_slashing::Config for Runtime {
Expand Down Expand Up @@ -1149,7 +1149,7 @@ impl paras_registrar::Config for Runtime {
type OnSwap = (Crowdloan, Slots, SwapLeases);
type ParaDeposit = ParaDeposit;
type DataDepositPerByte = DataDepositPerByte;
type WeightInfo = weights::runtime_common_paras_registrar::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_common_paras_registrar::WeightInfo<Runtime>;
}

parameter_types! {
Expand All @@ -1163,7 +1163,7 @@ impl slots::Config for Runtime {
type LeasePeriod = LeasePeriod;
type LeaseOffset = ();
type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, LeaseAdmin>;
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_common_slots::WeightInfo<Runtime>;
}

parameter_types! {
Expand All @@ -1184,7 +1184,7 @@ impl crowdloan::Config for Runtime {
type Registrar = Registrar;
type Auctioneer = Auctions;
type MaxMemoLength = MaxMemoLength;
type WeightInfo = weights::runtime_common_crowdloan::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_common_crowdloan::WeightInfo<Runtime>;
}

parameter_types! {
Expand All @@ -1203,14 +1203,14 @@ impl auctions::Config for Runtime {
type SampleLength = SampleLength;
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
type InitiateOrigin = EitherOf<EnsureRoot<Self::AccountId>, AuctionAdmin>;
type WeightInfo = weights::runtime_common_auctions::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_common_auctions::WeightInfo<Runtime>;
}

impl identity_migrator::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Reaper = EnsureSigned<AccountId>;
type ReapIdentityHandler = ToParachainIdentityReaper<Runtime, Self::AccountId>;
type WeightInfo = weights::runtime_common_identity_migrator::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_common_identity_migrator::WeightInfo<Runtime>;
}

type NisCounterpartInstance = pallet_balances::Instance2;
Expand Down Expand Up @@ -1353,7 +1353,7 @@ impl assigned_slots::Config for Runtime {
type PermanentSlotLeasePeriodLength = PermanentSlotLeasePeriodLength;
type TemporarySlotLeasePeriodLength = TemporarySlotLeasePeriodLength;
type MaxTemporarySlotPerLeasePeriod = MaxTemporarySlotPerLeasePeriod;
type WeightInfo = weights::runtime_common_assigned_slots::WeightInfo<Runtime>;
type WeightInfo = weights::polkadot_runtime_common_assigned_slots::WeightInfo<Runtime>;
}

impl validator_manager::Config for Runtime {
Expand Down
32 changes: 16 additions & 16 deletions polkadot/runtime/rococo/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ pub mod pallet_utility;
pub mod pallet_vesting;
pub mod pallet_whitelist;
pub mod pallet_xcm;
pub mod runtime_common_assigned_slots;
pub mod runtime_common_auctions;
pub mod runtime_common_claims;
pub mod runtime_common_crowdloan;
pub mod runtime_common_identity_migrator;
pub mod runtime_common_paras_registrar;
pub mod runtime_common_slots;
pub mod runtime_parachains_configuration;
pub mod runtime_parachains_coretime;
pub mod runtime_parachains_disputes;
pub mod runtime_parachains_hrmp;
pub mod runtime_parachains_inclusion;
pub mod runtime_parachains_initializer;
pub mod runtime_parachains_on_demand;
pub mod runtime_parachains_paras;
pub mod runtime_parachains_paras_inherent;
pub mod polkadot_runtime_common_assigned_slots;
pub mod polkadot_runtime_common_auctions;
pub mod polkadot_runtime_common_claims;
pub mod polkadot_runtime_common_crowdloan;
pub mod polkadot_runtime_common_identity_migrator;
pub mod polkadot_runtime_common_paras_registrar;
pub mod polkadot_runtime_common_slots;
pub mod polkadot_runtime_parachains_configuration;
pub mod polkadot_runtime_parachains_coretime;
pub mod polkadot_runtime_parachains_disputes;
pub mod polkadot_runtime_parachains_hrmp;
pub mod polkadot_runtime_parachains_inclusion;
pub mod polkadot_runtime_parachains_initializer;
pub mod polkadot_runtime_parachains_on_demand;
pub mod polkadot_runtime_parachains_paras;
pub mod polkadot_runtime_parachains_paras_inherent;
pub mod xcm;
Loading
Loading