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

Commit f191535

Browse files
authored
Enumeratable accounts (#195)
* Merge remote-tracking branch 'origin/master' into gav-xts-dont-panic * Update wasm. * consensus, session and staking all panic-safe. * Democracy doesn't panic in apply. * Fix tests. * Extra helper macro, council depanicked. * Fix one test. * Fix up all council tests. No panics! * Council voting depanicked. * Dispatch returns result. * session & staking tests updated * Fix democracy tests. * Fix council tests. * Fix up polkadot parachains in runtime * Fix borked merge * More Slicable support Support general `Option` and array types. * Basic storage types. * Existential deposit for contract creation * Basic implemnetation along with removals * Fix tests. * externalities builder fix. * Tests. * Fix up the runtime. * Fix tests. * Add generic `Address` type. * Initial function integration of Address into Extrinsic. * Fix build * All tests compile. * Fix (some) tests. * Fix signing. * Push error. * transfer can accept Address * Make Address generic over AccountIndex * Fix test * Make Council use Address for dispatch. * Fix build * Bend over backwards to support braindead derive. * Repot some files. * Fix tests. * Fix grumbles * Remove Default bound * Fix build for new nightly. * Make `apply_extrinsic` never panic, return useful Result. * More merge hell * Doesn't build, but might do soon * Serde woes * get substrate-runtime-staking compiling * Polkadot builds again! * Fix all build. * Fix tests & binaries. * Reserve some extra initial byte values of address for future format changes * Make semantic of `ReservedBalance` clear. * Fix panic handler. * Integrate other balance transformations into the new model Fix up staking tests. * Fix runtime tests. * Fix panic build. * Tests for demonstrating interaction between balance types. * Repot some runtime code * Fix checkedblock in non-std builds * Get rid of `DoLookup` phantom. * Attempt to make transaction_pool work with lookups. * Remove vscode settings * New attempt at making transaction pool work. * It builds again! * --all builds * Fix tests. * New build. * Test account nonce reset. * polkadot transaction pool tests/framework. * Address grumbles. * Revert bad `map_or` * Rebuild binaries, workaround. * Avoid casting to usize early. * reenable sync tests
1 parent 4760b35 commit f191535

File tree

67 files changed

+2343
-1269
lines changed

Some content is hidden

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

67 files changed

+2343
-1269
lines changed

Cargo.lock

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

demo/cli/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
122122
intentions: vec![],
123123
transaction_base_fee: 100,
124124
transaction_byte_fee: 1,
125+
transfer_fee: 0,
126+
creation_fee: 0,
127+
contract_fee: 0,
128+
reclaim_rebate: 0,
129+
existential_deposit: 500,
125130
balances: vec![(god_key.clone().into(), 1u64 << 63)].into_iter().collect(),
126131
validator_count: 12,
127132
sessions_per_era: 24, // 24 hours per era.

demo/executor/src/lib.rs

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ mod tests {
4646
use runtime_support::{Hashable, StorageValue, StorageMap};
4747
use state_machine::{CodeExecutor, TestExternalities};
4848
use primitives::twox_128;
49-
use demo_primitives::{Hash, BlockNumber};
49+
use demo_primitives::{Hash, BlockNumber, AccountId};
5050
use runtime_primitives::traits::Header as HeaderT;
51+
use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult, MaybeUnsigned};
5152
use {staking, system};
5253
use demo_runtime::{Header, Block, UncheckedExtrinsic, Extrinsic, Call, Concrete, Staking,
53-
BuildExternalities, GenesisConfig, SessionConfig, StakingConfig};
54+
BuildExternalities, GenesisConfig, SessionConfig, StakingConfig, BareExtrinsic};
5455
use ed25519::{Public, Pair};
5556

5657
const BLOATY_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm");
@@ -63,24 +64,28 @@ mod tests {
6364
)
6465
}
6566

