pub struct PeerHandler {
pub peer_table: PeerTable,
pub initiator: ActorRef<RLPxInitiator>,
}Expand description
An abstraction over the [Kademlia] containing logic to make requests to peers
Fields§
§peer_table: PeerTable§initiator: ActorRef<RLPxInitiator>Implementations§
Source§impl PeerHandler
impl PeerHandler
pub fn new( peer_table: PeerTable, initiator: ActorRef<RLPxInitiator>, ) -> PeerHandler
Sourcepub async fn eth_capable_peer_count(&self) -> usize
pub async fn eth_capable_peer_count(&self) -> usize
Number of peers known to the table that advertise the eth capabilities used for sync.
NOTE: this counts eth-capable peers regardless of whether they currently have a live
connection, so it can be greater than the number actually queryable via
get_random_peer (which requires a live connection). Used only for diagnostics; logged
as eth_capable_peers. Returns 0 on any peer-table error.
Sourcepub async fn request_block_headers(
&mut self,
start: u64,
sync_head: H256,
) -> Result<Option<Vec<BlockHeader>>, PeerHandlerError>
pub async fn request_block_headers( &mut self, start: u64, sync_head: H256, ) -> Result<Option<Vec<BlockHeader>>, PeerHandlerError>
Requests block headers from any suitable peer, starting from the start block hash towards either older or newer blocks depending on the order
Returns the block headers or None if:
- There are no available peers (the node just started up or was rejected by all other nodes)
- No peer returned a valid response in the given time and retry limits
Sourcepub async fn request_block_headers_from_hash(
&mut self,
start: H256,
order: BlockRequestOrder,
) -> Result<HeaderFetchOutcome, PeerHandlerError>
pub async fn request_block_headers_from_hash( &mut self, start: H256, order: BlockRequestOrder, ) -> Result<HeaderFetchOutcome, PeerHandlerError>
Requests block headers from any suitable peer, starting from the start block hash towards either older or newer blocks depending on the order
- No peer returned a valid response in the given time and retry limits Since request_block_headers brought problems in cases of reorg seen in this pr https://github.com/lambdaclass/ethrex/pull/4028, we have this other function to request block headers only for full sync.
Sourcepub async fn request_block_bodies(
&mut self,
block_headers: &[BlockHeader],
) -> Result<Option<Vec<BlockBody>>, PeerHandlerError>
pub async fn request_block_bodies( &mut self, block_headers: &[BlockHeader], ) -> Result<Option<Vec<BlockBody>>, PeerHandlerError>
Requests block bodies from any suitable peer given their block headers and validates them Returns the requested block bodies or None if:
- There are no available peers (the node just started up or was rejected by all other nodes)
- No peer returned a valid response in the given time and retry limits
- The block bodies are invalid given the block headers
Sourcepub async fn request_block_access_lists(
&mut self,
block_hashes: &[H256],
) -> Result<Option<Vec<Option<BlockAccessList>>>, PeerHandlerError>
pub async fn request_block_access_lists( &mut self, block_hashes: &[H256], ) -> Result<Option<Vec<Option<BlockAccessList>>>, PeerHandlerError>
Requests block access lists from a peer that supports eth/71. Returns a vector of optional BALs (one per requested block hash) or None if:
- There are no available eth/71 peers
- The peer did not respond in time
Sourcepub async fn read_peer_diagnostics(&self) -> Vec<PeerDiagnostics>
pub async fn read_peer_diagnostics(&self) -> Vec<PeerDiagnostics>
Returns diagnostic snapshots for all connected peers (scores, requests, eligibility).
Sourcepub async fn read_connected_peers(&mut self) -> Vec<PeerData>
pub async fn read_connected_peers(&mut self) -> Vec<PeerData>
Returns the PeerData for each connected Peer
pub async fn count_total_peers(&mut self) -> Result<usize, PeerHandlerError>
Sourcepub async fn get_block_header(
&mut self,
connection: &mut PeerConnection,
_permit: RequestPermit,
block_number: u64,
) -> Result<Option<BlockHeader>, PeerHandlerError>
pub async fn get_block_header( &mut self, connection: &mut PeerConnection, _permit: RequestPermit, block_number: u64, ) -> Result<Option<BlockHeader>, PeerHandlerError>
Requests a single block header by number from an already-selected peer.
Consumes a RequestPermit reserved by the caller at peer selection
time; the permit drops when this function returns, releasing the slot.
Trait Implementations§
Source§impl Clone for PeerHandler
impl Clone for PeerHandler
Source§fn clone(&self) -> PeerHandler
fn clone(&self) -> PeerHandler
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for PeerHandler
impl !UnwindSafe for PeerHandler
impl Freeze for PeerHandler
impl Send for PeerHandler
impl Sync for PeerHandler
impl Unpin for PeerHandler
impl UnsafeUnpin for PeerHandler
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.