From 7f05bd959f08a9cad42a542690e635b0b4e9db3c Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Thu, 24 Jan 2019 17:51:33 +0200 Subject: [PATCH] Migrate consensus (common, aura-primitives, aura, rhd) to 2018 edition (#1548) --- substrate/core/consensus/aura/Cargo.toml | 27 +++++++------- .../core/consensus/aura/primitives/Cargo.toml | 17 ++++----- .../core/consensus/aura/primitives/src/lib.rs | 11 ++---- substrate/core/consensus/aura/src/lib.rs | 36 ++----------------- substrate/core/consensus/aura/src/slots.rs | 7 ++-- substrate/core/consensus/common/Cargo.toml | 11 +++--- .../core/consensus/common/src/block_import.rs | 2 +- substrate/core/consensus/common/src/error.rs | 2 ++ .../core/consensus/common/src/evaluation.rs | 4 ++- .../core/consensus/common/src/import_queue.rs | 5 +-- substrate/core/consensus/common/src/lib.rs | 17 --------- substrate/core/consensus/rhd/Cargo.toml | 26 +++++++------- substrate/core/consensus/rhd/src/error.rs | 4 ++- substrate/core/consensus/rhd/src/lib.rs | 32 ++--------------- 14 files changed, 65 insertions(+), 136 deletions(-) diff --git a/substrate/core/consensus/aura/Cargo.toml b/substrate/core/consensus/aura/Cargo.toml index d0ab6f8d4c..e028aabcdf 100644 --- a/substrate/core/consensus/aura/Cargo.toml +++ b/substrate/core/consensus/aura/Cargo.toml @@ -3,17 +3,18 @@ name = "substrate-consensus-aura" version = "0.1.0" authors = ["Parity Technologies "] description = "Aura consensus algorithm for substrate" +edition = "2018" [dependencies] parity-codec = "2.2" -substrate-client = { path = "../../client" } -substrate-primitives = { path = "../../primitives" } -srml-support = { path = "../../../srml/support" } -sr-primitives = { path = "../../sr-primitives" } -sr-version = { path = "../../sr-version" } -sr-io = { path = "../../sr-io" } -substrate-consensus-aura-primitives = { path = "primitives" } -substrate-inherents = { path = "../../inherents" } +client = { package = "substrate-client", path = "../../client" } +primitives = { package = "substrate-primitives", path = "../../primitives" } +runtime_support = { package = "srml-support", path = "../../../srml/support" } +runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } +runtime_version = { package = "sr-version", path = "../../sr-version" } +runtime_io = { package = "sr-io", path = "../../sr-io" } +aura_primitives = { package = "substrate-consensus-aura-primitives", path = "primitives" } +inherents = { package = "substrate-inherents", path = "../../inherents" } srml-consensus = { path = "../../../srml/consensus" } srml-aura = { path = "../../../srml/aura" } futures = "0.1.17" @@ -21,12 +22,12 @@ tokio = "0.1.7" parking_lot = "0.7.1" error-chain = "0.12" log = "0.3" -substrate-consensus-common = { path = "../common" } +consensus_common = { package = "substrate-consensus-common", path = "../common" } [dev-dependencies] -substrate-keyring = { path = "../../keyring" } +keyring = { package = "substrate-keyring", path = "../../keyring" } substrate-executor = { path = "../../executor" } -substrate-network = { path = "../../network", features = ["test-helpers"]} -substrate-service = { path = "../../service" } -substrate-test-client = { path = "../../test-client" } +network = { package = "substrate-network", path = "../../network", features = ["test-helpers"]} +service = { package = "substrate-service", path = "../../service" } +test_client = { package = "substrate-test-client", path = "../../test-client" } env_logger = "0.4" diff --git a/substrate/core/consensus/aura/primitives/Cargo.toml b/substrate/core/consensus/aura/primitives/Cargo.toml index ea3041c99d..6104da2596 100644 --- a/substrate/core/consensus/aura/primitives/Cargo.toml +++ b/substrate/core/consensus/aura/primitives/Cargo.toml @@ -3,24 +3,25 @@ name = "substrate-consensus-aura-primitives" version = "0.1.0" authors = ["Parity Technologies "] description = "Primitives for Aura consensus" +edition = "2018" [dependencies] parity-codec = { version = "2.2", default-features = false } substrate-client = { path = "../../../client", default-features = false } -substrate-primitives = { path = "../../../primitives", default-features = false } -srml-support = { path = "../../../../srml/support", default-features = false } -sr-primitives = { path = "../../../sr-primitives", default-features = false } +primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false } +runtime_support = { package = "srml-support", path = "../../../../srml/support", default-features = false } +runtime_primitives = { package = "sr-primitives", path = "../../../sr-primitives", default-features = false } sr-version = { path = "../../../sr-version", default-features = false } -sr-io = { path = "../../../sr-io", default-features = false } +runtime_io = { package = "sr-io", path = "../../../sr-io", default-features = false } [features] default = ["std"] std = [ "parity-codec/std", "substrate-client/std", - "substrate-primitives/std", - "srml-support/std", - "sr-primitives/std", + "primitives/std", + "runtime_support/std", + "runtime_primitives/std", "sr-version/std", - "sr-io/std", + "runtime_io/std", ] diff --git a/substrate/core/consensus/aura/primitives/src/lib.rs b/substrate/core/consensus/aura/primitives/src/lib.rs index 54e4149f52..c37677283f 100644 --- a/substrate/core/consensus/aura/primitives/src/lib.rs +++ b/substrate/core/consensus/aura/primitives/src/lib.rs @@ -18,16 +18,9 @@ #![cfg_attr(not(feature = "std"), no_std)] -extern crate parity_codec as codec; -extern crate substrate_client as client; -extern crate substrate_primitives as primitives; -extern crate srml_support as runtime_support; -extern crate sr_io as runtime_io; -extern crate sr_primitives as runtime_primitives; - /// The ApiIds for Aura authorship API. pub mod id { - use client::runtime_api::ApiId; + use substrate_client::runtime_api::ApiId; /// ApiId for the AuraApi trait. pub const AURA_API: ApiId = *b"aura_api"; @@ -45,7 +38,7 @@ pub struct AuraConsensusData { /// Runtime-APIs pub mod api { - use client::decl_runtime_apis; + use substrate_client::decl_runtime_apis; decl_runtime_apis! { /// API necessary for block authorship with aura. pub trait AuraApi { diff --git a/substrate/core/consensus/aura/src/lib.rs b/substrate/core/consensus/aura/src/lib.rs index 40e0852276..f3ab407dce 100644 --- a/substrate/core/consensus/aura/src/lib.rs +++ b/substrate/core/consensus/aura/src/lib.rs @@ -26,42 +26,11 @@ //! Blocks from future steps will be either deferred or rejected depending on how //! far in the future they are. -extern crate parity_codec as codec; -extern crate substrate_client as client; -extern crate substrate_primitives as primitives; -extern crate srml_support as runtime_support; -extern crate sr_io as runtime_io; -extern crate sr_primitives as runtime_primitives; -extern crate substrate_consensus_aura_primitives as aura_primitives; -extern crate srml_aura; -extern crate substrate_inherents as inherents; - -extern crate substrate_consensus_common as consensus_common; -extern crate tokio; -extern crate sr_version as runtime_version; -extern crate parking_lot; - -#[macro_use] -extern crate log; -#[macro_use] -extern crate futures; - -#[cfg(test)] -extern crate substrate_keyring as keyring; -#[cfg(test)] -extern crate substrate_network as network; -#[cfg(test)] -extern crate substrate_service as service; -#[cfg(test)] -extern crate substrate_test_client as test_client; -#[cfg(test)] -extern crate env_logger; - mod slots; use std::{sync::{Arc, mpsc}, time::Duration, thread}; -use codec::Encode; +use parity_codec::Encode; use consensus_common::{ Authorities, BlockImport, Environment, Proposer, ForkChoiceStrategy }; @@ -80,6 +49,7 @@ use futures::{Stream, Future, IntoFuture, future::{self, Either}}; use tokio::timer::Timeout; use api::AuraApi; use slots::Slots; +use ::log::{warn, debug, log, info, trace}; use srml_aura::{ InherentType as AuraInherent, AuraInherentData, @@ -635,7 +605,7 @@ impl SlotDuration { C: ProvideRuntimeApi, C::Api: AuraApi, { - use codec::Decode; + use parity_codec::Decode; const SLOT_KEY: &[u8] = b"aura_slot_duration"; match client.get_aux(SLOT_KEY)? { diff --git a/substrate/core/consensus/aura/src/slots.rs b/substrate/core/consensus/aura/src/slots.rs index faf966e329..05ce5b1726 100644 --- a/substrate/core/consensus/aura/src/slots.rs +++ b/substrate/core/consensus/aura/src/slots.rs @@ -21,6 +21,7 @@ use std::time::{Instant, Duration}; use tokio::timer::Delay; use futures::prelude::*; +use futures::try_ready; use inherents::{InherentDataProviders, InherentData}; @@ -86,7 +87,7 @@ impl Stream for Slots { self.inner_delay = match self.inner_delay.take() { None => { // schedule wait. - let wait_until = match ::duration_now() { + let wait_until = match crate::duration_now() { None => return Ok(Async::Ready(None)), Some(now) => Instant::now() + time_until_next(now, slot_duration), }; @@ -103,8 +104,8 @@ impl Stream for Slots { // timeout has fired. let inherent_data = self.inherent_data_providers.create_inherent_data() - .map_err(::inherent_to_common_error)?; - let (timestamp, slot_num) = ::extract_timestamp_and_slot(&inherent_data)?; + .map_err(crate::inherent_to_common_error)?; + let (timestamp, slot_num) = crate::extract_timestamp_and_slot(&inherent_data)?; // reschedule delay for next slot. let ends_at = Instant::now() + time_until_next(Duration::from_secs(timestamp), slot_duration); diff --git a/substrate/core/consensus/common/Cargo.toml b/substrate/core/consensus/common/Cargo.toml index 1c3f335207..9b4b2c3353 100644 --- a/substrate/core/consensus/common/Cargo.toml +++ b/substrate/core/consensus/common/Cargo.toml @@ -3,19 +3,20 @@ name = "substrate-consensus-common" version = "0.1.0" authors = ["Parity Technologies "] description = "Common utilities for substrate consensus" +edition = "2018" [dependencies] log = "0.4" parking_lot = "0.7.1" -substrate-primitives = { path= "../../primitives" } -substrate-inherents = { path= "../../inherents" } +primitives = { package = "substrate-primitives", path= "../../primitives" } +inherents = { package = "substrate-inherents", path = "../../inherents" } error-chain = "0.12" futures = "0.1" -sr-version = { path = "../../sr-version" } -sr-primitives = { path = "../../sr-primitives" } +runtime_version = { package = "sr-version", path = "../../sr-version" } +runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } tokio = "0.1.7" parity-codec = "2.2" parity-codec-derive = "2.0" [dev-dependencies] -substrate-test-client = { path = "../../test-client" } +test_client = { package = "substrate-test-client", path = "../../test-client" } diff --git a/substrate/core/consensus/common/src/block_import.rs b/substrate/core/consensus/common/src/block_import.rs index 7eac5adc92..1fc4dc720d 100644 --- a/substrate/core/consensus/common/src/block_import.rs +++ b/substrate/core/consensus/common/src/block_import.rs @@ -157,7 +157,7 @@ pub trait JustificationImport { type Error: ::std::error::Error + Send + 'static; /// Called by the import queue when it is started. - fn on_start(&self, _link: &::import_queue::Link) { } + fn on_start(&self, _link: &crate::import_queue::Link) { } /// Import a Block justification and finalize the given block. fn import_justification( diff --git a/substrate/core/consensus/common/src/error.rs b/substrate/core/consensus/common/src/error.rs index caf325eeb3..337bbeeea5 100644 --- a/substrate/core/consensus/common/src/error.rs +++ b/substrate/core/consensus/common/src/error.rs @@ -16,6 +16,8 @@ //! Error types in Consensus use runtime_version::RuntimeVersion; +use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed, + impl_extract_backtrace, impl_error_chain_kind}; error_chain! { errors { diff --git a/substrate/core/consensus/common/src/evaluation.rs b/substrate/core/consensus/common/src/evaluation.rs index db35e2f411..a122017806 100644 --- a/substrate/core/consensus/common/src/evaluation.rs +++ b/substrate/core/consensus/common/src/evaluation.rs @@ -18,8 +18,10 @@ use super::MAX_TRANSACTIONS_SIZE; -use codec::Encode; +use parity_codec::Encode; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As}; +use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed, + impl_extract_backtrace, impl_error_chain_kind, bail}; type BlockNumber = u64; diff --git a/substrate/core/consensus/common/src/import_queue.rs b/substrate/core/consensus/common/src/import_queue.rs index eb601a8b56..3e4f4f6a0b 100644 --- a/substrate/core/consensus/common/src/import_queue.rs +++ b/substrate/core/consensus/common/src/import_queue.rs @@ -24,16 +24,17 @@ //! The `BasicQueue` and `BasicVerifier` traits allow serial queues to be //! instantiated simply. -use block_import::{ImportBlock, BlockImport, JustificationImport, ImportResult, BlockOrigin}; +use crate::block_import::{ImportBlock, BlockImport, JustificationImport, ImportResult, BlockOrigin}; use std::collections::{HashSet, VecDeque}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use parking_lot::{Condvar, Mutex, RwLock}; +use log::{trace, debug}; use runtime_primitives::Justification; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero, AuthorityIdFor}; -use error::Error as ConsensusError; +use crate::error::Error as ConsensusError; /// Shared block import struct used by the queue. pub type SharedBlockImport = Arc + Send + Sync>; diff --git a/substrate/core/consensus/common/src/lib.rs b/substrate/core/consensus/common/src/lib.rs index def4d2d962..73278ca579 100644 --- a/substrate/core/consensus/common/src/lib.rs +++ b/substrate/core/consensus/common/src/lib.rs @@ -26,23 +26,6 @@ // our error-chain could potentially blow up otherwise #![recursion_limit="128"] -extern crate substrate_primitives as primitives; -extern crate substrate_inherents as inherents; -extern crate futures; -extern crate parking_lot; -extern crate sr_version as runtime_version; -extern crate sr_primitives as runtime_primitives; -#[cfg(any(test, feature = "test-helpers"))] -extern crate substrate_test_client as test_client; -extern crate tokio; - -extern crate parity_codec as codec; -extern crate parity_codec_derive; - -#[macro_use] -extern crate error_chain; -#[macro_use] extern crate log; - use std::sync::Arc; use runtime_primitives::generic::BlockId; diff --git a/substrate/core/consensus/rhd/Cargo.toml b/substrate/core/consensus/rhd/Cargo.toml index 4a3001b12c..2facc46b33 100644 --- a/substrate/core/consensus/rhd/Cargo.toml +++ b/substrate/core/consensus/rhd/Cargo.toml @@ -3,21 +3,22 @@ name = "substrate-consensus-rhd" version = "0.1.0" authors = ["Parity Technologies "] description = "Rhododendron Round-Based consensus-algorithm for substrate" +edition = "2018" [dependencies] futures = "0.1.17" parity-codec = { version = "2.2" } parity-codec-derive = { version = "2.0" } -substrate-primitives = { path = "../../primitives" } -substrate-consensus-common = { path = "../common" } -substrate-client = { path = "../../client" } -substrate-transaction-pool = { path = "../../transaction-pool" } -srml-support = { path = "../../../srml/support" } +primitives = { package = "substrate-primitives", path = "../../primitives" } +consensus = { package = "substrate-consensus-common", path = "../common" } +client = { package = "substrate-client", path = "../../client" } +transaction_pool = { package = "substrate-transaction-pool", path = "../../transaction-pool" } +runtime_support = { package = "srml-support", path = "../../../srml/support" } srml-system = { path = "../../../srml/system" } srml-consensus = { path = "../../../srml/consensus" } -sr-primitives = { path = "../../sr-primitives" } -sr-version = { path = "../../sr-version" } -sr-io = { path = "../../sr-io" } +runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } +runtime_version = { package = "sr-version", path = "../../sr-version" } +runtime_io = { package = "sr-io", path = "../../sr-io" } tokio = "0.1.7" parking_lot = "0.7.1" error-chain = "0.12" @@ -25,7 +26,6 @@ log = "0.4" rhododendron = { version = "0.4.0", features = ["codec"] } exit-future = "0.1" - [dev-dependencies] substrate-keyring = { path = "../../keyring" } substrate-executor = { path = "../../executor" } @@ -33,8 +33,8 @@ substrate-executor = { path = "../../executor" } [features] default = ["std"] std = [ - "substrate-primitives/std", - "srml-support/std", - "sr-primitives/std", - "sr-version/std", + "primitives/std", + "runtime_support/std", + "runtime_primitives/std", + "runtime_version/std", ] diff --git a/substrate/core/consensus/rhd/src/error.rs b/substrate/core/consensus/rhd/src/error.rs index c18c36f679..7a97bbcace 100644 --- a/substrate/core/consensus/rhd/src/error.rs +++ b/substrate/core/consensus/rhd/src/error.rs @@ -18,6 +18,8 @@ use consensus::error::{Error as CommonError, ErrorKind as CommonErrorKind}; use primitives::AuthorityId; use client; +use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed, + impl_extract_backtrace, impl_error_chain_kind}; error_chain! { links { @@ -54,4 +56,4 @@ impl From for Error { fn from(e: CommonErrorKind) -> Self { CommonError::from(e).into() } -} \ No newline at end of file +} diff --git a/substrate/core/consensus/rhd/src/lib.rs b/substrate/core/consensus/rhd/src/lib.rs index 6441fb4e34..1282432f76 100644 --- a/substrate/core/consensus/rhd/src/lib.rs +++ b/substrate/core/consensus/rhd/src/lib.rs @@ -33,40 +33,12 @@ #![cfg(feature="rhd")] // FIXME: doesn't compile - https://github.com/paritytech/substrate/issues/1020 -extern crate parity_codec as codec; -extern crate substrate_primitives as primitives; -extern crate substrate_client as client; -extern crate substrate_consensus_common as consensus; -extern crate substrate_transaction_pool as transaction_pool; -extern crate srml_system; -extern crate srml_support as runtime_support; -extern crate sr_primitives as runtime_primitives; -extern crate sr_version as runtime_version; -extern crate sr_io as runtime_io; - -extern crate parking_lot; -extern crate rhododendron; -extern crate futures; -extern crate exit_future; -extern crate tokio; - -#[macro_use] -extern crate log; - -#[macro_use] -extern crate error_chain; - -#[macro_use] -extern crate parity_codec_derive; - -#[cfg(test)] -extern crate substrate_keyring; - use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::{self, Instant, Duration}; -use codec::{Decode, Encode}; +use parity_codec::{Decode, Encode}; +use parity_codec_derive::{Decode, Encode}; use consensus::offline_tracker::OfflineTracker; use consensus::error::{ErrorKind as CommonErrorKind}; use consensus::{Authorities, BlockImport, Environment, Proposer as BaseProposer};