mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
@@ -118,14 +118,12 @@ pub struct PhragmenResult<AccountId> {
|
||||
/// This, at the current version, resembles the `Exposure` defined in the staking SRML module, yet
|
||||
/// they do not necessarily have to be the same.
|
||||
#[derive(Default, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize, Eq, PartialEq))]
|
||||
pub struct Support<AccountId> {
|
||||
/// The amount of support as the effect of self-vote.
|
||||
pub own: ExtendedBalance,
|
||||
/// Total support.
|
||||
pub total: ExtendedBalance,
|
||||
/// Support from voters.
|
||||
pub others: Vec<PhragmenStakedAssignment<AccountId>>,
|
||||
pub voters: Vec<PhragmenStakedAssignment<AccountId>>,
|
||||
}
|
||||
|
||||
/// A linkage from a candidate and its [`Support`].
|
||||
@@ -368,20 +366,8 @@ pub fn build_support_map<Balance, AccountId, FS, C>(
|
||||
// per-things to be sound.
|
||||
let other_stake = *per_thing * nominator_stake;
|
||||
if let Some(support) = supports.get_mut(c) {
|
||||
if c == n {
|
||||
// This is a nomination from `n` to themselves. This will increase both the
|
||||
// `own` and `total` field.
|
||||
debug_assert!(*per_thing == Perbill::one()); // TODO: deal with this: do we want it?
|
||||
support.own = support.own.saturating_add(other_stake);
|
||||
support.total = support.total.saturating_add(other_stake);
|
||||
} else {
|
||||
// This is a nomination from `n` to someone else. Increase `total` and add an entry
|
||||
// inside `others`.
|
||||
// For an astronomically rich validator with more astronomically rich
|
||||
// set of nominators, this might saturate.
|
||||
support.total = support.total.saturating_add(other_stake);
|
||||
support.others.push((n.clone(), other_stake));
|
||||
}
|
||||
support.voters.push((n.clone(), other_stake));
|
||||
support.total = support.total.saturating_add(other_stake);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -450,8 +436,8 @@ fn do_equalize<Balance, AccountId, C>(
|
||||
let budget = to_votes(budget_balance);
|
||||
|
||||
// Nothing to do. This voter had nothing useful.
|
||||
// Defensive only. Assignment list should always be populated.
|
||||
if elected_edges.is_empty() { return 0; }
|
||||
// Defensive only. Assignment list should always be populated. 1 might happen for self vote.
|
||||
if elected_edges.is_empty() || elected_edges.len() == 1 { return 0; }
|
||||
|
||||
let stake_used = elected_edges
|
||||
.iter()
|
||||
@@ -492,7 +478,7 @@ fn do_equalize<Balance, AccountId, C>(
|
||||
elected_edges.iter_mut().for_each(|e| {
|
||||
if let Some(support) = support_map.get_mut(&e.0) {
|
||||
support.total = support.total.saturating_sub(e.1);
|
||||
support.others.retain(|i_support| i_support.0 != *voter);
|
||||
support.voters.retain(|i_support| i_support.0 != *voter);
|
||||
}
|
||||
e.1 = 0;
|
||||
});
|
||||
@@ -529,7 +515,7 @@ fn do_equalize<Balance, AccountId, C>(
|
||||
.saturating_add(last_stake)
|
||||
.saturating_sub(support.total);
|
||||
support.total = support.total.saturating_add(e.1);
|
||||
support.others.push((voter.clone(), e.1));
|
||||
support.voters.push((voter.clone(), e.1));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user