Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduces account existence providers reference counting #7363

Merged
merged 64 commits into from Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ebcc2fe
Initial draft
gavofyork Oct 20, 2020
16724ae
Latest changes
gavofyork Nov 9, 2020
8a15927
Final bits.
gavofyork Nov 11, 2020
866e78b
Fixes
gavofyork Nov 11, 2020
51aec12
Fixes
gavofyork Nov 12, 2020
3609f9e
Merge remote-tracking branch 'origin/master' into gav-account-provide…
gavofyork Nov 12, 2020
934fea6
Merge branch 'gav-account-provider-refs' of github.com:paritytech/sub…
gavofyork Nov 12, 2020
cbe14af
Test fixes
gavofyork Nov 18, 2020
82bb7f1
Merge remote-tracking branch 'origin/master' into gav-account-provide…
gavofyork Nov 18, 2020
be9eb12
Merge remote-tracking branch 'origin/master' into gav-account-provide…
gavofyork Nov 27, 2020
5823e35
Fix tests
gavofyork Dec 8, 2020
4b49fd4
Fix babe tests
gavofyork Dec 9, 2020
4134218
Merge remote-tracking branch 'origin/master' into gav-account-provide…
gavofyork Dec 9, 2020
dc5a96e
Fix
gavofyork Dec 9, 2020
24e41a3
Fix
gavofyork Dec 9, 2020
44fb86e
Fix
gavofyork Dec 9, 2020
4f214a6
Fix
gavofyork Dec 9, 2020
a20c16e
Fix
gavofyork Dec 9, 2020
0f02f26
fix warnings in assets
shawntabrizi Dec 14, 2020
84d94f4
Merge branch 'master' into gav-account-provider-refs
shawntabrizi Dec 14, 2020
e818dc7
Fix UI tests
shawntabrizi Dec 14, 2020
567e1b5
fix line width
shawntabrizi Dec 14, 2020
dadb7f9
Fix
gavofyork Dec 16, 2020
93d07b4
Merge branch 'gav-account-provider-refs' of github.com:paritytech/sub…
gavofyork Dec 16, 2020
928381f
Merge remote-tracking branch 'origin/master' into gav-account-provide…
gavofyork Dec 16, 2020
514bc5d
Update frame/system/src/lib.rs
gavofyork Dec 16, 2020
b6a7378
Update frame/system/src/lib.rs
gavofyork Dec 16, 2020
237bdb0
Fix
gavofyork Dec 16, 2020
3149164
Merge branch 'gav-account-provider-refs' of github.com:paritytech/sub…
gavofyork Dec 16, 2020
6bb2813
fix unused warnings
shawntabrizi Dec 16, 2020
968ca3f
Fix
gavofyork Dec 17, 2020
160838c
Merge branch 'gav-account-provider-refs' of github.com:paritytech/sub…
gavofyork Dec 17, 2020
f15cfeb
Update frame/system/src/lib.rs
gavofyork Dec 17, 2020
702ca55
Update frame/system/src/lib.rs
gavofyork Dec 17, 2020
d34d7f2
Fix
gavofyork Dec 17, 2020
1e23f19
fix slash and comprehensive slash test
shawntabrizi Dec 19, 2020
58643c5
fix reserved slash and comprehensive tests
shawntabrizi Dec 19, 2020
47c1cbe
check slash on non-existent account
shawntabrizi Dec 19, 2020
c856136
Revert "Fix UI tests"
shawntabrizi Dec 19, 2020
66e9be1
Fix
gavofyork Dec 19, 2020
269f36c
Merge branch 'master' into gav-account-provider-refs
shawntabrizi Dec 20, 2020
a075a5e
Fix utility tests
shawntabrizi Dec 20, 2020
e5abf6b
keep dispatch error backwards compatible
shawntabrizi Dec 20, 2020
dfc9bfe
Fix
gavofyork Dec 20, 2020
fbcde4a
Merge branch 'gav-account-provider-refs' of github.com:paritytech/sub…
gavofyork Dec 20, 2020
a3596de
Fix
gavofyork Dec 20, 2020
2df412e
fix ui test
shawntabrizi Dec 21, 2020
f0e1c6b
Companion checker shouldn't be so anal.
gavofyork Dec 21, 2020
d76a08b
Fix
gavofyork Dec 21, 2020
7d9d63a
Fix
gavofyork Dec 21, 2020
9c03134
Fix
gavofyork Dec 21, 2020
fd925e9
Apply suggestions from code review
shawntabrizi Dec 23, 2020
95a2255
Update frame/balances/src/lib.rs
shawntabrizi Dec 23, 2020
f55da2f
return correct slash info when failing gracefully
shawntabrizi Dec 23, 2020
16238a3
Merge branch 'master' into gav-account-provider-refs
shawntabrizi Dec 23, 2020
054516b
fix missing import
shawntabrizi Dec 23, 2020
4aa1bb4
Merge branch 'master' into gav-account-provider-refs
shawntabrizi Dec 28, 2020
2f4a6db
Merge branch 'master' into gav-account-provider-refs
shawntabrizi Dec 28, 2020
17438be
Update frame/system/src/lib.rs
gavofyork Jan 9, 2021
282a391
Merge branch 'master' into gav-account-provider-refs
gavofyork Jan 9, 2021
d5248d1
Fix
gavofyork Jan 10, 2021
9f1df71
Update frame/balances/src/tests_local.rs
gavofyork Jan 16, 2021
4491e73
Fixes
gavofyork Jan 16, 2021
859abab
Merge remote-tracking branch 'origin/master' into gav-account-provide…
gavofyork Jan 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .maintain/gitlab/check_polkadot_companion_build.sh
Expand Up @@ -69,8 +69,8 @@ then
pr_body="$(sed -n -r 's/^[[:space:]]+"body": (".*")[^"]+$/\1/p' "${pr_data_file}")"

