Update to latest Substrate master + warning fixes (#292)

* Update to latest Substrate master + warning fixes

* Update runtime/src/lib.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Bastian Köcher
2019-06-20 13:57:58 +02:00
committed by Robert Habermeier
parent 58ab4f6b9f
commit a016bac6ad
21 changed files with 989 additions and 1225 deletions
+1 -3
View File
@@ -193,7 +193,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sr_primitives::{
BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::{Digest, DigestItem, Header}
BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::Header
};
use balances;
use srml_support::{impl_outer_origin, assert_ok, assert_err, assert_noop};
@@ -213,12 +213,10 @@ mod tests {
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type Digest = Digest;
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
type Header = Header;
type Event = ();
type Log = DigestItem;
}
impl balances::Trait for Test {
type Balance = u64;
+1 -1
View File
@@ -37,7 +37,7 @@ decl_module! {
/// curated GRANDPA set.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
/// Changes the GRANDPA voter set.
fn set_voters(origin, voters: Vec<(T::SessionKey, u64)>) {
fn set_voters(origin, voters: Vec<(grandpa::AuthorityId, u64)>) {
system::ensure_root(origin)?;
grandpa::Module::<T>::schedule_change(voters, T::BlockNumber::zero(), None)?;
}
+60 -56
View File
@@ -27,10 +27,10 @@ mod slot_range;
mod slots;
use rstd::prelude::*;
use substrate_primitives::u32_trait::{_2, _4};
use substrate_primitives::u32_trait::{_1, _2, _3, _4};
use primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, SessionKey, Signature,
parachain, SessionSignature,
parachain, AuraId
};
use client::{
block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
@@ -38,13 +38,11 @@ use client::{
};
use sr_primitives::{
ApplyResult, generic, transaction_validity::TransactionValidity, create_runtime_str,
traits::{
BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, Convert, AuthorityIdFor
}
traits::{BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, Convert}, impl_opaque_keys
};
use version::RuntimeVersion;
use grandpa::fg_primitives::{self, ScheduledChange};
use council::{motions as council_motions, voting as council_voting};
use council::motions as council_motions;
#[cfg(feature = "std")]
use council::seats as council_seats;
#[cfg(any(feature = "std", test))]
@@ -56,7 +54,6 @@ use srml_support::{parameter_types, construct_runtime};
pub use staking::StakerStatus;
#[cfg(any(feature = "std", test))]
pub use sr_primitives::BuildStorage;
pub use consensus::Call as ConsensusCall;
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use parachains::{Call as ParachainsCall, INHERENT_IDENTIFIER as PARACHAIN_INHERENT_IDENTIFIER};
@@ -89,16 +86,15 @@ impl system::Trait for Runtime {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type Digest = generic::Digest<Log>;
type AccountId = AccountId;
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Event = Event;
type Log = Log;
}
impl aura::Trait for Runtime {
type HandleReport = aura::StakingSlasher<Runtime>;
type AuthorityId = AuraId;
}
impl indices::Trait for Runtime {
@@ -118,24 +114,33 @@ impl balances::Trait for Runtime {
type TransferPayment = ();
}
impl consensus::Trait for Runtime {
type Log = Log;
type SessionKey = SessionKey;
// the aura module handles offline-reports internally
// rather than using an explicit report system.
type InherentOfflineReport = ();
}
impl timestamp::Trait for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
}
parameter_types! {
pub const Period: BlockNumber = 10 * MINUTES;
pub const Offset: BlockNumber = 0;
}
type SessionHandlers = (Grandpa, Aura);
impl_opaque_keys! {
pub struct SessionKeys(grandpa::AuthorityId, AuraId);
}
// NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
// The number and order of items in `SessionHandler` *MUST* be the same number and order of keys in
// `SessionKeys`.
// TODO: Introduce some structure to tie these together to make it a bit less of a footgun. This
// should be easy, since OneSessionHandler trait provides the `Key` as an associated type. #2858
impl session::Trait for Runtime {
type ConvertAccountIdToSessionKey = ();
type OnSessionChange = Staking;
type OnSessionEnding = Staking;
type SessionHandler = SessionHandlers;
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type Event = Event;
type Keys = SessionKeys;
}
/// Converter for currencies to votes.
@@ -153,14 +158,20 @@ impl Convert<u128, u128> for CurrencyToVoteHandler {
fn convert(x: u128) -> u128 { x * Self::factor() }
}
parameter_types! {
pub const SessionsPerEra: session::SessionIndex = 6;
pub const BondingDuration: staking::EraIndex = 24 * 28;
}
impl staking::Trait for Runtime {
type OnRewardMinted = Treasury;
type CurrencyToVote = CurrencyToVoteHandler;
type Event = Event;
type Currency = balances::Module<Self>;
type Currency = Balances;
type Slash = ();
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
}
const MINUTES: BlockNumber = 6;
@@ -169,28 +180,36 @@ const BUCKS: Balance = 1_000_000_000_000;
parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const EmergencyVotingPeriod: BlockNumber = 3 * 24 * 60 * MINUTES;
pub const MinimumDeposit: Balance = 100 * BUCKS;
pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
pub const CooloffPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
}
impl democracy::Trait for Runtime {
type Currency = balances::Module<Self>;
type Proposal = Call;
type Event = Event;
type Currency = Balances;
type EnactmentPeriod = EnactmentPeriod;
type LaunchPeriod = LaunchPeriod;
type VotingPeriod = VotingPeriod;
type EmergencyVotingPeriod = EmergencyVotingPeriod;
type MinimumDeposit = MinimumDeposit;
type ExternalOrigin = council_motions::EnsureProportionAtLeast<_1, _2, AccountId>;
type ExternalMajorityOrigin = council_motions::EnsureProportionAtLeast<_2, _3, AccountId>;
type EmergencyOrigin = council_motions::EnsureProportionAtLeast<_1, _1, AccountId>;
type CancellationOrigin = council_motions::EnsureProportionAtLeast<_2, _3, AccountId>;
type VetoOrigin = council_motions::EnsureMember<AccountId>;
type CooloffPeriod = CooloffPeriod;
}
impl council::Trait for Runtime {
type Event = Event;
type BadPresentation = ();
type BadReaper = ();
}
impl council::voting::Trait for Runtime {
type Event = Event;
type BadVoterIndex = ();
type LoserCandidate = ();
type OnMembersChanged = CouncilMotions;
}
impl council::motions::Trait for Runtime {
@@ -201,16 +220,14 @@ impl council::motions::Trait for Runtime {
impl treasury::Trait for Runtime {
type Currency = balances::Module<Self>;
type ApproveOrigin = council_motions::EnsureMembers<_4>;
type RejectOrigin = council_motions::EnsureMembers<_2>;
type ApproveOrigin = council_motions::EnsureMembers<_4, AccountId>;
type RejectOrigin = council_motions::EnsureMembers<_2, AccountId>;
type Event = Event;
type MintedForSpending = ();
type ProposalRejection = ();
}
impl grandpa::Trait for Runtime {
type SessionKey = SessionKey;
type Log = Log;
type Event = Event;
}
@@ -240,26 +257,23 @@ impl sudo::Trait for Runtime {
}
construct_runtime!(
pub enum Runtime with Log(InternalLog: DigestItem<Hash, SessionKey, SessionSignature>) where
pub enum Runtime where
Block = Block,
NodeBlock = primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{default, Log(ChangesTrieRoot)},
Aura: aura::{Module},
System: system,
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
// consensus' Inherent is not provided because it assumes instant-finality blocks.
Consensus: consensus::{Module, Call, Storage, Config<T>, Log(AuthoritiesChange) },
Indices: indices,
Balances: balances,
Session: session,
Session: session::{Module, Call, Storage, Event, Config<T>},
Staking: staking,
Democracy: democracy,
Grandpa: grandpa::{Module, Call, Storage, Config<T>, Log(), Event<T>},
Grandpa: grandpa::{Module, Call, Storage, Config<T>, Event},
CuratedGrandpa: curated_grandpa::{Module, Call, Config<T>, Storage},
Council: council::{Module, Call, Storage, Event<T>},
CouncilVoting: council_voting,
CouncilMotions: council_motions::{Module, Call, Storage, Event<T>, Origin},
CouncilMotions: council_motions::{Module, Call, Storage, Event<T>, Origin<T>},
CouncilSeats: council_seats::{Config<T>},
Treasury: treasury,
Parachains: parachains::{Module, Call, Storage, Config<T>, Inherent, Origin},
@@ -271,7 +285,7 @@ construct_runtime!(
/// The address format for describing accounts.
pub type Address = <Indices as StaticLookup>::Source;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// A Block signed with a Justification
@@ -342,7 +356,7 @@ impl_runtime_apis! {
impl parachain::ParachainHost<Block> for Runtime {
fn validators() -> Vec<parachain::ValidatorId> {
Consensus::authorities() // only possible as long as parachain validator crypto === aura crypto
Aura::authorities() // only possible as long as parachain validator crypto === aura crypto
}
fn duty_roster() -> parachain::DutyRoster {
Parachains::calculate_duty_roster()
@@ -365,15 +379,7 @@ impl_runtime_apis! {
fn grandpa_pending_change(digest: &DigestFor<Block>)
-> Option<ScheduledChange<BlockNumber>>
{
for log in digest.logs.iter().filter_map(|l| match l {
Log(InternalLog::grandpa(grandpa_signal)) => Some(grandpa_signal),
_=> None
}) {
if let Some(change) = Grandpa::scrape_digest_change(log) {
return Some(change);
}
}
None
Grandpa::pending_change(digest)
}
fn grandpa_forced_change(_digest: &DigestFor<Block>)
@@ -387,15 +393,13 @@ impl_runtime_apis! {
}
}
impl consensus_aura::AuraApi<Block> for Runtime {
impl consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> u64 {
Aura::slot_duration()
}
}
impl consensus_authorities::AuthoritiesApi<Block> for Runtime {
fn authorities() -> Vec<AuthorityIdFor<Block>> {
Consensus::authorities()
fn authorities() -> Vec<AuraId> {
Aura::authorities()
}
}
+57 -22
View File
@@ -475,7 +475,7 @@ impl<T: Trait> Module<T> {
pub fn calculate_duty_roster() -> DutyRoster {
let parachains = Self::active_parachains();
let parachain_count = parachains.len();
let validator_count = <consensus::Module<T>>::authorities().len();
let validator_count = crate::Aura::authorities().len();
let validators_per_parachain = if parachain_count != 0 { (validator_count - 1) / parachain_count } else { 0 };
let mut roles_val = (0..validator_count).map(|i| match i {
@@ -628,7 +628,7 @@ impl<T: Trait> Module<T> {
}
}
let authorities = super::Consensus::authorities();
let authorities = super::Aura::authorities();
let duty_roster = Self::calculate_duty_roster();
// convert a duty roster, which is originally a Vec<Chain>, where each
@@ -761,14 +761,17 @@ mod tests {
use sr_io::{TestExternalities, with_externalities};
use substrate_primitives::{H256, Blake2Hasher};
use substrate_trie::NodeCodec;
use sr_primitives::{generic, BuildStorage};
use sr_primitives::traits::{BlakeTwo256, IdentityLookup};
use sr_primitives::{
BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::UintAuthorityId,
};
use primitives::{
parachain::{CandidateReceipt, HeadData, ValidityAttestation, ValidatorIndex}, SessionKey
parachain::{CandidateReceipt, HeadData, ValidityAttestation, ValidatorIndex}, SessionKey,
BlockNumber, AuraId
};
use keyring::{AuthorityKeyring, AccountKeyring};
use srml_support::{impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err};
use {consensus, timestamp};
use srml_support::{
impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, parameter_types,
};
use crate::parachains;
impl_outer_origin! {
@@ -785,33 +788,67 @@ mod tests {
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
impl consensus::Trait for Test {
type InherentOfflineReport = ();
type SessionKey = SessionKey;
type Log = crate::Log;
}
impl system::Trait for Test {
type Origin = Origin;
type Index = crate::Nonce;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type Digest = generic::Digest<crate::Log>;
type AccountId = crate::AccountId;
type Lookup = IdentityLookup<crate::AccountId>;
type Header = crate::Header;
type Event = ();
type Log = crate::Log;
}
parameter_types! {
pub const Period: BlockNumber = 1;
pub const Offset: BlockNumber = 0;
}
impl session::Trait for Test {
type ConvertAccountIdToSessionKey = ();
type OnSessionChange = ();
type OnSessionEnding = ();
type Keys = UintAuthorityId;
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type SessionHandler = ();
type Event = ();
}
impl timestamp::Trait for Test {
type Moment = u64;
type OnTimestampSet = ();
}
impl aura::Trait for Test {
type HandleReport = aura::StakingSlasher<Test>;
type AuthorityId = AuraId;
}
impl balances::Trait for Test {
type Balance = u64;
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
}
parameter_types! {
pub const SessionsPerEra: session::SessionIndex = 6;
pub const BondingDuration: staking::EraIndex = 24 * 28;
}
impl staking::Trait for Test {
type OnRewardMinted = ();
type CurrencyToVote = ();
type Event = ();
type Currency = balances::Module<Test>;
type Slash = ();
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
}
impl Trait for Test {
type Origin = Origin;
type Call = Call;
@@ -843,12 +880,7 @@ mod tests {
AccountKeyring::Two,
];
t.extend(consensus::GenesisConfig::<Test>{
code: vec![],
authorities: authority_keys.iter().map(|k| SessionKey::from(*k)).collect(),
}.build_storage().unwrap().0);
t.extend(session::GenesisConfig::<Test>{
session_length: 1000,
validators: validator_keys.iter().map(|k| crate::AccountId::from(*k)).collect(),
keys: vec![],
}.build_storage().unwrap().0);
@@ -856,6 +888,9 @@ mod tests {
parachains,
_phdata: Default::default(),
}.build_storage().unwrap().0);
t.extend(aura::GenesisConfig::<Test>{
authorities: authority_keys.iter().map(|k| SessionKey::from(*k)).collect(),
}.build_storage().unwrap().0);
t.into()
}
@@ -870,7 +905,7 @@ mod tests {
let duty_roster = Parachains::calculate_duty_roster();
let candidate_hash = candidate.candidate.hash();
let authorities = crate::Consensus::authorities();
let authorities = crate::Aura::authorities();
let extract_key = |public: SessionKey| {
AuthorityKeyring::from_raw_public(public.0).unwrap()
};
+2 -5
View File
@@ -112,7 +112,7 @@ type WinningData<T> = [Option<(Bidder<<T as system::Trait>::AccountId, ParaIdOf<
// index assigned to them, their winning bid and the range that they won.
type WinnersData<T> = Vec<(Option<NewBidder<<T as system::Trait>::AccountId>>, ParaIdOf<T>, BalanceOf<T>, SlotRange)>;
/// This module's storage items.
// This module's storage items.
decl_storage! {
trait Store for Module<T: Trait> as Slots {
@@ -781,9 +781,8 @@ mod tests {
use substrate_primitives::{Blake2Hasher, H256};
use sr_io::with_externalities;
use sr_primitives::{
BuildStorage,
BuildStorage, testing::Header,
traits::{BlakeTwo256, Hash, IdentityLookup, OnInitialize, OnFinalize},
testing::{Digest, DigestItem, Header}
};
use srml_support::{impl_outer_origin, parameter_types, assert_ok, assert_noop};
use balances;
@@ -804,12 +803,10 @@ mod tests {
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type Digest = Digest;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type Log = DigestItem;
}
impl balances::Trait for Test {