mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
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:
@@ -18,6 +18,7 @@
|
||||
//! `crate::request_responses::RequestResponsesBehaviour`.
|
||||
|
||||
use crate::schema::v1::{block_request::FromBlock, BlockResponse, Direction};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
@@ -27,17 +28,19 @@ use libp2p::PeerId;
|
||||
use log::debug;
|
||||
use lru::LruCache;
|
||||
use prost::Message;
|
||||
|
||||
use sc_client_api::BlockBackend;
|
||||
use sc_network_common::{
|
||||
use sc_network::{
|
||||
config::ProtocolId,
|
||||
request_responses::{IncomingRequest, OutgoingResponse, ProtocolConfig},
|
||||
sync::message::BlockAttributes,
|
||||
};
|
||||
use sc_network_common::sync::message::BlockAttributes;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, Header, One, Zero},
|
||||
};
|
||||
|
||||
use std::{
|
||||
cmp::min,
|
||||
hash::{Hash, Hasher},
|
||||
|
||||
@@ -24,22 +24,27 @@ use crate::{
|
||||
ChainSync, ClientError, SyncingService,
|
||||
};
|
||||
|
||||
use codec::{Decode, DecodeAll, Encode};
|
||||
use futures::{FutureExt, Stream, StreamExt};
|
||||
use futures_timer::Delay;
|
||||
use libp2p::PeerId;
|
||||
use lru::LruCache;
|
||||
use prometheus_endpoint::{
|
||||
register, Gauge, GaugeVec, MetricSource, Opts, PrometheusError, Registry, SourcedGauge, U64,
|
||||
};
|
||||
|
||||
use codec::{Decode, DecodeAll, Encode};
|
||||
use futures_timer::Delay;
|
||||
use sc_client_api::{BlockBackend, HeaderBackend, ProofProvider};
|
||||
use sc_consensus::import_queue::ImportQueueService;
|
||||
use sc_network_common::{
|
||||
use sc_network::{
|
||||
config::{
|
||||
NetworkConfiguration, NonDefaultSetConfig, ProtocolId, SyncMode as SyncOperationMode,
|
||||
},
|
||||
protocol::{event::Event, role::Roles, ProtocolName},
|
||||
event::Event,
|
||||
utils::LruHashSet,
|
||||
ProtocolName,
|
||||
};
|
||||
use sc_network_common::{
|
||||
role::Roles,
|
||||
sync::{
|
||||
message::{
|
||||
generic::{BlockData, BlockResponse},
|
||||
@@ -49,7 +54,6 @@ use sc_network_common::{
|
||||
BadPeer, ChainSync as ChainSyncT, ExtendedPeerInfo, PollBlockAnnounceValidation, SyncEvent,
|
||||
SyncMode,
|
||||
},
|
||||
utils::LruHashSet,
|
||||
};
|
||||
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
|
||||
use sp_blockchain::HeaderMetadata;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -20,9 +20,9 @@ use futures::{channel::oneshot, Stream};
|
||||
use libp2p::PeerId;
|
||||
|
||||
use sc_consensus::{BlockImportError, BlockImportStatus, JustificationSyncLink, Link};
|
||||
use sc_network_common::{
|
||||
service::{NetworkBlock, NetworkSyncForkRequest},
|
||||
sync::{ExtendedPeerInfo, SyncEvent, SyncEventStream, SyncStatus, SyncStatusProvider},
|
||||
use sc_network::{NetworkBlock, NetworkSyncForkRequest};
|
||||
use sc_network_common::sync::{
|
||||
ExtendedPeerInfo, SyncEvent, SyncEventStream, SyncStatus, SyncStatusProvider,
|
||||
};
|
||||
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
|
||||
use futures::channel::oneshot;
|
||||
use libp2p::{Multiaddr, PeerId};
|
||||
|
||||
use sc_consensus::{BlockImportError, BlockImportStatus};
|
||||
use sc_network_common::{
|
||||
use sc_network::{
|
||||
config::MultiaddrWithPeerId,
|
||||
protocol::ProtocolName,
|
||||
request_responses::{IfDisconnected, RequestFailure},
|
||||
service::{
|
||||
NetworkNotification, NetworkPeers, NetworkRequest, NetworkSyncForkRequest,
|
||||
NotificationSender, NotificationSenderError,
|
||||
},
|
||||
types::ProtocolName,
|
||||
NetworkNotification, NetworkPeers, NetworkRequest, NetworkSyncForkRequest,
|
||||
NotificationSenderError, NotificationSenderT,
|
||||
};
|
||||
use sc_peerset::ReputationChange;
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
mockall::mock! {
|
||||
@@ -135,7 +135,7 @@ mockall::mock! {
|
||||
&self,
|
||||
target: PeerId,
|
||||
protocol: ProtocolName,
|
||||
) -> Result<Box<dyn NotificationSender>, NotificationSenderError>;
|
||||
) -> Result<Box<dyn NotificationSenderT>, NotificationSenderError>;
|
||||
fn set_notification_handshake(&self, protocol: ProtocolName, handshake: Vec<u8>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,15 @@
|
||||
|
||||
use futures::{channel::oneshot, StreamExt};
|
||||
use libp2p::PeerId;
|
||||
use sc_network_common::{
|
||||
protocol::ProtocolName,
|
||||
|
||||
use sc_network::{
|
||||
request_responses::{IfDisconnected, RequestFailure},
|
||||
service::{NetworkNotification, NetworkPeers, NetworkRequest},
|
||||
types::ProtocolName,
|
||||
NetworkNotification, NetworkPeers, NetworkRequest,
|
||||
};
|
||||
use sc_peerset::ReputationChange;
|
||||
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Network-related services required by `sc-network-sync`
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
//! `crate::request_responses::RequestResponsesBehaviour`.
|
||||
|
||||
use crate::schema::v1::{KeyValueStateEntry, StateEntry, StateRequest, StateResponse};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
@@ -27,12 +28,14 @@ use libp2p::PeerId;
|
||||
use log::{debug, trace};
|
||||
use lru::LruCache;
|
||||
use prost::Message;
|
||||
|
||||
use sc_client_api::{BlockBackend, ProofProvider};
|
||||
use sc_network_common::{
|
||||
use sc_network::{
|
||||
config::ProtocolId,
|
||||
request_responses::{IncomingRequest, OutgoingResponse, ProtocolConfig},
|
||||
};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
|
||||
use std::{
|
||||
hash::{Hash, Hasher},
|
||||
num::NonZeroUsize,
|
||||
|
||||
@@ -22,14 +22,16 @@ use futures::{
|
||||
stream::StreamExt,
|
||||
};
|
||||
use log::debug;
|
||||
use sc_network_common::{
|
||||
|
||||
use sc_network::{
|
||||
config::ProtocolId,
|
||||
request_responses::{
|
||||
IncomingRequest, OutgoingResponse, ProtocolConfig as RequestResponseConfig,
|
||||
},
|
||||
sync::warp::{EncodedProof, WarpProofRequest, WarpSyncProvider},
|
||||
};
|
||||
use sc_network_common::sync::warp::{EncodedProof, WarpProofRequest, WarpSyncProvider};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
const MAX_RESPONSE_SIZE: u64 = 16 * 1024 * 1024;
|
||||
|
||||
Reference in New Issue
Block a user