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

Refactor all (demo) runtime modules to use new storage #98

Merged
merged 33 commits into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a83059a
Completely rework dispatch mechanism into something modular.
gavofyork Mar 13, 2018
82a178d
Council vote tests.
gavofyork Mar 13, 2018
1d28d9a
Fix tests.
gavofyork Mar 13, 2018
69c88c3
whitespace.
gavofyork Mar 13, 2018
b12a708
Fix demo runtime tests.
gavofyork Mar 14, 2018
e48e86d
Merge branch 'gav-demo' into gav-dispatch
gavofyork Mar 14, 2018
8e3cc51
Fix up tests.
gavofyork Mar 14, 2018
53e2fdf
Merge branch 'gav-demo' into gav-dispatch
gavofyork Mar 14, 2018
27ecd6f
Merge branch 'master' into gav-dispatch
gavofyork Mar 14, 2018
5eca74a
Remove dead code.
gavofyork Mar 14, 2018
7cece3b
Merge branch 'master' into gav-dispatch
gavofyork Mar 14, 2018
8c2396d
Timestamp uses new storage API.
gavofyork Mar 14, 2018
6b6c240
Move over system module to new API.
gavofyork Mar 14, 2018
a79dab2
Much nicer storage API, moved over staking module.
gavofyork Mar 15, 2018
1fd6b3e
More refactoring.
gavofyork Mar 15, 2018
51b4a8c
Democracy uses new storage API.
gavofyork Mar 15, 2018
8ada9f7
Council uses new RPC.
gavofyork Mar 16, 2018
c4f5f42
Fix more tests.
gavofyork Mar 16, 2018
d11f5ca
Use match for Id
gavofyork Mar 16, 2018
faa0a44
Use match for Id
gavofyork Mar 16, 2018
7912de1
Make PrivPass better protected.
gavofyork Mar 19, 2018
aac3899
Address other grumbles.
gavofyork Mar 19, 2018
26519c6
Give PrivPass a private member.
gavofyork Mar 19, 2018
9f32ea7
Testing PrivPass.
gavofyork Mar 19, 2018
8966951
Add docs.
gavofyork Mar 19, 2018
91d5e75
Merge branch 'gav-dispatch' into gav-storage-revamp
gavofyork Mar 19, 2018
7ee81e6
Recompile binaries after merge.
gavofyork Mar 19, 2018
33215e4
Merge branch 'master' into gav-storage-revamp
gavofyork Mar 19, 2018
cf9659e
Remove duplicated code.
gavofyork Mar 19, 2018
b8c0832
New binaries.
gavofyork Mar 19, 2018
57a9a79
Docs
gavofyork Mar 19, 2018
59c7a1a
Docs
gavofyork Mar 19, 2018
6f8f456
avoid use of (arguably) confusing terminology.
gavofyork Mar 19, 2018
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
34 changes: 17 additions & 17 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ mod tests {
use runtime_io;
use super::Executor;
use substrate_executor::WasmExecutor;
use codec::{KeyedVec, Slicable, Joiner};
use codec::{Slicable, Joiner};
use keyring::Keyring::{self, Alice, Bob};
use runtime_support::Hashable;
use runtime_support::{Hashable, StorageValue, StorageMap};
use state_machine::{CodeExecutor, TestExternalities};
use primitives::twox_128;
use demo_primitives::{Hash, Header, BlockNumber, Digest};
use demo_runtime::transaction::{Transaction, UncheckedTransaction};
use demo_runtime::block::Block;
use demo_runtime::runtime::staking::{self, balance, BALANCE_OF};
use demo_runtime::runtime::staking::{self, FreeBalanceOf, balance};
use demo_runtime::dispatch;
use ed25519::{Public, Pair};

Expand Down Expand Up @@ -75,8 +75,8 @@ mod tests {
#[test]
fn panic_execution_with_foreign_code_gives_error() {
let mut t: TestExternalities = map![
twox_128(&Alice.to_raw_public().to_keyed_vec(BALANCE_OF)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TRANSACTION_FEE).to_vec() => vec![0u8; 8]
twox_128(&FreeBalanceOf::key_for(*Alice)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TransactionFee::key()).to_vec() => vec![0u8; 8]
];

let r = Executor::new().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
Expand All @@ -86,8 +86,8 @@ mod tests {
#[test]
fn panic_execution_with_native_equivalent_code_gives_error() {
let mut t: TestExternalities = map![
twox_128(&Alice.to_raw_public().to_keyed_vec(BALANCE_OF)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TRANSACTION_FEE).to_vec() => vec![0u8; 8]
twox_128(&FreeBalanceOf::key_for(*Alice)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TransactionFee::key()).to_vec() => vec![0u8; 8]
];

let r = Executor::new().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
Expand All @@ -97,8 +97,8 @@ mod tests {
#[test]
fn successful_execution_with_native_equivalent_code_gives_ok() {
let mut t: TestExternalities = map![
twox_128(&Alice.to_raw_public().to_keyed_vec(BALANCE_OF)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TRANSACTION_FEE).to_vec() => vec![0u8; 8]
twox_128(&FreeBalanceOf::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TransactionFee::key()).to_vec() => vec![0u8; 8]
];

let r = Executor::new().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
Expand All @@ -113,8 +113,8 @@ mod tests {
#[test]
fn successful_execution_with_foreign_code_gives_ok() {
let mut t: TestExternalities = map![
twox_128(&Alice.to_raw_public().to_keyed_vec(BALANCE_OF)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TRANSACTION_FEE).to_vec() => vec![0u8; 8]
twox_128(&FreeBalanceOf::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TransactionFee::key()).to_vec() => vec![0u8; 8]
];

let r = Executor::new().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
Expand Down Expand Up @@ -158,7 +158,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("cfb76a83e40aa6a0d3f92255e6229e74808cae31d9f46053f31129b797540d03").into(),
hex!("7a388ce5b4eeadbb9268ae96e8822b223f4fd1841327d99f4e1c21fad81f97f2").into(),
vec![Transaction {
signed: Alice.into(),
nonce: 0,
Expand All @@ -171,7 +171,7 @@ mod tests {
construct_block(
2,
block1().1,
hex!("c713bd003e303648e8d904bcfa44084865c9b70c398547e678028cc7cf60907f").into(),
hex!("e4eb71be8b816f2061f32f284e9b429562cdc1b82f11725e5f965ff23439f5e9").into(),
vec![
Transaction {
signed: Bob.into(),
Expand Down Expand Up @@ -228,8 +228,8 @@ mod tests {
#[test]
fn panic_execution_gives_error() {
let mut t: TestExternalities = map![
twox_128(&Alice.to_raw_public().to_keyed_vec(BALANCE_OF)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TRANSACTION_FEE).to_vec() => vec![0u8; 8]
twox_128(&FreeBalanceOf::key_for(*Alice)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TransactionFee::key()).to_vec() => vec![0u8; 8]
];

let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm");
Expand All @@ -240,8 +240,8 @@ mod tests {
#[test]
fn successful_execution_gives_ok() {
let mut t: TestExternalities = map![
twox_128(&Alice.to_raw_public().to_keyed_vec(BALANCE_OF)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TRANSACTION_FEE).to_vec() => vec![0u8; 8]
twox_128(&FreeBalanceOf::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(staking::TransactionFee::key()).to_vec() => vec![0u8; 8]
];

let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm");
Expand Down
51 changes: 24 additions & 27 deletions demo/runtime/src/genesismap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use codec::{KeyedVec, Joiner};
use std::collections::HashMap;
use runtime_io::twox_128;
use runtime_support::Hashable;
use runtime_support::{Hashable, StorageMap, StorageList, StorageValue};
use primitives::Block;
use demo_primitives::{BlockNumber, AccountId};
use runtime::staking::Balance;
Expand Down Expand Up @@ -80,40 +80,37 @@ impl GenesisConfig {
pub fn genesis_map(&self) -> HashMap<Vec<u8>, Vec<u8>> {
let wasm_runtime = include_bytes!("../wasm/genesis.wasm").to_vec();
vec![
(&session::SESSION_LENGTH[..], vec![].and(&self.session_length)),
(&session::VALIDATOR_COUNT[..], vec![].and(&(self.validators.len() as u32))),
(session::SessionLength::key(), vec![].and(&self.session_length)),
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 🎊

(session::Validators::key(), vec![].and(&self.validators)),

(&staking::INTENTION_COUNT[..], vec![].and(&0u32)),
(&staking::SESSIONS_PER_ERA[..], vec![].and(&self.sessions_per_era)),
(&staking::CURRENT_ERA[..], vec![].and(&0u64)),
(&staking::Intention::len_key()[..], vec![].and(&0u32)),
(&staking::SessionsPerEra::key()[..], vec![].and(&self.sessions_per_era)),
(&staking::CurrentEra::key()[..], vec![].and(&0u64)),

(&democracy::LAUNCH_PERIOD[..], vec![].and(&self.launch_period)),
(&democracy::VOTING_PERIOD[..], vec![].and(&self.voting_period)),
(&democracy::MINIMUM_DEPOSIT[..], vec![].and(&self.minimum_deposit)),
(democracy::LaunchPeriod::key(), vec![].and(&self.launch_period)),
(democracy::VotingPeriod::key(), vec![].and(&self.voting_period)),
(democracy::MinimumDeposit::key(), vec![].and(&self.minimum_deposit)),

(&council::CANDIDACY_BOND[..], vec![].and(&self.candidacy_bond)),
(&council::VOTING_BOND[..], vec![].and(&self.voter_bond)),
(&council::PRESENT_SLASH_PER_VOTER[..], vec![].and(&self.present_slash_per_voter)),
(&council::CARRY_COUNT[..], vec![].and(&self.carry_count)),
(&council::PRESENTATION_DURATION[..], vec![].and(&self.presentation_duration)),
(&council::VOTING_PERIOD[..], vec![].and(&self.council_election_voting_period)),
(&council::TERM_DURATION[..], vec![].and(&self.council_term_duration)),
(&council::DESIRED_SEATS[..], vec![].and(&self.desired_seats)),
(&council::INACTIVE_GRACE_PERIOD[..], vec![].and(&self.inactive_grace_period)),
(council::CandidacyBond::key(), vec![].and(&self.candidacy_bond)),
(council::VotingBond::key(), vec![].and(&self.voter_bond)),
(council::PresentSlashPerVoter::key(), vec![].and(&self.present_slash_per_voter)),
(council::CarryCount::key(), vec![].and(&self.carry_count)),
(council::PresentationDuration::key(), vec![].and(&self.presentation_duration)),
(council::VotingPeriod::key(), vec![].and(&self.council_election_voting_period)),
(council::TermDuration::key(), vec![].and(&self.council_term_duration)),
(council::DesiredSeats::key(), vec![].and(&self.desired_seats)),
(council::InactiveGracePeriod::key(), vec![].and(&self.inactive_grace_period)),

(&council_vote::COOLOFF_PERIOD[..], vec![].and(&self.cooloff_period)),
(&council_vote::VOTING_PERIOD[..], vec![].and(&self.council_proposal_voting_period))
(council_vote::CooloffPeriod::key(), vec![].and(&self.cooloff_period)),
(council_vote::VotingPeriod::key(), vec![].and(&self.council_proposal_voting_period))
].into_iter()
.map(|(k, v)| (k.into(), v))
.chain(self.validators.iter()
.enumerate()
.map(|(i, account)| ((i as u32).to_keyed_vec(session::VALIDATOR_AT), vec![].and(account)))
).chain(self.balances.iter()
.map(|&(account, balance)| (account.to_keyed_vec(staking::BALANCE_OF), vec![].and(&balance)))
.chain(self.balances.iter()
.map(|&(account, balance)| (staking::FreeBalanceOf::key_for(&account), vec![].and(&balance)))
)
.map(|(k, v)| (twox_128(&k[..])[..].to_vec(), v.to_vec()))
.chain(vec![
(system::CODE[..].into(), wasm_runtime),
(system::CODE.to_vec(), wasm_runtime),
(consensus::AUTHORITY_COUNT[..].into(), vec![].and(&(self.authorities.len() as u32))),
].into_iter())
.chain(self.authorities.iter()
Expand All @@ -127,6 +124,6 @@ impl GenesisConfig {
pub fn additional_storage_with_genesis(genesis_block: &Block) -> HashMap<Vec<u8>, Vec<u8>> {
use codec::Slicable;
map![
twox_128(&0u64.to_keyed_vec(system::BLOCK_HASH_AT)).to_vec() => genesis_block.header.blake2_256().encode()
system::BlockHashAt::key_for(&0) => genesis_block.header.blake2_256().encode()
]
}
2 changes: 1 addition & 1 deletion demo/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#[allow(unused_imports)] #[macro_use] extern crate substrate_runtime_std as rstd;
#[macro_use] extern crate substrate_runtime_io as runtime_io;
extern crate substrate_runtime_support as runtime_support;
#[macro_use] extern crate substrate_runtime_support as runtime_support;
#[cfg(any(feature = "std", test))] extern crate substrate_keyring as keyring;

#[cfg(feature = "std")] #[macro_use] extern crate serde_derive;
Expand Down
Loading