Cleanup devp2p unused interface fn

This commit is contained in:
draganrakita 2020-12-17 12:57:34 +01:00 committed by rakita
parent a6bd3516e0
commit f723e288c3
6 changed files with 7 additions and 41 deletions

View File

@ -18,6 +18,7 @@ use bytes::Bytes;
use enum_primitive::FromPrimitive;
use ethereum_types::H256;
use network::{self, PeerId};
use devp2p::PAYLOAD_SOFT_LIMIT;
use parking_lot::RwLock;
use rlp::{Rlp, RlpStream};
use std::cmp;
@ -187,7 +188,6 @@ impl SyncSupplier {
if io.chain().is_processing_fork() {
return Err(PacketProcessError::ClientBusy);
}
let payload_soft_limit = io.payload_soft_limit();
// Packet layout:
// [ block: { P , B_32 }, maxHeaders: P, skip: P, reverse: P in { 0 , 1 } ]
let max_headers: usize = r.val_at(1)?;
@ -246,7 +246,7 @@ impl SyncSupplier {
data.append(&mut hdr.into_inner());
count += 1;
// Check that the packet won't be oversized
if data.len() > payload_soft_limit {
if data.len() > PAYLOAD_SOFT_LIMIT {
break;
}
} else {
@ -270,7 +270,6 @@ impl SyncSupplier {
/// Respond to GetBlockBodies request
fn return_block_bodies(io: &dyn SyncIo, r: &Rlp, peer_id: PeerId) -> RlpResponseResult {
let payload_soft_limit = io.payload_soft_limit();
let mut count = r.item_count().unwrap_or(0);
if count == 0 {
debug!(target: "sync", "Empty GetBlockBodies request, ignoring.");
@ -284,7 +283,7 @@ impl SyncSupplier {
data.append(&mut body.into_inner());
added += 1;
// Check that the packet won't be oversized
if data.len() > payload_soft_limit {
if data.len() > PAYLOAD_SOFT_LIMIT {
break;
}
}
@ -296,7 +295,6 @@ impl SyncSupplier {
}
fn return_receipts(io: &dyn SyncIo, rlp: &Rlp, peer_id: PeerId) -> RlpResponseResult {
let payload_soft_limit = io.payload_soft_limit();
let mut count = rlp.item_count().unwrap_or(0);
trace!(target: "sync", "{} -> GetReceipts: {} entries", peer_id, count);
if count == 0 {
@ -311,7 +309,7 @@ impl SyncSupplier {
if let Some(receipts) = io.chain().block_receipts(&rlp.val_at::<H256>(i)?) {
let mut receipts_bytes = ::rlp::encode(&receipts);
total_bytes += receipts_bytes.len();
if total_bytes > payload_soft_limit {
if total_bytes > PAYLOAD_SOFT_LIMIT {
break;
}
data.append(&mut receipts_bytes);

View File

@ -46,8 +46,6 @@ pub trait SyncIo {
}
/// Returns information on p2p session
fn peer_session_info(&self, peer_id: PeerId) -> Option<SessionInfo>;
/// Maximum mutually supported ETH protocol version
fn eth_protocol_version(&self, peer_id: PeerId) -> u8;
/// Maximum mutually supported version of a gien protocol.
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8;
/// Returns if the chain block queue empty
@ -58,8 +56,6 @@ pub trait SyncIo {
fn is_expired(&self) -> bool;
/// Return sync overlay
fn chain_overlay(&self) -> &RwLock<HashMap<BlockNumber, Bytes>>;
/// Returns the size the payload shouldn't exceed
fn payload_soft_limit(&self) -> usize;
}
/// Wraps `NetworkContext` and the blockchain client
@ -125,12 +121,6 @@ impl<'s> SyncIo for NetSyncIo<'s> {
self.network.is_expired()
}
fn eth_protocol_version(&self, peer_id: PeerId) -> u8 {
self.network
.protocol_version(self.network.subprotocol_name(), peer_id)
.unwrap_or(0)
}
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
self.network
.protocol_version(*protocol, peer_id)
@ -140,8 +130,4 @@ impl<'s> SyncIo for NetSyncIo<'s> {
fn peer_version(&self, peer_id: PeerId) -> ClientVersion {
self.network.peer_client_version(peer_id)
}
fn payload_soft_limit(&self) -> usize {
self.network.payload_soft_limit()
}
}

View File

@ -168,25 +168,17 @@ where
None
}
fn eth_protocol_version(&self, _peer: PeerId) -> u8 {
ETH_PROTOCOL_VERSION_64.0
}
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
if protocol == &PAR_PROTOCOL {
PAR_PROTOCOL_VERSION_2.0
} else {
self.eth_protocol_version(peer_id)
ETH_PROTOCOL_VERSION_64.0
}
}
fn chain_overlay(&self) -> &RwLock<HashMap<BlockNumber, Bytes>> {
&self.overlay
}
fn payload_soft_limit(&self) -> usize {
100_000
}
}
/// Mock for emulution of async run of new blocks

View File

@ -35,7 +35,6 @@ use std::{
time::Duration,
};
use connection::PAYLOAD_SOFT_LIMIT;
use discovery::{Discovery, NodeEntry, TableUpdates, MAX_DATAGRAM_SIZE};
use io::*;
use ip_utils::{map_external_address, select_public_address};
@ -226,10 +225,6 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> {
.map(|node| self.reserved_peers.contains(&node))
.unwrap_or(false)
}
fn payload_soft_limit(&self) -> usize {
PAYLOAD_SOFT_LIMIT
}
}
/// Shared host information

View File

@ -113,6 +113,8 @@ mod session;
pub use host::NetworkContext;
pub use service::NetworkService;
pub use connection::PAYLOAD_SOFT_LIMIT;
pub use io::TimerToken;
pub use node_table::{validate_node_url, NodeId};

View File

@ -320,9 +320,6 @@ pub trait NetworkContext {
/// Returns whether the given peer ID is a reserved peer.
fn is_reserved_peer(&self, peer: PeerId) -> bool;
/// Returns the size the payload shouldn't exceed
fn payload_soft_limit(&self) -> usize;
}
impl<'a, T> NetworkContext for &'a T
@ -382,10 +379,6 @@ where
fn is_reserved_peer(&self, peer: PeerId) -> bool {
(**self).is_reserved_peer(peer)
}
fn payload_soft_limit(&self) -> usize {
(**self).payload_soft_limit()
}
}
/// Network IO protocol handler. This needs to be implemented for each new subprotocol.