Function pallet_staking::offchain_election::trim_to_weight[][src]

pub fn trim_to_weight<T: Config, FN>(
    maximum_allowed_voters: u32,
    mut compact: CompactAssignments,
    nominator_index: FN
) -> Result<CompactAssignments, OffchainElectionError> where
    FN: Fn(&'r T::AccountId) -> Option<NominatorIndex>, 

Greedily reduce the size of the a solution to fit into the block, w.r.t. weight.

The weight of the solution is foremost a function of the number of voters (i.e. compact.len()). Aside from this, the other components of the weight are invariant. The number of winners shall not be changed (otherwise the solution is invalid) and the ElectionSize is merely a representation of the total number of stakers.

Thus, we reside to stripping away some voters. This means only changing the compact struct.

Note that the solution is already computed, and the winners are elected based on the merit of teh entire stake in the system. Nonetheless, some of the voters will be removed further down the line.

Indeed, the score must be computed after this step. If this step reduces the score too much, then the solution will be discarded.