Fix up polkadot runtime

This commit is contained in:
Gav
2018-08-30 09:57:09 +02:00
parent 7aff0dc99b
commit 5138feb801
24 changed files with 512 additions and 456 deletions
+6 -6
View File
@@ -16,10 +16,10 @@
//! Typesafe block interaction.
use super::{Call, Block, TIMESTAMP_SET_POSITION, PARACHAINS_SET_POSITION, NOTE_OFFLINE_POSITION};
use super::{Call, Block, TIMESTAMP_SET_POSITION, PARACHAINS_SET_POSITION, NOTE_MISSED_PROPOSAL_POSITION};
use timestamp::Call as TimestampCall;
use parachains::Call as ParachainsCall;
use session::Call as SessionCall;
use staking::Call as StakingCall;
use primitives::parachain::CandidateReceipt;
/// Provides a type-safe wrapper around a structurally valid block.
@@ -90,10 +90,10 @@ impl CheckedBlock {
}
}
/// Extract the noted offline validator indices (if any) from the block.
pub fn noted_offline(&self) -> &[u32] {
self.inner.extrinsics.get(NOTE_OFFLINE_POSITION as usize).and_then(|xt| match xt.extrinsic.function {
Call::Session(SessionCall::note_offline(ref x)) => Some(&x[..]),
/// Extract the noted missed proposal validator indices (if any) from the block.
pub fn noted_missed_proposal(&self) -> &[u32] {
self.inner.extrinsics.get(NOTE_MISSED_PROPOSAL_POSITION as usize).and_then(|xt| match xt.extrinsic.function {
Call::Staking(StakingCall::note_missed_proposal(ref x)) => Some(&x[..]),
_ => None,
}).unwrap_or(&[])
}
+36 -14
View File
@@ -45,9 +45,12 @@ extern crate substrate_primitives;
#[macro_use]
extern crate substrate_runtime_std as rstd;
#[macro_use]
extern crate substrate_codec_derive;
extern crate polkadot_primitives as primitives;
extern crate substrate_codec as codec;
extern crate substrate_runtime_balances as balances;
extern crate substrate_runtime_consensus as consensus;
extern crate substrate_runtime_council as council;
extern crate substrate_runtime_democracy as democracy;
@@ -67,7 +70,7 @@ mod utils;
#[cfg(feature = "std")]
pub use checked_block::CheckedBlock;
pub use utils::{inherent_extrinsics, check_extrinsic};
pub use staking::address::Address as RawAddress;
pub use balances::address::Address as RawAddress;
use primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Log, SessionKey, Signature};
use runtime_primitives::{generic, traits::{HasPublicAux, BlakeTwo256, Convert}};
@@ -85,11 +88,11 @@ pub use primitives::Header;
pub const TIMESTAMP_SET_POSITION: u32 = 0;
/// The position of the parachains set extrinsic.
pub const PARACHAINS_SET_POSITION: u32 = 1;
/// The position of the offline nodes noting extrinsic.
pub const NOTE_OFFLINE_POSITION: u32 = 2;
/// The position of the note_missed_proposal extrinsic in the block, if it exists.
pub const NOTE_MISSED_PROPOSAL_POSITION: u32 = 2;
/// The address format for describing accounts.
pub type Address = staking::Address<Concrete>;
pub type Address = balances::Address<Concrete>;
/// Block Id type for this block.
pub type BlockId = generic::BlockId<Block>;
/// Unchecked extrinsic type as expected by this runtime.
@@ -136,10 +139,21 @@ impl system::Trait for Concrete {
type Digest = generic::Digest<Log>;
type AccountId = AccountId;
type Header = Header;
type Event = Event;
}
/// System module for this concrete runtime.
pub type System = system::Module<Concrete>;
impl balances::Trait for Concrete {
type Balance = Balance;
type AccountIndex = AccountIndex;
type OnFreeBalanceZero = Staking;
type IsAccountLiquid = Staking;
type Event = Event;
}
/// Staking module for this concrete runtime.
pub type Balances = balances::Module<Concrete>;
impl consensus::Trait for Concrete {
type SessionKey = SessionKey;
}
@@ -162,17 +176,16 @@ impl Convert<AccountId, SessionKey> for SessionKeyConversion {
}
impl session::Trait for Concrete {
const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION;
type ConvertAccountIdToSessionKey = SessionKeyConversion;
type OnSessionChange = Staking;
type Event = Event;
}
/// Session module for this concrete runtime.
pub type Session = session::Module<Concrete>;
impl staking::Trait for Concrete {
type Balance = Balance;
type AccountIndex = AccountIndex;
type OnAccountKill = ();
const NOTE_MISSED_PROPOSAL_POSITION: u32 = NOTE_MISSED_PROPOSAL_POSITION;
type Event = Event;
}
/// Staking module for this concrete runtime.
pub type Staking = staking::Module<Concrete>;
@@ -196,15 +209,22 @@ impl parachains::Trait for Concrete {
}
pub type Parachains = parachains::Module<Concrete>;
impl_outer_event! {
pub enum Event for Concrete {
balances, session, staking
}
}
impl_outer_dispatch! {
/// Call type for polkadot transactions.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum Call where aux: <Concrete as HasPublicAux>::PublicAux {
Consensus = 0,
Session = 1,
Staking = 2,
Timestamp = 3,
Balances = 1,
Session = 2,
Staking = 3,
Timestamp = 4,
Democracy = 5,
Council = 6,
CouncilVoting = 7,
@@ -216,8 +236,9 @@ impl_outer_dispatch! {
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum PrivCall {
Consensus = 0,
Session = 1,
Staking = 2,
Balances = 1,
Session = 2,
Staking = 3,
Democracy = 5,
Council = 6,
CouncilVoting = 7,
@@ -226,13 +247,14 @@ impl_outer_dispatch! {
}
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Concrete, Block, Staking, Staking,
pub type Executive = executive::Executive<Concrete, Block, Balances, Balances,
(((((((), Parachains), Council), Democracy), Staking), Session), Timestamp)>;
impl_outer_config! {
pub struct GenesisConfig for Concrete {
ConsensusConfig => consensus,
SystemConfig => system,
BaalncesConfig => balances,
SessionConfig => session,
StakingConfig => staking,
DemocracyConfig => democracy,
+1 -1
View File
@@ -158,7 +158,7 @@ impl<T: Trait> Module<T> {
ensure!(aux.is_empty(), "set_heads must not be signed");
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
ensure!(
<system::Module<T>>::extrinsic_index() == T::SET_POSITION,
<system::Module<T>>::extrinsic_index() == Some(T::SET_POSITION),
"Parachain heads update extrinsic must be at position {} in the block"
// , T::SET_POSITION
);
+4 -4
View File
@@ -17,11 +17,11 @@
//! Utils for block interaction.
use rstd::prelude::*;
use super::{Call, UncheckedExtrinsic, Extrinsic, Staking};
use super::{Call, UncheckedExtrinsic, Extrinsic, Balances};
use runtime_primitives::traits::{Checkable, AuxLookup};
use timestamp::Call as TimestampCall;
use parachains::Call as ParachainsCall;
use session::Call as SessionCall;
use staking::Call as StakingCall;
/// Produces the list of inherent extrinsics.
pub fn inherent_extrinsics(data: ::primitives::InherentData) -> Vec<UncheckedExtrinsic> {
@@ -41,7 +41,7 @@ pub fn inherent_extrinsics(data: ::primitives::InherentData) -> Vec<UncheckedExt
if !data.offline_indices.is_empty() {
inherent.push(make_inherent(
Call::Session(SessionCall::note_offline(data.offline_indices))
Call::Staking(StakingCall::note_missed_proposal(data.offline_indices))
));
}
@@ -50,5 +50,5 @@ pub fn inherent_extrinsics(data: ::primitives::InherentData) -> Vec<UncheckedExt
/// Checks an unchecked extrinsic for validity.
pub fn check_extrinsic(xt: UncheckedExtrinsic) -> bool {
xt.check_with(Staking::lookup).is_ok()
xt.check_with(Balances::lookup).is_ok()
}