From d850e3a9357d534da6c8ce547215f588f9fa3261 Mon Sep 17 00:00:00 2001 From: Paolo La Camera Date: Tue, 24 Feb 2026 11:40:53 +0100 Subject: [PATCH 1/2] election-provider-multi-block: reduce overclaimed proof_size during Signed phase 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. --- .../election-provider-multi-block/src/lib.rs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/substrate/frame/election-provider-multi-block/src/lib.rs b/substrate/frame/election-provider-multi-block/src/lib.rs index bd956cba23595..c6cfd97cff0b8 100644 --- a/substrate/frame/election-provider-multi-block/src/lib.rs +++ b/substrate/frame/election-provider-multi-block/src/lib.rs @@ -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(¤t_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); From f52b008da368c1ddd13cf3a6b8b768a4428faf29 Mon Sep 17 00:00:00 2001 From: "cmd[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 24 Feb 2026 10:51:37 +0000 Subject: [PATCH 2/2] Update from github-actions[bot] running command 'prdoc --audience runtime_dev --bump patch' --- prdoc/pr_11156.prdoc | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 prdoc/pr_11156.prdoc diff --git a/prdoc/pr_11156.prdoc b/prdoc/pr_11156.prdoc new file mode 100644 index 0000000000000..cf7036bbd24ac --- /dev/null +++ b/prdoc/pr_11156.prdoc @@ -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