Cleanup devp2p unused interface fn
This commit is contained in:
parent
a6bd3516e0
commit
f723e288c3
@ -18,6 +18,7 @@ use bytes::Bytes;
|
|||||||
use enum_primitive::FromPrimitive;
|
use enum_primitive::FromPrimitive;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use network::{self, PeerId};
|
use network::{self, PeerId};
|
||||||
|
use devp2p::PAYLOAD_SOFT_LIMIT;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use rlp::{Rlp, RlpStream};
|
use rlp::{Rlp, RlpStream};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
@ -187,7 +188,6 @@ impl SyncSupplier {
|
|||||||
if io.chain().is_processing_fork() {
|
if io.chain().is_processing_fork() {
|
||||||
return Err(PacketProcessError::ClientBusy);
|
return Err(PacketProcessError::ClientBusy);
|
||||||
}
|
}
|
||||||
let payload_soft_limit = io.payload_soft_limit();
|
|
||||||
// Packet layout:
|
// Packet layout:
|
||||||
// [ block: { P , B_32 }, maxHeaders: P, skip: P, reverse: P in { 0 , 1 } ]
|
// [ block: { P , B_32 }, maxHeaders: P, skip: P, reverse: P in { 0 , 1 } ]
|
||||||
let max_headers: usize = r.val_at(1)?;
|
let max_headers: usize = r.val_at(1)?;
|
||||||
@ -246,7 +246,7 @@ impl SyncSupplier {
|
|||||||
data.append(&mut hdr.into_inner());
|
data.append(&mut hdr.into_inner());
|
||||||
count += 1;
|
count += 1;
|
||||||
// Check that the packet won't be oversized
|
// Check that the packet won't be oversized
|
||||||
if data.len() > payload_soft_limit {
|
if data.len() > PAYLOAD_SOFT_LIMIT {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -270,7 +270,6 @@ impl SyncSupplier {
|
|||||||
|
|
||||||
/// Respond to GetBlockBodies request
|
/// Respond to GetBlockBodies request
|
||||||
fn return_block_bodies(io: &dyn SyncIo, r: &Rlp, peer_id: PeerId) -> RlpResponseResult {
|
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);
|
let mut count = r.item_count().unwrap_or(0);
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
debug!(target: "sync", "Empty GetBlockBodies request, ignoring.");
|
debug!(target: "sync", "Empty GetBlockBodies request, ignoring.");
|
||||||
@ -284,7 +283,7 @@ impl SyncSupplier {
|
|||||||
data.append(&mut body.into_inner());
|
data.append(&mut body.into_inner());
|
||||||
added += 1;
|
added += 1;
|
||||||
// Check that the packet won't be oversized
|
// Check that the packet won't be oversized
|
||||||
if data.len() > payload_soft_limit {
|
if data.len() > PAYLOAD_SOFT_LIMIT {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,7 +295,6 @@ impl SyncSupplier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn return_receipts(io: &dyn SyncIo, rlp: &Rlp, peer_id: PeerId) -> RlpResponseResult {
|
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);
|
let mut count = rlp.item_count().unwrap_or(0);
|
||||||
trace!(target: "sync", "{} -> GetReceipts: {} entries", peer_id, count);
|
trace!(target: "sync", "{} -> GetReceipts: {} entries", peer_id, count);
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
@ -311,7 +309,7 @@ impl SyncSupplier {
|
|||||||
if let Some(receipts) = io.chain().block_receipts(&rlp.val_at::<H256>(i)?) {
|
if let Some(receipts) = io.chain().block_receipts(&rlp.val_at::<H256>(i)?) {
|
||||||
let mut receipts_bytes = ::rlp::encode(&receipts);
|
let mut receipts_bytes = ::rlp::encode(&receipts);
|
||||||
total_bytes += receipts_bytes.len();
|
total_bytes += receipts_bytes.len();
|
||||||
if total_bytes > payload_soft_limit {
|
if total_bytes > PAYLOAD_SOFT_LIMIT {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
data.append(&mut receipts_bytes);
|
data.append(&mut receipts_bytes);
|
||||||
|
@ -46,8 +46,6 @@ pub trait SyncIo {
|
|||||||
}
|
}
|
||||||
/// Returns information on p2p session
|
/// Returns information on p2p session
|
||||||
fn peer_session_info(&self, peer_id: PeerId) -> Option<SessionInfo>;
|
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.
|
/// Maximum mutually supported version of a gien protocol.
|
||||||
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8;
|
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8;
|
||||||
/// Returns if the chain block queue empty
|
/// Returns if the chain block queue empty
|
||||||
@ -58,8 +56,6 @@ pub trait SyncIo {
|
|||||||
fn is_expired(&self) -> bool;
|
fn is_expired(&self) -> bool;
|
||||||
/// Return sync overlay
|
/// Return sync overlay
|
||||||
fn chain_overlay(&self) -> &RwLock<HashMap<BlockNumber, Bytes>>;
|
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
|
/// Wraps `NetworkContext` and the blockchain client
|
||||||
@ -125,12 +121,6 @@ impl<'s> SyncIo for NetSyncIo<'s> {
|
|||||||
self.network.is_expired()
|
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 {
|
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
|
||||||
self.network
|
self.network
|
||||||
.protocol_version(*protocol, peer_id)
|
.protocol_version(*protocol, peer_id)
|
||||||
@ -140,8 +130,4 @@ impl<'s> SyncIo for NetSyncIo<'s> {
|
|||||||
fn peer_version(&self, peer_id: PeerId) -> ClientVersion {
|
fn peer_version(&self, peer_id: PeerId) -> ClientVersion {
|
||||||
self.network.peer_client_version(peer_id)
|
self.network.peer_client_version(peer_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn payload_soft_limit(&self) -> usize {
|
|
||||||
self.network.payload_soft_limit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -168,25 +168,17 @@ where
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eth_protocol_version(&self, _peer: PeerId) -> u8 {
|
|
||||||
ETH_PROTOCOL_VERSION_64.0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
|
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
|
||||||
if protocol == &PAR_PROTOCOL {
|
if protocol == &PAR_PROTOCOL {
|
||||||
PAR_PROTOCOL_VERSION_2.0
|
PAR_PROTOCOL_VERSION_2.0
|
||||||
} else {
|
} else {
|
||||||
self.eth_protocol_version(peer_id)
|
ETH_PROTOCOL_VERSION_64.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chain_overlay(&self) -> &RwLock<HashMap<BlockNumber, Bytes>> {
|
fn chain_overlay(&self) -> &RwLock<HashMap<BlockNumber, Bytes>> {
|
||||||
&self.overlay
|
&self.overlay
|
||||||
}
|
}
|
||||||
|
|
||||||
fn payload_soft_limit(&self) -> usize {
|
|
||||||
100_000
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mock for emulution of async run of new blocks
|
/// Mock for emulution of async run of new blocks
|
||||||
|
@ -35,7 +35,6 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use connection::PAYLOAD_SOFT_LIMIT;
|
|
||||||
use discovery::{Discovery, NodeEntry, TableUpdates, MAX_DATAGRAM_SIZE};
|
use discovery::{Discovery, NodeEntry, TableUpdates, MAX_DATAGRAM_SIZE};
|
||||||
use io::*;
|
use io::*;
|
||||||
use ip_utils::{map_external_address, select_public_address};
|
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))
|
.map(|node| self.reserved_peers.contains(&node))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn payload_soft_limit(&self) -> usize {
|
|
||||||
PAYLOAD_SOFT_LIMIT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shared host information
|
/// Shared host information
|
||||||
|
@ -113,6 +113,8 @@ mod session;
|
|||||||
pub use host::NetworkContext;
|
pub use host::NetworkContext;
|
||||||
pub use service::NetworkService;
|
pub use service::NetworkService;
|
||||||
|
|
||||||
|
pub use connection::PAYLOAD_SOFT_LIMIT;
|
||||||
|
|
||||||
pub use io::TimerToken;
|
pub use io::TimerToken;
|
||||||
pub use node_table::{validate_node_url, NodeId};
|
pub use node_table::{validate_node_url, NodeId};
|
||||||
|
|
||||||
|
@ -320,9 +320,6 @@ pub trait NetworkContext {
|
|||||||
|
|
||||||
/// Returns whether the given peer ID is a reserved peer.
|
/// Returns whether the given peer ID is a reserved peer.
|
||||||
fn is_reserved_peer(&self, peer: PeerId) -> bool;
|
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
|
impl<'a, T> NetworkContext for &'a T
|
||||||
@ -382,10 +379,6 @@ where
|
|||||||
fn is_reserved_peer(&self, peer: PeerId) -> bool {
|
fn is_reserved_peer(&self, peer: PeerId) -> bool {
|
||||||
(**self).is_reserved_peer(peer)
|
(**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.
|
/// Network IO protocol handler. This needs to be implemented for each new subprotocol.
|
||||||
|
Loading…
Reference in New Issue
Block a user