66-
fn alice() -> Hash {
67-
Keyring::Alice.to_raw_public().into()
67+
fn alice() -> AccountId {
68+
AccountId::from(Keyring::Alice.to_raw_public())
6869
}
6970

70-
fn bob() -> Hash {
71-
Keyring::Bob.to_raw_public().into()
71+
fn bob() -> AccountId {
72+
AccountId::from(Keyring::Bob.to_raw_public())
7273
}
7374

7475
fn xt() -> UncheckedExtrinsic {
75-
let extrinsic = Extrinsic {
76+
let extrinsic = BareExtrinsic {
7677
signed: alice(),
7778
index: 0,
78-
function: Call::Staking(staking::Call::transfer::<Concrete>(bob(), 69)),
79+
function: Call::Staking(staking::Call::transfer::<Concrete>(bob().into(), 69)),
7980
};
80-
let signature = Keyring::from_raw_public(extrinsic.signed.0).unwrap()
81-
.sign(&extrinsic.encode()).into();
82-
83-
UncheckedExtrinsic { extrinsic, signature }
81+
let signature = MaybeUnsigned(Keyring::from_raw_public(extrinsic.signed.0.clone()).unwrap()
82+
.sign(&extrinsic.encode()).into());
83+
let extrinsic = Extrinsic {
84+
signed: extrinsic.signed.into(),
85+
index: extrinsic.index,
86+
function: extrinsic.function,
87+
};
88+
UncheckedExtrinsic::new(extrinsic, signature)
8489
}
8590

8691
fn from_block_number(n: u64) -> Header {
@@ -93,28 +98,36 @@ mod tests {
9398
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
9499
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
95100
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
101+
twox_128(<staking::ExistentialDeposit<Concrete>>::key()).to_vec() => vec![0u8; 8],
102+
twox_128(<staking::TransferFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
103+
twox_128(<staking::NextEnumSet<Concrete>>::key()).to_vec() => vec![0u8; 8],
96104
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
97105
];
98106

99107
let r = Executor::new().call(&mut t, BLOATY_CODE, "initialise_block", &vec![].and(&from_block_number(1u64)));
100108
assert!(r.is_ok());
101-
let r = Executor::new().call(&mut t, BLOATY_CODE, "apply_extrinsic", &vec![].and(&xt()));
102-
assert!(r.is_err());
109+
let v = Executor::new().call(&mut t, BLOATY_CODE, "apply_extrinsic", &vec![].and(&xt())).unwrap();
110+
let r = ApplyResult::decode(&mut &v[..]).unwrap();
111+
assert_eq!(r, Err(ApplyError::CantPay));
103112
}
104113

105114
#[test]
106-
fn panic_execution_with_native_equivalent_code_gives_error() {
115+
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
107116
let mut t: TestExternalities = map![
108117
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
109118
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
110119
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
120+
twox_128(<staking::ExistentialDeposit<Concrete>>::key()).to_vec() => vec![0u8; 8],
121+
twox_128(<staking::TransferFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
122+
twox_128(<staking::NextEnumSet<Concrete>>::key()).to_vec() => vec![0u8; 8],
111123
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
112124
];
113125

114126
let r = Executor::new().call(&mut t, COMPACT_CODE, "initialise_block", &vec![].and(&from_block_number(1u64)));
115127
assert!(r.is_ok());
116-
let r = Executor::new().call(&mut t, COMPACT_CODE, "apply_extrinsic", &vec![].and(&xt()));
117-
assert!(r.is_err());
128+
let v = Executor::new().call(&mut t, COMPACT_CODE, "apply_extrinsic", &vec![].and(&xt())).unwrap();
129+
let r = ApplyResult::decode(&mut &v[..]).unwrap();
130+
assert_eq!(r, Err(ApplyError::CantPay));
118131
}
119132

120133
#[test]
@@ -123,6 +136,9 @@ mod tests {
123136
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
124137
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
125138
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
139+
twox_128(<staking::ExistentialDeposit<Concrete>>::key()).to_vec() => vec![0u8; 8],
140+
twox_128(<staking::TransferFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
141+
twox_128(<staking::NextEnumSet<Concrete>>::key()).to_vec() => vec![0u8; 8],
126142
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
127143
];
128144

@@ -132,8 +148,8 @@ mod tests {
132148
assert!(r.is_ok());
133149

134150
runtime_io::with_externalities(&mut t, || {
135-
assert_eq!(Staking::balance(&alice()), 42);
136-
assert_eq!(Staking::balance(&bob()), 69);
151+
assert_eq!(Staking::voting_balance(&alice()), 42);
152+
assert_eq!(Staking::voting_balance(&bob()), 69);
137153
});
138154
}
139155

@@ -143,6 +159,9 @@ mod tests {
143159
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
144160
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
145161
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
162+
twox_128(<staking::ExistentialDeposit<Concrete>>::key()).to_vec() => vec![0u8; 8],
163+
twox_128(<staking::TransferFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
164+
twox_128(<staking::NextEnumSet<Concrete>>::key()).to_vec() => vec![0u8; 8],
146165
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
147166
];
148167

@@ -152,8 +171,8 @@ mod tests {
152171
assert!(r.is_ok());
153172

154173
runtime_io::with_externalities(&mut t, || {
155-
assert_eq!(Staking::balance(&alice()), 42);
156-
assert_eq!(Staking::balance(&bob()), 69);
174+
assert_eq!(Staking::voting_balance(&alice()), 42);
175+
assert_eq!(Staking::voting_balance(&bob()), 69);
157176
});
158177
}
159178

@@ -176,20 +195,29 @@ mod tests {
176195
bonding_duration: 0,
177196
transaction_base_fee: 1,
178197
transaction_byte_fee: 0,
198+
existential_deposit: 0,
199+
transfer_fee: 0,
200+
creation_fee: 0,
201+
contract_fee: 0,
202+
reclaim_rebate: 0,
179203
}),
180204
democracy: Some(Default::default()),
181205
council: Some(Default::default()),
182206
}.build_externalities()
183207
}
184208

185-
fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, extrinsics: Vec<Extrinsic>) -> (Vec<u8>, Hash) {
209+
fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, extrinsics: Vec<BareExtrinsic>) -> (Vec<u8>, Hash) {
186210
use triehash::ordered_trie_root;
187211

188212
let extrinsics = extrinsics.into_iter().map(|extrinsic| {
189-
let signature = Pair::from(Keyring::from_public(Public::from_raw(extrinsic.signed.0)).unwrap())
190-
.sign(&extrinsic.encode()).into();
191-
192-
UncheckedExtrinsic { extrinsic, signature }
213+
let signature = MaybeUnsigned(Pair::from(Keyring::from_public(Public::from_raw(extrinsic.signed.0.clone())).unwrap())
214+
.sign(&extrinsic.encode()).into());
215+
let extrinsic = Extrinsic {
216+
signed: extrinsic.signed.into(),
217+
index: extrinsic.index,
218+
function: extrinsic.function,
219+
};
220+
UncheckedExtrinsic::new(extrinsic, signature)
193221
}).collect::<Vec<_>>();
194222

195223
let extrinsics_root = ordered_trie_root(extrinsics.iter().map(Slicable::encode)).0.into();
@@ -210,11 +238,11 @@ mod tests {
210238
construct_block(
211239
1,
212240
[69u8; 32].into(),
213-
hex!("76b0393b4958d3cb98bb51d9f4edb316af48485142b8721e94c3b52c75ec3243").into(),
214-
vec![Extrinsic {
241+
hex!("4f7a61bceecddc19d49fbee53f82402c2a8727c1b2aeb5e5070a59f0777a203b").into(),
242+
vec![BareExtrinsic {
215243
signed: alice(),
216244
index: 0,
217-
function: Call::Staking(staking::Call::transfer(bob(), 69)),
245+
function: Call::Staking(staking::Call::transfer(bob().into(), 69)),
218246
}]
219247
)
220248
}
@@ -223,17 +251,17 @@ mod tests {
223251
construct_block(
224252
2,
225253
block1().1,
226-
hex!("8ae9828a5988459d35fb428086170dead660176ee0766e89bc1a4b48153d4e88").into(),
254+
hex!("67c588603dd727601263cf8d6138a2003ffc0df793c5ea34e7defc945da24bf0").into(),
227255
vec![
228-
Extrinsic {
256+
BareExtrinsic {
229257
signed: bob(),
230258
index: 0,
231-
function: Call::Staking(staking::Call::transfer(alice(), 5)),
259+
function: Call::Staking(staking::Call::transfer(alice().into(), 5)),
232260
},
233-
Extrinsic {
261+
BareExtrinsic {
234262
signed: alice(),
235263
index: 1,
236-
function: Call::Staking(staking::Call::transfer(bob(), 15)),
264+
function: Call::Staking(staking::Call::transfer(bob().into(), 15)),
237265
}
238266
]
239267
)
@@ -246,15 +274,15 @@ mod tests {
246274
Executor::new().call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap();
247275

248276
runtime_io::with_externalities(&mut t, || {
249-
assert_eq!(Staking::balance(&alice()), 41);
250-
assert_eq!(Staking::balance(&bob()), 69);
277+
assert_eq!(Staking::voting_balance(&alice()), 41);
278+
assert_eq!(Staking::voting_balance(&bob()), 69);
251279
});
252280

253281
Executor::new().call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap();
254282

255283
runtime_io::with_externalities(&mut t, || {
256-
assert_eq!(Staking::balance(&alice()), 30);
257-
assert_eq!(Staking::balance(&bob()), 78);
284+
assert_eq!(Staking::voting_balance(&alice()), 30);
285+
assert_eq!(Staking::voting_balance(&bob()), 78);
258286
});
259287
}
260288

@@ -265,15 +293,15 @@ mod tests {
265293
WasmExecutor.call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap();
266294

267295
runtime_io::with_externalities(&mut t, || {
268-
assert_eq!(Staking::balance(&alice()), 41);
269-
assert_eq!(Staking::balance(&bob()), 69);
296+
assert_eq!(Staking::voting_balance(&alice()), 41);
297+
assert_eq!(Staking::voting_balance(&bob()), 69);
270298
});
271299

272300
WasmExecutor.call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap();
273301

274302
runtime_io::with_externalities(&mut t, || {
275-
assert_eq!(Staking::balance(&alice()), 30);
276-
assert_eq!(Staking::balance(&bob()), 78);
303+
assert_eq!(Staking::voting_balance(&alice()), 30);
304+
assert_eq!(Staking::voting_balance(&bob()), 78);
277305
});
278306
}
279307

@@ -283,14 +311,18 @@ mod tests {
283311
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
284312
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
285313
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
314+
twox_128(<staking::ExistentialDeposit<Concrete>>::key()).to_vec() => vec![0u8; 8],
315+
twox_128(<staking::TransferFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
316+
twox_128(<staking::NextEnumSet<Concrete>>::key()).to_vec() => vec![0u8; 8],
286317
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
287318
];
288319

289320
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm");
290321
let r = WasmExecutor.call(&mut t, &foreign_code[..], "initialise_block", &vec![].and(&from_block_number(1u64)));
291322
assert!(r.is_ok());
292-
let r = WasmExecutor.call(&mut t, &foreign_code[..], "apply_extrinsic", &vec![].and(&xt()));
293-
assert!(r.is_err());
323+
let r = WasmExecutor.call(&mut t, &foreign_code[..], "apply_extrinsic", &vec![].and(&xt())).unwrap();
324+
let r = ApplyResult::decode(&mut &r[..]).unwrap();
325+
assert_eq!(r, Err(ApplyError::CantPay));
294326
}
295327

296328
#[test]
@@ -299,18 +331,22 @@ mod tests {
299331
twox_128(&<staking::FreeBalance<Concrete>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
300332
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
301333
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
334+
twox_128(<staking::ExistentialDeposit<Concrete>>::key()).to_vec() => vec![0u8; 8],
335+
twox_128(<staking::TransferFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
336+
twox_128(<staking::NextEnumSet<Concrete>>::key()).to_vec() => vec![0u8; 8],
302337
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
303338
];
304339

305340
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm");
306341
let r = WasmExecutor.call(&mut t, &foreign_code[..], "initialise_block", &vec![].and(&from_block_number(1u64)));
307342
assert!(r.is_ok());
308-
let r = WasmExecutor.call(&mut t, &foreign_code[..], "apply_extrinsic", &vec![].and(&xt()));
309-
assert!(r.is_ok());
343+
let r = WasmExecutor.call(&mut t, &foreign_code[..], "apply_extrinsic", &vec![].and(&xt())).unwrap();
344+
let r = ApplyResult::decode(&mut &r[..]).unwrap();
345+
assert_eq!(r, Ok(ApplyOutcome::Success));
310346

311347
runtime_io::with_externalities(&mut t, || {
312-
assert_eq!(Staking::balance(&alice()), 42);
313-
assert_eq!(Staking::balance(&bob()), 69);
348+
assert_eq!(Staking::voting_balance(&alice()), 42);
349+
assert_eq!(Staking::voting_balance(&bob()), 69);
314350
});
315351
}
316352
}

demo/primitives/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub type BlockNumber = u64;
3535
/// certainly continue to be the same as the substrate's `AuthorityId`.
3636
pub type AccountId = ::primitives::H256;
3737

38+
/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
39+
/// never know...
40+
pub type AccountIndex = u32;
41+
3842
/// Balance of an account.
3943
pub type Balance = u64;
4044

@@ -49,4 +53,4 @@ pub type Index = u64;
4953
pub type Hash = primitives::H256;
5054

5155
/// Alias to 512-bit hash when used in the context of a signature on the relay chain.
52-
pub type Signature = runtime_primitives::Ed25519Signature;
56+
pub type Signature = runtime_primitives::MaybeUnsigned<runtime_primitives::Ed25519Signature>;

0 commit comments

Comments
 (0)