Skip to content
This repository was archived by the owner on Jul 4, 2022. It is now read-only.

Commit 9469920

Browse files
committed
Reverted #4820 (substrate), add doughnut and delegatedDispatchVerifier to substrate runtime declarations
1 parent 7aba7ff commit 9469920

File tree

85 files changed

+2152
-2514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2152
-2514
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template/node/src/chain_spec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use sp_core::{Pair, Public, sr25519};
22
use node_template_runtime::{
33
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
4-
IndicesConfig, SudoConfig, SystemConfig, WASM_BINARY, Signature
4+
SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY, Signature
55
};
66
use sp_consensus_aura::sr25519::{AuthorityId as AuraId};
77
use grandpa_primitives::{AuthorityId as GrandpaId};
@@ -128,7 +128,7 @@ fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
128128
changes_trie_config: Default::default(),
129129
}),
130130
indices: Some(IndicesConfig {
131-
indices: vec![],
131+
ids: endowed_accounts.clone(),
132132
}),
133133
balances: Some(BalancesConfig {
134134
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),

bin/node-template/pallets/template/src/mock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ impl system::Trait for Test {
3939
type AvailableBlockRatio = AvailableBlockRatio;
4040
type Version = ();
4141
type ModuleToIndex = ();
42-
type AccountData = ();
43-
type OnNewAccount = ();
44-
type OnReapAccount = ();
4542
type Doughnut = ();
4643
type DelegatedDispatchVerifier = ();
4744
}

bin/node-template/runtime/src/lib.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ impl system::Trait for Runtime {
168168
///
169169
/// This type is being generated by `construct_runtime!`.
170170
type ModuleToIndex = ModuleToIndex;
171-
/// What to do if a new account is created.
172-
type OnNewAccount = ();
173-
/// What to do if an account is fully reaped from the system.
174-
type OnReapAccount = Balances;
175-
/// The data to be stored in an account.
176-
type AccountData = balances::AccountData<Balance>;
177171
}
178172

179173
impl DoughnutRuntime for Runtime {
@@ -191,21 +185,16 @@ impl grandpa::Trait for Runtime {
191185
type Event = Event;
192186
}
193187

194-
parameter_types! {
195-
/// How much an index costs.
196-
pub const IndexDeposit: u128 = 100;
197-
}
198-
199188
impl indices::Trait for Runtime {
200189
/// The type for recording indexing into the account enumeration. If this ever overflows, there
201190
/// will be problems!
202191
type AccountIndex = AccountIndex;
192+
/// Use the standard means of resolving an index hint from an id.
193+
type ResolveHint = indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;
194+
/// Determine whether an account is dead.
195+
type IsDeadAccount = Balances;
203196
/// The ubiquitous event type.
204197
type Event = Event;
205-
/// The currency type.
206-
type Currency = Balances;
207-
/// How much an index costs.
208-
type Deposit = IndexDeposit;
209198
}
210199

211200
parameter_types! {
@@ -221,16 +210,22 @@ impl timestamp::Trait for Runtime {
221210

222211
parameter_types! {
223212
pub const ExistentialDeposit: u128 = 500;
213+
pub const CreationFee: u128 = 0;
224214
}
225215

226216
impl balances::Trait for Runtime {
227217
/// The type for recording an account's balance.
228218
type Balance = Balance;
219+
/// What to do if an account is fully reaped from the system.
220+
type OnReapAccount = System;
221+
/// What to do if a new account is created.
222+
type OnNewAccount = Indices;
229223
/// The ubiquitous event type.
230224
type Event = Event;
231225
type DustRemoval = ();
226+
type TransferPayment = ();
232227
type ExistentialDeposit = ExistentialDeposit;
233-
type AccountStore = System;
228+
type CreationFee = CreationFee;
234229
}
235230

236231
parameter_types! {
@@ -263,12 +258,12 @@ construct_runtime!(
263258
NodeBlock = opaque::Block,
264259
UncheckedExtrinsic = UncheckedExtrinsic
265260
{
266-
System: system::{Module, Call, Config, Storage, Event<T>},
261+
System: system::{Module, Call, Storage, Config, Event},
267262
Timestamp: timestamp::{Module, Call, Storage, Inherent},
268263
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
269264
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
270-
Indices: indices::{Module, Call, Storage, Event<T>, Config<T>},
271-
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
265+
Indices: indices,
266+
Balances: balances,
272267
TransactionPayment: transaction_payment::{Module, Storage},
273268
Sudo: sudo,
274269
// Used for the module template in `./template.rs`

bin/node/cli/src/chain_spec.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use sp_core::{Pair, Public, crypto::UncheckedInto, sr25519};
2121
use serde::{Serialize, Deserialize};
2222
use node_runtime::{
2323
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, DemocracyConfig,
24-
GrandpaConfig, ImOnlineConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
25-
IndicesConfig, SocietyConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, WASM_BINARY,
24+
GrandpaConfig, ImOnlineConfig, IndicesConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
25+
SocietyConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, WASM_BINARY,
2626
};
2727
use node_runtime::Block;
2828
use node_runtime::constants::currency::*;
@@ -235,7 +235,9 @@ pub fn testnet_genesis(
235235
.collect(),
236236
}),
237237
pallet_indices: Some(IndicesConfig {
238-
indices: vec![],
238+
ids: endowed_accounts.iter().cloned()
239+
.chain(initial_authorities.iter().map(|x| x.0.clone()))
240+
.collect::<Vec<_>>(),
239241
}),
240242
pallet_session: Some(SessionConfig {
241243
keys: initial_authorities.iter().map(|x| {

bin/node/executor/tests/basic.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use frame_system::{self, EventRecord, Phase};
3535

3636
use node_runtime::{
3737
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
38-
System, TransactionPayment, Event, TransactionBaseFee, TransactionByteFee,
38+
System, TransactionPayment, Event, TransactionBaseFee, TransactionByteFee, CreationFee,
3939
constants::currency::*,
4040
};
4141
use node_primitives::{Balance, Hash};
@@ -165,12 +165,15 @@ fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
165165
fn panic_execution_with_foreign_code_gives_error() {
166166
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
167167
top: map![
168-
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
168+
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
169169
(69u128, 0u128, 0u128, 0u128).encode()
170170
},
171171
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
172172
69_u128.encode()
173173
},
174+
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
175+
0_u128.encode()
176+
},
174177
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => {
175178
vec![0u8; 32]
176179
}
@@ -201,12 +204,15 @@ fn panic_execution_with_foreign_code_gives_error() {
201204
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
202205
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
203206
top: map![
204-
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
205-
(0u32, 69u128, 0u128, 0u128, 0u128).encode()
207+
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
208+
(69u128, 0u128, 0u128, 0u128).encode()
206209
},
207210
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
208211
69_u128.encode()
209212
},
213+
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
214+
0_u128.encode()
215+
},
210216
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => {
211217
vec![0u8; 32]
212218
}
@@ -237,12 +243,13 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
237243
fn successful_execution_with_native_equivalent_code_gives_ok() {
238244
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
239245
top: map![
240-
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
241-
(0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
246+
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
247+
(111 * DOLLARS, 0u128, 0u128, 0u128).encode()
242248
},
243249
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
244250
(111 * DOLLARS).encode()
245251
},
252+
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
246253
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
247254
],
248255
children: map![],
@@ -269,7 +276,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
269276
assert!(r.is_ok());
270277

271278
t.execute_with(|| {
272-
let fees = transfer_fee(&xt(), fm);
279+
let fees = transfer_fee(&xt(), fm) + CreationFee::get();
273280
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
274281
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
275282
});
@@ -279,12 +286,13 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
279286
fn successful_execution_with_foreign_code_gives_ok() {
280287
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
281288
top: map![
282-
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
283-
(0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
289+
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
290+
(111 * DOLLARS, 0u128, 0u128, 0u128).encode()
284291
},
285292
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
286293
(111 * DOLLARS).encode()
287294
},
295+
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
288296
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
289297
],
290298
children: map![],
@@ -311,7 +319,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
311319
assert!(r.is_ok());
312320

313321
t.execute_with(|| {
314-
let fees = transfer_fee(&xt(), fm);
322+
let fees = transfer_fee(&xt(), fm) + CreationFee::get();
315323
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
316324
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
317325
});
@@ -342,7 +350,7 @@ fn full_native_block_import_works() {
342350
let events = vec![
343351
EventRecord {
344352
phase: Phase::ApplyExtrinsic(0),
345-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
353+
event: Event::system(frame_system::Event::ExtrinsicSuccess(
346354
DispatchInfo { weight: 10000, class: DispatchClass::Operational, pays_fee: true }
347355
)),
348356
topics: vec![],
@@ -358,12 +366,13 @@ fn full_native_block_import_works() {
358366
alice().into(),
359367
bob().into(),
360368
69 * DOLLARS,
369+
0,
361370
)),
362371
topics: vec![],
363372
},
364373
EventRecord {
365374
phase: Phase::ApplyExtrinsic(1),
366-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
375+
event: Event::system(frame_system::Event::ExtrinsicSuccess(
367376
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
368377
)),
369378
topics: vec![],
@@ -394,7 +403,7 @@ fn full_native_block_import_works() {
394403
let events = vec![
395404
EventRecord {
396405
phase: Phase::ApplyExtrinsic(0),
397-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
406+
event: Event::system(frame_system::Event::ExtrinsicSuccess(
398407
DispatchInfo { weight: 10000, class: DispatchClass::Operational, pays_fee: true }
399408
)),
400409
topics: vec![],
@@ -411,13 +420,14 @@ fn full_native_block_import_works() {
411420
bob().into(),
412421
alice().into(),
413422
5 * DOLLARS,
423+
0,
414424
)
415425
),
416426
topics: vec![],
417427
},
418428
EventRecord {
419429
phase: Phase::ApplyExtrinsic(1),
420-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
430+
event: Event::system(frame_system::Event::ExtrinsicSuccess(
421431
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
422432
)),
423433
topics: vec![],
@@ -434,13 +444,14 @@ fn full_native_block_import_works() {
434444
alice().into(),
435445
bob().into(),
436446
15 * DOLLARS,
447+
0,
437448
)
438449
),
439450
topics: vec![],
440451
},
441452
EventRecord {
442453
phase: Phase::ApplyExtrinsic(2),
443-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
454+
event: Event::system(frame_system::Event::ExtrinsicSuccess(
444455
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
445456
)),
446457
topics: vec![],
@@ -703,9 +714,13 @@ fn native_big_block_import_fails_on_fallback() {
703714
fn panic_execution_gives_error() {
704715
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
705716
top: map![
717+
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
718+
(0_u128, 0_u128, 0_u128, 0_u128).encode()
719+
},
706720
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
707721
0_u128.encode()
708722
},
723+
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
709724
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
710725
],
711726
children: map![],
@@ -734,12 +749,13 @@ fn panic_execution_gives_error() {
734749
fn successful_execution_gives_ok() {
735750
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
736751
top: map![
737-
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
738-
(0u32, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
752+
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
753+
(111 * DOLLARS, 0u128, 0u128, 0u128).encode()
739754
},
740755
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
741756
(111 * DOLLARS).encode()
742757
},
758+
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
743759
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
744760
],
745761
children: map![],
@@ -763,11 +779,11 @@ fn successful_execution_gives_ok() {
763779
).0.unwrap().into_encoded();
764780
ApplyExtrinsicResult::decode(&mut &r[..])
765781
.unwrap()
766-
.expect("Extrinsic could not be applied")
767-
.expect("Extrinsic failed");
782+
.expect("Extrinsic could be applied")
783+
.expect("Extrinsic did not fail");
768784

769785
t.execute_with(|| {
770-
let fees = transfer_fee(&xt(), fm);
786+
let fees = transfer_fee(&xt(), fm) + CreationFee::get();
771787
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
772788
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
773789
});

bin/node/executor/tests/fees.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,16 @@ fn transaction_fee_is_correct_ultimate() {
134134
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
135135
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
136136
top: map![
137-
<frame_system::Account<Runtime>>::hashed_key_for(alice()) => {
138-
(0u32, 100 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
137+
<pallet_balances::Account<Runtime>>::hashed_key_for(alice()) => {
138+
(100 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
139139
},
140-
<frame_system::Account<Runtime>>::hashed_key_for(bob()) => {
141-
(0u32, 10 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
140+
<pallet_balances::Account<Runtime>>::hashed_key_for(bob()) => {
141+
(10 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
142142
},
143143
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
144-
(110 * DOLLARS).encode()
144+
(110 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
145145
},
146+
<pallet_indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
146147
<frame_system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
147148
],
148149
children: map![],

bin/node/executor/tests/submit_transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn submitted_transaction_should_be_valid() {
168168
let author = extrinsic.signature.clone().unwrap().0;
169169
let address = Indices::lookup(author).unwrap();
170170
let account = pallet_balances::AccountData { free: 5_000_000_000_000, ..Default::default() };
171-
<frame_system::Account<Runtime>>::insert(&address, (0u32, account));
171+
<pallet_balances::Account<Runtime, _>>::insert(&address, account);
172172

173173
// check validity
174174
let res = Executive::validate_transaction(extrinsic);

0 commit comments

Comments
 (0)