mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 00:28:01 +00:00
Introduces account existence providers reference counting (#7363)
* Initial draft * Latest changes * Final bits. * Fixes * Fixes * Test fixes * Fix tests * Fix babe tests * Fix * Fix * Fix * Fix * Fix * fix warnings in assets * Fix UI tests * fix line width * Fix * Update frame/system/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/system/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix * fix unused warnings * Fix * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Fix * fix slash and comprehensive slash test * fix reserved slash and comprehensive tests * check slash on non-existent account * Revert "Fix UI tests" This reverts commit e0002c0f13442f7d0c95a054a6c515536328a4a0. * Fix * Fix utility tests * keep dispatch error backwards compatible * Fix * Fix * fix ui test * Companion checker shouldn't be so anal. * Fix * Fix * Fix * Apply suggestions from code review Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Update frame/balances/src/lib.rs Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * return correct slash info when failing gracefully * fix missing import * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Fix * Update frame/balances/src/tests_local.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Fixes Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
@@ -327,16 +327,21 @@ pub(crate) mod tests {
|
||||
set_next_validators, Test, System, Session,
|
||||
};
|
||||
use frame_support::traits::{KeyOwnerProofSystem, OnInitialize};
|
||||
use frame_support::BasicExternalities;
|
||||
|
||||
type Historical = Module<Test>;
|
||||
|
||||
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
crate::GenesisConfig::<Test> {
|
||||
keys: NEXT_VALIDATORS.with(|l|
|
||||
l.borrow().iter().cloned().map(|i| (i, i, UintAuthorityId(i).into())).collect()
|
||||
),
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
let keys: Vec<_> = NEXT_VALIDATORS.with(|l|
|
||||
l.borrow().iter().cloned().map(|i| (i, i, UintAuthorityId(i).into())).collect()
|
||||
);
|
||||
BasicExternalities::execute_with_storage(&mut t, || {
|
||||
for (ref k, ..) in &keys {
|
||||
frame_system::Module::<Test>::inc_providers(k);
|
||||
}
|
||||
});
|
||||
crate::GenesisConfig::<Test> { keys }.assimilate_storage(&mut t).unwrap();
|
||||
sp_io::TestExternalities::new(t)
|
||||
}
|
||||
|
||||
|
||||
@@ -152,28 +152,27 @@ mod tests {
|
||||
};
|
||||
|
||||
use sp_runtime::testing::UintAuthorityId;
|
||||
use frame_support::BasicExternalities;
|
||||
|
||||
type Historical = Module<Test>;
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut ext = frame_system::GenesisConfig::default()
|
||||
let mut t = frame_system::GenesisConfig::default()
|
||||
.build_storage::<Test>()
|
||||
.expect("Failed to create test externalities.");
|
||||
|
||||
crate::GenesisConfig::<Test> {
|
||||
keys: NEXT_VALIDATORS.with(|l| {
|
||||
l.borrow()
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|i| (i, i, UintAuthorityId(i).into()))
|
||||
.collect()
|
||||
}),
|
||||
}
|
||||
.assimilate_storage(&mut ext)
|
||||
.unwrap();
|
||||
let keys: Vec<_> = NEXT_VALIDATORS.with(|l|
|
||||
l.borrow().iter().cloned().map(|i| (i, i, UintAuthorityId(i).into())).collect()
|
||||
);
|
||||
BasicExternalities::execute_with_storage(&mut t, || {
|
||||
for (ref k, ..) in &keys {
|
||||
frame_system::Module::<Test>::inc_providers(k);
|
||||
}
|
||||
});
|
||||
|
||||
crate::GenesisConfig::<Test>{ keys }.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
let mut ext = sp_io::TestExternalities::new(ext);
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
|
||||
let (offchain, offchain_state) = TestOffchainExt::with_offchain_db(ext.offchain_db());
|
||||
|
||||
|
||||
@@ -444,7 +444,7 @@ decl_storage! {
|
||||
for (account, val, keys) in config.keys.iter().cloned() {
|
||||
<Module<T>>::inner_set_keys(&val, keys)
|
||||
.expect("genesis config must not contain duplicates; qed");
|
||||
frame_system::Module::<T>::inc_ref(&account);
|
||||
assert!(frame_system::Module::<T>::inc_consumers(&account).is_ok());
|
||||
}
|
||||
|
||||
let initial_validators_0 = T::SessionManager::new_session(0)
|
||||
@@ -498,6 +498,8 @@ decl_error! {
|
||||
DuplicatedKey,
|
||||
/// No keys are associated with this account.
|
||||
NoKeys,
|
||||
/// Key setting account is not live, so it's impossible to associate keys.
|
||||
NoAccount,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,9 +748,11 @@ impl<T: Config> Module<T> {
|
||||
let who = T::ValidatorIdOf::convert(account.clone())
|
||||
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
|
||||
|
||||
frame_system::Module::<T>::inc_consumers(&account).map_err(|_| Error::<T>::NoAccount)?;
|
||||
let old_keys = Self::inner_set_keys(&who, keys)?;
|
||||
if old_keys.is_none() {
|
||||
frame_system::Module::<T>::inc_ref(&account);
|
||||
if old_keys.is_some() {
|
||||
let _ = frame_system::Module::<T>::dec_consumers(&account);
|
||||
// ^^^ Defensive only; Consumers were incremented just before, so should never fail.
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -796,7 +800,7 @@ impl<T: Config> Module<T> {
|
||||
let key_data = old_keys.get_raw(*id);
|
||||
Self::clear_key_owner(*id, key_data);
|
||||
}
|
||||
frame_system::Module::<T>::dec_ref(&account);
|
||||
frame_system::Module::<T>::dec_consumers(&account);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
use super::*;
|
||||
use std::cell::RefCell;
|
||||
use frame_support::{impl_outer_origin, parameter_types};
|
||||
use frame_support::{impl_outer_origin, parameter_types, BasicExternalities};
|
||||
use sp_core::{crypto::key_types::DUMMY, H256};
|
||||
use sp_runtime::{
|
||||
Perbill, impl_opaque_keys,
|
||||
@@ -178,11 +178,18 @@ pub fn reset_before_session_end_called() {
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
GenesisConfig::<Test> {
|
||||
keys: NEXT_VALIDATORS.with(|l|
|
||||
l.borrow().iter().cloned().map(|i| (i, i, UintAuthorityId(i).into())).collect()
|
||||
),
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
let keys: Vec<_> = NEXT_VALIDATORS.with(|l|
|
||||
l.borrow().iter().cloned().map(|i| (i, i, UintAuthorityId(i).into())).collect()
|
||||
);
|
||||
BasicExternalities::execute_with_storage(&mut t, || {
|
||||
for (ref k, ..) in &keys {
|
||||
frame_system::Module::<Test>::inc_providers(k);
|
||||
}
|
||||
frame_system::Module::<Test>::inc_providers(&4);
|
||||
// An additional identity that we use.
|
||||
frame_system::Module::<Test>::inc_providers(&69);
|
||||
});
|
||||
GenesisConfig::<Test> { keys }.assimilate_storage(&mut t).unwrap();
|
||||
sp_io::TestExternalities::new(t)
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@ fn keys_cleared_on_kill() {
|
||||
let id = DUMMY;
|
||||
assert_eq!(Session::key_owner(id, UintAuthorityId(1).get_raw(id)), Some(1));
|
||||
|
||||
assert!(!System::allow_death(&1));
|
||||
assert!(System::is_provider_required(&1));
|
||||
assert_ok!(Session::purge_keys(Origin::signed(1)));
|
||||
assert!(System::allow_death(&1));
|
||||
assert!(!System::is_provider_required(&1));
|
||||
|
||||
assert_eq!(Session::load_keys(&1), None);
|
||||
assert_eq!(Session::key_owner(id, UintAuthorityId(1).get_raw(id)), None);
|
||||
|
||||
Reference in New Issue
Block a user