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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dp/make-CallExecuto…
Browse files Browse the repository at this point in the history
…rs-generic-over-hasher-and-rlpcodec

* origin/master:
  Fixed sync stalling when import queue is full (#691)
  New extrinsic dispatch model (#678)
  remove parachain's Cargo.lock (#682)
  Implement json metadata for outer events (#672)
  Improvements to the Kademlia system (#688)
  Use BufReader and BufWriter (#684)
  Switch to using parity/rust:substrate which has rust nightly-2018-08-31 (#686)
  Update to latest libp2p (#673)
  Implement storage json metadata (#670)
  impl MaybeEmpty for H256 and u64 (aka AccountId in prod/tests) (#665)
  Speedup compilation (#671)
  Remove requirement of function indices for decl_module! (#666)
  DigestItem trait (v2) (#650)
  • Loading branch information
dvdplm committed Sep 8, 2018
2 parents dcde1ca + db02933 commit 2aa3597
Show file tree
Hide file tree
Showing 53 changed files with 3,221 additions and 2,746 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ stages:
- test
- build

image: parity/rust:gitlab-ci
image: parity/rust:substrate

variables:
CI_SERVER_NAME: "GitLab CI"
Expand Down
290 changes: 103 additions & 187 deletions Cargo.lock

Large diffs are not rendered by default.

73 changes: 38 additions & 35 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ mod tests {
use primitives::{twox_128, KeccakHasher};
use demo_primitives::{Hash, BlockNumber, AccountId};
use runtime_primitives::traits::Header as HeaderT;
use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult, MaybeUnsigned};
use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult};
use {balances, staking, session, system, consensus};
use system::{EventRecord, Phase};
use demo_runtime::{Header, Block, UncheckedExtrinsic, Extrinsic, Call, Runtime, Balances,
BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, BareExtrinsic, System, Event};
use demo_runtime::{Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System, Event};
use ed25519::{Public, Pair};

const BLOATY_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm");
Expand All @@ -77,20 +77,32 @@ mod tests {
AccountId::from(Keyring::Bob.to_raw_public())
}

fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
match xt.signed {
Some(signed) => {
let payload = (xt.index, xt.function);
let pair = Pair::from(Keyring::from_public(Public::from_raw(signed.clone().into())).unwrap());
let signature = pair.sign(&payload.encode()).into();
UncheckedExtrinsic {
signature: Some((balances::address::Address::Id(signed), signature)),
index: payload.0,
function: payload.1,
}
}
None => UncheckedExtrinsic {
signature: None,
index: xt.index,
function: xt.function,
},
}
}

fn xt() -> UncheckedExtrinsic {
let extrinsic = BareExtrinsic {
signed: alice(),
sign(CheckedExtrinsic {
signed: Some(alice()),
index: 0,
function: Call::Balances(balances::Call::transfer::<Runtime>(bob().into(), 69)),
};
let signature = MaybeUnsigned(Keyring::from_raw_public(extrinsic.signed.0.clone()).unwrap()
.sign(&extrinsic.encode()).into());
let extrinsic = Extrinsic {
signed: extrinsic.signed.into(),
index: extrinsic.index,
function: extrinsic.function,
};
UncheckedExtrinsic::new(extrinsic, signature)
})
}

fn from_block_number(n: u64) -> Header {
Expand Down Expand Up @@ -225,19 +237,10 @@ mod tests {
}.build_storage().unwrap().into()
}

fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, extrinsics: Vec<BareExtrinsic>) -> (Vec<u8>, Hash) {
fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, extrinsics: Vec<CheckedExtrinsic>) -> (Vec<u8>, Hash) {
use triehash::ordered_trie_root;

let extrinsics = extrinsics.into_iter().map(|extrinsic| {
let signature = MaybeUnsigned(Pair::from(Keyring::from_public(Public::from_raw(extrinsic.signed.0.clone())).unwrap())
.sign(&extrinsic.encode()).into());
let extrinsic = Extrinsic {
signed: extrinsic.signed.into(),
index: extrinsic.index,
function: extrinsic.function,
};
UncheckedExtrinsic::new(extrinsic, signature)
}).collect::<Vec<_>>();
let extrinsics = extrinsics.into_iter().map(sign).collect::<Vec<_>>();

let extrinsics_root = ordered_trie_root::<KeccakHasher, _, _>(extrinsics.iter().map(Encode::encode)).0.into();

Expand All @@ -261,8 +264,8 @@ mod tests {
// hex!("3437bf4b182ab17bb322af5c67e55f6be487a77084ad2b4e27ddac7242e4ad21").into(),
// Keccak
hex!("508a68a0918f614b86b2ccfd0975754f6d2abe1026a34e42d6d8d5abdf4db010").into(),
vec![BareExtrinsic {
signed: alice(),
vec![CheckedExtrinsic {
signed: Some(alice()),
index: 0,
function: Call::Balances(balances::Call::transfer(bob().into(), 69)),
}]
Expand All @@ -276,15 +279,15 @@ mod tests {
// Blake
// hex!("741fcb660e6fa9f625fbcd993b49f6c1cc4040f5e0cc8727afdedf11fd3c464b").into(),
// Keccak
hex!("171f1b2c01c9c616e40ee2d842a699286b50a5a74874b56d826094dadedffb27").into(),
hex!("a72ec570c7642d9ad06ef0e5dd37be65fb04b71e0ab52b3927d760ed6c777a1f").into(),
vec![
BareExtrinsic {
signed: bob(),
CheckedExtrinsic {
signed: Some(bob()),
index: 0,
function: Call::Balances(balances::Call::transfer(alice().into(), 5)),
},
BareExtrinsic {
signed: alice(),
CheckedExtrinsic {
signed: Some(alice()),
index: 1,
function: Call::Balances(balances::Call::transfer(bob().into(), 15)),
}
Expand All @@ -300,10 +303,10 @@ mod tests {
// hex!("2c7231a9c210a7aa4bea169d944bc4aaacd517862b244b8021236ffa7f697991").into(),
// Keccak
hex!("e45221804da3a3609454d4e09debe6364cc6af63c2ff067d802d1af62fea32ae").into(),
vec![BareExtrinsic {
signed: alice(),
vec![CheckedExtrinsic {
signed: Some(alice()),
index: 0,
function: Call::Consensus(consensus::Call::remark(vec![0; 60000])),
function: Call::Consensus(consensus::Call::remark(vec![0; 60000000])),
}]
)
}
Expand Down
2 changes: 1 addition & 1 deletion demo/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ pub type Index = u64;
pub type Hash = primitives::H256;

/// Alias to 512-bit hash when used in the context of a signature on the relay chain.
pub type Signature = runtime_primitives::MaybeUnsigned<runtime_primitives::Ed25519Signature>;
pub type Signature = runtime_primitives::Ed25519Signature;
106 changes: 52 additions & 54 deletions demo/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ extern crate substrate_runtime_timestamp as timestamp;
extern crate substrate_runtime_version as version;
extern crate demo_primitives;

use rstd::prelude::*;
use demo_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, SessionKey, Signature};
use runtime_primitives::generic;
use runtime_primitives::traits::{Convert, BlakeTwo256};
use runtime_primitives::traits::{Convert, BlakeTwo256, DigestItem};
use version::RuntimeVersion;

#[cfg(any(feature = "std", test))]
Expand All @@ -65,7 +64,7 @@ pub use runtime_primitives::BuildStorage;
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
/// Runtime runtime type used to parameterize the various modules.
/// Runtime type used to collate and parameterize the various modules.
pub struct Runtime;

/// Runtime version.
Expand All @@ -77,22 +76,15 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
};

/// Version module for this concrete runtime.
pub type Version = version::Module<Runtime>;

impl version::Trait for Runtime {
const VERSION: RuntimeVersion = VERSION;
}

impl system::Trait for Runtime {
type PublicAux = Self::AccountId;
type Origin = Origin;
type Index = Index;
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type Digest = generic::Digest<Vec<u8>>;
type Digest = generic::Digest<Log>;
type AccountId = AccountId;
type Header = generic::Header<BlockNumber, BlakeTwo256, Vec<u8>>;
type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
type Event = Event;
}

Expand All @@ -112,6 +104,7 @@ pub type Balances = balances::Module<Runtime>;

impl consensus::Trait for Runtime {
const NOTE_OFFLINE_POSITION: u32 = 1;
type Log = Log;
type SessionKey = SessionKey;
type OnOfflineValidator = Staking;
}
Expand Down Expand Up @@ -154,7 +147,7 @@ impl staking::Trait for Runtime {
pub type Staking = staking::Module<Runtime>;

impl democracy::Trait for Runtime {
type Proposal = PrivCall;
type Proposal = Call;
}

/// Democracy module for this concrete runtime.
Expand All @@ -173,50 +166,29 @@ impl_outer_event! {
}
}

impl_outer_dispatch! {
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum Call where aux: <Runtime as system::Trait>::PublicAux {
Consensus = 0,
Balances = 1,
Session = 2,
Staking = 3,
Timestamp = 4,
Democracy = 5,
Council = 6,
CouncilVoting = 7,
impl_outer_log! {
pub enum Log for Runtime {
consensus
}
}

#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum PrivCall {
Consensus = 0,
Balances = 1,
Session = 2,
Staking = 3,
Democracy = 4,
Council = 5,
CouncilVoting = 6,
impl_outer_origin! {
pub enum Origin for Runtime {
}
}

/// The address format for describing accounts.
pub type Address = balances::Address<Runtime>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Vec<u8>>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Index, Call, Signature>;
/// Extrinsic type as expected by this runtime. This is not the type that is signed.
pub type Extrinsic = generic::Extrinsic<Address, Index, Call>;
/// Extrinsic type that is signed.
pub type BareExtrinsic = generic::Extrinsic<AccountId, Index, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Balances, Balances,
(((((), Council), Democracy), Staking), Session)>;
impl_outer_dispatch! {
pub enum Call where origin: Origin {
Consensus,
Balances,
Session,
Staking,
Timestamp,
Democracy,
Council,
CouncilVoting,
}
}

impl_outer_config! {
pub struct GenesisConfig for Runtime {
Expand All @@ -231,9 +203,35 @@ impl_outer_config! {
}
}

impl DigestItem for Log {
type AuthoritiesChange = consensus::AuthoritiesChange<SessionKey>;

fn as_authorities_change(&self) -> Option<&Self::AuthoritiesChange> {
match *self {
Log::consensus(ref item) => item.as_authorities_change(),
}
}
}

/// The address format for describing accounts.
pub type Address = balances::Address<Runtime>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Index, Call, Signature>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Index, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Balances, Balances,
(((((), Council), Democracy), Staking), Session)>;

pub mod api {
impl_stubs!(
version => |()| super::Version::version(),
version => |()| super::VERSION,
authorities => |()| super::Consensus::authorities(),
events => |()| super::System::events(),
initialise_block => |header| super::Executive::initialise_block(&header),
Expand Down
2 changes: 1 addition & 1 deletion demo/runtime/wasm/Cargo.lock

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

Loading

0 comments on commit 2aa3597

Please sign in to comment.