mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 16:41:10 +00:00
Proposal: Defensive trait for infallible frame operations (#10626)
* add a blueprint of how defensive traits could look like * add something for arithmetic as well * add some use cases in different pallets * some build fixing * Some new stuff and examples * Fix deadly bug * add more doc. * undo faulty change to assets pallet * Update frame/support/src/traits/misc.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * some review comments * remove draft comment * Fix ident test * Fix proxy tests as well * a few new ideas * Fix build * Fix doc Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -24,8 +24,8 @@ use frame_election_provider_support::{
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{
|
||||
Currency, CurrencyToVote, EstimateNextNewSession, Get, Imbalance, LockableCurrency,
|
||||
OnUnbalanced, UnixTime, WithdrawReasons,
|
||||
Currency, CurrencyToVote, Defensive, EstimateNextNewSession, Get, Imbalance,
|
||||
LockableCurrency, OnUnbalanced, UnixTime, WithdrawReasons,
|
||||
},
|
||||
weights::{Weight, WithPostDispatchInfo},
|
||||
};
|
||||
@@ -775,10 +775,8 @@ impl<T: Config> Pallet<T> {
|
||||
pub fn do_add_nominator(who: &T::AccountId, nominations: Nominations<T::AccountId>) {
|
||||
if !Nominators::<T>::contains_key(who) {
|
||||
// maybe update sorted list. Error checking is defensive-only - this should never fail.
|
||||
if T::SortedListProvider::on_insert(who.clone(), Self::weight_of(who)).is_err() {
|
||||
log!(warn, "attempt to insert duplicate nominator ({:#?})", who);
|
||||
debug_assert!(false, "attempt to insert duplicate nominator");
|
||||
};
|
||||
let _ = T::SortedListProvider::on_insert(who.clone(), Self::weight_of(who))
|
||||
.defensive_unwrap_or_default();
|
||||
|
||||
debug_assert_eq!(T::SortedListProvider::sanity_check(), Ok(()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user