mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
b793666ca5
* Abstracts elections-phragmen pallet to use NposSolver * Update frame/elections-phragmen/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/elections-phragmen/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * changes the name of the pallet; adds changelog * update changelog * Adds weight testing * Adds log macro_rules * renames elections-phragment dir to elections * weights rename * fixes typo in cargo toml * pre/post solve weight scafolding * refactor do_post_election * refactors into pre and post election solve for independent benchmarking * deconstructs PreElectionResults struct * updates benchmarking pre and post election solve; mock weights * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * addresses PR comments * adds pre_solve and post_sove weights * Adds comments on election pallet id param name change * ".git/.scripts/bench-bot.sh" pallet dev pallet_elections * Finishes pre-post solve weights * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/elections/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Addresses PR comments: no panic in on_init path; nits * Fixes node build * Implements approval voting to use as a `NposSolver` (#13367) * Implements the approval voting methods in sp_npos_elections * fmt * remove unecessary file * comment clarification * re-run weights * fix typo * updates MaxVoters in tests for integrity_tests to pass * Refactors election provider support benchmarks outside its own crate (#13431) * Refactors election provider support benchmarks outside its own crate --------- Co-authored-by: command-bot <> --------- Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: parity-processbot <> Co-authored-by: Ross Bulat <ross@parity.io>
71 lines
2.5 KiB
Rust
71 lines
2.5 KiB
Rust
use super::super::*;
|
|
|
|
/// Migrate the locks and vote stake on accounts (as specified with param `to_migrate`) that have
|
|
/// more than their free balance locked.
|
|
///
|
|
/// This migration addresses a bug were a voter could lock up to their reserved balance + free
|
|
/// balance. Since locks are only designed to operate on free balance, this put those affected in a
|
|
/// situation where they could increase their free balance but still not be able to use their funds
|
|
/// because they were less than the lock.
|
|
pub fn migrate<T: Config>(to_migrate: Vec<T::AccountId>) -> Weight {
|
|
let mut weight = Weight::zero();
|
|
|
|
for who in to_migrate.iter() {
|
|
if let Ok(mut voter) = Voting::<T>::try_get(who) {
|
|
let free_balance = T::Currency::free_balance(who);
|
|
|
|
weight = weight.saturating_add(T::DbWeight::get().reads(2));
|
|
|
|
if voter.stake > free_balance {
|
|
voter.stake = free_balance;
|
|
Voting::<T>::insert(&who, voter);
|
|
|
|
let pallet_id = T::PalletId::get();
|
|
T::Currency::set_lock(pallet_id, who, free_balance, WithdrawReasons::all());
|
|
|
|
weight = weight.saturating_add(T::DbWeight::get().writes(2));
|
|
}
|
|
}
|
|
}
|
|
|
|
weight
|
|
}
|
|
|
|
/// Given the list of voters to migrate return a function that does some checks and information
|
|
/// prior to migration. This can be linked to [`frame_support::traits::OnRuntimeUpgrade::
|
|
/// pre_upgrade`] for further testing.
|
|
pub fn pre_migrate_fn<T: Config>(to_migrate: Vec<T::AccountId>) -> Box<dyn Fn() -> ()> {
|
|
Box::new(move || {
|
|
for who in to_migrate.iter() {
|
|
if let Ok(voter) = Voting::<T>::try_get(who) {
|
|
let free_balance = T::Currency::free_balance(who);
|
|
|
|
if voter.stake > free_balance {
|
|
// all good
|
|
} else {
|
|
log::warn!("pre-migrate elections-phragmen: voter={:?} has less stake then free balance", who);
|
|
}
|
|
} else {
|
|
log::warn!("pre-migrate elections-phragmen: cannot find voter={:?}", who);
|
|
}
|
|
}
|
|
log::info!("pre-migrate elections-phragmen complete");
|
|
})
|
|
}
|
|
|
|
/// Some checks for after migration. This can be linked to
|
|
/// [`frame_support::traits::OnRuntimeUpgrade::post_upgrade`] for further testing.
|
|
///
|
|
/// Panics if anything goes wrong.
|
|
pub fn post_migrate<T: crate::Config>() {
|
|
for (who, voter) in Voting::<T>::iter() {
|
|
let free_balance = T::Currency::free_balance(&who);
|
|
|
|
assert!(voter.stake <= free_balance, "migration should have made locked <= free_balance");
|
|
// Ideally we would also check that the locks and AccountData.misc_frozen where correctly
|
|
// updated, but since both of those are generic we can't do that without further bounding T.
|
|
}
|
|
|
|
log::info!("post-migrate elections-phragmen complete");
|
|
}
|