Skip to content

Commit cc7ebe0

Browse files
author
ordian
authored
short-term fix for para inherent weight overestimation (#5082)
closes #849 ## Context For the background on this and the long-term fix, see #849 (comment). ## Changes * The weigh files are renamed from `runtime_(parachains|common).*` to `polkadot_runtime_(parachains|common).*`. The reason for it is the renaming introduced in #4633. The new weight command and files are generated now include `polkadot_` prefix. * The WeightInfo for `paras_inherent` now includes `enter_empty` which calculates the cost of processing an empty parachains inherent. This cost is subtracted dynamically when calculating other weights (so the other weights remain the same) ## Benefits See #849 (comment), but TL;DR is that we are not blocked on weights for scaling the number of validators and cores further. Resolved questions: - [x] why new benchmarks for westend are doing fewer db IOPS? Is it due polkadot-sdk update (db IOPS diff)? or the bench setup is no longer valid? https://github.com/polkadot-fellows/runtimes/blob/7723274a2c5cbb10213379271094d5180716ca7d/relay/polkadot/src/weights/runtime_parachains_paras_inherent.rs#L131-L196 Answer: see background section of #5270 TODOs: - [x] Rerun benchmarks for Rococo and Westend - [x] PRDoc --------- Co-authored-by: command-bot <>
1 parent 5620196 commit cc7ebe0

File tree

42 files changed

+270
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+270
-207
lines changed

polkadot/runtime/parachains/src/builder.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,10 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
221221
.expect("self.block_number is u32")
222222
}
223223

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

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

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

