mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
processing peer refactor
This commit is contained in:
@@ -80,7 +80,7 @@ impl From<bool> for StreamTerminator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum ResponseType {
|
pub enum ResponseType {
|
||||||
Block,
|
Block,
|
||||||
Blob,
|
Blob,
|
||||||
@@ -815,15 +815,11 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let root = request_ref.requested_block_root;
|
let root = request_ref.requested_block_root;
|
||||||
let peer_id = match response_type {
|
let peer_id = request_ref.processing_peer(response_type);
|
||||||
ResponseType::Block => match request_ref.block_request_state.processing_peer() {
|
|
||||||
Ok(peer) => peer,
|
let peer_id = match peer_id {
|
||||||
Err(_) => return,
|
Ok(peer) => peer,
|
||||||
},
|
Err(_) => return,
|
||||||
ResponseType::Blob => match request_ref.blob_request_state.processing_peer() {
|
|
||||||
Ok(peer) => peer,
|
|
||||||
Err(_) => return,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let should_remove_lookup = match result {
|
let should_remove_lookup = match result {
|
||||||
@@ -924,16 +920,9 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
|
|||||||
return debug!(self.log, "Process response for a parent lookup request that was not found"; "chain_hash" => %chain_hash);
|
return debug!(self.log, "Process response for a parent lookup request that was not found"; "chain_hash" => %chain_hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
let peer_id = match response_type {
|
let peer_id = parent_lookup
|
||||||
ResponseType::Block => parent_lookup
|
.current_parent_request
|
||||||
.current_parent_request
|
.processing_peer(response_type);
|
||||||
.block_request_state
|
|
||||||
.processing_peer(),
|
|
||||||
ResponseType::Blob => parent_lookup
|
|
||||||
.current_parent_request
|
|
||||||
.blob_request_state
|
|
||||||
.processing_peer(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let peer_id = match peer_id {
|
let peer_id = match peer_id {
|
||||||
Ok(peer) => peer,
|
Ok(peer) => peer,
|
||||||
|
|||||||
@@ -321,28 +321,6 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
|
|||||||
Ok(blobs)
|
Ok(blobs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_block_processing_peer(&self, chain_hash: Hash256) -> Option<PeerId> {
|
|
||||||
if self.chain_hash == chain_hash {
|
|
||||||
return self
|
|
||||||
.current_parent_request
|
|
||||||
.block_request_state
|
|
||||||
.processing_peer()
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_blob_processing_peer(&self, chain_hash: Hash256) -> Option<PeerId> {
|
|
||||||
if self.chain_hash == chain_hash {
|
|
||||||
return self
|
|
||||||
.current_parent_request
|
|
||||||
.blob_request_state
|
|
||||||
.processing_peer()
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn failed_block_attempts(&self) -> u8 {
|
pub fn failed_block_attempts(&self) -> u8 {
|
||||||
self.current_parent_request.failed_attempts()
|
self.current_parent_request.failed_attempts()
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use strum::IntoStaticStr;
|
|||||||
use types::blob_sidecar::BlobIdentifier;
|
use types::blob_sidecar::BlobIdentifier;
|
||||||
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
|
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
|
||||||
|
|
||||||
use super::PeerShouldHave;
|
use super::{PeerShouldHave, ResponseType};
|
||||||
|
|
||||||
pub struct SingleBlockLookup<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> {
|
pub struct SingleBlockLookup<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> {
|
||||||
pub requested_block_root: Hash256,
|
pub requested_block_root: Hash256,
|
||||||
@@ -392,6 +392,13 @@ impl<const MAX_ATTEMPTS: u8, T: BeaconChainTypes> SingleBlockLookup<MAX_ATTEMPTS
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn processing_peer(&self, response_type: ResponseType) -> Result<PeerId, ()> {
|
||||||
|
match response_type {
|
||||||
|
ResponseType::Block => self.block_request_state.processing_peer(),
|
||||||
|
ResponseType::Blob => self.blob_request_state.processing_peer(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const MAX_ATTEMPTS: u8> SingleLookupRequestState<MAX_ATTEMPTS> {
|
impl<const MAX_ATTEMPTS: u8> SingleLookupRequestState<MAX_ATTEMPTS> {
|
||||||
|
|||||||
Reference in New Issue
Block a user