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

Composite accounts #4820

Merged
merged 64 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
17d7f63
Basic account composition.
gavofyork Feb 3, 2020
ae6f092
Add try_mutate_exists
gavofyork Feb 4, 2020
21e1565
De-duplicate
gavofyork Feb 4, 2020
c202dda
Refactor away the UpdateBalanceOutcome
gavofyork Feb 4, 2020
7aa6647
Expunge final UpdateBalanceOutcome refs
gavofyork Feb 4, 2020
b03d937
Refactor transfer
gavofyork Feb 4, 2020
1b74a2c
Refactor reservable currency stuff.
gavofyork Feb 4, 2020
74db69f
Test with the alternative setup.
gavofyork Feb 4, 2020
02d039d
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 4, 2020
d153672
Fixes
gavofyork Feb 4, 2020
459c30b
Test with both setups.
gavofyork Feb 5, 2020
f4ab417
Fixes
gavofyork Feb 5, 2020
35fcb32
Fix
gavofyork Feb 5, 2020
158863b
Fix macros
bkchr Feb 5, 2020
d7ce210
Make indices opt-in
gavofyork Feb 5, 2020
51ea88b
Remove CreationFee, and make indices opt-in.
gavofyork Feb 5, 2020
9c5539a
Fix construct_runtime
bkchr Feb 5, 2020
aed4da9
Fix last few bits
gavofyork Feb 6, 2020
21254ed
Fix tests
bkchr Feb 6, 2020
f929007
Update trait impls
gavofyork Feb 6, 2020
234ca8a
Don't hardcode the system event
bkchr Feb 6, 2020
c12175d
Make tests build and fix some stuff.
gavofyork Feb 6, 2020
ae0a7c6
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 6, 2020
133c060
Pointlessly bump runtime version
gavofyork Feb 6, 2020
5870f62
Fix benchmark
gavofyork Feb 6, 2020
2579ff7
Another fix
gavofyork Feb 6, 2020
571e209
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 6, 2020
f9adced
Whitespace
gavofyork Feb 6, 2020
2cc84bd
Make indices module economically safe
gavofyork Feb 7, 2020
06cd3a0
Migrations for indices.
gavofyork Feb 7, 2020
b656032
Fix
gavofyork Feb 7, 2020
6d02d1d
Whilespace
gavofyork Feb 7, 2020
091bf0e
Trim defunct migrations
gavofyork Feb 8, 2020
48a3450
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 8, 2020
ae75d69
Remove unused storage item
gavofyork Feb 8, 2020
10d28d2
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 9, 2020
02e67b7
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 9, 2020
e4a398a
More contains_key fixes
gavofyork Feb 9, 2020
9f01bf0
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 10, 2020
1a59997
Docs.
gavofyork Feb 10, 2020
fd6adae
Bump runtime
gavofyork Feb 10, 2020
29cefa1
Merge branch 'master' into gav-composite-account
gavofyork Feb 10, 2020
740e8a3
Merge branch 'master' into gav-composite-account
jacogr Feb 11, 2020
30cee70
Remove unneeded code
gavofyork Feb 11, 2020
6afee76
Merge branch 'gav-composite-account' of github.com:paritytech/substra…
gavofyork Feb 11, 2020
6444cc1
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 12, 2020
5890e24
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 12, 2020
411595d
Fix test
gavofyork Feb 12, 2020
a26c44d
Fix test
gavofyork Feb 12, 2020
bbacb94
Merge branch 'master' into gav-composite-account
gavofyork Feb 12, 2020
2f07990
Update frame/balances/src/lib.rs
gavofyork Feb 13, 2020
680c1f7
Fix ED logic
gavofyork Feb 13, 2020
446ace0
Merge branch 'gav-composite-account' of github.com:paritytech/substra…
gavofyork Feb 13, 2020
3c29022
Repatriate reserved logic
gavofyork Feb 13, 2020
cc6edb8
Typo
gavofyork Feb 13, 2020
df85e74
Fix typo
shawntabrizi Feb 13, 2020
db5c064
Merge branch 'gav-composite-account' of github.com:paritytech/substra…
gavofyork Feb 13, 2020
a7d2980
Update frame/system/src/lib.rs
gavofyork Feb 13, 2020
49bc2e0
Update frame/system/src/lib.rs
gavofyork Feb 13, 2020
c9e852c
Last few fixes
gavofyork Feb 13, 2020
86b132e
Merge branch 'gav-composite-account' of github.com:paritytech/substra…
gavofyork Feb 13, 2020
c472b53
Another fix
gavofyork Feb 13, 2020
dedc512
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 13, 2020
e424b22
Build fix
gavofyork Feb 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bin/node-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use sp_core::{Pair, Public, sr25519};
use node_template_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY, Signature
IndicesConfig, SudoConfig, SystemConfig, WASM_BINARY, Signature
};
use sp_consensus_aura::sr25519::{AuthorityId as AuraId};
use grandpa_primitives::{AuthorityId as GrandpaId};
Expand Down Expand Up @@ -128,7 +128,7 @@ fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
changes_trie_config: Default::default(),
}),
indices: Some(IndicesConfig {
ids: endowed_accounts.clone(),
indices: vec![],
}),
balances: Some(BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
Expand Down
3 changes: 3 additions & 0 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ impl system::Trait for Test {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = ();
type OnNewAccount = ();
type OnReapAccount = ();
}
impl Trait for Test {
type Event = ();
Expand Down
33 changes: 19 additions & 14 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ impl system::Trait for Runtime {
///
/// This type is being generated by `construct_runtime!`.
type ModuleToIndex = ModuleToIndex;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnReapAccount = Balances;
/// The data to be stored in an account.
type AccountData = balances::AccountData<Balance>;
}

impl aura::Trait for Runtime {
Expand All @@ -171,16 +177,21 @@ impl grandpa::Trait for Runtime {
type Event = Event;
}

parameter_types! {
/// How much an index costs.
pub const IndexDeposit: u128 = 100;
}

impl indices::Trait for Runtime {
/// The type for recording indexing into the account enumeration. If this ever overflows, there
/// will be problems!
type AccountIndex = AccountIndex;
/// Use the standard means of resolving an index hint from an id.
type ResolveHint = indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;
/// Determine whether an account is dead.
type IsDeadAccount = Balances;
/// The ubiquitous event type.
type Event = Event;
/// The currency type.
type Currency = Balances;
/// How much an index costs.
type Deposit = IndexDeposit;
}

parameter_types! {
Expand All @@ -196,22 +207,16 @@ impl timestamp::Trait for Runtime {

parameter_types! {
pub const ExistentialDeposit: u128 = 500;
pub const CreationFee: u128 = 0;
}

impl balances::Trait for Runtime {
/// The type for recording an account's balance.
type Balance = Balance;
/// What to do if an account is fully reaped from the system.
type OnReapAccount = System;
/// What to do if a new account is created.
type OnNewAccount = Indices;
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type CreationFee = CreationFee;
type AccountStore = System;
}

parameter_types! {
Expand Down Expand Up @@ -244,12 +249,12 @@ construct_runtime!(
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module, Call, Storage, Config, Event},
System: system::{Module, Call, Config, Storage, Event<T>},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
Indices: indices,
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
Balances: balances,
Indices: indices::{Module, Call, Storage, Event<T>, Config<T>},
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: transaction_payment::{Module, Storage},
Sudo: sudo,
// Used for the module template in `./template.rs`
Expand Down
8 changes: 3 additions & 5 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use sp_core::{Pair, Public, crypto::UncheckedInto, sr25519};
use serde::{Serialize, Deserialize};
use node_runtime::{
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, DemocracyConfig,
GrandpaConfig, ImOnlineConfig, IndicesConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
SocietyConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, WASM_BINARY,
GrandpaConfig, ImOnlineConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
IndicesConfig, SocietyConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, WASM_BINARY,
};
use node_runtime::Block;
use node_runtime::constants::currency::*;
Expand Down Expand Up @@ -239,9 +239,7 @@ pub fn testnet_genesis(
.collect(),
}),
pallet_indices: Some(IndicesConfig {
ids: endowed_accounts.iter().cloned()
.chain(initial_authorities.iter().map(|x| x.0.clone()))
.collect::<Vec<_>>(),
indices: vec![],
}),
pallet_session: Some(SessionConfig {
keys: initial_authorities.iter().map(|x| {
Expand Down
56 changes: 20 additions & 36 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use frame_system::{self, EventRecord, Phase};

use node_runtime::{
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
System, TransactionPayment, Event, TransactionBaseFee, TransactionByteFee, CreationFee,
System, TransactionPayment, Event, TransactionBaseFee, TransactionByteFee,
constants::currency::*,
};
use node_primitives::{Balance, Hash};
Expand Down Expand Up @@ -163,15 +163,12 @@ fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
fn panic_execution_with_foreign_code_gives_error() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
top: map![
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
(69u128, 0u128, 0u128, 0u128).encode()
},
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
69_u128.encode()
},
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
0_u128.encode()
},
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => {
vec![0u8; 32]
}
Expand Down Expand Up @@ -202,15 +199,12 @@ fn panic_execution_with_foreign_code_gives_error() {
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
top: map![
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
(69u128, 0u128, 0u128, 0u128).encode()
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
(0u32, 69u128, 0u128, 0u128, 0u128).encode()
},
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
69_u128.encode()
},
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
0_u128.encode()
},
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => {
vec![0u8; 32]
}
Expand Down Expand Up @@ -241,13 +235,12 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
fn successful_execution_with_native_equivalent_code_gives_ok() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
top: map![
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
(111 * DOLLARS, 0u128, 0u128, 0u128).encode()
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
(0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
},
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(111 * DOLLARS).encode()
},
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
],
children: map![],
Expand All @@ -274,7 +267,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
assert!(r.is_ok());

t.execute_with(|| {
let fees = transfer_fee(&xt(), fm) + CreationFee::get();
let fees = transfer_fee(&xt(), fm);
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
});
Expand All @@ -284,13 +277,12 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
fn successful_execution_with_foreign_code_gives_ok() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
top: map![
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
(111 * DOLLARS, 0u128, 0u128, 0u128).encode()
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
(0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
},
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(111 * DOLLARS).encode()
},
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
],
children: map![],
Expand All @@ -317,7 +309,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
assert!(r.is_ok());

t.execute_with(|| {
let fees = transfer_fee(&xt(), fm) + CreationFee::get();
let fees = transfer_fee(&xt(), fm);
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
});
Expand Down Expand Up @@ -348,7 +340,7 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::system(frame_system::Event::ExtrinsicSuccess(
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 10000, class: DispatchClass::Operational, pays_fee: true }
)),
topics: vec![],
Expand All @@ -364,13 +356,12 @@ fn full_native_block_import_works() {
alice().into(),
bob().into(),
69 * DOLLARS,
0,
)),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::system(frame_system::Event::ExtrinsicSuccess(
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
)),
topics: vec![],
Expand Down Expand Up @@ -401,7 +392,7 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::system(frame_system::Event::ExtrinsicSuccess(
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 10000, class: DispatchClass::Operational, pays_fee: true }
)),
topics: vec![],
Expand All @@ -418,14 +409,13 @@ fn full_native_block_import_works() {
bob().into(),
alice().into(),
5 * DOLLARS,
0,
)
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::system(frame_system::Event::ExtrinsicSuccess(
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
)),
topics: vec![],
Expand All @@ -442,14 +432,13 @@ fn full_native_block_import_works() {
alice().into(),
bob().into(),
15 * DOLLARS,
0,
)
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::system(frame_system::Event::ExtrinsicSuccess(
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
)),
topics: vec![],
Expand Down Expand Up @@ -712,13 +701,9 @@ fn native_big_block_import_fails_on_fallback() {
fn panic_execution_gives_error() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
top: map![
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
(0_u128, 0_u128, 0_u128, 0_u128).encode()
},
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
0_u128.encode()
},
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
],
children: map![],
Expand Down Expand Up @@ -747,13 +732,12 @@ fn panic_execution_gives_error() {
fn successful_execution_gives_ok() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
top: map![
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
(111 * DOLLARS, 0u128, 0u128, 0u128).encode()
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
(0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
},
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(111 * DOLLARS).encode()
},
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
],
children: map![],
Expand All @@ -777,11 +761,11 @@ fn successful_execution_gives_ok() {
).0.unwrap().into_encoded();
ApplyExtrinsicResult::decode(&mut &r[..])
.unwrap()
.expect("Extrinsic could be applied")
.expect("Extrinsic did not fail");
.expect("Extrinsic could not be applied")
.expect("Extrinsic failed");

t.execute_with(|| {
let fees = transfer_fee(&xt(), fm) + CreationFee::get();
let fees = transfer_fee(&xt(), fm);
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
});
Expand Down
11 changes: 5 additions & 6 deletions bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,15 @@ fn transaction_fee_is_correct_ultimate() {
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
top: map![
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
(100 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
(0u32, 100 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
},
<pallet_balances::Account<Runtime>>::hashed_key_for(bob()) => {
(10 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
<frame_system::Account<Runtime>>::hashed_key_for(bob()) => {
(0u32, 10 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
},
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(110 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
(110 * DOLLARS).encode()
},
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
],
children: map![],
Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn submitted_transaction_should_be_valid() {
let author = extrinsic.signature.clone().unwrap().0;
let address = Indices::lookup(author).unwrap();
let account = pallet_balances::AccountData { free: 5_000_000_000_000, ..Default::default() };
<pallet_balances::Account<Runtime, _>>::insert(&address, account);
<frame_system::Account<Runtime>>::insert(&address, (0u32, account));

// check validity
let res = Executive::validate_transaction(extrinsic);
Expand Down
Loading