diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 6f2f0e72cc..e8801b6376 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -1918,7 +1918,6 @@ dependencies = [ name = "node-executor" version = "0.1.0" dependencies = [ - "hex-literal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "node-primitives 0.1.0", "node-runtime 0.1.0", "parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/substrate/core/finality-grandpa/Cargo.toml b/substrate/core/finality-grandpa/Cargo.toml index 51e24eeba4..6f22aeaa5c 100644 --- a/substrate/core/finality-grandpa/Cargo.toml +++ b/substrate/core/finality-grandpa/Cargo.toml @@ -2,33 +2,31 @@ name = "substrate-finality-grandpa" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2018" [dependencies] futures = "0.1" -parity-codec = "3.0" -parity-codec-derive = "3.0" -sr-primitives = { path = "../sr-primitives" } -substrate-consensus-common = { path = "../consensus/common" } -substrate-primitives = { path = "../primitives" } -substrate-client = { path = "../client" } -substrate-network = { path = "../network" } -substrate-service = { path = "../service", optional = true } log = "0.4" parking_lot = "0.7.1" tokio = "0.1.7" -substrate-finality-grandpa-primitives = { path = "primitives" } rand = "0.6" - -[dependencies.finality-grandpa] -version = "0.6.0" -features = ["derive-codec"] +parity-codec = "3.0" +parity-codec-derive = "3.0" +runtime_primitives = { package = "sr-primitives", path = "../sr-primitives" } +consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" } +substrate-primitives = { path = "../primitives" } +client = { package = "substrate-client", path = "../client" } +network = { package = "substrate-network", path = "../network" } +service = { package = "substrate-service", path = "../service", optional = true } +fg_primitives = { package = "substrate-finality-grandpa-primitives", path = "primitives" } +grandpa = { package = "finality-grandpa", version = "0.6.0", features = ["derive-codec"] } [dev-dependencies] -substrate-network = { path = "../network", features = ["test-helpers"] } -substrate-keyring = { path = "../keyring" } -substrate-test-client = { path = "../test-client"} +network = { package = "substrate-network", path = "../network", features = ["test-helpers"] } +keyring = { package = "substrate-keyring", path = "../keyring" } +test_client = { package = "substrate-test-client", path = "../test-client"} env_logger = "0.6" [features] default = ["service-integration"] -service-integration = ["substrate-service"] +service-integration = ["service"] diff --git a/substrate/core/finality-grandpa/primitives/Cargo.toml b/substrate/core/finality-grandpa/primitives/Cargo.toml index 6fa99337a0..d4752176fc 100644 --- a/substrate/core/finality-grandpa/primitives/Cargo.toml +++ b/substrate/core/finality-grandpa/primitives/Cargo.toml @@ -2,22 +2,23 @@ name = "substrate-finality-grandpa-primitives" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2018" [dependencies] -substrate-client = { path = "../../client", default-features = false } +client = { package = "substrate-client", path = "../../client", default-features = false } substrate-primitives = { path = "../../primitives", default-features = false } parity-codec = { version = "3.0", default-features = false } parity-codec-derive = { version = "3.0", default-features = false } sr-primitives = { path = "../../sr-primitives", default-features = false } -sr-std = { path = "../../sr-std", default-features = false } +rstd = { package = "sr-std", path = "../../sr-std", default-features = false } [features] default = ["std"] std = [ "substrate-primitives/std", - "substrate-client/std", + "client/std", "parity-codec/std", "parity-codec-derive/std", "sr-primitives/std", - "sr-std/std", + "rstd/std", ] diff --git a/substrate/core/finality-grandpa/primitives/src/lib.rs b/substrate/core/finality-grandpa/primitives/src/lib.rs index 6e8c10da31..9055156ca3 100644 --- a/substrate/core/finality-grandpa/primitives/src/lib.rs +++ b/substrate/core/finality-grandpa/primitives/src/lib.rs @@ -22,20 +22,10 @@ #[cfg(not(feature = "std"))] extern crate alloc; -extern crate substrate_primitives; -extern crate sr_primitives; -extern crate parity_codec; - -#[macro_use] -extern crate parity_codec_derive; - -#[macro_use] -extern crate substrate_client as client; - -extern crate sr_std as rstd; - +use parity_codec_derive::{Encode, Decode}; use substrate_primitives::Ed25519AuthorityId; use sr_primitives::traits::{DigestFor, NumberFor}; +use client::decl_runtime_apis; use rstd::vec::Vec; /// A scheduled change of authority set. diff --git a/substrate/core/finality-grandpa/src/authorities.rs b/substrate/core/finality-grandpa/src/authorities.rs index 54bddbde81..71793c45aa 100644 --- a/substrate/core/finality-grandpa/src/authorities.rs +++ b/substrate/core/finality-grandpa/src/authorities.rs @@ -19,6 +19,8 @@ use parking_lot::RwLock; use substrate_primitives::Ed25519AuthorityId; use grandpa::VoterSet; +use parity_codec_derive::{Encode, Decode}; +use log::{debug, info}; use std::cmp::Ord; use std::fmt::Debug; @@ -276,7 +278,7 @@ impl + Clone> PendingChange { mod tests { use super::*; - fn ignore_existing_changes(_a: &A) -> Result<(), ::Error> { + fn ignore_existing_changes(_a: &A) -> Result<(), crate::Error> { Ok(()) } diff --git a/substrate/core/finality-grandpa/src/communication.rs b/substrate/core/finality-grandpa/src/communication.rs index 51994e7d38..4bfbe4c74e 100644 --- a/substrate/core/finality-grandpa/src/communication.rs +++ b/substrate/core/finality-grandpa/src/communication.rs @@ -23,11 +23,12 @@ use std::sync::Arc; use grandpa::VoterSet; use futures::prelude::*; use futures::sync::mpsc; -use codec::{Encode, Decode}; +use log::{debug, trace}; +use parity_codec::{Encode, Decode}; use substrate_primitives::{ed25519, Ed25519AuthorityId}; use runtime_primitives::traits::Block as BlockT; use tokio::timer::Interval; -use {Error, Network, Message, SignedMessage, Commit, CompactCommit}; +use crate::{Error, Network, Message, SignedMessage, Commit, CompactCommit}; fn localized_payload(round: u64, set_id: u64, message: &E) -> Vec { (message, round, set_id).encode() @@ -245,9 +246,9 @@ pub(crate) fn check_message_sig( round: u64, set_id: u64, ) -> Result<(), ()> { - let as_public = ::ed25519::Public::from_raw(id.0); + let as_public = ed25519::Public::from_raw(id.0); let encoded_raw = localized_payload(round, set_id, message); - if ::ed25519::verify_strong(signature, &encoded_raw, as_public) { + if ed25519::verify_strong(signature, &encoded_raw, as_public) { Ok(()) } else { debug!(target: "afg", "Bad signature on message from {:?}", id); diff --git a/substrate/core/finality-grandpa/src/consensus_changes.rs b/substrate/core/finality-grandpa/src/consensus_changes.rs index c3f3c274e4..3e891e8b30 100644 --- a/substrate/core/finality-grandpa/src/consensus_changes.rs +++ b/substrate/core/finality-grandpa/src/consensus_changes.rs @@ -15,6 +15,7 @@ // along with Substrate. If not, see . use std::sync::Arc; +use parity_codec_derive::{Encode, Decode}; /// Consensus-related data changes tracker. #[derive(Clone, Debug, Encode, Decode)] diff --git a/substrate/core/finality-grandpa/src/environment.rs b/substrate/core/finality-grandpa/src/environment.rs index 7c52da3e34..eab2311be6 100644 --- a/substrate/core/finality-grandpa/src/environment.rs +++ b/substrate/core/finality-grandpa/src/environment.rs @@ -18,7 +18,8 @@ use std::fmt; use std::sync::Arc; use std::time::{Duration, Instant}; -use codec::Encode; +use log::{debug, warn, info}; +use parity_codec::Encode; use futures::prelude::*; use tokio::timer::Delay; @@ -38,10 +39,10 @@ use crate::{ AUTHORITY_SET_KEY, CONSENSUS_CHANGES_KEY, LAST_COMPLETED_KEY, Commit, Config, Error, Network, Precommit, Prevote, LastCompleted, }; -use authorities::{AuthoritySet, SharedAuthoritySet}; -use consensus_changes::SharedConsensusChanges; -use justification::GrandpaJustification; -use until_imported::UntilVoteTargetImported; +use crate::authorities::{AuthoritySet, SharedAuthoritySet}; +use crate::consensus_changes::SharedConsensusChanges; +use crate::justification::GrandpaJustification; +use crate::until_imported::UntilVoteTargetImported; /// The environment we run GRANDPA in. pub(crate) struct Environment, RA> { @@ -246,7 +247,7 @@ impl, N, RA> voter::Environment( + let incoming = crate::communication::checked_message_stream::( round, self.set_id, self.network.messages_for(round, self.set_id), @@ -256,7 +257,7 @@ impl, N, RA> voter::Environment( + let (out_rx, outgoing) = crate::communication::outgoing_messages::( round, self.set_id, local_key.cloned(), diff --git a/substrate/core/finality-grandpa/src/finality_proof.rs b/substrate/core/finality-grandpa/src/finality_proof.rs index 6335d9bac3..efce7aa1cb 100644 --- a/substrate/core/finality-grandpa/src/finality_proof.rs +++ b/substrate/core/finality-grandpa/src/finality_proof.rs @@ -36,7 +36,8 @@ use client::{ error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult}, light::fetcher::RemoteCallRequest, }; -use codec::{Encode, Decode}; +use parity_codec::{Encode, Decode}; +use parity_codec_derive::{Encode, Decode}; use grandpa::BlockNumberOps; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{ @@ -44,7 +45,7 @@ use runtime_primitives::traits::{ }; use substrate_primitives::{Ed25519AuthorityId, H256}; -use justification::GrandpaJustification; +use crate::justification::GrandpaJustification; /// Prepare proof-of-finality for the given block. /// diff --git a/substrate/core/finality-grandpa/src/import.rs b/substrate/core/finality-grandpa/src/import.rs index 20f31c2cb9..003e27033a 100644 --- a/substrate/core/finality-grandpa/src/import.rs +++ b/substrate/core/finality-grandpa/src/import.rs @@ -16,7 +16,8 @@ use std::sync::Arc; -use codec::Encode; +use log::{debug, trace, info}; +use parity_codec::Encode; use futures::sync::mpsc; use client::{blockchain, CallExecutor, Client}; @@ -35,10 +36,10 @@ use runtime_primitives::traits::{ use substrate_primitives::{H256, Ed25519AuthorityId, Blake2Hasher}; use crate::{AUTHORITY_SET_KEY, Error}; -use authorities::SharedAuthoritySet; -use consensus_changes::SharedConsensusChanges; -use environment::{canonical_at_height, finalize_block, ExitOrError, NewAuthoritySet}; -use justification::GrandpaJustification; +use crate::authorities::SharedAuthoritySet; +use crate::consensus_changes::SharedConsensusChanges; +use crate::environment::{canonical_at_height, finalize_block, ExitOrError, NewAuthoritySet}; +use crate::justification::GrandpaJustification; /// A block-import handler for GRANDPA. /// @@ -123,7 +124,7 @@ impl, RA, PRA> BlockImport fn import_block(&self, mut block: ImportBlock, new_authorities: Option>) -> Result { - use authorities::PendingChange; + use crate::authorities::PendingChange; use client::blockchain::HeaderBackend; let hash = block.post_header().hash(); diff --git a/substrate/core/finality-grandpa/src/justification.rs b/substrate/core/finality-grandpa/src/justification.rs index 867b0adb78..563840bc17 100644 --- a/substrate/core/finality-grandpa/src/justification.rs +++ b/substrate/core/finality-grandpa/src/justification.rs @@ -20,7 +20,8 @@ use client::{CallExecutor, Client}; use client::backend::Backend; use client::blockchain::HeaderBackend; use client::error::{Error as ClientError, ErrorKind as ClientErrorKind}; -use codec::Decode; +use parity_codec::Decode; +use parity_codec_derive::{Encode, Decode}; use grandpa::VoterSet; use grandpa::{Error as GrandpaError}; use runtime_primitives::generic::BlockId; @@ -28,7 +29,7 @@ use runtime_primitives::traits::{NumberFor, Block as BlockT, Header as HeaderT}; use substrate_primitives::{H256, Ed25519AuthorityId, Blake2Hasher}; use crate::{Commit, Error}; -use communication; +use crate::communication; /// A GRANDPA justification for block finality, it includes a commit message and /// an ancestry proof including all headers routing all precommit target blocks diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index 54e01822d7..45e363bc03 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -52,45 +52,15 @@ //! any signaled changes based on whether the signaling block is included in the //! newly-finalized chain. -extern crate finality_grandpa as grandpa; -extern crate futures; -extern crate substrate_client as client; -extern crate sr_primitives as runtime_primitives; -extern crate substrate_consensus_common as consensus_common; -extern crate substrate_network as network; -extern crate substrate_primitives; -extern crate tokio; -extern crate parking_lot; -extern crate parity_codec as codec; -extern crate substrate_finality_grandpa_primitives as fg_primitives; -extern crate rand; - -#[macro_use] -extern crate log; - -#[cfg(feature="service-integration")] -extern crate substrate_service as service; - -#[cfg(test)] -extern crate substrate_keyring as keyring; - -#[cfg(test)] -extern crate substrate_test_client as test_client; - -#[cfg(test)] -extern crate env_logger; - -#[macro_use] -extern crate parity_codec_derive; - use futures::prelude::*; +use log::{debug, info, warn}; use futures::sync::{self, mpsc, oneshot}; use client::{ BlockchainEvents, CallExecutor, Client, backend::Backend, error::Error as ClientError, }; use client::blockchain::HeaderBackend; -use codec::{Encode, Decode}; +use parity_codec::{Encode, Decode}; use runtime_primitives::traits::{ NumberFor, Block as BlockT, Header as HeaderT, DigestFor, ProvideRuntimeApi, Hash as HashT, DigestItemFor, DigestItem, @@ -407,7 +377,7 @@ pub fn block_import, RA, PRA>( authority_set } - Some(raw) => ::authorities::AuthoritySet::decode(&mut &raw[..]) + Some(raw) => crate::authorities::AuthoritySet::decode(&mut &raw[..]) .ok_or_else(|| ::client::error::ErrorKind::Backend( format!("GRANDPA authority set kept in invalid format") ))? @@ -466,7 +436,7 @@ fn committer_communication, B, E, N, RA>( DigestItemFor: DigestItem, { // verification stream - let commit_in = ::communication::checked_commit_stream::( + let commit_in = crate::communication::checked_commit_stream::( set_id, network.commit_messages(set_id), voters.clone(), @@ -483,7 +453,7 @@ fn committer_communication, B, E, N, RA>( .map(|pair| voters.contains_key(&pair.public().into())) .unwrap_or(false); - let commit_out = ::communication::CommitsOut::::new( + let commit_out = crate::communication::CommitsOut::::new( network.clone(), set_id, is_voter, diff --git a/substrate/core/finality-grandpa/src/service_integration.rs b/substrate/core/finality-grandpa/src/service_integration.rs index c4f5398312..1986c5c0a4 100644 --- a/substrate/core/finality-grandpa/src/service_integration.rs +++ b/substrate/core/finality-grandpa/src/service_integration.rs @@ -19,7 +19,7 @@ use client; use service::{FullBackend, FullExecutor, ServiceFactory}; -pub type BlockImportForService = ::GrandpaBlockImport< +pub type BlockImportForService = crate::GrandpaBlockImport< FullBackend, FullExecutor, ::Block, @@ -32,9 +32,9 @@ pub type BlockImportForService = ::GrandpaBlockImport< >, >; -pub type LinkHalfForService = ::LinkHalf< +pub type LinkHalfForService = crate::LinkHalf< FullBackend, FullExecutor, ::Block, ::RuntimeApi ->; \ No newline at end of file +>; diff --git a/substrate/core/finality-grandpa/src/tests.rs b/substrate/core/finality-grandpa/src/tests.rs index 552e553bf5..270761aed3 100644 --- a/substrate/core/finality-grandpa/src/tests.rs +++ b/substrate/core/finality-grandpa/src/tests.rs @@ -29,7 +29,7 @@ use client::{ runtime_api::{Core, RuntimeVersion, ApiExt}, }; use test_client::{self, runtime::BlockNumber}; -use codec::Decode; +use parity_codec::Decode; use consensus_common::{BlockOrigin, ForkChoiceStrategy, ImportBlock, ImportResult}; use consensus_common::import_queue::{SharedBlockImport, SharedJustificationImport}; use std::collections::{HashMap, HashSet}; @@ -372,7 +372,7 @@ fn run_to_completion(blocks: u64, net: Arc>, peers: &[Keyr for (peer_id, key) in peers.iter().enumerate() { let highest_finalized = highest_finalized.clone(); let (client, link) = { - let mut net = net.lock(); + let net = net.lock(); // temporary needed for some reason let link = net.peers[peer_id].data.lock().take().expect("link initialized at startup; qed"); ( @@ -469,7 +469,7 @@ fn finalize_3_voters_1_observer() { for (peer_id, local_key) in all_peers.enumerate() { let (client, link) = { - let mut net = net.lock(); + let net = net.lock(); let link = net.peers[peer_id].data.lock().take().expect("link initialized at startup; qed"); ( net.peers[peer_id].client().clone(), @@ -546,7 +546,7 @@ fn transition_3_voters_twice_1_observer() { assert_eq!(peer.client().info().unwrap().chain.best_number, 1, "Peer #{} failed to sync", i); - let set_raw = peer.client().backend().get_aux(::AUTHORITY_SET_KEY).unwrap().unwrap(); + let set_raw = peer.client().backend().get_aux(crate::AUTHORITY_SET_KEY).unwrap().unwrap(); let set = AuthoritySet::::decode(&mut &set_raw[..]).unwrap(); assert_eq!(set.current(), (0, make_ids(peers_a).as_slice())); @@ -620,7 +620,7 @@ fn transition_3_voters_twice_1_observer() { for (peer_id, local_key) in all_peers { let (client, link) = { - let mut net = net.lock(); + let net = net.lock(); let link = net.peers[peer_id].data.lock().take().expect("link initialized at startup; qed"); ( net.peers[peer_id].client().clone(), @@ -632,7 +632,7 @@ fn transition_3_voters_twice_1_observer() { .take_while(|n| Ok(n.header.number() < &30)) .for_each(move |_| Ok(())) .map(move |()| { - let set_raw = client.backend().get_aux(::AUTHORITY_SET_KEY).unwrap().unwrap(); + let set_raw = client.backend().get_aux(crate::AUTHORITY_SET_KEY).unwrap().unwrap(); let set = AuthoritySet::::decode(&mut &set_raw[..]).unwrap(); assert_eq!(set.current(), (2, make_ids(peers_c).as_slice())); diff --git a/substrate/core/finality-grandpa/src/until_imported.rs b/substrate/core/finality-grandpa/src/until_imported.rs index edc86d6ce7..3d68e8cd84 100644 --- a/substrate/core/finality-grandpa/src/until_imported.rs +++ b/substrate/core/finality-grandpa/src/until_imported.rs @@ -22,6 +22,7 @@ use super::{BlockStatus, Error, SignedMessage, CompactCommit}; +use log::{debug, warn}; use client::ImportNotifications; use futures::prelude::*; use futures::stream::Fuse; @@ -114,8 +115,8 @@ impl Stream for UntilImported Async::Ready(Some(input)) => { // new input: schedule wait of any parts which require // blocks to be known. - let mut ready = &mut self.ready; - let mut pending = &mut self.pending; + let ready = &mut self.ready; + let pending = &mut self.pending; M::schedule_wait( input, &self.status_check, @@ -300,7 +301,7 @@ impl BlockUntilImported for BlockCommitMessage { // check integrity: all precommits for same hash have same number. let canon_number = match checked_hashes.entry(target_hash) { Entry::Occupied(entry) => entry.get().number().clone(), - Entry::Vacant(mut entry) => { + Entry::Vacant(entry) => { if let Some(number) = status_check.block_number(target_hash)? { entry.insert(KnownOrUnknown::Known(number)); number diff --git a/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index 9bf282dec8..8fe26f1793 100644 Binary files a/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/substrate/node/executor/Cargo.toml b/substrate/node/executor/Cargo.toml index 501c8a7b54..2a97543744 100644 --- a/substrate/node/executor/Cargo.toml +++ b/substrate/node/executor/Cargo.toml @@ -6,7 +6,6 @@ description = "Substrate node implementation in Rust." edition = "2018" [dependencies] -hex-literal = "0.1" trie-root = "0.11" parity-codec = "3.0" runtime_io = { package = "sr-io", path = "../../core/sr-io" } diff --git a/substrate/node/executor/src/lib.rs b/substrate/node/executor/src/lib.rs index 2edd2b7966..e198183624 100644 --- a/substrate/node/executor/src/lib.rs +++ b/substrate/node/executor/src/lib.rs @@ -48,7 +48,6 @@ mod tests { BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System, SystemConfig, GrandpaConfig, IndicesConfig, FeesConfig, Event, Log}; use wabt; - use hex_literal::{hex, hex_impl}; use primitives::map; const BLOATY_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.wasm"); @@ -354,7 +353,7 @@ mod tests { ).0.unwrap(); } - let mut correct_header = match Executor::new(None).call::<_, NeverNativeValue, fn() -> _>( + let correct_header = match Executor::new(None).call::<_, NeverNativeValue, fn() -> _>( env, "BlockBuilder_finalise_block", &[0u8;0], diff --git a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm index 3eb99c7be3..d797e49831 100644 Binary files a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm and b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm differ