Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions prdoc/pr_11156.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: 'election-provider-multi-block: reduce overclaimed proof_size during Signed
phase'
doc:
- audience: Runtime Dev
description: |-
on_initialize claimed on_initialize_into_signed weight (> ~3M proof_size) every block during the Signed phase, but the heavy work (loading voter snapshots) only happens once when transitioning from Snapshot into Signed.
Use discriminant comparison to distinguish phase entry from same-phase ticks, falling back to on_initialize_nothing for the latter.
crates:
- name: pallet-election-provider-multi-block
bump: patch
25 changes: 19 additions & 6 deletions substrate/frame/election-provider-multi-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,25 @@ pub mod pallet {
if !matches!(current_phase, Phase::Export(_)) {
let next_phase = current_phase.next();

let weight2 = match next_phase {
Phase::Signed(_) => T::WeightInfo::on_initialize_into_signed(),
Phase::SignedValidation(_) =>
T::WeightInfo::on_initialize_into_signed_validation(),
Phase::Unsigned(_) => T::WeightInfo::on_initialize_into_unsigned(),
_ => T::WeightInfo::on_initialize_nothing(),
let weight2 = {
use sp_std::mem::discriminant;
if discriminant(&current_phase) != discriminant(&next_phase) {
// Claim the heavy phase-entry weight only when the
// discriminant actually changes (e.g. Snapshot -> Signed).
// Ticks within the same phase (e.g. Signed(N) -> Signed(N-1))
// only write CurrentPhase.
// For Snapshot blocks the real cost is already accounted for by weight1
// above.
match next_phase {
Phase::Signed(_) => T::WeightInfo::on_initialize_into_signed(),
Phase::SignedValidation(_) =>
T::WeightInfo::on_initialize_into_signed_validation(),
Phase::Unsigned(_) => T::WeightInfo::on_initialize_into_unsigned(),
_ => T::WeightInfo::on_initialize_nothing(),
}
} else {
T::WeightInfo::on_initialize_nothing()
}
};

Self::phase_transition(next_phase);
Expand Down
Loading