mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Sync active request byrange ids logs (#6914)
- Re-opened PR from https://github.com/sigp/lighthouse/pull/6869 Writing and running tests I noted that the sync RPC requests are very verbose now. `DataColumnsByRootRequestId { id: 123, requester: Custody(CustodyId { requester: CustodyRequester(SingleLookupReqId { req_id: 121, lookup_id: 101 }) }) }` Since this Id is logged rather often I believe there's value in 1. Making them more succinct for log verbosity 2. Make them a string that's easy to copy and work with elastic Write custom `Display` implementations to render Ids in a more DX format _ DataColumnsByRootRequestId with a block lookup_ ``` 123/Custody/121/Lookup/101 ``` _DataColumnsByRangeRequestId_ ``` 123/122/RangeSync/0/5492900659401505034 ``` - This one will be shorter after https://github.com/sigp/lighthouse/pull/6868 Also made the logs format and text consistent across all methods
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use libp2p::swarm::ConnectionId;
|
||||
use types::{
|
||||
BlobSidecar, DataColumnSidecar, Epoch, EthSpec, Hash256, LightClientBootstrap,
|
||||
LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, SignedBeaconBlock,
|
||||
};
|
||||
|
||||
use crate::rpc::{
|
||||
methods::{ResponseTermination, RpcResponse, RpcSuccessResponse, StatusMessage},
|
||||
SubstreamId,
|
||||
};
|
||||
use libp2p::swarm::ConnectionId;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::sync::Arc;
|
||||
use types::{
|
||||
BlobSidecar, DataColumnSidecar, Epoch, EthSpec, Hash256, LightClientBootstrap,
|
||||
LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, SignedBeaconBlock,
|
||||
};
|
||||
|
||||
/// Identifier of requests sent by a peer.
|
||||
pub type PeerRequestId = (ConnectionId, SubstreamId);
|
||||
@@ -235,9 +234,108 @@ impl slog::Value for RequestId {
|
||||
}
|
||||
}
|
||||
|
||||
// This custom impl reduces log boilerplate not printing `DataColumnsByRootRequestId` on each id log
|
||||
impl std::fmt::Display for DataColumnsByRootRequestId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} {:?}", self.id, self.requester)
|
||||
macro_rules! impl_display {
|
||||
($structname: ty, $format: literal, $($field:ident),*) => {
|
||||
impl Display for $structname {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, $format, $(self.$field,)*)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Since each request Id is deeply nested with various types, if rendered with Debug on logs they
|
||||
// take too much visual space. This custom Display implementations make the overall Id short while
|
||||
// not losing information
|
||||
impl_display!(BlocksByRangeRequestId, "{}/{}", id, parent_request_id);
|
||||
impl_display!(BlobsByRangeRequestId, "{}/{}", id, parent_request_id);
|
||||
impl_display!(DataColumnsByRangeRequestId, "{}/{}", id, parent_request_id);
|
||||
impl_display!(ComponentsByRangeRequestId, "{}/{}", id, requester);
|
||||
impl_display!(DataColumnsByRootRequestId, "{}/{}", id, requester);
|
||||
impl_display!(SingleLookupReqId, "{}/Lookup/{}", req_id, lookup_id);
|
||||
impl_display!(CustodyId, "{}", requester);
|
||||
impl_display!(SamplingId, "{}/{}", sampling_request_id, id);
|
||||
|
||||
impl Display for DataColumnsByRootRequester {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Custody(id) => write!(f, "Custody/{id}"),
|
||||
Self::Sampling(id) => write!(f, "Sampling/{id}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for CustodyRequester {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for RangeRequestId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::RangeSync { chain_id, batch_id } => write!(f, "RangeSync/{batch_id}/{chain_id}"),
|
||||
Self::BackfillSync { batch_id } => write!(f, "BackfillSync/{batch_id}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SamplingRequestId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SamplingRequester {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::ImportedBlock(block) => write!(f, "ImportedBlock/{block}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn display_id_data_columns_by_root_custody() {
|
||||
let id = DataColumnsByRootRequestId {
|
||||
id: 123,
|
||||
requester: DataColumnsByRootRequester::Custody(CustodyId {
|
||||
requester: CustodyRequester(SingleLookupReqId {
|
||||
req_id: 121,
|
||||
lookup_id: 101,
|
||||
}),
|
||||
}),
|
||||
};
|
||||
assert_eq!(format!("{id}"), "123/Custody/121/Lookup/101");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_id_data_columns_by_root_sampling() {
|
||||
let id = DataColumnsByRootRequestId {
|
||||
id: 123,
|
||||
requester: DataColumnsByRootRequester::Sampling(SamplingId {
|
||||
id: SamplingRequester::ImportedBlock(Hash256::ZERO),
|
||||
sampling_request_id: SamplingRequestId(101),
|
||||
}),
|
||||
};
|
||||
assert_eq!(format!("{id}"), "123/Sampling/101/ImportedBlock/0x0000000000000000000000000000000000000000000000000000000000000000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_id_data_columns_by_range() {
|
||||
let id = DataColumnsByRangeRequestId {
|
||||
id: 123,
|
||||
parent_request_id: ComponentsByRangeRequestId {
|
||||
id: 122,
|
||||
requester: RangeRequestId::RangeSync {
|
||||
chain_id: 54,
|
||||
batch_id: Epoch::new(0),
|
||||
},
|
||||
},
|
||||
};
|
||||
assert_eq!(format!("{id}"), "123/122/RangeSync/0/54");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user