pr_companion="$(echo "${pr_body}" | sed -n -r \
-e 's;^.*polkadot companion: paritytech/polkadot#([0-9]+).*$;\1;p' \
-e 's;^.*polkadot companion: https://github.com/paritytech/polkadot/pull/([0-9]+).*$;\1;p' \
-e 's;^.*[Cc]ompanion.*paritytech/polkadot#([0-9]+).*$;\1;p' \
-e 's;^.*[Cc]ompanion.*https://github.com/paritytech/polkadot/pull/([0-9]+).*$;\1;p' \
| tail -n 1)"

if [ "${pr_companion}" ]
Expand Down
4 changes: 2 additions & 2 deletions .maintain/gitlab/check_polkadot_companion_status.sh
Expand Up @@ -43,8 +43,8 @@ pr_body="$(curl -H "${github_header}" -s ${github_api_substrate_pull_url}/${CI_C

# get companion if explicitly specified
pr_companion="$(echo "${pr_body}" | sed -n -r \
-e 's;^.*polkadot companion: paritytech/polkadot#([0-9]+).*$;\1;p' \
-e 's;^.*polkadot companion: https://github.com/paritytech/polkadot/pull/([0-9]+).*$;\1;p' \
-e 's;^.*[Cc]ompanion.*paritytech/polkadot#([0-9]+).*$;\1;p' \
-e 's;^.*[Cc]ompanion.*https://github.com/paritytech/polkadot/pull/([0-9]+).*$;\1;p' \
| tail -n 1)"

if [ -z "${pr_companion}" ]
Expand Down
16 changes: 8 additions & 8 deletions bin/node/executor/tests/basic.rs
Expand Up @@ -192,7 +192,7 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
let mut t = new_test_ext(compact_code_unwrap(), false);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(0u32, 0u32, 69u128, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 69u128, 0u128, 0u128, 0u128).encode()
);
t.insert(<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(), 69_u128.encode());
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
Expand Down Expand Up @@ -221,11 +221,11 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
let mut t = new_test_ext(compact_code_unwrap(), false);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
);
t.insert(
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
Expand Down Expand Up @@ -264,11 +264,11 @@ fn successful_execution_with_foreign_code_gives_ok() {
let mut t = new_test_ext(bloaty_code_unwrap(), false);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
);
t.insert(
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
Expand Down Expand Up @@ -702,7 +702,7 @@ fn panic_execution_gives_error() {
let mut t = new_test_ext(bloaty_code_unwrap(), false);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
);
t.insert(<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(), 0_u128.encode());
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
Expand Down Expand Up @@ -731,11 +731,11 @@ fn successful_execution_gives_ok() {
let mut t = new_test_ext(compact_code_unwrap(), false);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
);
t.insert(
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
Expand Down
19 changes: 11 additions & 8 deletions bin/node/executor/tests/fees.rs
Expand Up @@ -121,6 +121,15 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
});
}

fn new_account_info(free_dollars: u128) -> Vec<u8> {
frame_system::AccountInfo {
nonce: 0u32,
consumers: 0,
providers: 0,
data: (free_dollars * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS),
}.encode()
}