292293
fn mock_head_data() -> HeadData {
@@ -356,11 +357,11 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
356357
availability_votes,
357358
commitments,
358359
);
359-
inclusion::PendingAvailability::<T>::mutate(para_id, |maybe_andidates| {
360-
if let Some(candidates) = maybe_andidates {
360+
inclusion::PendingAvailability::<T>::mutate(para_id, |maybe_candidates| {
361+
if let Some(candidates) = maybe_candidates {
361362
candidates.push_back(candidate_availability);
362363
} else {
363-
*maybe_andidates =
364+
*maybe_candidates =
364365
Some([candidate_availability].into_iter().collect::<VecDeque<_>>());
365366
}
366367
});

polkadot/runtime/parachains/src/paras_inherent/benchmarking.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ use polkadot_primitives::v7::GroupIndex;
2626
use crate::builder::BenchBuilder;
2727

2828
benchmarks! {
29+
enter_empty {
30+
let scenario = BenchBuilder::<T>::new()
31+
.build();
32+
33+
let mut benchmark = scenario.data.clone();
34+
35+
benchmark.bitfields.clear();
36+
benchmark.backed_candidates.clear();
37+
benchmark.disputes.clear();
38+
}: enter(RawOrigin::None, benchmark)
39+
verify {
40+
// Assert that the block was not discarded
41+
assert!(Included::<T>::get().is_some());
42+
}
2943
// Variant over `v`, the number of dispute statements in a dispute statement set. This gives the
3044
// weight of a single dispute statement set.
3145
enter_variable_disputes {
@@ -92,18 +106,8 @@ benchmarks! {
92106
// Variant over `v`, the amount of validity votes for a backed candidate. This gives the weight
93107
// of a single backed candidate.
94108
enter_backed_candidates_variable {
95-
// NOTE: the starting value must be over half of the max validators per group so the backed
96-
// candidate is not rejected. Also, we cannot have more validity votes than validators in
97-
// the group.
98-
99-
// Do not use this range for Rococo because it only has 1 validator per backing group,
100-
// which causes issues when trying to create slopes with the benchmarking analysis. Instead
101-
// use v = 1 for running Rococo benchmarks
102-
let v in (BenchBuilder::<T>::fallback_min_validity_votes())
103-
..(BenchBuilder::<T>::fallback_max_validators());
104-
105-
// Comment in for running rococo benchmarks
106-
// let v = 1;
109+
let v in (BenchBuilder::<T>::fallback_min_backing_votes())
110+
..(BenchBuilder::<T>::fallback_max_validators_per_core());
107111

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

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

159162
let cores_with_backed: BTreeMap<_, _>
160-
= vec![(0, BenchBuilder::<T>::fallback_min_validity_votes())]
163+
= vec![(0, BenchBuilder::<T>::fallback_min_backing_votes())]
161164
.into_iter()
162165
.collect();
163166

@@ -168,8 +171,10 @@ benchmarks! {
168171

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

171-
// let votes = BenchBuilder::<T>::fallback_min_validity_votes() as usize;
172-
let votes = min(scheduler::Pallet::<T>::group_validators(GroupIndex::from(0)).unwrap().len(), BenchBuilder::<T>::fallback_min_validity_votes() as usize);
174+
let votes = min(
175+
scheduler::Pallet::<T>::group_validators(GroupIndex::from(0)).unwrap().len(),
176+
BenchBuilder::<T>::fallback_min_backing_votes() as usize
177+
);
173178

174179
// There is 1 backed
175180
assert_eq!(benchmark.backed_candidates.len(), 1);

polkadot/runtime/parachains/src/paras_inherent/weights.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use polkadot_primitives::{
2828
use super::{BackedCandidate, Config, DisputeStatementSet, Weight};
2929

3030
pub trait WeightInfo {
31+
/// The weight of processing an empty parachain inherent.
32+
fn enter_empty() -> Weight;
3133
/// Variant over `v`, the count of dispute statements in a dispute statement set. This gives the
3234
/// weight of a single dispute statement set.
3335
fn enter_variable_disputes(v: u32) -> Weight;
@@ -45,6 +47,9 @@ pub struct TestWeightInfo;
4547
// mock.
4648
#[cfg(not(feature = "runtime-benchmarks"))]
4749
impl WeightInfo for TestWeightInfo {
50+
fn enter_empty() -> Weight {
51+
Weight::zero()
52+
}
4853
fn enter_variable_disputes(v: u32) -> Weight {
4954
// MAX Block Weight should fit 4 disputes
5055
Weight::from_parts(80_000 * v as u64 + 80_000, 0)
@@ -66,6 +71,9 @@ impl WeightInfo for TestWeightInfo {
6671
// running as a test.
6772
#[cfg(feature = "runtime-benchmarks")]
6873
impl WeightInfo for TestWeightInfo {
74+
fn enter_empty() -> Weight {
75+
Weight::zero()
76+
}
6977
fn enter_variable_disputes(_v: u32) -> Weight {
7078
Weight::zero()
7179
}
@@ -123,7 +131,8 @@ where
123131
set_proof_size_to_tx_size(
124132
<<T as Config>::WeightInfo as WeightInfo>::enter_variable_disputes(
125133
statement_set.as_ref().statements.len() as u32,
126-
),
134+
)
135+
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty()),
127136
statement_set,
128137
)
129138
}
@@ -133,14 +142,16 @@ pub fn signed_bitfields_weight<T: Config>(
133142
) -> Weight {
134143
set_proof_size_to_tx_size(
135144
<<T as Config>::WeightInfo as WeightInfo>::enter_bitfields()
145+
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty())
136146
.saturating_mul(bitfields.len() as u64),
137147
bitfields,
138148
)
139149
}
140150

141151
pub fn signed_bitfield_weight<T: Config>(bitfield: &UncheckedSignedAvailabilityBitfield) -> Weight {
142152
set_proof_size_to_tx_size(
143-
<<T as Config>::WeightInfo as WeightInfo>::enter_bitfields(),
153+
<<T as Config>::WeightInfo as WeightInfo>::enter_bitfields()
154+
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty()),
144155
bitfield,
145156
)
146157
}
@@ -155,7 +166,8 @@ pub fn backed_candidate_weight<T: frame_system::Config + Config>(
155166
<<T as Config>::WeightInfo as WeightInfo>::enter_backed_candidates_variable(
156167
candidate.validity_votes().len() as u32,
157168
)
158-
},
169+
}
170+
.saturating_sub(<<T as Config>::WeightInfo as WeightInfo>::enter_empty()),
159171
candidate,
160172
)
161173
}

polkadot/runtime/rococo/src/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090
fn on_reap_identity(who: &AccountId, fields: u32, subs: u32) -> DispatchResult {
9191
use crate::{
9292
impls::IdentityMigratorCalls::PokeDeposit,
93-
weights::runtime_common_identity_migrator::WeightInfo as MigratorWeights,
93+
weights::polkadot_runtime_common_identity_migrator::WeightInfo as MigratorWeights,
9494
};
9595

9696
let total_to_send = Self::calculate_remote_deposit(fields, subs);

polkadot/runtime/rococo/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl claims::Config for Runtime {
674674
type VestingSchedule = Vesting;
675675
type Prefix = Prefix;
676676
type MoveClaimOrigin = EnsureRoot<AccountId>;
677-
type WeightInfo = weights::runtime_common_claims::WeightInfo<Runtime>;
677+
type WeightInfo = weights::polkadot_runtime_common_claims::WeightInfo<Runtime>;
678678
}
679679

680680
parameter_types! {
@@ -940,7 +940,7 @@ impl pallet_proxy::Config for Runtime {
940940
impl parachains_origin::Config for Runtime {}
941941

942942
impl parachains_configuration::Config for Runtime {
943-
type WeightInfo = weights::runtime_parachains_configuration::WeightInfo<Runtime>;
943+
type WeightInfo = weights::polkadot_runtime_parachains_configuration::WeightInfo<Runtime>;
944944
}
945945

946946
impl parachains_shared::Config for Runtime {
@@ -963,7 +963,7 @@ impl parachains_inclusion::Config for Runtime {
963963
type DisputesHandler = ParasDisputes;
964964
type RewardValidators = RewardValidators;
965965
type MessageQueue = MessageQueue;
966-
type WeightInfo = weights::runtime_parachains_inclusion::WeightInfo<Runtime>;
966+
type WeightInfo = weights::polkadot_runtime_parachains_inclusion::WeightInfo<Runtime>;
967967
}
968968

969969
parameter_types! {
@@ -972,7 +972,7 @@ parameter_types! {
972972

973973
impl parachains_paras::Config for Runtime {
974974
type RuntimeEvent = RuntimeEvent;
975-
type WeightInfo = weights::runtime_parachains_paras::WeightInfo<Runtime>;
975+
type WeightInfo = weights::polkadot_runtime_parachains_paras::WeightInfo<Runtime>;
976976
type UnsignedPriority = ParasUnsignedPriority;
977977
type QueueFootprinter = ParaInclusion;
978978
type NextSessionRotation = Babe;
@@ -1046,11 +1046,11 @@ impl parachains_hrmp::Config for Runtime {
10461046
HrmpChannelSizeAndCapacityWithSystemRatio,
10471047
>;
10481048
type VersionWrapper = crate::XcmPallet;
1049-
type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo<Runtime>;
1049+
type WeightInfo = weights::polkadot_runtime_parachains_hrmp::WeightInfo<Runtime>;
10501050
}
10511051

10521052
impl parachains_paras_inherent::Config for Runtime {
1053-
type WeightInfo = weights::runtime_parachains_paras_inherent::WeightInfo<Runtime>;
1053+
type WeightInfo = weights::polkadot_runtime_parachains_paras_inherent::WeightInfo<Runtime>;
10541054
}
10551055

10561056
impl parachains_scheduler::Config for Runtime {
@@ -1079,7 +1079,7 @@ impl coretime::Config for Runtime {
10791079
type Currency = Balances;
10801080
type BrokerId = BrokerId;
10811081
type BrokerPotLocation = BrokerPot;
1082-
type WeightInfo = weights::runtime_parachains_coretime::WeightInfo<Runtime>;
1082+
type WeightInfo = weights::polkadot_runtime_parachains_coretime::WeightInfo<Runtime>;
10831083
type SendXcm = crate::xcm_config::XcmRouter;
10841084
type AssetTransactor = crate::xcm_config::LocalAssetTransactor;
10851085
type AccountToLocation = xcm_builder::AliasesIntoAccountId32<
@@ -1100,7 +1100,7 @@ impl parachains_on_demand::Config for Runtime {
11001100
type RuntimeEvent = RuntimeEvent;
11011101
type Currency = Balances;
11021102
type TrafficDefaultValue = OnDemandTrafficDefaultValue;
1103-
type WeightInfo = weights::runtime_parachains_on_demand::WeightInfo<Runtime>;
1103+
type WeightInfo = weights::polkadot_runtime_parachains_on_demand::WeightInfo<Runtime>;
11041104
type MaxHistoricalRevenue = MaxHistoricalRevenue;
11051105
type PalletId = OnDemandPalletId;
11061106
}
@@ -1110,15 +1110,15 @@ impl parachains_assigner_coretime::Config for Runtime {}
11101110
impl parachains_initializer::Config for Runtime {
11111111
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
11121112
type ForceOrigin = EnsureRoot<AccountId>;
1113-
type WeightInfo = weights::runtime_parachains_initializer::WeightInfo<Runtime>;
1113+
type WeightInfo = weights::polkadot_runtime_parachains_initializer::WeightInfo<Runtime>;
11141114
type CoretimeOnNewSession = Coretime;
11151115
}
11161116

11171117
impl parachains_disputes::Config for Runtime {
11181118
type RuntimeEvent = RuntimeEvent;
11191119
type RewardValidators = ();
11201120
type SlashingHandler = parachains_slashing::SlashValidatorsForDisputes<ParasSlashing>;
1121-
type WeightInfo = weights::runtime_parachains_disputes::WeightInfo<Runtime>;
1121+
type WeightInfo = weights::polkadot_runtime_parachains_disputes::WeightInfo<Runtime>;
11221122
}
11231123

11241124
impl parachains_slashing::Config for Runtime {
@@ -1149,7 +1149,7 @@ impl paras_registrar::Config for Runtime {
11491149
type OnSwap = (Crowdloan, Slots, SwapLeases);
11501150
type ParaDeposit = ParaDeposit;
11511151
type DataDepositPerByte = DataDepositPerByte;
1152-
type WeightInfo = weights::runtime_common_paras_registrar::WeightInfo<Runtime>;
1152+
type WeightInfo = weights::polkadot_runtime_common_paras_registrar::WeightInfo<Runtime>;
11531153
}
11541154

11551155
parameter_types! {
@@ -1163,7 +1163,7 @@ impl slots::Config for Runtime {
11631163
type LeasePeriod = LeasePeriod;
11641164
type LeaseOffset = ();
11651165
type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, LeaseAdmin>;
1166-
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
1166+
type WeightInfo = weights::polkadot_runtime_common_slots::WeightInfo<Runtime>;
11671167
}
11681168

11691169
parameter_types! {
@@ -1184,7 +1184,7 @@ impl crowdloan::Config for Runtime {
11841184
type Registrar = Registrar;
11851185
type Auctioneer = Auctions;
11861186
type MaxMemoLength = MaxMemoLength;
1187-
type WeightInfo = weights::runtime_common_crowdloan::WeightInfo<Runtime>;
1187+
type WeightInfo = weights::polkadot_runtime_common_crowdloan::WeightInfo<Runtime>;
11881188
}
11891189

11901190
parameter_types! {
@@ -1203,14 +1203,14 @@ impl auctions::Config for Runtime {
12031203
type SampleLength = SampleLength;
12041204
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
12051205
type InitiateOrigin = EitherOf<EnsureRoot<Self::AccountId>, AuctionAdmin>;
1206-
type WeightInfo = weights::runtime_common_auctions::WeightInfo<Runtime>;
1206+
type WeightInfo = weights::polkadot_runtime_common_auctions::WeightInfo<Runtime>;
12071207
}
12081208

12091209
impl identity_migrator::Config for Runtime {
12101210
type RuntimeEvent = RuntimeEvent;
12111211
type Reaper = EnsureSigned<AccountId>;
12121212
type ReapIdentityHandler = ToParachainIdentityReaper<Runtime, Self::AccountId>;
1213-
type WeightInfo = weights::runtime_common_identity_migrator::WeightInfo<Runtime>;
1213+
type WeightInfo = weights::polkadot_runtime_common_identity_migrator::WeightInfo<Runtime>;
12141214
}
12151215

12161216
type NisCounterpartInstance = pallet_balances::Instance2;
@@ -1353,7 +1353,7 @@ impl assigned_slots::Config for Runtime {
13531353
type PermanentSlotLeasePeriodLength = PermanentSlotLeasePeriodLength;
13541354
type TemporarySlotLeasePeriodLength = TemporarySlotLeasePeriodLength;
13551355
type MaxTemporarySlotPerLeasePeriod = MaxTemporarySlotPerLeasePeriod;
1356-
type WeightInfo = weights::runtime_common_assigned_slots::WeightInfo<Runtime>;
1356+
type WeightInfo = weights::polkadot_runtime_common_assigned_slots::WeightInfo<Runtime>;
13571357
}
13581358

13591359
impl validator_manager::Config for Runtime {

polkadot/runtime/rococo/src/weights/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ pub mod pallet_utility;
4444
pub mod pallet_vesting;
4545
pub mod pallet_whitelist;
4646
pub mod pallet_xcm;
47-
pub mod runtime_common_assigned_slots;
48-
pub mod runtime_common_auctions;
49-
pub mod runtime_common_claims;
50-
pub mod runtime_common_crowdloan;
51-
pub mod runtime_common_identity_migrator;
52-
pub mod runtime_common_paras_registrar;
53-
pub mod runtime_common_slots;
54-
pub mod runtime_parachains_configuration;
55-
pub mod runtime_parachains_coretime;
56-
pub mod runtime_parachains_disputes;
57-
pub mod runtime_parachains_hrmp;
58-
pub mod runtime_parachains_inclusion;
59-
pub mod runtime_parachains_initializer;
60-
pub mod runtime_parachains_on_demand;
61-
pub mod runtime_parachains_paras;
62-
pub mod runtime_parachains_paras_inherent;
47+
pub mod polkadot_runtime_common_assigned_slots;
48+
pub mod polkadot_runtime_common_auctions;
49+
pub mod polkadot_runtime_common_claims;
50+
pub mod polkadot_runtime_common_crowdloan;
51+
pub mod polkadot_runtime_common_identity_migrator;
52+
pub mod polkadot_runtime_common_paras_registrar;
53+
pub mod polkadot_runtime_common_slots;
54+
pub mod polkadot_runtime_parachains_configuration;
55+
pub mod polkadot_runtime_parachains_coretime;
56+
pub mod polkadot_runtime_parachains_disputes;
57+
pub mod polkadot_runtime_parachains_hrmp;
58+
pub mod polkadot_runtime_parachains_inclusion;
59+
pub mod polkadot_runtime_parachains_initializer;
60+
pub mod polkadot_runtime_parachains_on_demand;
61+
pub mod polkadot_runtime_parachains_paras;
62+
pub mod polkadot_runtime_parachains_paras_inherent;
6363
pub mod xcm;

0 commit comments

Comments
 (0)