Update Pallet Bags List to use ListError (#11342)

* extract list error changes from kiz-revamp-sorted-list-providers-2-approval-stake

* some fixes

* weight -> score

* Update tests.rs

* Update tests.rs

* more fixes

* remove score updated event

* Update frame/bags-list/src/lib.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Shawn Tabrizi
2022-05-03 23:13:58 +01:00
committed by GitHub
parent e397e0b634
commit 6d6f1e173b
8 changed files with 109 additions and 79 deletions
+6 -4
View File
@@ -803,7 +803,7 @@ impl<T: Config> Pallet<T> {
pub fn do_remove_nominator(who: &T::AccountId) -> bool {
let outcome = if Nominators::<T>::contains_key(who) {
Nominators::<T>::remove(who);
T::VoterList::on_remove(who);
let _ = T::VoterList::on_remove(who).defensive();
true
} else {
false
@@ -850,7 +850,7 @@ impl<T: Config> Pallet<T> {
pub fn do_remove_validator(who: &T::AccountId) -> bool {
let outcome = if Validators::<T>::contains_key(who) {
Validators::<T>::remove(who);
T::VoterList::on_remove(who);
let _ = T::VoterList::on_remove(who).defensive();
true
} else {
false
@@ -1343,11 +1343,13 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsAndValidatorsM
// nothing to do on insert.
Ok(())
}
fn on_update(_: &T::AccountId, _weight: Self::Score) {
fn on_update(_: &T::AccountId, _weight: VoteWeight) -> Result<(), Self::Error> {
// nothing to do on update.
Ok(())
}
fn on_remove(_: &T::AccountId) {
fn on_remove(_: &T::AccountId) -> Result<(), Self::Error> {
// nothing to do on remove.
Ok(())
}
fn unsafe_regenerate(
_: impl IntoIterator<Item = T::AccountId>,
+8 -5
View File
@@ -22,8 +22,8 @@ use frame_support::{
dispatch::Codec,
pallet_prelude::*,
traits::{
Currency, CurrencyToVote, DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get,
LockIdentifier, LockableCurrency, OnUnbalanced, UnixTime,
Currency, CurrencyToVote, Defensive, DefensiveSaturating, EnsureOrigin,
EstimateNextNewSession, Get, LockIdentifier, LockableCurrency, OnUnbalanced, UnixTime,
},
weights::Weight,
};
@@ -858,7 +858,8 @@ pub mod pallet {
Self::update_ledger(&controller, &ledger);
// update this staker in the sorted list, if they exist in it.
if T::VoterList::contains(&stash) {
T::VoterList::on_update(&stash, Self::weight_of(&ledger.stash));
let _ =
T::VoterList::on_update(&stash, Self::weight_of(&ledger.stash)).defensive();
debug_assert_eq!(T::VoterList::sanity_check(), Ok(()));
}
@@ -941,7 +942,8 @@ pub mod pallet {
// update this staker in the sorted list, if they exist in it.
if T::VoterList::contains(&ledger.stash) {
T::VoterList::on_update(&ledger.stash, Self::weight_of(&ledger.stash));
let _ = T::VoterList::on_update(&ledger.stash, Self::weight_of(&ledger.stash))
.defensive();
}
Self::deposit_event(Event::<T>::Unbonded(ledger.stash, value));
@@ -1426,7 +1428,8 @@ pub mod pallet {
// NOTE: ledger must be updated prior to calling `Self::weight_of`.
Self::update_ledger(&controller, &ledger);
if T::VoterList::contains(&ledger.stash) {
T::VoterList::on_update(&ledger.stash, Self::weight_of(&ledger.stash));
let _ = T::VoterList::on_update(&ledger.stash, Self::weight_of(&ledger.stash))
.defensive();
}
let removed_chunks = 1u32 // for the case where the last iterated chunk is not removed