mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 20:55:41 +00:00
Some benchmarks for phragmen (#2650)
* Add some benchmarks for phragmen * Fix dep. import. * Clean up with some macros. * more details. * Fix dual import. * Remove wrong assertions. * Add a few more.
This commit is contained in:
@@ -107,29 +107,29 @@ pub fn elect<T: Trait + 'static, FV, FN, FS>(
|
||||
// Candidates who have 0 stake => have no votes or all null-votes. Kick them out not.
|
||||
let mut nominators: Vec<Nominator<T::AccountId>> = Vec::with_capacity(validator_iter.size_hint().0 + nominator_iter.size_hint().0);
|
||||
let mut candidates = validator_iter.map(|(who, _)| {
|
||||
let stash_balance = stash_of(&who);
|
||||
(Candidate { who, ..Default::default() }, stash_balance)
|
||||
})
|
||||
.filter_map(|(mut c, s)| {
|
||||
c.approval_stake += to_votes(s);
|
||||
if c.approval_stake.is_zero() {
|
||||
None
|
||||
} else {
|
||||
Some((c, s))
|
||||
}
|
||||
})
|
||||
.enumerate()
|
||||
.map(|(idx, (c, s))| {
|
||||
nominators.push(Nominator {
|
||||
who: c.who.clone(),
|
||||
edges: vec![ Edge { who: c.who.clone(), candidate_index: idx, ..Default::default() }],
|
||||
budget: to_votes(s),
|
||||
load: Fraction::zero(),
|
||||
});
|
||||
c_idx_cache.insert(c.who.clone(), idx);
|
||||
c
|
||||
})
|
||||
.collect::<Vec<Candidate<T::AccountId>>>();
|
||||
let stash_balance = stash_of(&who);
|
||||
(Candidate { who, ..Default::default() }, stash_balance)
|
||||
})
|
||||
.filter_map(|(mut c, s)| {
|
||||
c.approval_stake += to_votes(s);
|
||||
if c.approval_stake.is_zero() {
|
||||
None
|
||||
} else {
|
||||
Some((c, s))
|
||||
}
|
||||
})
|
||||
.enumerate()
|
||||
.map(|(idx, (c, s))| {
|
||||
nominators.push(Nominator {
|
||||
who: c.who.clone(),
|
||||
edges: vec![ Edge { who: c.who.clone(), candidate_index: idx, ..Default::default() }],
|
||||
budget: to_votes(s),
|
||||
load: Fraction::zero(),
|
||||
});
|
||||
c_idx_cache.insert(c.who.clone(), idx);
|
||||
c
|
||||
})
|
||||
.collect::<Vec<Candidate<T::AccountId>>>();
|
||||
|
||||
// 2- Collect the nominators with the associated votes.
|
||||
// Also collect approval stake along the way.
|
||||
|
||||
Reference in New Issue
Block a user