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 <dmitry@markin.tech>

* Fix cargo doc

---------

Co-authored-by: Dmitry Markin <dmitry@markin.tech>
This commit is contained in:
Aaro Altonen
2023-03-14 14:06:40 +02:00
committed by GitHub
parent 5d718e45c1
commit 9ced14e2de
85 changed files with 1411 additions and 1434 deletions
+25 -19
View File
@@ -28,23 +28,13 @@
//! the network, or whenever a block has been successfully verified, call the appropriate method in
//! order to update it.
pub mod block_request_handler;
pub mod blocks;
pub mod engine;
pub mod mock;
mod schema;
pub mod service;
pub mod state;
pub mod state_request_handler;
pub mod warp;
pub mod warp_request_handler;
use crate::{
blocks::BlockCollection,
schema::v1::{StateRequest, StateResponse},
state::StateSync,
warp::{WarpProofImportResult, WarpSync},
};
use codec::{Decode, DecodeAll, Encode};
use extra_requests::ExtraRequests;
use futures::{
@@ -52,18 +42,22 @@ use futures::{
};
use libp2p::{request_response::OutboundFailure, PeerId};
use log::{debug, error, info, trace, warn};
use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
use prost::Message;
use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
use sc_client_api::{BlockBackend, ProofProvider};
use sc_consensus::{
import_queue::ImportQueueService, BlockImportError, BlockImportStatus, IncomingBlock,
};
use sc_network_common::{
use sc_network::{
config::{
NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake, ProtocolId, SetConfig,
},
protocol::{role::Roles, ProtocolName},
request_responses::{IfDisconnected, RequestFailure},
types::ProtocolName,
};
use sc_network_common::{
role::Roles,
sync::{
message::{
BlockAnnounce, BlockAnnouncesHandshake, BlockAttributes, BlockData, BlockRequest,
@@ -76,7 +70,6 @@ use sc_network_common::{
SyncState, SyncStatus,
},
};
pub use service::chain_sync::SyncingService;
use sp_arithmetic::traits::Saturating;
use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata};
use sp_consensus::{
@@ -90,6 +83,7 @@ use sp_runtime::{
},
EncodedJustification, Justifications,
};
use std::{
collections::{hash_map::Entry, HashMap, HashSet},
iter,
@@ -97,9 +91,21 @@ use std::{
pin::Pin,
sync::Arc,
};
use warp::TargetBlockImportResult;
pub use service::chain_sync::SyncingService;
mod extra_requests;
mod schema;
pub mod block_request_handler;
pub mod blocks;
pub mod engine;
pub mod mock;
pub mod service;
pub mod state;
pub mod state_request_handler;
pub mod warp;
pub mod warp_request_handler;
/// Maximum blocks to request in a single packet.
const MAX_BLOCKS_TO_REQUEST: usize = 64;
@@ -927,9 +933,9 @@ where
match warp_sync.import_target_block(
blocks.pop().expect("`blocks` len checked above."),
) {
TargetBlockImportResult::Success =>
warp::TargetBlockImportResult::Success =>
return Ok(OnBlockData::Continue),
TargetBlockImportResult::BadResponse =>
warp::TargetBlockImportResult::BadResponse =>
return Err(BadPeer(*who, rep::VERIFICATION_FAIL)),
}
} else if blocks.is_empty() {
@@ -3160,7 +3166,7 @@ mod test {
use futures::{executor::block_on, future::poll_fn};
use sc_block_builder::BlockBuilderProvider;
use sc_network_common::{
protocol::role::Role,
role::Role,
sync::message::{BlockData, BlockState, FromBlock},
};
use sp_blockchain::HeaderBackend;