Migrate consensus (common, aura-primitives, aura, rhd) to 2018 edition (#1548)

This commit is contained in:
Stanislav Tkach
2019-01-24 17:51:33 +02:00
committed by Gav Wood
parent a5cafa68b1
commit 7f05bd959f
14 changed files with 65 additions and 136 deletions
+14 -13
View File
@@ -3,17 +3,18 @@ name = "substrate-consensus-aura"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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"
@@ -3,24 +3,25 @@ name = "substrate-consensus-aura-primitives"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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",
]
@@ -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 {
+3 -33
View File
@@ -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<B>,
{
use codec::Decode;
use parity_codec::Decode;
const SLOT_KEY: &[u8] = b"aura_slot_duration";
match client.get_aux(SLOT_KEY)? {
+4 -3
View File
@@ -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);