Commit 9b66efa7 authored by Shawn Tabrizi's avatar Shawn Tabrizi Committed by Gavin Wood
Browse files

Update to latest Substrate (7688cbc) (#329)



* Initial fixes

* Clean up Timestamp

* Patch futures

* Typo

* Fix compilation of tests

* Fix parachains tests

* Update runtime/src/parachains.rs
Co-Authored-By: thiolliere's avatarthiolliere <gui.thiolliere@gmail.com>

* Update runtime/src/parachains.rs
Co-Authored-By: default avatarGavin Wood <github@gavwood.com>
parent 12cb9cb5
Pipeline #43729 passed with stages
in 24 minutes and 19 seconds
This diff is collapsed.
......@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
futures = "0.1.17"
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
client = { package = "substrate-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
parity-codec = "4.1"
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
......
......@@ -50,6 +50,7 @@ use std::sync::Arc;
use std::time::Duration;
use futures::{future, Stream, Future, IntoFuture};
use futures03::{TryStreamExt as _, StreamExt as _};
use log::{info, warn};
use client::BlockchainEvents;
use primitives::{ed25519, Pair};
......@@ -334,6 +335,7 @@ impl<P, E> Worker for CollationNode<P, E> where
let parachain_context = build_parachain_context.build(validation_network.clone()).unwrap();
let inner_exit = exit.clone();
let work = client.import_notification_stream()
.map(|v| Ok::<_, ()>(v)).compat()
.for_each(move |notification| {
macro_rules! try_fr {
($e:expr) => {
......
......@@ -26,7 +26,8 @@ offchain_primitives = { package = "substrate-offchain-primitives", git = "https:
aura = { package = "srml-aura", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
authorship = { package = "srml-authorship", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
balances = { package = "srml-balances", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
council = { package = "srml-council", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
collective = { package = "srml-collective", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
elections = { package = "srml-elections", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
democracy = { package = "srml-democracy", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
finality-tracker = { package = "srml-finality-tracker", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
......@@ -70,7 +71,8 @@ std = [
"aura/std",
"authorship/std",
"balances/std",
"council/std",
"collective/std",
"elections/std",
"democracy/std",
"executive/std",
"finality-tracker/std",
......
......@@ -211,6 +211,9 @@ mod tests {
// configuration traits of modules we want to use.
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl system::Trait for Test {
type Origin = Origin;
type Index = u64;
......@@ -221,6 +224,7 @@ mod tests {
type Lookup = IdentityLookup<u64>;
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
}
parameter_types! {
......
......@@ -42,9 +42,7 @@ use sr_primitives::{
};
use version::RuntimeVersion;
use grandpa::{AuthorityId as GrandpaId, fg_primitives::{self, ScheduledChange}};
use council::motions as council_motions;
#[cfg(feature = "std")]
use council::seats as council_seats;
use elections::VoteIndex;
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
......@@ -60,7 +58,6 @@ pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use parachains::{Call as ParachainsCall, INHERENT_IDENTIFIER as PARACHAIN_INHERENT_IDENTIFIER};
pub use sr_primitives::{Permill, Perbill};
pub use timestamp::BlockPeriod;
pub use srml_support::StorageValue;
// Make the WASM binary available.
......@@ -91,11 +88,15 @@ const BUCKS: Balance = DOTS / 100;
const CENTS: Balance = BUCKS / 100;
const MILLICENTS: Balance = CENTS / 1_000;
const SECS_PER_BLOCK: BlockNumber = 10;
const SECS_PER_BLOCK: BlockNumber = 6;
const MINUTES: BlockNumber = 60 / SECS_PER_BLOCK;
const HOURS: BlockNumber = MINUTES * 60;
const DAYS: BlockNumber = HOURS * 24;
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl system::Trait for Runtime {
type Origin = Origin;
type Index = Nonce;
......@@ -106,6 +107,7 @@ impl system::Trait for Runtime {
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Event = Event;
type BlockHashCount = BlockHashCount;
}
impl aura::Trait for Runtime {
......@@ -162,9 +164,14 @@ impl balances::Trait for Runtime {
type TransactionByteFee = TransactionByteFee;
}
parameter_types! {
pub const MinimumPeriod: u64 = SECS_PER_BLOCK / 2;
}
impl timestamp::Trait for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = MinimumPeriod;
}
parameter_types! {
......@@ -264,14 +271,22 @@ impl democracy::Trait for Runtime {
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 ExternalOrigin = collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilInstance>;
type ExternalMajorityOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilInstance>;
type ExternalPushOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalInstance>;
type EmergencyOrigin = collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilInstance>;
type CancellationOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilInstance>;
type VetoOrigin = collective::EnsureMember<AccountId, CouncilInstance>;
type CooloffPeriod = CooloffPeriod;
}
type CouncilInstance = collective::Instance1;
impl collective::Trait<CouncilInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
}
parameter_types! {
pub const CandidacyBond: Balance = 10 * BUCKS;
pub const VotingBond: Balance = 1 * BUCKS;
......@@ -279,29 +294,31 @@ parameter_types! {
pub const PresentSlashPerVoter: Balance = 1 * CENTS;
pub const CarryCount: u32 = 6;
// one additional vote should go by before an inactive voter can be reaped.
pub const InactiveGracePeriod: council::VoteIndex = 1;
pub const CouncilVotingPeriod: BlockNumber = 2 * DAYS;
pub const InactiveGracePeriod: VoteIndex = 1;
pub const ElectionsVotingPeriod: BlockNumber = 2 * DAYS;
pub const DecayRatio: u32 = 0;
}
impl council::Trait for Runtime {
impl elections::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type BadPresentation = ();
type BadReaper = ();
type BadVoterIndex = ();
type LoserCandidate = ();
type OnMembersChanged = CouncilMotions;
type ChangeMembers = Council;
type CandidacyBond = CandidacyBond;
type VotingBond = VotingBond;
type VotingFee = VotingFee;
type PresentSlashPerVoter = PresentSlashPerVoter;
type CarryCount = CarryCount;
type InactiveGracePeriod = InactiveGracePeriod;
type CouncilVotingPeriod = CouncilVotingPeriod;
type VotingPeriod = ElectionsVotingPeriod;
type DecayRatio = DecayRatio;
}
impl council::motions::Trait for Runtime {
type TechnicalInstance = collective::Instance2;
impl collective::Trait<TechnicalInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
......@@ -316,8 +333,8 @@ parameter_types! {
impl treasury::Trait for Runtime {
type Currency = Balances;
type ApproveOrigin = council_motions::EnsureMembers<_4, AccountId>;
type RejectOrigin = council_motions::EnsureMembers<_2, AccountId>;
type ApproveOrigin = collective::EnsureMembers<_4, AccountId, CouncilInstance>;
type RejectOrigin = collective::EnsureMembers<_2, AccountId, CouncilInstance>;
type Event = Event;
type MintedForSpending = ();
type ProposalRejection = ();
......@@ -376,16 +393,16 @@ construct_runtime!(
{
System: system::{Module, Call, Storage, Config, Event},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Authorship: authorship::{Module, Call, Storage},
Indices: indices,
Balances: balances,
Staking: staking::{default, OfflineWorker},
Session: session::{Module, Call, Storage, Event, Config<T>},
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
Council: council::{Module, Call, Storage, Event<T>},
CouncilMotions: council_motions::{Module, Call, Storage, Event<T>, Origin<T>},
CouncilSeats: council_seats::{Config<T>},
Council: collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
TechnicalCommittee: collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
Elections: elections::{Module, Call, Storage, Event<T>, Config<T>},
FinalityTracker: finality_tracker::{Module, Call, Inherent},
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
CuratedGrandpa: curated_grandpa::{Module, Call, Config<T>, Storage},
......
......@@ -818,11 +818,12 @@ mod tests {
use substrate_primitives::{H256, Blake2Hasher};
use substrate_trie::NodeCodec;
use sr_primitives::{
traits::{BlakeTwo256, IdentityLookup}, testing::UintAuthorityId,
traits::{BlakeTwo256, IdentityLookup},
testing::{UintAuthorityId, Header},
};
use primitives::{
parachain::{CandidateReceipt, HeadData, ValidityAttestation, ValidatorIndex}, SessionKey,
BlockNumber, AuraId
BlockNumber, AuraId,
};
use keyring::{AuthorityKeyring, AccountKeyring};
use srml_support::{
......@@ -844,16 +845,20 @@ mod tests {
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl system::Trait for Test {
type Origin = Origin;
type Index = crate::Nonce;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = crate::AccountId;
type Lookup = IdentityLookup<crate::AccountId>;
type Header = crate::Header;
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
}
parameter_types! {
......@@ -868,18 +873,22 @@ mod tests {
type SessionHandler = ();
type Event = ();
type SelectInitialValidators = staking::Module<Self>;
type ValidatorId = crate::AccountId;
type ValidatorId = u64;
type ValidatorIdOf = staking::StashOf<Self>;
}
impl session::historical::Trait for Test {
type FullIdentification = staking::Exposure<crate::AccountId, Balance>;
type FullIdentification = staking::Exposure<u64, Balance>;
type FullIdentificationOf = staking::ExposureOf<Self>;
}
parameter_types! {
pub const MinimumPeriod: u64 = 3;
}
impl timestamp::Trait for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
}
impl aura::Trait for Test {
......@@ -960,7 +969,7 @@ mod tests {
];
t.extend(session::GenesisConfig::<Test>{
keys: vec![],
keys: vec![(1, UintAuthorityId(1))],
}.build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
parachains,
......
......@@ -801,6 +801,9 @@ mod tests {
// configuration traits of modules we want to use.
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl system::Trait for Test {
type Origin = Origin;
type Index = u64;
......@@ -811,6 +814,7 @@ mod tests {
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
}
parameter_types! {
......
......@@ -19,8 +19,8 @@
use primitives::{ed25519, sr25519, Pair, crypto::UncheckedInto};
use polkadot_primitives::{AccountId, SessionKey};
use polkadot_runtime::{
GenesisConfig, CouncilSeatsConfig, DemocracyConfig, SystemConfig, AuraConfig,
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, Perbill, SessionKeys,
GenesisConfig, CouncilConfig, ElectionsConfig, DemocracyConfig, SystemConfig, AuraConfig,
SessionConfig, StakingConfig, BalancesConfig, Perbill, SessionKeys, TechnicalCommitteeConfig,
GrandpaConfig, SudoConfig, IndicesConfig, CuratedGrandpaConfig, StakerStatus, WASM_BINARY,
};
use telemetry::TelemetryEndpoints;
......@@ -109,15 +109,20 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
}),
democracy: Some(Default::default()),
council_seats: Some(CouncilSeatsConfig {
active_council: vec![],
collective_Instance1: Some(CouncilConfig {
members: vec![],
phantom: Default::default(),
}),
collective_Instance2: Some(TechnicalCommitteeConfig {
members: vec![],
phantom: Default::default(),
}),
elections: Some(ElectionsConfig {
members: vec![],
presentation_duration: 1 * DAYS,
term_duration: 28 * DAYS,
desired_seats: 0,
}),
timestamp: Some(TimestampConfig {
minimum_period: SECS_PER_BLOCK / 2, // due to the nature of aura the slots are 2*period
}),
sudo: Some(SudoConfig {
key: endowed_accounts[0].clone(),
}),
......@@ -197,7 +202,7 @@ pub fn testnet_genesis(
const STASH: u128 = 1 << 20;
const ENDOWMENT: u128 = 1 << 20;
let council_desired_seats = (endowed_accounts.len() / 2 - initial_authorities.len()) as u32;
let desired_seats = (endowed_accounts.len() / 2 - initial_authorities.len()) as u32;
GenesisConfig {
system: Some(SystemConfig {
......@@ -231,20 +236,25 @@ pub fn testnet_genesis(
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
}),
democracy: Some(DemocracyConfig::default()),
council_seats: Some(CouncilSeatsConfig {
active_council: endowed_accounts.iter()
collective_Instance1: Some(CouncilConfig {
members: vec![],
phantom: Default::default(),
}),
collective_Instance2: Some(TechnicalCommitteeConfig {
members: vec![],
phantom: Default::default(),
}),
elections: Some(ElectionsConfig {
members: endowed_accounts.iter()
.filter(|&endowed| initial_authorities.iter()
.find(|&(_, controller, _)| controller == endowed)
.is_none()
).map(|a| (a.clone(), 1000000)).collect(),
presentation_duration: 10,
term_duration: 1000000,
desired_seats: council_desired_seats,
desired_seats: desired_seats,
}),
parachains: Some(Default::default()),
timestamp: Some(TimestampConfig {
minimum_period: 2, // 2*2=4 second block time.
}),
sudo: Some(SudoConfig {
key: root_key,
}),
......
......@@ -57,7 +57,7 @@ pub struct CustomConfiguration {
// FIXME: rather than putting this on the config, let's have an actual intermediate setup state
// https://github.com/paritytech/substrate/issues/1134
pub grandpa_import_setup: Option<(
Arc<grandpa::BlockImportForService<Factory>>,
grandpa::BlockImportForService<Factory>,
grandpa::LinkHalfForService<Factory>
)>,
......@@ -320,15 +320,13 @@ service::construct_service_factory! {
grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>, _>(
client.clone(), client.clone(), select_chain
)?;
let block_import = Arc::new(block_import);
let justification_import = block_import.clone();
config.custom.grandpa_import_setup = Some((block_import.clone(), link_half));
import_queue::<_, _, ed25519::Pair>(
slot_duration,
block_import,
Some(justification_import),
None,
Box::new(block_import),
Some(Box::new(justification_import)),
None,
client,
config.custom.inherent_data_providers.clone(),
......@@ -346,19 +344,17 @@ service::construct_service_factory! {
let block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, LightClient<Self>>(
client.clone(), Arc::new(fetch_checker), client.clone()
)?;
let block_import = Arc::new(block_import);
let finality_proof_import = block_import.clone();
let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder();
import_queue::<_, _, ed25519::Pair>(
SlotDuration::get_or_compute(&*client)?,
block_import,
Box::new(block_import),
None,
Some(finality_proof_import),
Some(finality_proof_request_builder),
Some(Box::new(finality_proof_import)),
client,
config.custom.inherent_data_providers.clone(),
).map_err(Into::into)
).map_err(Into::into).map(|q| (q, finality_proof_request_builder))
}},
SelectChain = LongestChain<FullBackend<Self>, Self::Block>
{ |config: &FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
......
......@@ -6,6 +6,7 @@ edition = "2018"
[dependencies]
futures = "0.1.17"
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
parking_lot = "0.7.1"
tokio = "0.1.7"
derive_more = "0.14.0"
......
......@@ -31,6 +31,7 @@ use client::blockchain::HeaderBackend;
use consensus::SelectChain;
use extrinsic_store::Store as ExtrinsicStore;
use futures::prelude::*;
use futures03::{TryStreamExt as _, StreamExt as _};
use log::error;
use primitives::ed25519;
use polkadot_primitives::{Block, BlockId, AuraId};
......@@ -73,6 +74,7 @@ fn prune_unneeded_availability<P>(client: Arc<P>, extrinsic_store: ExtrinsicStor
where P: Send + Sync + BlockchainEvents<Block> + BlockBody<Block> + 'static
{
client.finality_notification_stream()
.map(|v| Ok::<_, ()>(v)).compat()
.for_each(move |notification| {
let hash = notification.hash;
let parent_hash = notification.header.parent_hash;
......@@ -135,6 +137,7 @@ pub(crate) fn start<C, N, P, SC>(
let key = key.clone();
client.import_notification_stream()
.map(|v| Ok::<_, ()>(v)).compat()
.for_each(move |notification| {
let parent_hash = notification.hash;
if notification.is_new_best {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment