mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +00:00
Fix misc PeerDAS todos (#6862)
Address misc PeerDAS TODOs that are not too big for a dedicated PR I'll justify each TODO on an inlined comment
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::sync::network_context::{
|
||||
DataColumnsByRootRequestId, DataColumnsByRootSingleBlockRequest,
|
||||
};
|
||||
|
||||
use beacon_chain::validator_monitor::timestamp_now;
|
||||
use beacon_chain::BeaconChainTypes;
|
||||
use fnv::FnvHashMap;
|
||||
use lighthouse_network::service::api_types::{CustodyId, DataColumnsByRootRequester};
|
||||
@@ -61,7 +61,8 @@ struct ActiveBatchColumnsRequest {
|
||||
indices: Vec<ColumnIndex>,
|
||||
}
|
||||
|
||||
pub type CustodyRequestResult<E> = Result<Option<(DataColumnSidecarList<E>, PeerGroup)>, Error>;
|
||||
pub type CustodyRequestResult<E> =
|
||||
Result<Option<(DataColumnSidecarList<E>, PeerGroup, Duration)>, Error>;
|
||||
|
||||
impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
|
||||
pub(crate) fn new(
|
||||
@@ -102,8 +103,6 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
|
||||
resp: RpcResponseResult<DataColumnSidecarList<T::EthSpec>>,
|
||||
cx: &mut SyncNetworkContext<T>,
|
||||
) -> CustodyRequestResult<T::EthSpec> {
|
||||
// TODO(das): Should downscore peers for verify errors here
|
||||
|
||||
let Some(batch_request) = self.active_batch_columns_requests.get_mut(&req_id) else {
|
||||
warn!(self.log,
|
||||
"Received custody column response for unrequested index";
|
||||
@@ -115,7 +114,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
|
||||
};
|
||||
|
||||
match resp {
|
||||
Ok((data_columns, _seen_timestamp)) => {
|
||||
Ok((data_columns, seen_timestamp)) => {
|
||||
debug!(self.log,
|
||||
"Custody column download success";
|
||||
"id" => ?self.custody_id,
|
||||
@@ -141,7 +140,12 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
|
||||
.ok_or(Error::BadState("unknown column_index".to_owned()))?;
|
||||
|
||||
if let Some(data_column) = data_columns.remove(column_index) {
|
||||
column_request.on_download_success(req_id, peer_id, data_column)?;
|
||||
column_request.on_download_success(
|
||||
req_id,
|
||||
peer_id,
|
||||
data_column,
|
||||
seen_timestamp,
|
||||
)?;
|
||||
} else {
|
||||
// Peer does not have the requested data.
|
||||
// TODO(das) do not consider this case a success. We know for sure the block has
|
||||
@@ -204,20 +208,23 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
|
||||
if self.column_requests.values().all(|r| r.is_downloaded()) {
|
||||
// All requests have completed successfully.
|
||||
let mut peers = HashMap::<PeerId, Vec<usize>>::new();
|
||||
let mut seen_timestamps = vec![];
|
||||
let columns = std::mem::take(&mut self.column_requests)
|
||||
.into_values()
|
||||
.map(|request| {
|
||||
let (peer, data_column) = request.complete()?;
|
||||
let (peer, data_column, seen_timestamp) = request.complete()?;
|
||||
peers
|
||||
.entry(peer)
|
||||
.or_default()
|
||||
.push(data_column.index as usize);
|
||||
seen_timestamps.push(seen_timestamp);
|
||||
Ok(data_column)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
let peer_group = PeerGroup::from_set(peers);
|
||||
return Ok(Some((columns, peer_group)));
|
||||
let max_seen_timestamp = seen_timestamps.into_iter().max().unwrap_or(timestamp_now());
|
||||
return Ok(Some((columns, peer_group, max_seen_timestamp)));
|
||||
}
|
||||
|
||||
let mut columns_to_request_by_peer = HashMap::<PeerId, Vec<ColumnIndex>>::new();
|
||||
@@ -335,7 +342,7 @@ struct ColumnRequest<E: EthSpec> {
|
||||
enum Status<E: EthSpec> {
|
||||
NotStarted(Instant),
|
||||
Downloading(DataColumnsByRootRequestId),
|
||||
Downloaded(PeerId, Arc<DataColumnSidecar<E>>),
|
||||
Downloaded(PeerId, Arc<DataColumnSidecar<E>>, Duration),
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ColumnRequest<E> {
|
||||
@@ -404,6 +411,7 @@ impl<E: EthSpec> ColumnRequest<E> {
|
||||
req_id: DataColumnsByRootRequestId,
|
||||
peer_id: PeerId,
|
||||
data_column: Arc<DataColumnSidecar<E>>,
|
||||
seen_timestamp: Duration,
|
||||
) -> Result<(), Error> {
|
||||
match &self.status {
|
||||
Status::Downloading(expected_req_id) => {
|
||||
@@ -413,7 +421,7 @@ impl<E: EthSpec> ColumnRequest<E> {
|
||||
req_id,
|
||||
});
|
||||
}
|
||||
self.status = Status::Downloaded(peer_id, data_column);
|
||||
self.status = Status::Downloaded(peer_id, data_column, seen_timestamp);
|
||||
Ok(())
|
||||
}
|
||||
other => Err(Error::BadState(format!(
|
||||
@@ -422,9 +430,11 @@ impl<E: EthSpec> ColumnRequest<E> {
|
||||
}
|
||||
}
|
||||
|
||||
fn complete(self) -> Result<(PeerId, Arc<DataColumnSidecar<E>>), Error> {
|
||||
fn complete(self) -> Result<(PeerId, Arc<DataColumnSidecar<E>>, Duration), Error> {
|
||||
match self.status {
|
||||
Status::Downloaded(peer_id, data_column) => Ok((peer_id, data_column)),
|
||||
Status::Downloaded(peer_id, data_column, seen_timestamp) => {
|
||||
Ok((peer_id, data_column, seen_timestamp))
|
||||
}
|
||||
other => Err(Error::BadState(format!(
|
||||
"bad state complete expected Downloaded got {other:?}"
|
||||
))),
|
||||
|
||||
Reference in New Issue
Block a user