mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: add display to FromEngine and other messages (#10986)
This commit is contained in:
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user