Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Bring back the on_finalize weight of staking. #8463

Merged
13 commits merged into from
Mar 29, 2021
16 changes: 8 additions & 8 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ impl Default for ElectionCompute {
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct RawSolution<C> {
/// Compact election edges.
compact: C,
pub compact: C,
coriolinus marked this conversation as resolved.
Show resolved Hide resolved
/// The _claimed_ score of the solution.
score: ElectionScore,
pub score: ElectionScore,
/// The round at which this solution should be submitted.
round: u32,
pub round: u32,
}

impl<C: Default> Default for RawSolution<C> {
Expand All @@ -402,13 +402,13 @@ pub struct ReadySolution<A> {
///
/// This is target-major vector, storing each winners, total backing, and each individual
/// backer.
supports: Supports<A>,
pub supports: Supports<A>,
/// The score of the solution.
///
/// This is needed to potentially challenge the solution.
score: ElectionScore,
pub score: ElectionScore,
/// How this election was computed.
compute: ElectionCompute,
pub compute: ElectionCompute,
}

/// A snapshot of all the data that is needed for en entire round. They are provided by
Expand All @@ -432,10 +432,10 @@ pub struct RoundSnapshot<A> {
pub struct SolutionOrSnapshotSize {
/// The length of voters.
#[codec(compact)]
voters: u32,
pub voters: u32,
/// The length of targets.
#[codec(compact)]
targets: u32,
pub targets: u32,
}

/// Internal errors of the pallet.
Expand Down
9 changes: 8 additions & 1 deletion frame/election-provider-multi-phase/src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,16 @@ impl<T: Config> Pallet<T> {
size,
T::MinerMaxWeight::get(),
);

log!(
debug,
"miner: current compact solution voters = {}, maximum_allowed = {}",
"initial solution voters = {}, snapshot = {:?}, maximum_allowed(capped) = {}",
compact.voter_count(),
size,
maximum_allowed_voters,
);

// trim weight.
let compact = Self::trim_compact(maximum_allowed_voters, compact, &voter_index)?;

// re-calc score.
Expand Down Expand Up @@ -252,10 +256,12 @@ impl<T: Config> Pallet<T> {
}
}

log!(debug, "removed {} voter to meet the max weight limit.", to_remove);
Ok(compact)
}
_ => {
// nada, return as-is
log!(debug, "Didn't remove any voter for weight limits.");
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
Ok(compact)
}
}
Expand Down Expand Up @@ -330,6 +336,7 @@ impl<T: Config> Pallet<T> {
voters.min(size.voters),
max_weight,
);
log!(debug, "maximum allowed voters would have been {}.", voters);
voters.min(size.voters)
}

Expand Down
5 changes: 5 additions & 0 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,11 @@ decl_module! {
}
}

fn on_initialize(_now: T::BlockNumber) -> Weight {
// just return the weight of the on_finalize
T::DbWeight::get().reads_writes(1, 1)
}

fn on_finalize() {
// Set the start of the first era.
if let Some(mut active_era) = Self::active_era() {
Expand Down