Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
767464b
Remove useless internal messages
tomaka Jul 5, 2019
ba89727
Remove NetworkService::disconnect_peer
tomaka Jul 5, 2019
e2fff25
Remove NetworkMsg altogether
tomaka Jul 5, 2019
c5e53a7
Rename ProtocolMsg ServerToWorkerMsg
tomaka Jul 5, 2019
3710c73
Remove useless code
tomaka Jul 5, 2019
d913cc3
Add example for parse_str_addr
tomaka Jul 5, 2019
33cb15e
Move parse_str_addr and ProtocolId to config
tomaka Jul 5, 2019
bc41398
Don't reexport the content of config
tomaka Jul 5, 2019
2176a7a
Rework the imports
tomaka Jul 5, 2019
747ff26
More reexports rework
tomaka Jul 5, 2019
d8b906c
Add documentation
tomaka Jul 5, 2019
7fb318d
Move finalization report to network future
tomaka Jul 5, 2019
d17e86e
Move on_block_imported to worker
tomaka Jul 5, 2019
376af2f
get_value/put_value no longer locking
tomaka Jul 5, 2019
5ebd712
local_peer_id() no longer locks
tomaka Jul 5, 2019
0a438ea
Remove FetchFuture
tomaka Jul 6, 2019
f7cfc59
Service imports cleanup
tomaka Jul 6, 2019
e656de2
Produce the network state in the network task
tomaka Jul 6, 2019
a44c3d8
Merge network task and RPC network task
tomaka Jul 6, 2019
0fb23f7
Move network methods to NetworkWorker
tomaka Jul 6, 2019
6d9c632
Remove Arc peers system from network
tomaka Jul 6, 2019
6736be2
add_reserved_peer now goes through the channel
tomaka Jul 6, 2019
cdb227f
Remove Mutex around network swarm
tomaka Jul 6, 2019
6b5faf9
Remove the FnOnce alias traits
tomaka Jul 7, 2019
f780d23
Replace is_offline with num_connected
tomaka Jul 7, 2019
d518cd0
Improve style of poll()
tomaka Jul 7, 2019
02571df
Fix network tests
tomaka Jul 7, 2019
9464c72
Some doc in service module
tomaka Jul 7, 2019
97ddf4a
Remove macro export
tomaka Jul 7, 2019
9779f0a
Minor doc changes
tomaka Jul 7, 2019
66c469d
Merge remote-tracking branch 'upstream/master' into cleanup-net-service
tomaka Jul 7, 2019
db730d1
Remove the synchronized() method of the import queue
tomaka Jul 7, 2019
31d330c
Line width
tomaka Jul 7, 2019
e8d8d4d
Line widths
tomaka Jul 7, 2019
43962d1
Fix import queue tests
tomaka Jul 7, 2019
94b5ea8
Fix CLI tests
tomaka Jul 8, 2019
ec85aa9
Merge remote-tracking branch 'upstream/master' into cleanup-net-service
tomaka Jul 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where C: Components {
let mut last_number = None;
let mut last_update = time::Instant::now();

let display_notifications = service.network_status().for_each(move |net_status| {
let display_notifications = service.network_status().for_each(move |(net_status, _)| {

let info = client.info();
let best_number = info.chain.best_number.saturated_into::<u64>();
Expand Down
41 changes: 20 additions & 21 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ use service::{
};
use network::{
self, multiaddr::Protocol,
config::{NetworkConfiguration, TransportConfig, NonReservedPeerMode, NodeKeyConfig},
build_multiaddr,
config::{NetworkConfiguration, TransportConfig, NonReservedPeerMode, NodeKeyConfig, build_multiaddr},
};
use primitives::H256;

Expand Down Expand Up @@ -250,16 +249,16 @@ where
params.node_key.as_ref().map(parse_secp256k1_secret).unwrap_or_else(||
Ok(params.node_key_file
.or_else(|| net_config_file(net_config_dir, NODE_KEY_SECP256K1_FILE))
.map(network::Secret::File)
.unwrap_or(network::Secret::New)))
.map(network::config::Secret::File)
.unwrap_or(network::config::Secret::New)))
.map(NodeKeyConfig::Secp256k1),

NodeKeyType::Ed25519 =>
params.node_key.as_ref().map(parse_ed25519_secret).unwrap_or_else(||
Ok(params.node_key_file
.or_else(|| net_config_file(net_config_dir, NODE_KEY_ED25519_FILE))
.map(network::Secret::File)
.unwrap_or(network::Secret::New)))
.map(network::config::Secret::File)
.unwrap_or(network::config::Secret::New)))
.map(NodeKeyConfig::Ed25519)
}
}
Expand All @@ -277,18 +276,18 @@ fn invalid_node_key(e: impl std::fmt::Display) -> error::Error {
}

