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

Commit 7a79f54

Browse files
gavofyorkshawntabrizikianenigmagui1117apopiak
authored
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 e818dc7. * 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>
1 parent cfb8157 commit 7a79f54

34 files changed

Lines changed: 814 additions & 447 deletions

File tree

.maintain/gitlab/check_polkadot_companion_build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ then
6767
pr_body="$(sed -n -r 's/^[[:space:]]+"body": (".*")[^"]+$/\1/p' "${pr_data_file}")"
6868

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

7474
if [ "${pr_companion}" ]

.maintain/gitlab/check_polkadot_companion_status.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pr_body="$(curl -H "${github_header}" -s ${github_api_substrate_pull_url}/${CI_C
4343

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

5050
if [ -z "${pr_companion}" ]

bin/node/executor/tests/basic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
192192
let mut t = new_test_ext(compact_code_unwrap(), false);
193193
t.insert(
194194
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
195-
(0u32, 0u32, 69u128, 0u128, 0u128, 0u128).encode()
195+
(0u32, 0u32, 0u32, 69u128, 0u128, 0u128, 0u128).encode()
196196
);
197197
t.insert(<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(), 69_u128.encode());
198198
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
@@ -221,11 +221,11 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
221221
let mut t = new_test_ext(compact_code_unwrap(), false);
222222
t.insert(
223223
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
224-
(0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
224+
(0u32, 0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
225225
);
226226
t.insert(
227227
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
228-
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
228+
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
229229
);
230230
t.insert(
231231
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
@@ -264,11 +264,11 @@ fn successful_execution_with_foreign_code_gives_ok() {
264264
let mut t = new_test_ext(bloaty_code_unwrap(), false);
265265
t.insert(
266266
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
267-
(0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
267+
(0u32, 0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
268268
);
269269
t.insert(
270270
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
271-
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
271+
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
272272
);
273273
t.insert(
274274
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
@@ -702,7 +702,7 @@ fn panic_execution_gives_error() {
702702
let mut t = new_test_ext(bloaty_code_unwrap(), false);
703703
t.insert(
704704
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
705-
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
705+
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
706706
);
707707
t.insert(<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(), 0_u128.encode());
708708
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
@@ -731,11 +731,11 @@ fn successful_execution_gives_ok() {
731731
let mut t = new_test_ext(compact_code_unwrap(), false);
732732
t.insert(
733733
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
734-
(0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
734+
(0u32, 0u32, 0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
735735
);
736736
t.insert(
737737
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
738-
(0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
738+
(0u32, 0u32, 0u32, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
739739
);
740740
t.insert(
741741
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),

bin/node/executor/tests/fees.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
121121
});
122122
}
123123

124+
fn new_account_info(free_dollars: u128) -> Vec<u8> {
125+
frame_system::AccountInfo {
126+
nonce: 0u32,
127+
consumers: 0,
128+
providers: 0,
129+
data: (free_dollars * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS),
130+
}.encode()
131+
}
132+
124133
#[test]
125134
fn transaction_fee_is_correct() {
126135
// This uses the exact values of substrate-node.
@@ -131,14 +140,8 @@ fn transaction_fee_is_correct() {
131140
// - 1 milli-dot based on current polkadot runtime.
132141
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
133142
let mut t = new_test_ext(compact_code_unwrap(), false);
134-
t.insert(
135-
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
136-
(0u32, 0u32, 100 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
137-
);
138-
t.insert(
139-
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
140-
(0u32, 0u32, 10 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
141-
);
143+
t.insert(<frame_system::Account<Runtime>>::hashed_key_for(alice()), new_account_info(100));
144+
t.insert(<frame_system::Account<Runtime>>::hashed_key_for(bob()), new_account_info(10));
142145
t.insert(
143146
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
144147
(110 * DOLLARS).encode()

bin/node/executor/tests/submit_transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ fn submitted_transaction_should_be_valid() {
253253
let author = extrinsic.signature.clone().unwrap().0;
254254
let address = Indices::lookup(author).unwrap();
255255
let data = pallet_balances::AccountData { free: 5_000_000_000_000, ..Default::default() };
256-
let account = frame_system::AccountInfo { nonce: 0, refcount: 0, data };
256+
let account = frame_system::AccountInfo { nonce: 0, consumers: 0, providers: 0, data };
257257
<frame_system::Account<Runtime>>::insert(&address, account);
258258

259259
// check validity

frame/assets/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ decl_error! {
274274
MinBalanceZero,
275275
/// A mint operation lead to an overflow.
276276
Overflow,
277+
/// Some internal state is broken.
278+
BadState,
277279
}
278280
}
279281

@@ -863,7 +865,7 @@ impl<T: Config> Module<T> {
863865
) -> Result<bool, DispatchError> {
864866
let accounts = d.accounts.checked_add(1).ok_or(Error::<T>::Overflow)?;
865867
let r = Ok(if frame_system::Module::<T>::account_exists(who) {
866-
frame_system::Module::<T>::inc_ref(who);
868+
frame_system::Module::<T>::inc_consumers(who).map_err(|_| Error::<T>::BadState)?;
867869
false
868870
} else {
869871
ensure!(d.zombies < d.max_zombies, Error::<T>::TooManyZombies);
@@ -881,7 +883,9 @@ impl<T: Config> Module<T> {
881883
is_zombie: &mut bool,
882884
) {
883885
if *is_zombie && frame_system::Module::<T>::account_exists(who) {
884-
frame_system::Module::<T>::inc_ref(who);
886+
// If the account exists, then it should have at least one provider
887+
// so this cannot fail... but being defensive anyway.
888+
let _ = frame_system::Module::<T>::inc_consumers(who);
885889
*is_zombie = false;
886890
d.zombies = d.zombies.saturating_sub(1);
887891
}
@@ -895,7 +899,7 @@ impl<T: Config> Module<T> {
895899
if is_zombie {
896900
d.zombies = d.zombies.saturating_sub(1);
897901
} else {
898-
frame_system::Module::<T>::dec_ref(who);
902+
frame_system::Module::<T>::dec_consumers(who);
899903
}
900904
d.accounts = d.accounts.saturating_sub(1);
901905
}

frame/babe/src/mock.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes
379379
.build_storage::<Test>()
380380
.unwrap();
381381

382+
let balances: Vec<_> = (0..authorities.len())
383+
.map(|i| (i as u64, 10_000_000))
384+
.collect();
385+
386+
pallet_balances::GenesisConfig::<Test> { balances }
387+
.assimilate_storage(&mut t)
388+
.unwrap();
389+
382390
// stashes are the index.
383391
let session_keys: Vec<_> = authorities
384392
.iter()
@@ -394,6 +402,12 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes
394402
})
395403
.collect();
396404

405+
// NOTE: this will initialize the babe authorities
406+
// through OneSessionHandler::on_genesis_session
407+
pallet_session::GenesisConfig::<Test> { keys: session_keys }
408+
.assimilate_storage(&mut t)
409+
.unwrap();
410+
397411
// controllers are the index + 1000
398412
let stakers: Vec<_> = (0..authorities.len())
399413
.map(|i| {
@@ -406,20 +420,6 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes
406420
})
407421
.collect();
408422

409-
let balances: Vec<_> = (0..authorities.len())
410-
.map(|i| (i as u64, 10_000_000))
411-
.collect();
412-
413-
// NOTE: this will initialize the babe authorities
414-
// through OneSessionHandler::on_genesis_session
415-
pallet_session::GenesisConfig::<Test> { keys: session_keys }
416-
.assimilate_storage(&mut t)
417-
.unwrap();
418-
419-
pallet_balances::GenesisConfig::<Test> { balances }
420-
.assimilate_storage(&mut t)
421-
.unwrap();
422-
423423
let staking_config = pallet_staking::GenesisConfig::<Test> {
424424
stakers,
425425
validator_count: 8,

0 commit comments

Comments
 (0)