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

Remove unused light-client leftover #13687

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Changes from all commits
Commits
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
39 changes: 1 addition & 38 deletions client/network/sync/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ use sc_network_common::{
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use sp_blockchain::HeaderMetadata;
use sp_consensus::block_validation::BlockAnnounceValidator;
use sp_runtime::{
traits::{Block as BlockT, CheckedSub, Header, NumberFor, Zero},
SaturatedConversion,
};
use sp_runtime::traits::{Block as BlockT, Header, NumberFor, Zero};

use std::{
collections::{HashMap, HashSet},
Expand All @@ -77,24 +74,15 @@ use std::{
/// Interval at which we perform time based maintenance
const TICK_TIMEOUT: std::time::Duration = std::time::Duration::from_millis(1100);

/// When light node connects to the full node and the full node is behind light node
/// for at least `LIGHT_MAXIMAL_BLOCKS_DIFFERENCE` blocks, we consider it not useful
/// and disconnect to free connection slot.
const LIGHT_MAXIMAL_BLOCKS_DIFFERENCE: u64 = 8192;

/// Maximum number of known block hashes to keep for a peer.
const MAX_KNOWN_BLOCKS: usize = 1024; // ~32kb per peer + LruHashSet overhead

mod rep {
use sc_peerset::ReputationChange as Rep;
/// Reputation change when we are a light client and a peer is behind us.
pub const PEER_BEHIND_US_LIGHT: Rep = Rep::new(-(1 << 8), "Useless for a light peer");
/// We received a message that failed to decode.
pub const BAD_MESSAGE: Rep = Rep::new(-(1 << 12), "Bad message");
/// Peer has different genesis.
pub const GENESIS_MISMATCH: Rep = Rep::new_fatal("Genesis mismatch");
/// Peer role does not match (e.g. light peer connecting to another light peer).
pub const BAD_ROLE: Rep = Rep::new_fatal("Unsupported role");
/// Peer send us a block announcement that failed at validation.
pub const BAD_BLOCK_ANNOUNCEMENT: Rep = Rep::new(-(1 << 12), "Bad block announcement");
}
Expand Down Expand Up @@ -834,31 +822,6 @@ where
return Err(())
}

if self.roles.is_light() {
// we're not interested in light peers
if status.roles.is_light() {
log::debug!(target: "sync", "Peer {} is unable to serve light requests", who);
self.network_service.report_peer(who, rep::BAD_ROLE);
self.network_service
.disconnect_peer(who, self.block_announce_protocol_name.clone());
return Err(())
}

// we don't interested in peers that are far behind us
let self_best_block = self.client.info().best_number;
let blocks_difference = self_best_block
.checked_sub(&status.best_number)
.unwrap_or_else(Zero::zero)
.saturated_into::<u64>();
if blocks_difference > LIGHT_MAXIMAL_BLOCKS_DIFFERENCE {
log::debug!(target: "sync", "Peer {} is far behind us and will unable to serve light requests", who);
self.network_service.report_peer(who, rep::PEER_BEHIND_US_LIGHT);
self.network_service
.disconnect_peer(who, self.block_announce_protocol_name.clone());
return Err(())
}
}

let no_slot_peer = self.default_peers_set_no_slot_peers.contains(&who);
let this_peer_reserved_slot: usize = if no_slot_peer { 1 } else { 0 };

Expand Down