/// Parse a Secp256k1 secret key from a hex string into a `network::Secret`.
fn parse_secp256k1_secret(hex: &String) -> error::Result<network::Secp256k1Secret> {
fn parse_secp256k1_secret(hex: &String) -> error::Result<network::config::Secp256k1Secret> {
H256::from_str(hex).map_err(invalid_node_key).and_then(|bytes|
network::identity::secp256k1::SecretKey::from_bytes(bytes)
.map(network::Secret::Input)
network::config::identity::secp256k1::SecretKey::from_bytes(bytes)
.map(network::config::Secret::Input)
.map_err(invalid_node_key))
}

/// Parse a Ed25519 secret key from a hex string into a `network::Secret`.
fn parse_ed25519_secret(hex: &String) -> error::Result<network::Ed25519Secret> {
fn parse_ed25519_secret(hex: &String) -> error::Result<network::config::Ed25519Secret> {
H256::from_str(&hex).map_err(invalid_node_key).and_then(|bytes|
network::identity::ed25519::SecretKey::from_bytes(bytes)
.map(network::Secret::Input)
network::config::identity::ed25519::SecretKey::from_bytes(bytes)
.map(network::config::Secret::Input)
.map_err(invalid_node_key))
}

Expand Down Expand Up @@ -810,7 +809,7 @@ fn kill_color(s: &str) -> String {
mod tests {
use super::*;
use tempdir::TempDir;
use network::identity::{secp256k1, ed25519};
use network::config::identity::{secp256k1, ed25519};

#[test]
fn tests_node_name_good() {
Expand Down Expand Up @@ -842,10 +841,10 @@ mod tests {
node_key_file: None
};
node_key_config(params, &net_config_dir).and_then(|c| match c {
NodeKeyConfig::Secp256k1(network::Secret::Input(ref ski))
NodeKeyConfig::Secp256k1(network::config::Secret::Input(ref ski))
if node_key_type == NodeKeyType::Secp256k1 &&
&sk[..] == ski.to_bytes() => Ok(()),
NodeKeyConfig::Ed25519(network::Secret::Input(ref ski))
NodeKeyConfig::Ed25519(network::config::Secret::Input(ref ski))
if node_key_type == NodeKeyType::Ed25519 &&
&sk[..] == ski.as_ref() => Ok(()),
_ => Err(error::Error::Input("Unexpected node key config".into()))
Expand All @@ -870,9 +869,9 @@ mod tests {
node_key_file: Some(file.clone())
};
node_key_config(params, &net_config_dir).and_then(|c| match c {
NodeKeyConfig::Secp256k1(network::Secret::File(ref f))
NodeKeyConfig::Secp256k1(network::config::Secret::File(ref f))
if node_key_type == NodeKeyType::Secp256k1 && f == &file => Ok(()),
NodeKeyConfig::Ed25519(network::Secret::File(ref f))
NodeKeyConfig::Ed25519(network::config::Secret::File(ref f))
if node_key_type == NodeKeyType::Ed25519 && f == &file => Ok(()),
_ => Err(error::Error::Input("Unexpected node key config".into()))
})
Expand Down Expand Up @@ -904,9 +903,9 @@ mod tests {
let typ = params.node_key_type;
node_key_config::<String>(params, &None)
.and_then(|c| match c {
NodeKeyConfig::Secp256k1(network::Secret::New)
NodeKeyConfig::Secp256k1(network::config::Secret::New)
if typ == NodeKeyType::Secp256k1 => Ok(()),
NodeKeyConfig::Ed25519(network::Secret::New)
NodeKeyConfig::Ed25519(network::config::Secret::New)
if typ == NodeKeyType::Ed25519 => Ok(()),
_ => Err(error::Error::Input("Unexpected node key config".into()))
})
Expand All @@ -919,10 +918,10 @@ mod tests {
let typ = params.node_key_type;
node_key_config(params, &Some(net_config_dir.clone()))
.and_then(move |c| match c {
NodeKeyConfig::Secp256k1(network::Secret::File(ref f))
NodeKeyConfig::Secp256k1(network::config::Secret::File(ref f))
if typ == NodeKeyType::Secp256k1 &&
f == &dir.join(NODE_KEY_SECP256K1_FILE) => Ok(()),
NodeKeyConfig::Ed25519(network::Secret::File(ref f))
NodeKeyConfig::Ed25519(network::config::Secret::File(ref f))
if typ == NodeKeyType::Ed25519 &&
f == &dir.join(NODE_KEY_ED25519_FILE) => Ok(()),
_ => Err(error::Error::Input("Unexpected node key config".into()))
Expand Down
4 changes: 2 additions & 2 deletions core/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,8 @@ mod tests {
}
}

fn peer(&self, i: usize) -> &Peer<Self::PeerData, DummySpecialization> {
&self.peers[i]
fn peer(&mut self, i: usize) -> &mut Peer<Self::PeerData, DummySpecialization> {
&mut self.peers[i]
}

fn peers(&self) -> &Vec<Peer<Self::PeerData, DummySpecialization>> {
Expand Down
4 changes: 2 additions & 2 deletions core/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,9 @@ mod tests {
})
}

fn peer(&self, i: usize) -> &Peer<Self::PeerData, DummySpecialization> {
fn peer(&mut self, i: usize) -> &mut Peer<Self::PeerData, DummySpecialization> {
trace!(target: "babe", "Retreiving a peer");
&self.peers[i]
&mut self.peers[i]
}

fn peers(&self) -> &Vec<Peer<Self::PeerData, DummySpecialization>> {
Expand Down
1 change: 0 additions & 1 deletion core/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ test-client = { package = "substrate-test-runtime-client", path = "../../test-ru

[features]
default = []
test-helpers = []
3 changes: 0 additions & 3 deletions core/consensus/common/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ pub trait Link<B: BlockT>: Send {
fn report_peer(&mut self, _who: Origin, _reputation_change: i32) {}
/// Restart sync.
fn restart(&mut self) {}
/// Synchronization request has been processed.
#[cfg(any(test, feature = "test-helpers"))]
fn synchronized(&mut self) {}
}

/// Block import successful result.
Expand Down
16 changes: 0 additions & 16 deletions core/consensus/common/src/import_queue/basic_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ impl<B: BlockT> BasicQueue<B> {
manual_poll: None,
}
}

/// Send synchronization request to the block import channel.
///
/// The caller should wait for Link::synchronized() call to ensure that it
/// has synchronized with ImportQueue.
#[cfg(any(test, feature = "test-helpers"))]
pub fn synchronize(&self) {
let _ = self.sender.unbounded_send(ToWorkerMsg::Synchronize);
}
}

impl<B: BlockT> ImportQueue<B> for BasicQueue<B> {
Expand Down Expand Up @@ -153,8 +144,6 @@ enum ToWorkerMsg<B: BlockT> {
ImportBlocks(BlockOrigin, Vec<IncomingBlock<B>>),
ImportJustification(Origin, B::Hash, NumberFor<B>, Justification),
ImportFinalityProof(Origin, B::Hash, NumberFor<B>, Vec<u8>),
#[cfg(any(test, feature = "test-helpers"))]
Synchronize,
}

struct BlockImportWorker<B: BlockT, V: Verifier<B>> {
Expand Down Expand Up @@ -213,11 +202,6 @@ impl<B: BlockT, V: 'static + Verifier<B>> BlockImportWorker<B, V> {
ToWorkerMsg::ImportJustification(who, hash, number, justification) => {
worker.import_justification(who, hash, number, justification);
}
#[cfg(any(test, feature = "test-helpers"))]
ToWorkerMsg::Synchronize => {
trace!(target: "sync", "Sending sync message");
worker.result_sender.synchronized();
},
}
}
});
Expand Down
10 changes: 0 additions & 10 deletions core/consensus/common/src/import_queue/buffered_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ enum BlockImportWorkerMsg<B: BlockT> {
SetFinalityProofRequestBuilder(SharedFinalityProofRequestBuilder<B>),
ReportPeer(Origin, i32),
Restart,
#[cfg(any(test, feature = "test-helpers"))]
Synchronized,
}

impl<B: BlockT> Link<B> for BufferedLinkSender<B> {
Expand Down Expand Up @@ -120,11 +118,6 @@ impl<B: BlockT> Link<B> for BufferedLinkSender<B> {
fn restart(&mut self) {
let _ = self.tx.unbounded_send(BlockImportWorkerMsg::Restart);
}

#[cfg(any(test, feature = "test-helpers"))]
fn synchronized(&mut self) {
let _ = self.tx.unbounded_send(BlockImportWorkerMsg::Synchronized);
}
}

/// See [`buffered_link`].
Expand Down Expand Up @@ -168,9 +161,6 @@ impl<B: BlockT> BufferedLinkReceiver<B> {
link.report_peer(who, reput),
BlockImportWorkerMsg::Restart =>
link.restart(),
#[cfg(any(test, feature = "test-helpers"))]
BlockImportWorkerMsg::Synchronized =>
link.synchronized(),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion core/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fg_primitives = { package = "substrate-finality-grandpa-primitives", path = "pri
grandpa = { package = "finality-grandpa", version = "0.8.1", features = ["derive-codec"] }

[dev-dependencies]
consensus_common = { package = "substrate-consensus-common", path = "../consensus/common", features = ["test-helpers"] }
grandpa = { package = "finality-grandpa", version = "0.8.1", features = ["derive-codec", "test-helpers"] }
network = { package = "substrate-network", path = "../network", features = ["test-helpers"] }
keyring = { package = "substrate-keyring", path = "../keyring" }
Expand Down
8 changes: 4 additions & 4 deletions core/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ impl TestNetFactory for GrandpaTestNet {
}
}

fn peer(&self, i: usize) -> &GrandpaPeer {
&self.peers[i]
fn peer(&mut self, i: usize) -> &mut GrandpaPeer {
&mut self.peers[i]
}

fn peers(&self) -> &Vec<GrandpaPeer> {
Expand Down Expand Up @@ -949,7 +949,7 @@ fn allows_reimporting_change_blocks() {
let peers_b = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob];
let voters = make_ids(peers_a);
let api = TestApi::new(voters);
let net = GrandpaTestNet::new(api.clone(), 3);
let mut net = GrandpaTestNet::new(api.clone(), 3);

let client = net.peer(0).client().clone();
let (block_import, ..) = net.make_block_import(client.clone());
Expand Down Expand Up @@ -998,7 +998,7 @@ fn test_bad_justification() {
let peers_b = &[AuthorityKeyring::Alice, AuthorityKeyring::Bob];
let voters = make_ids(peers_a);
let api = TestApi::new(voters);
let net = GrandpaTestNet::new(api.clone(), 3);
let mut net = GrandpaTestNet::new(api.clone(), 3);

let client = net.peer(0).client().clone();
let (block_import, ..) = net.make_block_import(client.clone());
Expand Down
3 changes: 1 addition & 2 deletions core/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ quickcheck = "0.8.5"
rand = "0.6.5"
test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" }
test_runtime = { package = "substrate-test-runtime", path = "../../core/test-runtime" }
consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common", features = ["test-helpers"] }
tempdir = "0.3"
tokio = "0.1.11"

[features]
default = []
test-helpers = ["keyring", "test-client", "consensus/test-helpers", "tokio"]
test-helpers = ["keyring", "test-client", "tokio"]
3 changes: 2 additions & 1 deletion core/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use crate::{
debug_info, discovery::DiscoveryBehaviour, discovery::DiscoveryOut, DiscoveryNetBehaviour, event::DhtEvent
debug_info, discovery::DiscoveryBehaviour, discovery::DiscoveryOut, DiscoveryNetBehaviour,
protocol::event::DhtEvent
};
use crate::{ExHashT, specialization::NetworkSpecialization};
use crate::protocol::{CustomMessageOutcome, Protocol};
Expand Down
Loading