mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 23:41:07 +00:00
Decouple Stkaing and Election - Part1: Support traits (#7908)
* Base features and traits. * Fix the build * Remove unused boxing * Self review cleanup * Fix build
This commit is contained in:
@@ -232,10 +232,11 @@
|
||||
//!
|
||||
//! The controller account can free a portion (or all) of the funds using the
|
||||
//! [`unbond`](enum.Call.html#variant.unbond) call. Note that the funds are not immediately
|
||||
//! accessible. Instead, a duration denoted by [`BondingDuration`](./trait.Config.html#associatedtype.BondingDuration)
|
||||
//! (in number of eras) must pass until the funds can actually be removed. Once the
|
||||
//! `BondingDuration` is over, the [`withdraw_unbonded`](./enum.Call.html#variant.withdraw_unbonded)
|
||||
//! call can be used to actually withdraw the funds.
|
||||
//! accessible. Instead, a duration denoted by
|
||||
//! [`BondingDuration`](./trait.Config.html#associatedtype.BondingDuration) (in number of eras) must
|
||||
//! pass until the funds can actually be removed. Once the `BondingDuration` is over, the
|
||||
//! [`withdraw_unbonded`](./enum.Call.html#variant.withdraw_unbonded) call can be used to actually
|
||||
//! withdraw the funds.
|
||||
//!
|
||||
//! Note that there is a limitation to the number of fund-chunks that can be scheduled to be
|
||||
//! unlocked in the future via [`unbond`](enum.Call.html#variant.unbond). In case this maximum
|
||||
@@ -304,7 +305,7 @@ use frame_support::{
|
||||
};
|
||||
use pallet_session::historical;
|
||||
use sp_runtime::{
|
||||
Percent, Perbill, PerU16, PerThing, InnerOf, RuntimeDebug, DispatchError,
|
||||
Percent, Perbill, PerU16, InnerOf, RuntimeDebug, DispatchError,
|
||||
curve::PiecewiseLinear,
|
||||
traits::{
|
||||
Convert, Zero, StaticLookup, CheckedSub, Saturating, SaturatedConversion,
|
||||
@@ -327,14 +328,14 @@ use frame_system::{
|
||||
};
|
||||
use sp_npos_elections::{
|
||||
ExtendedBalance, Assignment, ElectionScore, ElectionResult as PrimitiveElectionResult,
|
||||
build_support_map, evaluate_support, seq_phragmen, generate_solution_type,
|
||||
is_score_better, VotingLimit, SupportMap, VoteWeight,
|
||||
to_support_map, EvaluateSupport, seq_phragmen, generate_solution_type, is_score_better,
|
||||
SupportMap, VoteWeight, CompactSolution, PerThing128,
|
||||
};
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
const STAKING_ID: LockIdentifier = *b"staking ";
|
||||
pub const MAX_UNLOCKING_CHUNKS: usize = 32;
|
||||
pub const MAX_NOMINATIONS: usize = <CompactAssignments as VotingLimit>::LIMIT;
|
||||
pub const MAX_NOMINATIONS: usize = <CompactAssignments as CompactSolution>::LIMIT;
|
||||
|
||||
pub(crate) const LOG_TARGET: &'static str = "staking";
|
||||
|
||||
@@ -2105,7 +2106,7 @@ decl_module! {
|
||||
#[weight = T::WeightInfo::submit_solution_better(
|
||||
size.validators.into(),
|
||||
size.nominators.into(),
|
||||
compact.len() as u32,
|
||||
compact.voter_count() as u32,
|
||||
winners.len() as u32,
|
||||
)]
|
||||
pub fn submit_election_solution(
|
||||
@@ -2139,7 +2140,7 @@ decl_module! {
|
||||
#[weight = T::WeightInfo::submit_solution_better(
|
||||
size.validators.into(),
|
||||
size.nominators.into(),
|
||||
compact.len() as u32,
|
||||
compact.voter_count() as u32,
|
||||
winners.len() as u32,
|
||||
)]
|
||||
pub fn submit_election_solution_unsigned(
|
||||
@@ -2601,13 +2602,11 @@ impl<T: Config> Module<T> {
|
||||
);
|
||||
|
||||
// build the support map thereof in order to evaluate.
|
||||
let supports = build_support_map::<T::AccountId>(
|
||||
&winners,
|
||||
&staked_assignments,
|
||||
).map_err(|_| Error::<T>::OffchainElectionBogusEdge)?;
|
||||
let supports = to_support_map::<T::AccountId>(&winners, &staked_assignments)
|
||||
.map_err(|_| Error::<T>::OffchainElectionBogusEdge)?;
|
||||
|
||||
// Check if the score is the same as the claimed one.
|
||||
let submitted_score = evaluate_support(&supports);
|
||||
let submitted_score = (&supports).evaluate();
|
||||
ensure!(submitted_score == claimed_score, Error::<T>::OffchainElectionBogusScore);
|
||||
|
||||
// At last, alles Ok. Exposures and store the result.
|
||||
@@ -2863,7 +2862,7 @@ impl<T: Config> Module<T> {
|
||||
Self::slashable_balance_of_fn(),
|
||||
);
|
||||
|
||||
let supports = build_support_map::<T::AccountId>(
|
||||
let supports = to_support_map::<T::AccountId>(
|
||||
&elected_stashes,
|
||||
&staked_assignments,
|
||||
)
|
||||
@@ -2902,7 +2901,7 @@ impl<T: Config> Module<T> {
|
||||
/// Self votes are added and nominations before the most recent slashing span are ignored.
|
||||
///
|
||||
/// No storage item is updated.
|
||||
pub fn do_phragmen<Accuracy: PerThing>(
|
||||
pub fn do_phragmen<Accuracy: PerThing128>(
|
||||
iterations: usize,
|
||||
) -> Option<PrimitiveElectionResult<T::AccountId, Accuracy>>
|
||||
where
|
||||
@@ -2952,7 +2951,7 @@ impl<T: Config> Module<T> {
|
||||
all_nominators,
|
||||
Some((iterations, 0)), // exactly run `iterations` rounds.
|
||||
)
|
||||
.map_err(|err| log!(error, "Call to seq-phragmen failed due to {}", err))
|
||||
.map_err(|err| log!(error, "Call to seq-phragmen failed due to {:?}", err))
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user