diff --git a/crates/rbuilder/src/live_builder/mod.rs b/crates/rbuilder/src/live_builder/mod.rs index 0d748584..6725e8c7 100644 --- a/crates/rbuilder/src/live_builder/mod.rs +++ b/crates/rbuilder/src/live_builder/mod.rs @@ -19,7 +19,9 @@ use crate::{ watchdog::spawn_watchdog_thread, }, telemetry::inc_active_slots, - utils::{error_storage::spawn_error_storage_writer, Signer}, + utils::{ + error_storage::spawn_error_storage_writer, provider_head_state::ProviderHeadState, Signer, + }, }; use ahash::HashSet; use alloy_consensus::Header; @@ -218,6 +220,8 @@ where ?current_time, payload_timestamp = ?payload.timestamp(), ?time_to_slot, + parent_hash = ?payload.parent_block_hash(), + provider_head_state = ?ProviderHeadState::new(&self.provider), "Received payload, time till slot timestamp", ); @@ -225,6 +229,7 @@ where if time_until_slot_end.is_negative() { warn!( slot = payload.slot(), + parent_hash = ?payload.parent_block_hash(), "Slot already ended, skipping block building" ); continue; @@ -238,7 +243,7 @@ where { Ok(header) => header, Err(err) => { - warn!("Failed to get parent header for new slot: {:?}", err); + warn!(parent_hash = ?payload.parent_block_hash(),"Failed to get parent header for new slot: {:?}", err); continue; } } @@ -247,6 +252,7 @@ where debug!( slot = payload.slot(), block = payload.block(), + parent_hash = ?payload.parent_block_hash(), "Got header for slot" ); diff --git a/crates/rbuilder/src/utils/mod.rs b/crates/rbuilder/src/utils/mod.rs index 768ca0dd..346742cf 100644 --- a/crates/rbuilder/src/utils/mod.rs +++ b/crates/rbuilder/src/utils/mod.rs @@ -9,6 +9,7 @@ pub mod reconnect; mod test_data_generator; mod tx_signer; +pub mod provider_head_state; #[cfg(test)] pub mod test_utils; pub mod tracing; diff --git a/crates/rbuilder/src/utils/provider_head_state.rs b/crates/rbuilder/src/utils/provider_head_state.rs new file mode 100644 index 00000000..a73df854 --- /dev/null +++ b/crates/rbuilder/src/utils/provider_head_state.rs @@ -0,0 +1,43 @@ +//! Mod for gathering info about reth's head. + +use alloy_primitives::BlockNumber; +use reth_errors::ProviderResult; +use reth_provider::{BlockHashReader, BlockNumReader}; +use revm_primitives::B256; + +/// For debugging. Results of asking for block number + hash to a BlockHashReader+BlockNumReader +#[derive(Debug)] +pub struct ProviderHeadStateBlockHash { + /// Result of getting some (last/best) block number from the BlockNumReader + pub block_number: ProviderResult, + /// If block_number.is_ok -> Some(BlockHashReader::block_hash(block_number)) + pub block_hash: Option>>, +} + +impl ProviderHeadStateBlockHash { + pub fn new( + provider: &P, + block_number: ProviderResult, + ) -> Self { + Self { + block_number: block_number.clone(), + block_hash: block_number.map_or(None, |b| Some(provider.block_hash(b))), + } + } +} + +/// For debugging. Results of asking to the StateProviderFactory info about last_block and best block. +#[derive(Debug)] +pub struct ProviderHeadState { + pub last_block: ProviderHeadStateBlockHash, + pub best_block: ProviderHeadStateBlockHash, +} + +impl ProviderHeadState { + pub fn new(provider: &P) -> Self { + Self { + last_block: ProviderHeadStateBlockHash::new(provider, provider.last_block_number()), + best_block: ProviderHeadStateBlockHash::new(provider, provider.best_block_number()), + } + } +}