Update to lastest Substrate master (#443)

This commit is contained in:
Bastian Köcher
2019-09-24 13:09:30 +02:00
committed by Robert Habermeier
parent 444a19ec5f
commit 4f4baa9b07
9 changed files with 249 additions and 271 deletions
+189 -182
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -306,7 +306,7 @@ impl<P, E> Worker for CollationNode<P, E> where
}; };
let is_known = move |block_hash: &Hash| { let is_known = move |block_hash: &Hash| {
use client::BlockStatus; use consensus_common::BlockStatus;
use polkadot_network::gossip::Known; use polkadot_network::gossip::Known;
match known_oracle.block_status(&BlockId::hash(*block_hash)) { match known_oracle.block_status(&BlockId::hash(*block_hash)) {
+1 -5
View File
@@ -21,14 +21,10 @@
use rstd::prelude::*; use rstd::prelude::*;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use srml_support::{decl_storage, decl_module, ensure}; use srml_support::{decl_storage, decl_module, ensure, dispatch::Result, traits::Get};
use primitives::{Hash, parachain::{AttestedCandidate, CandidateReceipt, Id as ParaId}}; use primitives::{Hash, parachain::{AttestedCandidate, CandidateReceipt, Id as ParaId}};
use sr_staking_primitives::SessionIndex; use sr_staking_primitives::SessionIndex;
use {system, session};
use srml_support::{
StorageValue, StorageMap, StorageDoubleMap, dispatch::Result, traits::Get,
};
use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier}; use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier};
use system::ensure_none; use system::ensure_none;
+1 -1
View File
@@ -18,7 +18,7 @@
use rstd::prelude::*; use rstd::prelude::*;
use sr_io::{keccak_256, secp256k1_ecdsa_recover}; use sr_io::{keccak_256, secp256k1_ecdsa_recover};
use srml_support::{StorageValue, StorageMap, decl_event, decl_storage, decl_module}; use srml_support::{decl_event, decl_storage, decl_module};
use srml_support::traits::{Currency, Get}; use srml_support::traits::{Currency, Get};
use system::ensure_none; use system::ensure_none;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
+9 -9
View File
@@ -67,7 +67,7 @@
//! funds ultimately end up in module's fund sub-account. //! funds ultimately end up in module's fund sub-account.
use srml_support::{ use srml_support::{
StorageValue, StorageMap, decl_module, decl_storage, decl_event, storage::child, ensure, decl_module, decl_storage, decl_event, storage::child, ensure,
traits::{Currency, Get, OnUnbalanced, WithdrawReason, ExistenceRequirement} traits::{Currency, Get, OnUnbalanced, WithdrawReason, ExistenceRequirement}
}; };
use system::ensure_signed; use system::ensure_signed;
@@ -187,7 +187,7 @@ decl_event! {
decl_module! { decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin { pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default; fn deposit_event() = default;
/// Create a new crowdfunding campaign for a parachain slot deposit for the current auction. /// Create a new crowdfunding campaign for a parachain slot deposit for the current auction.
#[weight = SimpleDispatchInfo::FixedNormal(100_000)] #[weight = SimpleDispatchInfo::FixedNormal(100_000)]
fn create(origin, fn create(origin,
@@ -233,7 +233,7 @@ decl_module! {
Self::deposit_event(RawEvent::Created(index)); Self::deposit_event(RawEvent::Created(index));
} }
/// Contribute to a crowd sale. This will transfer some balance over to fund a parachain /// Contribute to a crowd sale. This will transfer some balance over to fund a parachain
/// slot. It will be withdrawable in two instances: the parachain becomes retired; or the /// slot. It will be withdrawable in two instances: the parachain becomes retired; or the
/// slot is /// slot is
@@ -312,7 +312,7 @@ decl_module! {
Self::deposit_event(RawEvent::DeployDataFixed(index)); Self::deposit_event(RawEvent::DeployDataFixed(index));
} }
/// Complete onboarding process for a winning parachain fund. This can be called once by /// Complete onboarding process for a winning parachain fund. This can be called once by
/// any origin once a fund wins a slot and the fund has set its deploy data (using /// any origin once a fund wins a slot and the fund has set its deploy data (using
/// `fix_deploy_data`). /// `fix_deploy_data`).
@@ -337,7 +337,7 @@ decl_module! {
Self::deposit_event(RawEvent::Onboarded(index, para_id)); Self::deposit_event(RawEvent::Onboarded(index, para_id));
} }
/// Note that a successful fund has lost its parachain slot, and place it into retirement. /// Note that a successful fund has lost its parachain slot, and place it into retirement.
fn begin_retirement(origin, #[compact] index: FundIndex) { fn begin_retirement(origin, #[compact] index: FundIndex) {
let _ = ensure_signed(origin)?; let _ = ensure_signed(origin)?;
@@ -388,7 +388,7 @@ decl_module! {
Self::deposit_event(RawEvent::Withdrew(who, index, balance)); Self::deposit_event(RawEvent::Withdrew(who, index, balance));
} }
/// Remove a fund after either: it was unsuccessful and it timed out; or it was successful /// Remove a fund after either: it was unsuccessful and it timed out; or it was successful
/// but it has been retired from its parachain slot. This places any deposits that were not /// but it has been retired from its parachain slot. This places any deposits that were not
/// withdrawn into the treasury. /// withdrawn into the treasury.
@@ -422,7 +422,7 @@ decl_module! {
Self::deposit_event(RawEvent::Dissolved(index)); Self::deposit_event(RawEvent::Dissolved(index));
} }
fn on_finalize(n: T::BlockNumber) { fn on_finalize(n: T::BlockNumber) {
if let Some(n) = <slots::Module<T>>::is_ending(n) { if let Some(n) = <slots::Module<T>>::is_ending(n) {
let auction_index = <slots::Module<T>>::auction_counter(); let auction_index = <slots::Module<T>>::auction_counter();
@@ -1041,7 +1041,7 @@ mod tests {
assert_eq!(Balances::free_balance(3), 2990); assert_eq!(Balances::free_balance(3), 2990);
}); });
} }
#[test] #[test]
fn withdraw_handles_basic_errors() { fn withdraw_handles_basic_errors() {
with_externalities(&mut new_test_ext(), || { with_externalities(&mut new_test_ext(), || {
@@ -1079,7 +1079,7 @@ mod tests {
// Skip all the way to the end // Skip all the way to the end
run_to_block(50); run_to_block(50);
// Check current funds (contributions + deposit) // Check current funds (contributions + deposit)
assert_eq!(Balances::free_balance(Crowdfund::fund_account_id(0)), 601); assert_eq!(Balances::free_balance(Crowdfund::fund_account_id(0)), 601);
+7 -28
View File
@@ -41,12 +41,11 @@ use client::{
use sr_primitives::{ use sr_primitives::{
ApplyResult, generic, Permill, Perbill, impl_opaque_keys, create_runtime_str, key_types, ApplyResult, generic, Permill, Perbill, impl_opaque_keys, create_runtime_str, key_types,
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError}, transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
weights::{Weight, DispatchInfo}, weights::{Weight, DispatchInfo}, curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, SignedExtension}, traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension},
curve::PiecewiseLinear,
}; };
use version::RuntimeVersion; use version::RuntimeVersion;
use grandpa::{AuthorityId as GrandpaId, fg_primitives::{self, ScheduledChange}}; use grandpa::{AuthorityId as GrandpaId, fg_primitives};
use babe_primitives::AuthorityId as BabeId; use babe_primitives::AuthorityId as BabeId;
use elections::VoteIndex; use elections::VoteIndex;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
@@ -662,45 +661,25 @@ impl_runtime_apis! {
} }
impl fg_primitives::GrandpaApi<Block> for Runtime { impl fg_primitives::GrandpaApi<Block> for Runtime {
fn grandpa_pending_change(digest: &DigestFor<Block>)
-> Option<ScheduledChange<BlockNumber>>
{
Grandpa::pending_change(digest)
}
fn grandpa_forced_change(digest: &DigestFor<Block>)
-> Option<(BlockNumber, ScheduledChange<BlockNumber>)>
{
Grandpa::forced_change(digest)
}
fn grandpa_authorities() -> Vec<(GrandpaId, u64)> { fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
Grandpa::grandpa_authorities() Grandpa::grandpa_authorities()
} }
} }
impl babe_primitives::BabeApi<Block> for Runtime { impl babe_primitives::BabeApi<Block> for Runtime {
fn startup_data() -> babe_primitives::BabeConfiguration { fn configuration() -> babe_primitives::BabeConfiguration {
// The choice of `c` parameter (where `1 - c` represents the // The choice of `c` parameter (where `1 - c` represents the
// probability of a slot being empty), is done in accordance to the // probability of a slot being empty), is done in accordance to the
// slot duration and expected target block time, for safely // slot duration and expected target block time, for safely
// resisting network delays of maximum two seconds. // resisting network delays of maximum two seconds.
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results> // <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
babe_primitives::BabeConfiguration { babe_primitives::BabeConfiguration {
median_required_blocks: 1000,
slot_duration: Babe::slot_duration(), slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY, c: PRIMARY_PROBABILITY,
} genesis_authorities: Babe::authorities(),
}
fn epoch() -> babe_primitives::Epoch {
babe_primitives::Epoch {
start_slot: Babe::epoch_start_slot(),
authorities: Babe::authorities(),
epoch_index: Babe::epoch_index(),
randomness: Babe::randomness(), randomness: Babe::randomness(),
duration: EpochDuration::get(), secondary_slots: true,
secondary_slots: Babe::secondary_slots().0,
} }
} }
} }
+1 -2
View File
@@ -31,8 +31,7 @@ use primitives::{Hash, Balance, parachain::{
}}; }};
use {system, session}; use {system, session};
use srml_support::{ use srml_support::{
StorageValue, StorageMap, Parameter, dispatch::Result, Parameter, dispatch::Result, traits::{Currency, Get, WithdrawReason, ExistenceRequirement},
traits::{Currency, Get, WithdrawReason, ExistenceRequirement}
}; };
use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier}; use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier};
+2 -2
View File
@@ -23,8 +23,8 @@ use sr_primitives::traits::{CheckedSub, StaticLookup, Zero, One, CheckedConversi
use sr_primitives::weights::SimpleDispatchInfo; use sr_primitives::weights::SimpleDispatchInfo;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use srml_support::{ use srml_support::{
decl_module, decl_storage, decl_event, StorageValue, StorageMap, ensure, decl_module, decl_storage, decl_event, StorageMap, ensure,
traits::{Currency, ReservableCurrency, WithdrawReason, ExistenceRequirement, Get} traits::{Currency, ReservableCurrency, WithdrawReason, ExistenceRequirement, Get},
}; };
use primitives::parachain::AccountIdConversion; use primitives::parachain::AccountIdConversion;
use crate::parachains::ParachainRegistrar; use crate::parachains::ParachainRegistrar;
+38 -41
View File
@@ -27,7 +27,7 @@ use polkadot_runtime::GenesisConfig;
use polkadot_network::{gossip::{self as network_gossip, Known}, validation::ValidationNetwork}; use polkadot_network::{gossip::{self as network_gossip, Known}, validation::ValidationNetwork};
use service::{error::{Error as ServiceError}, Configuration, ServiceBuilder}; use service::{error::{Error as ServiceError}, Configuration, ServiceBuilder};
use transaction_pool::txpool::{Pool as TransactionPool}; use transaction_pool::txpool::{Pool as TransactionPool};
use babe::{import_queue, start_babe, Config}; use babe::{import_queue, start_babe};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider}; use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use inherents::InherentDataProviders; use inherents::InherentDataProviders;
use log::info; use log::info;
@@ -79,8 +79,6 @@ macro_rules! new_full_start {
($config:expr) => {{ ($config:expr) => {{
let mut import_setup = None; let mut import_setup = None;
let inherent_data_providers = inherents::InherentDataProviders::new(); let inherent_data_providers = inherents::InherentDataProviders::new();
let mut tasks_to_spawn = None;
let builder = service::ServiceBuilder::new_full::< let builder = service::ServiceBuilder::new_full::<
Block, RuntimeApi, polkadot_executor::Executor Block, RuntimeApi, polkadot_executor::Executor
>($config)? >($config)?
@@ -90,33 +88,37 @@ macro_rules! new_full_start {
.with_transaction_pool(|config, client| .with_transaction_pool(|config, client|
Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::ChainApi::new(client))) Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::ChainApi::new(client)))
)? )?
.with_import_queue(|_config, client, mut select_chain, transaction_pool| { .with_import_queue(|_config, client, mut select_chain, _| {
let select_chain = select_chain.take() let select_chain = select_chain.take()
.ok_or_else(|| service::Error::SelectChainRequired)?; .ok_or_else(|| service::Error::SelectChainRequired)?;
let (block_import, link_half) = let (grandpa_block_import, grandpa_link) =
grandpa::block_import::<_, _, _, RuntimeApi, _, _>( grandpa::block_import::<_, _, _, RuntimeApi, _, _>(
client.clone(), client.clone(), select_chain client.clone(), &*client, select_chain
)?; )?;
let justification_import = block_import.clone(); let justification_import = grandpa_block_import.clone();
let (import_queue, babe_link, babe_block_import, pruning_task) = babe::import_queue( let (block_import, babe_link) = babe::block_import(
babe::Config::get_or_compute(&*client)?, babe::Config::get_or_compute(&*client)?,
block_import, grandpa_block_import,
Some(Box::new(justification_import)), client.clone(),
None, client.clone(),
client.clone(),
client,
inherent_data_providers.clone(),
Some(transaction_pool)
)?; )?;
import_setup = Some((babe_block_import.clone(), link_half, babe_link)); let import_queue = babe::import_queue(
tasks_to_spawn = Some(vec![Box::new(pruning_task)]); babe_link.clone(),
block_import.clone(),
Some(Box::new(justification_import)),
None,
client.clone(),
client,
inherent_data_providers.clone(),
)?;
import_setup = Some((block_import, grandpa_link, babe_link));
Ok(import_queue) Ok(import_queue)
})?; })?;
(builder, import_setup, inherent_data_providers, tasks_to_spawn) (builder, import_setup, inherent_data_providers)
}} }}
} }
@@ -144,7 +146,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
let disable_grandpa = config.disable_grandpa; let disable_grandpa = config.disable_grandpa;
let name = config.name.clone(); let name = config.name.clone();
let (builder, mut import_setup, inherent_data_providers, mut tasks_to_spawn) = new_full_start!(config); let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);
let service = builder let service = builder
.with_network_protocol(|config| Ok(PolkadotProtocol::new(config.custom.collating_for.clone())))? .with_network_protocol(|config| Ok(PolkadotProtocol::new(config.custom.collating_for.clone())))?
@@ -156,17 +158,6 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
let (block_import, link_half, babe_link) = import_setup.take() let (block_import, link_half, babe_link) = import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed"); .expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
// spawn any futures that were created in the previous setup steps
if let Some(tasks) = tasks_to_spawn.take() {
for task in tasks {
service.spawn_task(
task.select(service.on_exit())
.map(|_| ())
.map_err(|_| ())
);
}
}
if is_collator { if is_collator {
info!( info!(
"The node cannot start as an authority because it is also configured to run as a collator." "The node cannot start as an authority because it is also configured to run as a collator."
@@ -185,7 +176,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
let gossip_validator_select_chain = select_chain.clone(); let gossip_validator_select_chain = select_chain.clone();
let is_known = move |block_hash: &Hash| { let is_known = move |block_hash: &Hash| {
use client::BlockStatus; use consensus_common::BlockStatus;
match known_oracle.block_status(&BlockId::hash(*block_hash)) { match known_oracle.block_status(&BlockId::hash(*block_hash)) {
Err(_) | Ok(BlockStatus::Unknown) | Ok(BlockStatus::Queued) => None, Err(_) | Ok(BlockStatus::Unknown) | Ok(BlockStatus::Queued) => None,
@@ -253,7 +244,6 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?; let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
let babe_config = babe::BabeParams { let babe_config = babe::BabeParams {
config: Config::get_or_compute(&*client)?,
keystore: service.keystore(), keystore: service.keystore(),
client, client,
select_chain, select_chain,
@@ -262,7 +252,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
sync_oracle: service.network(), sync_oracle: service.network(),
inherent_data_providers: inherent_data_providers.clone(), inherent_data_providers: inherent_data_providers.clone(),
force_authoring: force_authoring, force_authoring: force_authoring,
time_source: babe_link, babe_link,
}; };
let babe = start_babe(babe_config)?; let babe = start_babe(babe_config)?;
@@ -332,28 +322,35 @@ pub fn new_light(config: Configuration<CustomConfiguration, GenesisConfig>)
.with_transaction_pool(|config, client| .with_transaction_pool(|config, client|
Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client)))
)? )?
.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, transaction_pool| { .with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _| {
let fetch_checker = fetcher let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone()) .map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?; .ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>( let grandpa_block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, _>(
client.clone(), backend, Arc::new(fetch_checker), client.clone() client.clone(), backend, Arc::new(fetch_checker), client.clone()
)?; )?;
let finality_proof_import = block_import.clone(); let finality_proof_import = grandpa_block_import.clone();
let finality_proof_request_builder = let finality_proof_request_builder =
finality_proof_import.create_finality_proof_request_builder(); finality_proof_import.create_finality_proof_request_builder();
let (babe_block_import, babe_link) = babe::block_import(
babe::Config::get_or_compute(&*client)?,
grandpa_block_import,
client.clone(),
client.clone(),
)?;
// FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`. // FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`.
let (import_queue, ..) = import_queue( let import_queue = import_queue(
Config::get_or_compute(&*client)?, babe_link,
block_import, babe_block_import,
None, None,
Some(Box::new(finality_proof_import)), Some(Box::new(finality_proof_import)),
client.clone(), client.clone(),
client, client,
inherent_data_providers.clone(), inherent_data_providers.clone(),
Some(transaction_pool)
)?; )?;
Ok((import_queue, finality_proof_request_builder)) Ok((import_queue, finality_proof_request_builder))