Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 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
5d5f194
Initial util code for random beacon
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
53eb893
Merge branch 'gav-storage-revamp' into gav-random-beacon
gavofyork Mar 16, 2018
d228593
Generic mix.
gavofyork Mar 16, 2018
a90fbe3
Integrate random beacon
gavofyork Mar 16, 2018
d352727
Update binaries.
gavofyork Mar 16, 2018
19f7258
Fixes relating to with_ext removal.
gavofyork Mar 16, 2018
ff2fa3c
Remove dead code.
gavofyork Mar 16, 2018
c674963
Rework mixer into an iterator adaptor.
gavofyork Mar 17, 2018
c49d8a9
Merge branch 'master' into gav-random-beacon
gavofyork Mar 19, 2018
74a59b9
Link to paper.
gavofyork Mar 19, 2018
23ca1b2
Algorithm cleanups
gavofyork Mar 19, 2018
1bb150b
Merge and fix test.
gavofyork Mar 19, 2018
2e9fa09
Docs.
gavofyork Mar 19, 2018
e4c2b27
Fix typo.
gavofyork Mar 19, 2018
90dd1a5
rename
gavofyork Mar 19, 2018
f197714
Fix tests.
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
Prev Previous commit
Next Next commit
Merge branch 'master' into gav-random-beacon
  • Loading branch information
gavofyork committed Mar 19, 2018
commit c49d8a9b189cfbed9d9e01ff6086e006a06f33d7
5 changes: 3 additions & 2 deletions demo/runtime/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

//! Dispatch system. Just dispatches calls.

use runtime::{staking, system};
use runtime::{staking, democracy};
pub use rstd::prelude::Vec;
pub use codec::{Slicable, Input, NonTrivialSlicable};

