Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 897b95d

Browse files
Move code from sc-network-common back to sc-network (#13592)
* Move service tests to `client/network/tests` These tests depend on `sc-network` and `sc-network-sync` so they should live outside the crate. * Move some configs from `sc-network-common` to `sc-network` * Move `NetworkService` traits to `sc-network` * Move request-responses to `sc-network` * Remove more stuff * Remove rest of configs from `sc-network-common` to `sc-network` * Remove more stuff * Fix warnings * Update client/network/src/request_responses.rs Co-authored-by: Dmitry Markin <[email protected]> * Fix cargo doc --------- Co-authored-by: Dmitry Markin <[email protected]>
1 parent 4f28d29 commit 897b95d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1411
-1434
lines changed

Cargo.lock

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node/cli/src/service.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ use node_primitives::Block;
3131
use sc_client_api::BlockBackend;
3232
use sc_consensus_babe::{self, SlotProportion};
3333
use sc_executor::NativeElseWasmExecutor;
34-
use sc_network::NetworkService;
35-
use sc_network_common::{
36-
protocol::event::Event, service::NetworkEventStream, sync::warp::WarpSyncParams,
37-
};
34+
use sc_network::{event::Event, NetworkEventStream, NetworkService};
35+
use sc_network_common::sync::warp::WarpSyncParams;
3836
use sc_network_sync::SyncingService;
3937
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
4038
use sc_telemetry::{Telemetry, TelemetryWorker};

client/authority-discovery/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rand = "0.8.5"
2828
thiserror = "1.0"
2929
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" }
3030
sc-client-api = { version = "4.0.0-dev", path = "../api" }
31+
sc-network = { version = "0.10.0-dev", path = "../network/" }
3132
sc-network-common = { version = "0.10.0-dev", path = "../network/common" }
3233
sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
3334
sp-authority-discovery = { version = "4.0.0-dev", path = "../../primitives/authority-discovery" }

client/authority-discovery/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use futures::{
4040
};
4141

4242
use libp2p::{Multiaddr, PeerId};
43-
use sc_network_common::protocol::event::DhtEvent;
43+
use sc_network::event::DhtEvent;
4444
use sp_authority_discovery::AuthorityId;
4545
use sp_blockchain::HeaderBackend;
4646
use sp_runtime::traits::Block as BlockT;

client/authority-discovery/src/worker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ use log::{debug, error, log_enabled};
4343
use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64};
4444
use prost::Message;
4545
use rand::{seq::SliceRandom, thread_rng};
46-
use sc_network_common::{
47-
protocol::event::DhtEvent,
48-
service::{KademliaKey, NetworkDHTProvider, NetworkSigner, NetworkStateInfo, Signature},
46+
use sc_network::{
47+
event::DhtEvent, KademliaKey, NetworkDHTProvider, NetworkSigner, NetworkStateInfo, Signature,
4948
};
5049
use sp_api::{ApiError, ProvideRuntimeApi};
5150
use sp_authority_discovery::{

client/authority-discovery/src/worker/tests.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ use futures::{
2929
sink::SinkExt,
3030
task::LocalSpawn,
3131
};
32-
use libp2p::{core::multiaddr, identity::Keypair, PeerId};
32+
use libp2p::{
33+
core::multiaddr,
34+
identity::{error::SigningError, Keypair},
35+
kad::record::Key as KademliaKey,
36+
PeerId,
37+
};
3338
use prometheus_endpoint::prometheus::default_registry;
3439

3540
use sc_client_api::HeaderBackend;
36-
use sc_network_common::service::{KademliaKey, Signature, SigningError};
41+
use sc_network::Signature;
3742
use sp_api::{ApiRef, ProvideRuntimeApi};
3843
use sp_keystore::{testing::KeyStore, CryptoStore};
3944
use sp_runtime::traits::{Block as BlockT, NumberFor, Zero};

client/chain-spec/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ serde_json = "1.0.85"
1919
sc-client-api = { version = "4.0.0-dev", path = "../api" }
2020
sc-chain-spec-derive = { version = "4.0.0-dev", path = "./derive" }
2121
sc-executor = { version = "0.10.0-dev", path = "../executor" }
22-
sc-network-common = { version = "0.10.0-dev", path = "../network/common" }
22+
sc-network = { version = "0.10.0-dev", path = "../network" }
2323
sc-telemetry = { version = "4.0.0-dev", path = "../telemetry" }
2424
sp-blockchain = { version = "4.0.0-dev", path = "../../primitives/blockchain" }
2525
sp-core = { version = "7.0.0", path = "../../primitives/core" }

client/chain-spec/src/chain_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#![warn(missing_docs)]
2121

2222
use crate::{extension::GetExtension, ChainType, Properties, RuntimeGenesis};
23-
use sc_network_common::config::MultiaddrWithPeerId;
23+
use sc_network::config::MultiaddrWithPeerId;
2424
use sc_telemetry::TelemetryEndpoints;
2525
use serde::{Deserialize, Serialize};
2626
use serde_json as json;

client/chain-spec/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub use self::{
189189
};
190190
pub use sc_chain_spec_derive::{ChainSpecExtension, ChainSpecGroup};
191191

192-
use sc_network_common::config::MultiaddrWithPeerId;
192+
use sc_network::config::MultiaddrWithPeerId;
193193
use sc_telemetry::TelemetryEndpoints;
194194
use serde::{de::DeserializeOwned, Serialize};
195195
use sp_core::storage::Storage;

client/cli/src/arg_enums.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,15 @@ pub enum SyncMode {
251251
Warp,
252252
}
253253

254-
impl Into<sc_network_common::config::SyncMode> for SyncMode {
255-
fn into(self) -> sc_network_common::config::SyncMode {
254+
impl Into<sc_network::config::SyncMode> for SyncMode {
255+
fn into(self) -> sc_network::config::SyncMode {
256256
match self {
257-
SyncMode::Full => sc_network_common::config::SyncMode::Full,
258-
SyncMode::Fast => sc_network_common::config::SyncMode::Fast {
259-
skip_proofs: false,
260-
storage_chain_mode: false,
261-
},
262-
SyncMode::FastUnsafe => sc_network_common::config::SyncMode::Fast {
263-
skip_proofs: true,
264-
storage_chain_mode: false,
265-
},
266-
SyncMode::Warp => sc_network_common::config::SyncMode::Warp,
257+
SyncMode::Full => sc_network::config::SyncMode::Full,
258+
SyncMode::Fast =>
259+
sc_network::config::SyncMode::Fast { skip_proofs: false, storage_chain_mode: false },
260+
SyncMode::FastUnsafe =>
261+
sc_network::config::SyncMode::Fast { skip_proofs: true, storage_chain_mode: false },
262+
SyncMode::Warp => sc_network::config::SyncMode::Warp,
267263
}
268264
}
269265
}

client/cli/src/params/network_params.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
use crate::{arg_enums::SyncMode, params::node_key_params::NodeKeyParams};
2020
use clap::Args;
21-
use sc_network::{config::NetworkConfiguration, multiaddr::Protocol};
22-
use sc_network_common::config::{NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig};
21+
use sc_network::{
22+
config::{
23+
NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig,
24+
},
25+
multiaddr::Protocol,
26+
};
2327
use sc_service::{
2428
config::{Multiaddr, MultiaddrWithPeerId},
2529
ChainSpec, ChainType,

client/cli/src/params/node_key_params.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

1919
use clap::Args;
20-
use sc_network_common::config::{identity::ed25519, NodeKeyConfig};
20+
use sc_network::config::{identity::ed25519, NodeKeyConfig};
2121
use sp_core::H256;
2222
use std::{path::PathBuf, str::FromStr};
2323

@@ -92,7 +92,7 @@ impl NodeKeyParams {
9292
let secret = if let Some(node_key) = self.node_key.as_ref() {
9393
parse_ed25519_secret(node_key)?
9494
} else {
95-
sc_network_common::config::Secret::File(
95+
sc_network::config::Secret::File(
9696
self.node_key_file
9797
.clone()
9898
.unwrap_or_else(|| net_config_dir.join(NODE_KEY_ED25519_FILE)),
@@ -111,10 +111,10 @@ fn invalid_node_key(e: impl std::fmt::Display) -> error::Error {
111111
}
112112

113113
/// Parse a Ed25519 secret key from a hex string into a `sc_network::Secret`.
114-
fn parse_ed25519_secret(hex: &str) -> error::Result<sc_network_common::config::Ed25519Secret> {
114+
fn parse_ed25519_secret(hex: &str) -> error::Result<sc_network::config::Ed25519Secret> {
115115
H256::from_str(hex).map_err(invalid_node_key).and_then(|bytes| {
116116
ed25519::SecretKey::from_bytes(bytes)
117-
.map(sc_network_common::config::Secret::Input)
117+
.map(sc_network::config::Secret::Input)
118118
.map_err(invalid_node_key)
119119
})
120120
}
@@ -123,7 +123,7 @@ fn parse_ed25519_secret(hex: &str) -> error::Result<sc_network_common::config::E
123123
mod tests {
124124
use super::*;
125125
use clap::ValueEnum;
126-
use sc_network_common::config::identity::{ed25519, Keypair};
126+
use sc_network::config::identity::{ed25519, Keypair};
127127
use std::fs;
128128

129129
#[test]
@@ -140,7 +140,7 @@ mod tests {
140140
node_key_file: None,
141141
};
142142
params.node_key(net_config_dir).and_then(|c| match c {
143-
NodeKeyConfig::Ed25519(sc_network_common::config::Secret::Input(ref ski))
143+
NodeKeyConfig::Ed25519(sc_network::config::Secret::Input(ref ski))
144144
if node_key_type == NodeKeyType::Ed25519 && &sk[..] == ski.as_ref() =>
145145
Ok(()),
146146
_ => Err(error::Error::Input("Unexpected node key config".into())),
@@ -200,7 +200,7 @@ mod tests {
200200
let dir = PathBuf::from(net_config_dir.clone());
201201
let typ = params.node_key_type;
202202
params.node_key(net_config_dir).and_then(move |c| match c {
203-
NodeKeyConfig::Ed25519(sc_network_common::config::Secret::File(ref f))
203+
NodeKeyConfig::Ed25519(sc_network::config::Secret::File(ref f))
204204
if typ == NodeKeyType::Ed25519 && f == &dir.join(NODE_KEY_ED25519_FILE) =>
205205
Ok(()),
206206
_ => Err(error::Error::Input("Unexpected node key config".into())),

client/consensus/beefy/src/communication/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ pub(crate) mod beefy_protocol_name {
6767
/// For standard protocol name see [`beefy_protocol_name::gossip_protocol_name`].
6868
pub fn beefy_peers_set_config(
6969
gossip_protocol_name: sc_network::ProtocolName,
70-
) -> sc_network_common::config::NonDefaultSetConfig {
71-
let mut cfg =
72-
sc_network_common::config::NonDefaultSetConfig::new(gossip_protocol_name, 1024 * 1024);
70+
) -> sc_network::config::NonDefaultSetConfig {
71+
let mut cfg = sc_network::config::NonDefaultSetConfig::new(gossip_protocol_name, 1024 * 1024);
7372
cfg.allow_non_reserved(25, 25);
7473
cfg
7574
}

client/consensus/beefy/src/communication/request_response/incoming_requests_handler.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ use futures::{
2323
};
2424
use log::{debug, trace};
2525
use sc_client_api::BlockBackend;
26-
use sc_network::{config as netconfig, config::RequestResponseConfig, PeerId, ReputationChange};
27-
use sc_network_common::protocol::ProtocolName;
26+
use sc_network::{
27+
config as netconfig, config::RequestResponseConfig, types::ProtocolName, PeerId,
28+
ReputationChange,
29+
};
2830
use sp_consensus_beefy::BEEFY_ENGINE_ID;
2931
use sp_runtime::traits::Block;
3032
use std::{marker::PhantomData, sync::Arc};

client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ use codec::Encode;
2222
use futures::channel::{oneshot, oneshot::Canceled};
2323
use log::{debug, warn};
2424
use parking_lot::Mutex;
25-
use sc_network::{PeerId, ProtocolName};
26-
use sc_network_common::{
25+
use sc_network::{
2726
request_responses::{IfDisconnected, RequestFailure},
28-
service::NetworkRequest,
27+
NetworkRequest, PeerId, ProtocolName,
2928
};
3029
use sp_consensus_beefy::{crypto::AuthorityId, ValidatorSet};
3130
use sp_runtime::traits::{Block, NumberFor};

client/consensus/beefy/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ use parking_lot::Mutex;
3838
use prometheus::Registry;
3939
use sc_client_api::{Backend, BlockBackend, BlockchainEvents, FinalityNotifications, Finalizer};
4040
use sc_consensus::BlockImport;
41-
use sc_network::ProtocolName;
42-
use sc_network_common::service::NetworkRequest;
41+
use sc_network::{NetworkRequest, ProtocolName};
4342
use sc_network_gossip::{GossipEngine, Network as GossipNetwork, Syncing as GossipSyncing};
4443
use sp_api::{HeaderT, NumberFor, ProvideRuntimeApi};
4544
use sp_blockchain::{

client/consensus/grandpa/src/communication/gossip.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use parity_scale_codec::{Decode, Encode};
9191
use prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64};
9292
use rand::seq::SliceRandom;
9393
use sc_network::{PeerId, ReputationChange};
94-
use sc_network_common::protocol::role::ObservedRole;
94+
use sc_network_common::role::ObservedRole;
9595
use sc_network_gossip::{MessageIntent, ValidatorContext};
9696
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG};
9797
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
@@ -820,7 +820,7 @@ impl<Block: BlockT> Inner<Block> {
820820
fn note_set(&mut self, set_id: SetId, authorities: Vec<AuthorityId>) -> MaybeMessage<Block> {
821821
let local_view = match self.local_view {
822822
ref mut x @ None => x.get_or_insert(LocalView::new(set_id, Round(1))),
823-
Some(ref mut v) =>
823+
Some(ref mut v) => {
824824
if v.set_id == set_id {
825825
let diff_authorities = self.authorities.iter().collect::<HashSet<_>>() !=
826826
authorities.iter().collect::<HashSet<_>>();
@@ -841,7 +841,8 @@ impl<Block: BlockT> Inner<Block> {
841841
return None
842842
} else {
843843
v
844-
},
844+
}
845+
},
845846
};
846847

847848
local_view.update_set(set_id);

client/consensus/grandpa/src/communication/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use finality_grandpa::{
4646
Message::{Precommit, Prevote, PrimaryPropose},
4747
};
4848
use parity_scale_codec::{Decode, Encode};
49-
use sc_network::ReputationChange;
49+
use sc_network::{NetworkBlock, NetworkSyncForkRequest, ReputationChange};
5050
use sc_network_gossip::{GossipEngine, Network as GossipNetwork};
5151
use sc_telemetry::{telemetry, TelemetryHandle, CONSENSUS_DEBUG, CONSENSUS_INFO};
5252
use sp_keystore::SyncCryptoStorePtr;
@@ -59,10 +59,7 @@ use crate::{
5959
use gossip::{
6060
FullCatchUpMessage, FullCommitMessage, GossipMessage, GossipValidator, PeerReport, VoteMessage,
6161
};
62-
use sc_network_common::{
63-
service::{NetworkBlock, NetworkSyncForkRequest},
64-
sync::SyncEventStream,
65-
};
62+
use sc_network_common::sync::SyncEventStream;
6663
use sc_utils::mpsc::TracingUnboundedReceiver;
6764
use sp_consensus_grandpa::{AuthorityId, AuthoritySignature, RoundNumber, SetId as SetIdNumber};
6865

@@ -77,7 +74,7 @@ pub(crate) const NEIGHBOR_REBROADCAST_PERIOD: Duration = Duration::from_secs(2 *
7774

7875
pub mod grandpa_protocol_name {
7976
use sc_chain_spec::ChainSpec;
80-
use sc_network_common::protocol::ProtocolName;
77+
use sc_network::types::ProtocolName;
8178

8279
pub(crate) const NAME: &str = "/grandpa/1";
8380
/// Old names for the notifications protocol, used for backward compatibility.

0 commit comments

Comments
 (0)