mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
Get rid of NetworkService in ChainSync (#2143)
Move peer banning from `ChainSync` to `SyncingEngine`.
This commit is contained in:
@@ -27,7 +27,7 @@ use crate::{
|
||||
block_request_handler::MAX_BLOCKS_IN_RESPONSE,
|
||||
chain_sync::{
|
||||
BlockRequestAction, ChainSync, ImportBlocksAction, ImportJustificationsAction,
|
||||
OnBlockResponse,
|
||||
OnBlockResponse, OnStateResponse,
|
||||
},
|
||||
pending_responses::{PendingResponses, ResponseEvent},
|
||||
schema::v1::{StateRequest, StateResponse},
|
||||
@@ -455,11 +455,9 @@ where
|
||||
let chain_sync = ChainSync::new(
|
||||
mode,
|
||||
client.clone(),
|
||||
block_announce_protocol_name.clone(),
|
||||
max_parallel_downloads,
|
||||
max_blocks_per_request,
|
||||
warp_sync_config,
|
||||
network_service.clone(),
|
||||
)?;
|
||||
|
||||
let (tx, service_rx) = tracing_unbounded("mpsc_chain_sync", 100_000);
|
||||
@@ -917,7 +915,7 @@ where
|
||||
/// Called by peer when it is disconnecting.
|
||||
///
|
||||
/// Returns a result if the handshake of this peer was indeed accepted.
|
||||
pub fn on_sync_peer_disconnected(&mut self, peer_id: PeerId) -> Result<(), ()> {
|
||||
fn on_sync_peer_disconnected(&mut self, peer_id: PeerId) -> Result<(), ()> {
|
||||
if let Some(info) = self.peers.remove(&peer_id) {
|
||||
if self.important_peers.contains(&peer_id) {
|
||||
log::warn!(target: LOG_TARGET, "Reserved peer {peer_id} disconnected");
|
||||
@@ -961,7 +959,7 @@ where
|
||||
///
|
||||
/// Returns `Ok` if the handshake is accepted and the peer added to the list of peers we sync
|
||||
/// from.
|
||||
pub fn on_sync_peer_connected(
|
||||
fn on_sync_peer_connected(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
status: &BlockAnnouncesHandshake<B>,
|
||||
@@ -1212,6 +1210,13 @@ where
|
||||
OnBlockResponse::ImportJustifications(action) =>
|
||||
self.import_justifications(action),
|
||||
OnBlockResponse::Nothing => {},
|
||||
OnBlockResponse::DisconnectPeer(BadPeer(peer_id, rep)) => {
|
||||
self.network_service.disconnect_peer(
|
||||
peer_id,
|
||||
self.block_announce_protocol_name.clone(),
|
||||
);
|
||||
self.network_service.report_peer(peer_id, rep);
|
||||
},
|
||||
}
|
||||
},
|
||||
Err(BlockResponseError::DecodeFailed(e)) => {
|
||||
@@ -1257,14 +1262,27 @@ where
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(import_blocks_action) =
|
||||
self.chain_sync.on_state_response(peer_id, response)
|
||||
{
|
||||
self.import_blocks(import_blocks_action);
|
||||
match self.chain_sync.on_state_response(peer_id, response) {
|
||||
OnStateResponse::ImportBlocks(import_blocks_action) =>
|
||||
self.import_blocks(import_blocks_action),
|
||||
OnStateResponse::DisconnectPeer(BadPeer(peer_id, rep)) => {
|
||||
self.network_service.disconnect_peer(
|
||||
peer_id,
|
||||
self.block_announce_protocol_name.clone(),
|
||||
);
|
||||
self.network_service.report_peer(peer_id, rep);
|
||||
},
|
||||
OnStateResponse::Nothing => {},
|
||||
}
|
||||
},
|
||||
PeerRequest::WarpProof => {
|
||||
self.chain_sync.on_warp_sync_response(peer_id, EncodedProof(resp));
|
||||
if let Err(BadPeer(peer_id, rep)) =
|
||||
self.chain_sync.on_warp_sync_response(&peer_id, EncodedProof(resp))
|
||||
{
|
||||
self.network_service
|
||||
.disconnect_peer(peer_id, self.block_announce_protocol_name.clone());
|
||||
self.network_service.report_peer(peer_id, rep);
|
||||
}
|
||||
},
|
||||
},
|
||||
Ok(Err(e)) => {
|
||||
|
||||
Reference in New Issue
Block a user