[big refactor] Remove crate aliasing. (#4395)

* Rename: Phase 1.

* Unify codec.

* Fixing: Phase 2

* Fixing: Phase 3.

* Fixing: Phase 4.

* Fixing: Phase 5.

* Fixing: Phase 6.

* Fixing: Phase 7.

* Fixing: Phase 8. Tests

* Fixing: Phase 9. Tests!!!

* Fixing: Phase 10. Moar tests!

* Finally done!

* More fixes.

* Rename primitives:: to sp_core::

* Apply renames in finality-grandpa.

* Fix benches.

* Fix benches 2.

* Revert node-template.

* Fix frame-system in our modules.
This commit is contained in:
Tomasz Drwięga
2019-12-16 13:36:49 +01:00
committed by Gavin Wood
parent f14d98a439
commit 8778ca7dc8
485 changed files with 4023 additions and 4005 deletions
@@ -83,10 +83,10 @@
//! We only send polite messages to peers,
use sp_runtime::traits::{NumberFor, Block as BlockT, Zero};
use network_gossip::{GossipEngine, MessageIntent, ValidatorContext};
use network::{config::Roles, PeerId, ReputationChange};
use codec::{Encode, Decode};
use fg_primitives::AuthorityId;
use sc_network_gossip::{GossipEngine, MessageIntent, ValidatorContext};
use sc_network::{config::Roles, PeerId, ReputationChange};
use parity_scale_codec::{Encode, Decode};
use sp_finality_grandpa::AuthorityId;
use sc_telemetry::{telemetry, CONSENSUS_DEBUG};
use log::{trace, debug, warn};
@@ -908,15 +908,15 @@ impl<Block: BlockT> Inner<Block> {
// too many equivocations (we exceed the fault-tolerance bound).
for vote in last_completed_round.votes {
match vote.message {
grandpa::Message::Prevote(prevote) => {
prevotes.push(grandpa::SignedPrevote {
finality_grandpa::Message::Prevote(prevote) => {
prevotes.push(finality_grandpa::SignedPrevote {
prevote,
signature: vote.signature,
id: vote.id,
});
},
grandpa::Message::Precommit(precommit) => {
precommits.push(grandpa::SignedPrecommit {
finality_grandpa::Message::Precommit(precommit) => {
precommits.push(finality_grandpa::SignedPrecommit {
precommit,
signature: vote.signature,
id: vote.id,
@@ -1280,7 +1280,7 @@ impl<Block: BlockT> GossipValidator<Block> {
}
}
impl<Block: BlockT> network_gossip::Validator<Block> for GossipValidator<Block> {
impl<Block: BlockT> sc_network_gossip::Validator<Block> for GossipValidator<Block> {
fn new_peer(&self, context: &mut dyn ValidatorContext<Block>, who: &PeerId, roles: Roles) {
let packet = {
let mut inner = self.inner.write();
@@ -1306,7 +1306,7 @@ impl<Block: BlockT> network_gossip::Validator<Block> for GossipValidator<Block>
}
fn validate(&self, context: &mut dyn ValidatorContext<Block>, who: &PeerId, data: &[u8])
-> network_gossip::ValidationResult<Block::Hash>
-> sc_network_gossip::ValidationResult<Block::Hash>
{
let (action, broadcast_topics, peer_reply) = self.do_validate(who, data);
@@ -1323,15 +1323,15 @@ impl<Block: BlockT> network_gossip::Validator<Block> for GossipValidator<Block>
Action::Keep(topic, cb) => {
self.report(who.clone(), cb);
context.broadcast_message(topic, data.to_vec(), false);
network_gossip::ValidationResult::ProcessAndKeep(topic)
sc_network_gossip::ValidationResult::ProcessAndKeep(topic)
}
Action::ProcessAndDiscard(topic, cb) => {
self.report(who.clone(), cb);
network_gossip::ValidationResult::ProcessAndDiscard(topic)
sc_network_gossip::ValidationResult::ProcessAndDiscard(topic)
}
Action::Discard(cb) => {
self.report(who.clone(), cb);
network_gossip::ValidationResult::Discard
sc_network_gossip::ValidationResult::Discard
}
}
}
@@ -1502,9 +1502,9 @@ impl<B: BlockT> Future for ReportingTask<B> {
mod tests {
use super::*;
use super::environment::SharedVoterSetState;
use network_gossip::Validator as GossipValidatorT;
use sc_network_gossip::Validator as GossipValidatorT;
use sc_network_test::Block;
use primitives::{crypto::Public, H256};
use sp_core::{crypto::Public, H256};
// some random config (not really needed)
fn config() -> crate::Config {
@@ -1726,7 +1726,7 @@ mod tests {
round: Round(1),
set_id: SetId(set_id),
message: SignedMessage::<Block> {
message: grandpa::Message::Prevote(grandpa::Prevote {
message: finality_grandpa::Message::Prevote(finality_grandpa::Prevote {
target_hash: Default::default(),
target_number: 10,
}),
@@ -1739,7 +1739,7 @@ mod tests {
round: Round(1),
set_id: SetId(set_id),
message: SignedMessage::<Block> {
message: grandpa::Message::Prevote(grandpa::Prevote {
message: finality_grandpa::Message::Prevote(finality_grandpa::Prevote {
target_hash: Default::default(),
target_number: 10,
}),
@@ -1770,7 +1770,7 @@ mod tests {
let mut inner = val.inner.write();
inner.validate_catch_up_message(&peer, &FullCatchUpMessage {
set_id: SetId(set_id),
message: grandpa::CatchUp {
message: finality_grandpa::CatchUp {
round_number: 10,
prevotes: Default::default(),
precommits: Default::default(),
@@ -1806,7 +1806,7 @@ mod tests {
completed_rounds.push(environment::CompletedRound {
number: 2,
state: grandpa::round::State::genesis(Default::default()),
state: finality_grandpa::round::State::genesis(Default::default()),
base: Default::default(),
votes: Default::default(),
});
@@ -31,13 +31,13 @@ use std::sync::Arc;
use futures::{prelude::*, future::Executor as _, sync::mpsc};
use futures03::{compat::Compat, stream::StreamExt, future::FutureExt as _, future::TryFutureExt as _};
use grandpa::Message::{Prevote, Precommit, PrimaryPropose};
use grandpa::{voter, voter_set::VoterSet};
use finality_grandpa::Message::{Prevote, Precommit, PrimaryPropose};
use finality_grandpa::{voter, voter_set::VoterSet};
use log::{debug, trace};
use network::ReputationChange;
use network_gossip::{GossipEngine, Network};
use codec::{Encode, Decode};
use primitives::Pair;
use sc_network::ReputationChange;
use sc_network_gossip::{GossipEngine, Network};
use parity_scale_codec::{Encode, Decode};
use sp_core::Pair;
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, NumberFor};
use sc_telemetry::{telemetry, CONSENSUS_DEBUG, CONSENSUS_INFO};
@@ -49,7 +49,7 @@ use crate::environment::HasVoted;
use gossip::{
GossipMessage, FullCatchUpMessage, FullCommitMessage, VoteMessage, GossipValidator
};
use fg_primitives::{
use sp_finality_grandpa::{
AuthorityPair, AuthorityId, AuthoritySignature, SetId as SetIdNumber, RoundNumber,
};
@@ -59,11 +59,11 @@ mod periodic;
#[cfg(test)]
mod tests;
pub use fg_primitives::GRANDPA_ENGINE_ID;
pub use sp_finality_grandpa::GRANDPA_ENGINE_ID;
// cost scalars for reporting peers.
mod cost {
use network::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
pub(super) const PAST_REJECTION: Rep = Rep::new(-50, "Grandpa: Past message");
pub(super) const BAD_SIGNATURE: Rep = Rep::new(-100, "Grandpa: Bad signature");
pub(super) const MALFORMED_CATCH_UP: Rep = Rep::new(-1000, "Grandpa: Malformed cath-up");
@@ -87,7 +87,7 @@ mod cost {
// benefit scalars for reporting peers.
mod benefit {
use network::ReputationChange as Rep;
use sc_network::ReputationChange as Rep;
pub(super) const NEIGHBOR_MESSAGE: Rep = Rep::new(100, "Grandpa: Neighbor message");
pub(super) const ROUND_MESSAGE: Rep = Rep::new(100, "Grandpa: Round message");
pub(super) const BASIC_VALIDATED_CATCH_UP: Rep = Rep::new(200, "Grandpa: Catch-up message");
@@ -356,7 +356,7 @@ impl<B: BlockT> NetworkBridge<B> {
/// If the given vector of peers is empty then the underlying implementation
/// should make a best effort to fetch the block from any peers it is
/// connected to (NOTE: this assumption will change in the future #3629).
pub(crate) fn set_sync_fork_request(&self, peers: Vec<network::PeerId>, hash: B::Hash, number: NumberFor<B>) {
pub(crate) fn set_sync_fork_request(&self, peers: Vec<sc_network::PeerId>, hash: B::Hash, number: NumberFor<B>) {
self.gossip_engine.set_sync_fork_request(peers, hash, number)
}
}
@@ -370,7 +370,7 @@ fn incoming_global<B: BlockT>(
) -> impl Stream<Item = CommunicationIn<B>, Error = Error> {
let process_commit = move |
msg: FullCommitMessage<B>,
mut notification: network_gossip::TopicNotification,
mut notification: sc_network_gossip::TopicNotification,
gossip_engine: &mut GossipEngine<B>,
gossip_validator: &Arc<GossipValidator<B>>,
voters: &VoterSet<AuthorityId>,
@@ -432,7 +432,7 @@ fn incoming_global<B: BlockT>(
let process_catch_up = move |
msg: FullCatchUpMessage<B>,
mut notification: network_gossip::TopicNotification,
mut notification: sc_network_gossip::TopicNotification,
gossip_engine: &mut GossipEngine<B>,
gossip_validator: &Arc<GossipValidator<B>>,
voters: &VoterSet<AuthorityId>,
@@ -557,15 +557,15 @@ impl<Block: BlockT> Sink for OutgoingMessages<Block>
fn start_send(&mut self, mut msg: Message<Block>) -> StartSend<Message<Block>, Error> {
// if we've voted on this round previously under the same key, send that vote instead
match &mut msg {
grandpa::Message::PrimaryPropose(ref mut vote) =>
finality_grandpa::Message::PrimaryPropose(ref mut vote) =>
if let Some(propose) = self.has_voted.propose() {
*vote = propose.clone();
},
grandpa::Message::Prevote(ref mut vote) =>
finality_grandpa::Message::Prevote(ref mut vote) =>
if let Some(prevote) = self.has_voted.prevote() {
*vote = prevote.clone();
},
grandpa::Message::Precommit(ref mut vote) =>
finality_grandpa::Message::Precommit(ref mut vote) =>
if let Some(precommit) = self.has_voted.precommit() {
*vote = precommit.clone();
},
@@ -660,7 +660,7 @@ fn check_compact_commit<Block: BlockT>(
.enumerate()
{
use crate::communication::gossip::Misbehavior;
use grandpa::Message as GrandpaMessage;
use finality_grandpa::Message as GrandpaMessage;
if let Err(()) = check_message_sig::<Block>(
&GrandpaMessage::Precommit(precommit.clone()),
@@ -772,7 +772,7 @@ fn check_catch_up<Block: BlockT>(
// check signatures on all contained prevotes.
let signatures_checked = check_signatures::<Block, _>(
msg.prevotes.iter().map(|vote| {
(grandpa::Message::Prevote(vote.prevote.clone()), &vote.id, &vote.signature)
(finality_grandpa::Message::Prevote(vote.prevote.clone()), &vote.id, &vote.signature)
}),
msg.round_number,
set_id.0,
@@ -782,7 +782,7 @@ fn check_catch_up<Block: BlockT>(
// check signatures on all contained precommits.
let _ = check_signatures::<Block, _>(
msg.precommits.iter().map(|vote| {
(grandpa::Message::Precommit(vote.precommit.clone()), &vote.id, &vote.signature)
(finality_grandpa::Message::Precommit(vote.precommit.clone()), &vote.id, &vote.signature)
}),
msg.round_number,
set_id.0,
@@ -18,15 +18,15 @@
use std::time::{Instant, Duration};
use codec::Encode;
use parity_scale_codec::Encode;
use futures::prelude::*;
use futures::sync::mpsc;
use futures_timer::Delay;
use futures03::future::{FutureExt as _, TryFutureExt as _};
use log::{debug, warn};
use network::PeerId;
use network_gossip::GossipEngine;
use sc_network::PeerId;
use sc_network_gossip::GossipEngine;
use sp_runtime::traits::{NumberFor, Block as BlockT};
use super::gossip::{NeighborPacket, GossipMessage};
@@ -47,7 +47,7 @@ impl<B: BlockT> NeighborPacketSender<B> {
/// Send a neighbor packet for the background worker to gossip to peers.
pub fn send(
&self,
who: Vec<network::PeerId>,
who: Vec<sc_network::PeerId>,
neighbor_packet: NeighborPacket<NumberFor<B>>,
) {
if let Err(err) = self.0.unbounded_send((who, neighbor_packet)) {
@@ -18,24 +18,24 @@
use futures::sync::mpsc;
use futures::prelude::*;
use network::{Event as NetworkEvent, PeerId, config::Roles};
use sc_network::{Event as NetworkEvent, PeerId, config::Roles};
use sc_network_test::{Block, Hash};
use network_gossip::Validator;
use sc_network_gossip::Validator;
use tokio::runtime::current_thread;
use std::sync::Arc;
use keyring::Ed25519Keyring;
use codec::Encode;
use sp_keyring::Ed25519Keyring;
use parity_scale_codec::Encode;
use sp_runtime::{ConsensusEngineId, traits::NumberFor};
use std::{pin::Pin, task::{Context, Poll}};
use crate::environment::SharedVoterSetState;
use fg_primitives::{AuthorityList, GRANDPA_ENGINE_ID};
use sp_finality_grandpa::{AuthorityList, GRANDPA_ENGINE_ID};
use super::gossip::{self, GossipValidator};
use super::{AuthorityId, VoterSet, Round, SetId};
enum Event {
EventStream(mpsc::UnboundedSender<NetworkEvent>),
WriteNotification(network::PeerId, Vec<u8>),
Report(network::PeerId, network::ReputationChange),
WriteNotification(sc_network::PeerId, Vec<u8>),
Report(sc_network::PeerId, sc_network::ReputationChange),
Announce(Hash),
}
@@ -44,7 +44,7 @@ struct TestNetwork {
sender: mpsc::UnboundedSender<Event>,
}
impl network_gossip::Network<Block> for TestNetwork {
impl sc_network_gossip::Network<Block> for TestNetwork {
fn event_stream(&self)
-> Box<dyn futures::Stream<Item = NetworkEvent, Error = ()> + Send> {
let (tx, rx) = mpsc::unbounded();
@@ -52,7 +52,7 @@ impl network_gossip::Network<Block> for TestNetwork {
Box::new(rx)
}
fn report_peer(&self, who: network::PeerId, cost_benefit: network::ReputationChange) {
fn report_peer(&self, who: sc_network::PeerId, cost_benefit: sc_network::ReputationChange) {
let _ = self.sender.unbounded_send(Event::Report(who, cost_benefit));
}
@@ -70,19 +70,19 @@ impl network_gossip::Network<Block> for TestNetwork {
fn set_sync_fork_request(
&self,
_peers: Vec<network::PeerId>,
_peers: Vec<sc_network::PeerId>,
_hash: Hash,
_number: NumberFor<Block>,
) {}
}
impl network_gossip::ValidatorContext<Block> for TestNetwork {
impl sc_network_gossip::ValidatorContext<Block> for TestNetwork {
fn broadcast_topic(&mut self, _: Hash, _: bool) { }
fn broadcast_message(&mut self, _: Hash, _: Vec<u8>, _: bool) { }
fn send_message(&mut self, who: &network::PeerId, data: Vec<u8>) {
<Self as network_gossip::Network<Block>>::write_notification(
fn send_message(&mut self, who: &sc_network::PeerId, data: Vec<u8>) {
<Self as sc_network_gossip::Network<Block>>::write_notification(
self,
who.clone(),
GRANDPA_ENGINE_ID,
@@ -90,7 +90,7 @@ impl network_gossip::ValidatorContext<Block> for TestNetwork {
);
}
fn send_topic(&mut self, _: &network::PeerId, _: Hash, _: bool) { }
fn send_topic(&mut self, _: &sc_network::PeerId, _: Hash, _: bool) { }
}
struct Tester {
@@ -132,8 +132,8 @@ fn config() -> crate::Config {
fn voter_set_state() -> SharedVoterSetState<Block> {
use crate::authorities::AuthoritySet;
use crate::environment::VoterSetState;
use grandpa::round::State as RoundState;
use primitives::H256;
use finality_grandpa::round::State as RoundState;
use sp_core::H256;
let state = RoundState::genesis((H256::zero(), 0));
let base = state.prevote_ghost.unwrap();
@@ -193,11 +193,11 @@ fn make_ids(keys: &[Ed25519Keyring]) -> AuthorityList {
struct NoopContext;
impl network_gossip::ValidatorContext<Block> for NoopContext {
impl sc_network_gossip::ValidatorContext<Block> for NoopContext {
fn broadcast_topic(&mut self, _: Hash, _: bool) { }
fn broadcast_message(&mut self, _: Hash, _: Vec<u8>, _: bool) { }
fn send_message(&mut self, _: &network::PeerId, _: Vec<u8>) { }
fn send_topic(&mut self, _: &network::PeerId, _: Hash, _: bool) { }
fn send_message(&mut self, _: &sc_network::PeerId, _: Vec<u8>) { }
fn send_topic(&mut self, _: &sc_network::PeerId, _: Hash, _: bool) { }
}
#[test]
@@ -213,9 +213,9 @@ fn good_commit_leads_to_relay() {
let target_hash: Hash = [1; 32].into();
let target_number = 500;
let precommit = grandpa::Precommit { target_hash: target_hash.clone(), target_number };
let precommit = finality_grandpa::Precommit { target_hash: target_hash.clone(), target_number };
let payload = super::localized_payload(
round, set_id, &grandpa::Message::Precommit(precommit.clone())
round, set_id, &finality_grandpa::Message::Precommit(precommit.clone())
);
let mut precommits = Vec::new();
@@ -224,11 +224,11 @@ fn good_commit_leads_to_relay() {
for (i, key) in private.iter().enumerate() {
precommits.push(precommit.clone());
let signature = fg_primitives::AuthoritySignature::from(key.sign(&payload[..]));
let signature = sp_finality_grandpa::AuthoritySignature::from(key.sign(&payload[..]));
auth_data.push((signature, public[i].0.clone()))
}
grandpa::CompactCommit {
finality_grandpa::CompactCommit {
target_hash,
target_number,
precommits,
@@ -242,14 +242,14 @@ fn good_commit_leads_to_relay() {
message: commit,
}).encode();
let id = network::PeerId::random();
let id = sc_network::PeerId::random();
let global_topic = super::global_topic::<Block>(set_id);
let threads_pool = futures03::executor::ThreadPool::new().unwrap();
let test = make_test_network(&threads_pool).0
.and_then(move |tester| {
// register a peer.
tester.gossip_validator.new_peer(&mut NoopContext, &id, network::config::Roles::FULL);
tester.gossip_validator.new_peer(&mut NoopContext, &id, sc_network::config::Roles::FULL);
Ok((tester, id))
})
.and_then(move |(tester, id)| {
@@ -291,8 +291,8 @@ fn good_commit_leads_to_relay() {
let handle_commit = commits_in.into_future()
.map(|(item, _)| {
match item.unwrap() {
grandpa::voter::CommunicationIn::Commit(_, _, mut callback) => {
callback.run(grandpa::voter::CommitProcessingOutcome::good());
finality_grandpa::voter::CommunicationIn::Commit(_, _, mut callback) => {
callback.run(finality_grandpa::voter::CommitProcessingOutcome::good());
},
_ => panic!("commit expected"),
}
@@ -330,9 +330,9 @@ fn bad_commit_leads_to_report() {
let target_hash: Hash = [1; 32].into();
let target_number = 500;
let precommit = grandpa::Precommit { target_hash: target_hash.clone(), target_number };
let precommit = finality_grandpa::Precommit { target_hash: target_hash.clone(), target_number };
let payload = super::localized_payload(
round, set_id, &grandpa::Message::Precommit(precommit.clone())
round, set_id, &finality_grandpa::Message::Precommit(precommit.clone())
);
let mut precommits = Vec::new();
@@ -341,11 +341,11 @@ fn bad_commit_leads_to_report() {
for (i, key) in private.iter().enumerate() {
precommits.push(precommit.clone());
let signature = fg_primitives::AuthoritySignature::from(key.sign(&payload[..]));
let signature = sp_finality_grandpa::AuthoritySignature::from(key.sign(&payload[..]));
auth_data.push((signature, public[i].0.clone()))
}
grandpa::CompactCommit {
finality_grandpa::CompactCommit {
target_hash,
target_number,
precommits,
@@ -359,14 +359,14 @@ fn bad_commit_leads_to_report() {
message: commit,
}).encode();
let id = network::PeerId::random();
let id = sc_network::PeerId::random();
let global_topic = super::global_topic::<Block>(set_id);
let threads_pool = futures03::executor::ThreadPool::new().unwrap();
let test = make_test_network(&threads_pool).0
.and_then(move |tester| {
// register a peer.
tester.gossip_validator.new_peer(&mut NoopContext, &id, network::config::Roles::FULL);
tester.gossip_validator.new_peer(&mut NoopContext, &id, sc_network::config::Roles::FULL);
Ok((tester, id))
})
.and_then(move |(tester, id)| {
@@ -408,8 +408,8 @@ fn bad_commit_leads_to_report() {
let handle_commit = commits_in.into_future()
.map(|(item, _)| {
match item.unwrap() {
grandpa::voter::CommunicationIn::Commit(_, _, mut callback) => {
callback.run(grandpa::voter::CommitProcessingOutcome::bad());
finality_grandpa::voter::CommunicationIn::Commit(_, _, mut callback) => {
callback.run(finality_grandpa::voter::CommitProcessingOutcome::bad());
},
_ => panic!("commit expected"),
}
@@ -435,14 +435,14 @@ fn bad_commit_leads_to_report() {
#[test]
fn peer_with_higher_view_leads_to_catch_up_request() {
let id = network::PeerId::random();
let id = sc_network::PeerId::random();
let threads_pool = futures03::executor::ThreadPool::new().unwrap();
let (tester, mut net) = make_test_network(&threads_pool);
let test = tester
.and_then(move |tester| {
// register a peer with authority role.
tester.gossip_validator.new_peer(&mut NoopContext, &id, network::config::Roles::AUTHORITY);
tester.gossip_validator.new_peer(&mut NoopContext, &id, sc_network::config::Roles::AUTHORITY);
Ok((tester, id))
})
.and_then(move |(tester, id)| {
@@ -459,7 +459,7 @@ fn peer_with_higher_view_leads_to_catch_up_request() {
// neighbor packets are always discard
match result {
network_gossip::ValidationResult::Discard => {},
sc_network_gossip::ValidationResult::Discard => {},
_ => panic!("wrong expected outcome from neighbor validation"),
}