Better Handle Dead Accounts in Balances (#7843)

* Don't mutate storage when account is dead and should stay dead

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* more concrete storage noop

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
This commit is contained in:
Shawn Tabrizi
2021-01-07 13:42:37 -04:00
committed by GitHub
parent 779c4f8616
commit 93ecff9b7c
4 changed files with 59 additions and 30 deletions
+24 -1
View File
@@ -40,7 +40,7 @@ macro_rules! decl_tests {
use crate::*;
use sp_runtime::{FixedPointNumber, traits::{SignedExtension, BadOrigin}};
use frame_support::{
assert_noop, assert_ok, assert_err,
assert_noop, assert_storage_noop, assert_ok, assert_err,
traits::{
LockableCurrency, LockIdentifier, WithdrawReasons,
Currency, ReservableCurrency, ExistenceRequirement::AllowDeath, StoredMap
@@ -796,5 +796,28 @@ macro_rules! decl_tests {
);
});
}
#[test]
fn operations_on_dead_account_should_not_change_state() {
// These functions all use `mutate_account` which may introduce a storage change when
// the account never existed to begin with, and shouldn't exist in the end.
<$ext_builder>::default()
.existential_deposit(0)
.build()
.execute_with(|| {
assert!(!<Test as Config>::AccountStore::is_explicit(&1337));
// Unreserve
assert_storage_noop!(assert_eq!(Balances::unreserve(&1337, 42), 42));
// Reserve
assert_noop!(Balances::reserve(&1337, 42), Error::<Test, _>::InsufficientBalance);
// Slash Reserve
assert_storage_noop!(assert_eq!(Balances::slash_reserved(&1337, 42).1, 42));
// Repatriate Reserve
assert_noop!(Balances::repatriate_reserved(&1337, &1338, 42, Status::Free), Error::<Test, _>::DeadAccount);
// Slash
assert_storage_noop!(assert_eq!(Balances::slash(&1337, 42).1, 42));
});
}
}
}