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

Refactor Account Storage into Accounts Pallet #8254

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
00302af
Initial setup
shawntabrizi Mar 3, 2021
b650e71
more
shawntabrizi Mar 3, 2021
f30ab3b
Merge branch 'master' into shawntabrizi-refactor-accounts
shawntabrizi Mar 4, 2021
4f3634e
fixes
shawntabrizi Mar 4, 2021
f0b52de
updates
shawntabrizi Mar 4, 2021
6dc817f
more fixes
shawntabrizi Mar 4, 2021
c9be890
expose hashed key for
shawntabrizi Mar 4, 2021
48e2002
Introduce ReferencedAccount
shawntabrizi Mar 4, 2021
bfd0016
more ReferencedAccount
shawntabrizi Mar 4, 2021
b304543
node-template fix
shawntabrizi Mar 4, 2021
81a7749
Add Basic Account to FRAME System
shawntabrizi Mar 4, 2021
7e1e4c3
start moving tests
shawntabrizi Mar 4, 2021
bf6f729
more tests moved
shawntabrizi Mar 4, 2021
049e718
fix system tests
shawntabrizi Mar 4, 2021
7343111
downgrade from frame to pallet
shawntabrizi Mar 4, 2021
2244675
fixing up tests
shawntabrizi Mar 4, 2021
c96b5e5
fix more tests
shawntabrizi Mar 4, 2021
27d97cc
fix more tests
shawntabrizi Mar 5, 2021
a3d14fe
Update frame/accounts/src/lib.rs
gavofyork Mar 5, 2021
284fc25
Update frame/accounts/src/lib.rs
gavofyork Mar 5, 2021
3ff3748
Update frame/accounts/src/lib.rs
gavofyork Mar 5, 2021
e4cd56d
Merge branch 'master' into shawntabrizi-refactor-accounts
shawntabrizi Mar 8, 2021
f7ed2ba
fix more tests
shawntabrizi Mar 8, 2021
586bf73
fix more tests
shawntabrizi Mar 8, 2021
02fa345
fix more tests
shawntabrizi Mar 9, 2021
8e889f6
fix more tests
shawntabrizi Mar 9, 2021
3956a23
executor test fixes
shawntabrizi Mar 9, 2021
7c84785
use proper storage item for executor tests
shawntabrizi Mar 9, 2021
1e2185a
more test fixes
shawntabrizi Mar 9, 2021
b9fdb7e
move trait impls out of mod pallet
shawntabrizi Mar 9, 2021
9308566
Merge branch 'master' into shawntabrizi-refactor-accounts
shawntabrizi Mar 9, 2021
89303fd
merge patches
shawntabrizi Mar 9, 2021
add54ec
fix contract tests
shawntabrizi Mar 9, 2021
031a2b7
more fixes
shawntabrizi Mar 11, 2021
ccd5ad1
Merge branch 'master' into shawntabrizi-refactor-accounts
shawntabrizi Mar 11, 2021
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
31 changes: 31 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ members = [
"client/tracing/proc-macro",
"client/transaction-pool",
"client/transaction-pool/graph",
"frame/accounts",
"frame/system/rpc/runtime-api",
"frame/assets",
"frame/atomic-swap",
"frame/aura",
Expand Down Expand Up @@ -113,7 +115,6 @@ members = [
"frame/support/test",
"frame/system",
"frame/system/benchmarking",
"frame/system/rpc/runtime-api",
"frame/timestamp",
"frame/transaction-payment",
"frame/transaction-payment/rpc",
Expand Down
6 changes: 2 additions & 4 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sp_runtime::{
use frame_system as system;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
Expand Down Expand Up @@ -44,9 +44,7 @@ impl system::Config for Test {
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type AccountStorage = System;
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
}
Expand Down
1 change: 1 addition & 0 deletions bin/node-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features =

pallet-aura = { version = "3.0.0", default-features = false, path = "../../../frame/aura" }
pallet-balances = { version = "3.0.0", default-features = false, path = "../../../frame/balances" }
pallet-accounts = { version = "3.0.0", default-features = false, path = "../../../frame/accounts" }
frame-support = { version = "3.0.0", default-features = false, path = "../../../frame/support" }
pallet-grandpa = { version = "3.0.0", default-features = false, path = "../../../frame/grandpa" }
pallet-randomness-collective-flip = { version = "3.0.0", default-features = false, path = "../../../frame/randomness-collective-flip" }
Expand Down
22 changes: 15 additions & 7 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ parameter_types! {
}

// Configure FRAME pallets to include in runtime.

impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
Expand Down Expand Up @@ -178,16 +177,22 @@ impl frame_system::Config for Runtime {
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
/// This is where we store account information.
type AccountStorage = Accounts;
}

impl pallet_accounts::Config for Runtime {
type Event = Event;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
type OnKilledAccount = ();
/// The data to be stored in an account.
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
}

impl pallet_aura::Config for Runtime {
Expand Down Expand Up @@ -238,7 +243,8 @@ impl pallet_balances::Config for Runtime {
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type AccountStore = Accounts;
type ReferencedAccount = Accounts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name suggestion: AccountReferences?

type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -271,6 +277,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Accounts: pallet_accounts::{Module, Call, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Aura: pallet_aura::{Module, Config<T>},
Expand Down Expand Up @@ -427,7 +434,8 @@ impl_runtime_apis! {

impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
System::account_nonce(account)
use frame_support::traits::BasicAccount;
Accounts::account_nonce(&account)
}
}

Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sp-transaction-pool = { version = "3.0.0", default-features = false, path = "../
sp-version = { version = "3.0.0", default-features = false, path = "../../../primitives/version" }

# frame dependencies
pallet-accounts = { version = "3.0.0", default-features = false, path = "../../../frame/accounts" }
frame-executive = { version = "3.0.0", default-features = false, path = "../../../frame/executive" }
frame-benchmarking = { version = "3.1.0", default-features = false, path = "../../../frame/benchmarking", optional = true }
frame-support = { version = "3.0.0", default-features = false, path = "../../../frame/support" }
Expand Down
20 changes: 16 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,16 @@ impl frame_system::Config for Runtime {
type BlockHashCount = BlockHashCount;
type Version = Version;
type PalletInfo = PalletInfo;
type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>;
type SS58Prefix = SS58Prefix;
type AccountStorage = Accounts;
}

impl pallet_accounts::Config for Runtime {
type Event = Event;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>;
type SS58Prefix = SS58Prefix;
}

impl pallet_utility::Config for Runtime {
Expand Down Expand Up @@ -372,7 +377,8 @@ impl pallet_balances::Config for Runtime {
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = frame_system::Module<Runtime>;
type AccountStore = Accounts;
type ReferencedAccount = Accounts;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -436,6 +442,7 @@ impl pallet_session::Config for Runtime {
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type ReferencedAccount = Accounts;
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -501,6 +508,7 @@ impl pallet_staking::Config for Runtime {
// a single extrinsic.
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type ElectionProvider = ElectionProviderMultiPhase;
type ReferencedAccount = Accounts;
type WeightInfo = pallet_staking::weights::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -952,6 +960,7 @@ impl pallet_recovery::Config for Runtime {
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
type MaxFriends = MaxFriends;
type ReferencedAccount = Accounts;
type RecoveryDeposit = RecoveryDeposit;
}

Expand Down Expand Up @@ -1042,6 +1051,7 @@ impl pallet_assets::Config for Runtime {
type StringLimit = StringLimit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ReferencedAccount = Accounts;
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -1078,6 +1088,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Accounts: pallet_accounts::{Module, Call, Storage, Event<T>},
Utility: pallet_utility::{Module, Call, Event},
Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Expand Down Expand Up @@ -1323,7 +1334,8 @@ impl_runtime_apis! {

impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
System::account_nonce(account)
use frame_support::traits::BasicAccount;
Accounts::account_nonce(&account)
}
}

Expand Down
40 changes: 40 additions & 0 deletions frame/accounts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "pallet-accounts"
version = "3.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME accounts module"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" }
frame-support = { version = "3.0.0", default-features = false, path = "../support" }
frame-system = { version = "3.0.0", default-features = false, path = "../system" }
log = { version = "0.4.14", default-features = false }

[dev-dependencies]
serde = { version = "1.0.101", features = ["derive"] }
sp-core = { version = "3.0.0", path = "../../primitives/core" }
sp-io = { version = "3.0.0", path = "../../primitives/io" }

[features]
default = ["std"]
std = [
"codec/std",
"sp-std/std",
"frame-support/std",
"frame-system/std",
"log/std",
]
runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
Loading