chore: add display to FromEngine and other messages (#10986)

This commit is contained in:
Matthias Seitz
2024-09-18 15:11:38 +02:00
committed by GitHub
parent 5cd603d346
commit 94c15c0074
3 changed files with 54 additions and 1 deletions

View File

@ -8,6 +8,7 @@ use reth_rpc_types::engine::{
ForkchoiceUpdateError, ForkchoiceUpdated, PayloadId, PayloadStatus, PayloadStatusEnum,
};
use std::{
fmt::Display,
future::Future,
pin::Pin,
task::{ready, Context, Poll},
@ -160,3 +161,31 @@ pub enum BeaconEngineMessage<Engine: EngineTypes> {
/// Message with exchanged transition configuration.
TransitionConfigurationExchanged,
}
impl<Engine: EngineTypes> Display for BeaconEngineMessage<Engine> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NewPayload { payload, .. } => {
write!(
f,
"NewPayload(parent: {}, number: {}, hash: {})",
payload.parent_hash(),
payload.block_number(),
payload.block_hash()
)
}
Self::ForkchoiceUpdated { state, payload_attrs, .. } => {
// we don't want to print the entire payload attributes, because for OP this
// includes all txs
write!(
f,
"ForkchoiceUpdated {{ state: {state:?}, has_payload_attributes: {} }}",
payload_attrs.is_some()
)
}
Self::TransitionConfigurationExchanged => {
write!(f, "TransitionConfigurationExchanged")
}
}
}
}

View File

@ -12,6 +12,7 @@ use reth_engine_primitives::EngineTypes;
use reth_primitives::{SealedBlockWithSenders, B256};
use std::{
collections::HashSet,
fmt::Display,
sync::mpsc::Sender,
task::{ready, Context, Poll},
};
@ -228,6 +229,17 @@ pub enum EngineApiRequest<T: EngineTypes> {
InsertExecutedBlock(ExecutedBlock),
}
impl<T: EngineTypes> Display for EngineApiRequest<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Beacon(msg) => msg.fmt(f),
Self::InsertExecutedBlock(block) => {
write!(f, "InsertExecutedBlock({:?})", block.block().num_hash())
}
}
}
}
impl<T: EngineTypes> From<BeaconEngineMessage<T>> for EngineApiRequest<T> {
fn from(msg: BeaconEngineMessage<T>) -> Self {
Self::Beacon(msg)
@ -276,6 +288,18 @@ pub enum FromEngine<Req> {
DownloadedBlocks(Vec<SealedBlockWithSenders>),
}
impl<Req: Display> Display for FromEngine<Req> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Event(ev) => write!(f, "Event({ev:?})"),
Self::Request(req) => write!(f, "Request({req})"),
Self::DownloadedBlocks(blocks) => {
write!(f, "DownloadedBlocks({} blocks)", blocks.len())
}
}
}
}
impl<Req> From<FromOrchestrator> for FromEngine<Req> {
fn from(event: FromOrchestrator) -> Self {
Self::Event(event)

View File

@ -631,7 +631,7 @@ where
loop {
match self.try_recv_engine_message() {
Ok(Some(msg)) => {
debug!(target: "engine::tree", ?msg, "received new engine message");
debug!(target: "engine::tree", %msg, "received new engine message");
if let Err(fatal) = self.on_engine_message(msg) {
error!(target: "engine::tree", %fatal, "insert block fatal error");
return