/// Implement a dispatch module to create a pairing of a dispatch trait and enum.
#[macro_export]
macro_rules! impl_dispatch {
(
Expand Down Expand Up @@ -232,7 +233,7 @@ impl_meta_dispatch! {
impl_meta_dispatch! {
pub mod privileged;
path privileged;
trait system::PrivPass;
trait democracy::PrivPass;
System(mod system) = 0;
Session(mod session) = 1;
Staking(mod staking) = 2;
Expand Down
6 changes: 3 additions & 3 deletions demo/runtime/src/runtime/council.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use codec::KeyedVec;
use runtime_support::{StorageMap, StorageValue};
use demo_primitives::{AccountId, Hash, BlockNumber};
use runtime::{staking, system, session};
use runtime::system::PrivPass;
use runtime::democracy::PrivPass;
use runtime::staking::{PublicPass, Balance};

// no polynomial attacks:
Expand Down Expand Up @@ -1026,7 +1026,7 @@ mod tests {
internal::end_block();

system::testing::set_block_number(8);
PrivPass.set_desired_seats(3);
PrivPass::test().set_desired_seats(3);
internal::end_block();

system::testing::set_block_number(10);
Expand Down Expand Up @@ -1283,7 +1283,7 @@ mod tests {

system::testing::set_block_number(8);
PublicPass::test(&Ferdie).set_approvals(vec![false, false, true, false], 1);
PrivPass.set_desired_seats(3);
PrivPass::test().set_desired_seats(3);
internal::end_block();

system::testing::set_block_number(10);
Expand Down
2 changes: 1 addition & 1 deletion demo/runtime/src/runtime/council_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use runtime_support::{StorageValue, StorageMap};
use demo_primitives::{AccountId, Hash, BlockNumber};
use runtime::{system, democracy, council};
use runtime::staking::{PublicPass, Balance};
use runtime::system::PrivPass;
use runtime::democracy::PrivPass;
use dispatch::PrivCall as Proposal;

type ProposalHash = [u8; 32];
Expand Down
6 changes: 2 additions & 4 deletions demo/runtime/src/runtime/democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use runtime_support::{StorageValue, StorageMap};
use demo_primitives::{AccountId, Hash, BlockNumber};
use dispatch::PrivCall as Proposal;
use runtime::{staking, system, session};
use runtime::system::PrivPass;
use runtime::staking::{PublicPass, Balance};

/// A token for privileged dispatch. Can only be created in this module.
Expand All @@ -41,6 +40,7 @@ pub type PropIndex = u32;
/// A referendum index.
pub type ReferendumIndex = u32;

/// A means of determining if a vote is past pass threshold.
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
pub enum VoteThreshold {
Expand Down Expand Up @@ -164,8 +164,6 @@ pub fn tally(ref_index: ReferendumIndex) -> (staking::Balance, staking::Balance)
.fold((0, 0), |(a, b), (c, d)| (a + c, b + d))
}

pub type BoxedProposal = Box<Proposal>;

impl_dispatch! {
pub mod public;
fn propose(proposal: Box<Proposal>, value: Balance) = 0;
Expand Down Expand Up @@ -274,7 +272,7 @@ pub mod internal {
let total_stake = staking::total_stake();
clear_referendum(index);
if vote_threshold.approved(approve, against, total_stake) {
proposal.dispatch(PrivPass);
proposal.dispatch(PrivPass::new());
}
NextTally::put(index + 1);
}
Expand Down
8 changes: 4 additions & 4 deletions demo/runtime/src/runtime/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use codec::KeyedVec;
use runtime_support::{storage, StorageValue, StorageMap};
use demo_primitives::{AccountId, SessionKey, BlockNumber};
use runtime::{system, staking, consensus};
use runtime::system::PrivPass;
use runtime::democracy::PrivPass;
use runtime::staking::PublicPass;

storage_items!{
Expand Down Expand Up @@ -183,14 +183,14 @@ mod tests {
with_externalities(&mut t, || {
// Block 1: Change to length 3; no visible change.
system::testing::set_block_number(1);
PrivPass.set_length(3);
PrivPass::test().set_length(3);
check_rotate_session();
assert_eq!(length(), 2);
assert_eq!(current_index(), 0);

// Block 2: Length now changed to 3. Index incremented.
system::testing::set_block_number(2);
PrivPass.set_length(3);
PrivPass::test().set_length(3);
check_rotate_session();
assert_eq!(length(), 3);
assert_eq!(current_index(), 1);
Expand All @@ -203,7 +203,7 @@ mod tests {

// Block 4: Change to length 2; no visible change.
system::testing::set_block_number(4);
PrivPass.set_length(2);
PrivPass::test().set_length(2);
check_rotate_session();
assert_eq!(length(), 3);
assert_eq!(current_index(), 1);
Expand Down
8 changes: 4 additions & 4 deletions demo/runtime/src/runtime/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl_dispatch! {
fn force_new_era() = 3;
}

impl privileged::Dispatch for system::PrivPass {
impl privileged::Dispatch for democracy::PrivPass {
/// Set the number of sessions in an era.
fn set_sessions_per_era(self, new: BlockNumber) {
NextSessionsPerEra::put(&new);
Expand Down Expand Up @@ -570,8 +570,8 @@ mod tests {
use codec::{KeyedVec, Joiner};
use keyring::Keyring::*;
use demo_primitives::AccountId;
use runtime::{staking, session, system};
use runtime::system::PrivPass;
use runtime::{staking, session};
use runtime::democracy::PrivPass;
use runtime::staking::public::{Call, Dispatch};
use runtime::staking::privileged::{Call as PCall, Dispatch as PDispatch};

Expand Down Expand Up @@ -675,7 +675,7 @@ mod tests {

// Block 3: Schedule an era length change; no visible changes.
system::testing::set_block_number(3);
PrivPass.set_sessions_per_era(3);
PrivPass::test().set_sessions_per_era(3);
check_new_era();
assert_eq!(SessionsPerEra::get(), 2u64);
assert_eq!(LastEraLengthChange::get(), 0u64);
Expand Down
6 changes: 6 additions & 0 deletions demo/runtime/src/runtime/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ storage_items! {
Digest: b"sys:dig" => default block::Digest;
}

storage_items! {
pub Nonce: b"sys:non" => default map [ AccountId => TxOrder ];
pub BlockHashAt: b"sys:old" => required map [ BlockNumber => Hash ];
}

pub const CODE: &'static[u8] = b":code";


pub struct PrivPass;

impl_dispatch! {
Expand Down
25 changes: 14 additions & 11 deletions substrate/runtime-support/src/storage/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

use codec;
use rstd::vec::Vec;
#[doc(hidden)]
pub use rstd::borrow::Borrow;

/// Abstraction around storage.
Expand All @@ -58,10 +59,12 @@ pub trait Storage {
/// Load the bytes of a key from storage. Can panic if the type is incorrect.
fn get<T: codec::Slicable>(&self, key: &[u8]) -> Option<T>;

/// Load the bytes of a key from storage. Can panic if the type is incorrect.
/// Load the bytes of a key from storage. Can panic if the type is incorrect. Will panic if
/// it's not there.
fn require<T: codec::Slicable>(&self, key: &[u8]) -> T { self.get(key).expect("Required values must be in storage") }

/// Load the bytes of a key from storage. Can panic if the type is incorrect.
/// Load the bytes of a key from storage. Can panic if the type is incorrect. The type's
/// default is returned if it's not there.
fn get_or_default<T: codec::Slicable + Default>(&self, key: &[u8]) -> T { self.get(key).unwrap_or_default() }

/// Put a value in under a key.
Expand All @@ -78,7 +81,7 @@ pub trait Storage {
}

/// Take a value from storage, deleting it after reading.
fn seize<T: codec::Slicable>(&self, key: &[u8]) -> T { self.take(key).expect("Required values must be in storage") }
fn take_or_panic<T: codec::Slicable>(&self, key: &[u8]) -> T { self.take(key).expect("Required values must be in storage") }

/// Take a value from storage, deleting it after reading.
fn take_or_default<T: codec::Slicable + Default>(&self, key: &[u8]) -> T { self.take(key).unwrap_or_default() }
Expand Down Expand Up @@ -347,11 +350,11 @@ macro_rules! storage_items {
storage_items!($($t)*);
};
($name:ident : $key:expr => required $ty:ty; $($t:tt)*) => {
__storage_items_internal!(() () ($ty) (require) (seize) $name: $key => $ty);
__storage_items_internal!(() () ($ty) (require) (take_or_panic) $name: $key => $ty);
storage_items!($($t)*);
};
(pub $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => {
__storage_items_internal!((pub) () ($ty) (require) (seize) $name: $key => $ty);
__storage_items_internal!((pub) () ($ty) (require) (take_or_panic) $name: $key => $ty);
storage_items!($($t)*);
};

Expand All @@ -372,11 +375,11 @@ macro_rules! storage_items {
storage_items!($($t)*);
};
($name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => {
__storage_items_internal!(() ($getfn) ($ty) (require) (seize) $name: $key => $ty);
__storage_items_internal!(() ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty);
storage_items!($($t)*);
};
(pub $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => {
__storage_items_internal!((pub) ($getfn) ($ty) (require) (seize) $name: $key => $ty);
__storage_items_internal!((pub) ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty);
storage_items!($($t)*);
};

Expand All @@ -398,11 +401,11 @@ macro_rules! storage_items {
storage_items!($($t)*);
};
($name:ident : $prefix:expr => required map [$kty: ty => $ty:ty]; $($t:tt)*) => {
__storage_items_internal!(() () ($ty) (require) (seize) $name: $prefix => map [$kty => $ty]);
__storage_items_internal!(() () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]);
storage_items!($($t)*);
};
(pub $name:ident : $prefix:expr => required map [$kty: ty => $ty:ty]; $($t:tt)*) => {
__storage_items_internal!((pub) () ($ty) (require) (seize) $name: $prefix => map [$kty => $ty]);
__storage_items_internal!((pub) () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]);
storage_items!($($t)*);
};

Expand All @@ -423,11 +426,11 @@ macro_rules! storage_items {
storage_items!($($t)*);
};
($name:ident get($getfn:ident) : $prefix:expr => required map [$kty: ty => $ty:ty]; $($t:tt)*) => {
__storage_items_internal!(() ($getfn) ($ty) (require) (seize) $name: $prefix => map [$kty => $ty]);
__storage_items_internal!(() ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]);
storage_items!($($t)*);
};
(pub $name:ident get($getfn:ident) : $prefix:expr => required map [$kty: ty => $ty:ty]; $($t:tt)*) => {
__storage_items_internal!((pub) ($getfn) ($ty) (require) (seize) $name: $prefix => map [$kty => $ty]);
__storage_items_internal!((pub) ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]);
storage_items!($($t)*);
};

Expand Down
1 change: 1 addition & 0 deletions substrate/runtime-support/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub fn put_raw(key: &[u8], value: &[u8]) {
runtime_io::set_storage(&twox_128(key)[..], value)
}

/// The underlying runtime storage.
pub struct RuntimeStorage;

impl ::GenericStorage for RuntimeStorage {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.