#[test]
fn transaction_fee_is_correct() {
// This uses the exact values of substrate-node.
Expand All @@ -131,14 +140,8 @@ fn transaction_fee_is_correct() {
// - 1 milli-dot based on current polkadot runtime.
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
let mut t = new_test_ext(compact_code_unwrap(), false);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
(0u32, 0u32, 100 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
);
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
(0u32, 0u32, 10 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
);
t.insert(<frame_system::Account<Runtime>>::hashed_key_for(alice()), new_account_info(100));
t.insert(<frame_system::Account<Runtime>>::hashed_key_for(bob()), new_account_info(10));
t.insert(
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
(110 * DOLLARS).encode()
Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/submit_transaction.rs
Expand Up @@ -253,7 +253,7 @@ fn submitted_transaction_should_be_valid() {
let author = extrinsic.signature.clone().unwrap().0;
let address = Indices::lookup(author).unwrap();
let data = pallet_balances::AccountData { free: 5_000_000_000_000, ..Default::default() };
let account = frame_system::AccountInfo { nonce: 0, refcount: 0, data };
let account = frame_system::AccountInfo { nonce: 0, consumers: 0, providers: 0, data };
<frame_system::Account<Runtime>>::insert(&address, account);

// check validity
Expand Down
10 changes: 7 additions & 3 deletions frame/assets/src/lib.rs
Expand Up @@ -274,6 +274,8 @@ decl_error! {
MinBalanceZero,
/// A mint operation lead to an overflow.
Overflow,
/// Some internal state is broken.
BadState,
}
}

Expand Down Expand Up @@ -863,7 +865,7 @@ impl<T: Config> Module<T> {
) -> Result<bool, DispatchError> {
let accounts = d.accounts.checked_add(1).ok_or(Error::<T>::Overflow)?;
let r = Ok(if frame_system::Module::<T>::account_exists(who) {
frame_system::Module::<T>::inc_ref(who);
frame_system::Module::<T>::inc_consumers(who).map_err(|_| Error::<T>::BadState)?;
false
} else {
ensure!(d.zombies < d.max_zombies, Error::<T>::TooManyZombies);
Expand All @@ -881,7 +883,9 @@ impl<T: Config> Module<T> {
is_zombie: &mut bool,
) {
if *is_zombie && frame_system::Module::<T>::account_exists(who) {
frame_system::Module::<T>::inc_ref(who);
// If the account exists, then it should have at least one provider
// so this cannot fail... but being defensive anyway.
let _ = frame_system::Module::<T>::inc_consumers(who);
*is_zombie = false;
d.zombies = d.zombies.saturating_sub(1);
}
Expand All @@ -895,7 +899,7 @@ impl<T: Config> Module<T> {
if is_zombie {
d.zombies = d.zombies.saturating_sub(1);
} else {
frame_system::Module::<T>::dec_ref(who);
frame_system::Module::<T>::dec_consumers(who);
}
d.accounts = d.accounts.saturating_sub(1);
}
Expand Down
28 changes: 14 additions & 14 deletions frame/babe/src/mock.rs
Expand Up @@ -379,6 +379,14 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes
.build_storage::<Test>()
.unwrap();

let balances: Vec<_> = (0..authorities.len())
.map(|i| (i as u64, 10_000_000))
.collect();

pallet_balances::GenesisConfig::<Test> { balances }
.assimilate_storage(&mut t)
.unwrap();

// stashes are the index.
let session_keys: Vec<_> = authorities
.iter()
Expand All @@ -394,6 +402,12 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes
})
.collect();

// NOTE: this will initialize the babe authorities
// through OneSessionHandler::on_genesis_session
pallet_session::GenesisConfig::<Test> { keys: session_keys }
.assimilate_storage(&mut t)
.unwrap();

// controllers are the index + 1000
let stakers: Vec<_> = (0..authorities.len())
.map(|i| {
Expand All @@ -406,20 +420,6 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes
})
.collect();

let balances: Vec<_> = (0..authorities.len())
.map(|i| (i as u64, 10_000_000))
.collect();

// NOTE: this will initialize the babe authorities
// through OneSessionHandler::on_genesis_session
pallet_session::GenesisConfig::<Test> { keys: session_keys }
.assimilate_storage(&mut t)
.unwrap();

pallet_balances::GenesisConfig::<Test> { balances }
.assimilate_storage(&mut t)
.unwrap();

let staking_config = pallet_staking::GenesisConfig::<Test> {
stakers,
validator_count: 8,
Expand Down