mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
docs: enhance DebugNode trait documentation (#16872)
Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
This commit is contained in:
@@ -7,18 +7,78 @@ use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider,
|
||||
use reth_node_api::{BlockTy, FullNodeComponents};
|
||||
use std::sync::Arc;
|
||||
use tracing::info;
|
||||
/// [`Node`] extension with support for debugging utilities, see [`DebugNodeLauncher`] for more
|
||||
/// context.
|
||||
|
||||
/// [`Node`] extension with support for debugging utilities.
|
||||
///
|
||||
/// This trait provides additional necessary conversion from RPC block type to the node's
|
||||
/// primitive block type, e.g. `alloy_rpc_types_eth::Block` to the node's internal block
|
||||
/// representation.
|
||||
///
|
||||
/// This is used in conjunction with the [`DebugNodeLauncher`] to enable debugging features such as:
|
||||
///
|
||||
/// - **Etherscan Integration**: Use Etherscan as a consensus client to follow the chain and submit
|
||||
/// blocks to the local engine.
|
||||
/// - **RPC Consensus Client**: Connect to an external RPC endpoint to fetch blocks and submit them
|
||||
/// to the local engine to follow the chain.
|
||||
///
|
||||
/// See [`DebugNodeLauncher`] for the launcher that enables these features.
|
||||
///
|
||||
/// # Implementation
|
||||
///
|
||||
/// To implement this trait, you need to:
|
||||
/// 1. Define the RPC block type (typically `alloy_rpc_types_eth::Block`)
|
||||
/// 2. Implement the conversion from RPC format to your primitive block type
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```ignore
|
||||
/// impl<N: FullNodeComponents<Types = Self>> DebugNode<N> for MyNode {
|
||||
/// type RpcBlock = alloy_rpc_types_eth::Block;
|
||||
///
|
||||
/// fn rpc_to_primitive_block(rpc_block: Self::RpcBlock) -> BlockTy<Self> {
|
||||
/// // Convert from RPC format to primitive format by converting the transactions
|
||||
/// rpc_block.into_consensus().convert_transactions()
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub trait DebugNode<N: FullNodeComponents>: Node<N> {
|
||||
/// RPC block type. Used by [`DebugConsensusClient`] to fetch blocks and submit them to the
|
||||
/// engine.
|
||||
/// engine. This is inteded to match the block format returned by the external RPC endpoint.
|
||||
type RpcBlock: Serialize + DeserializeOwned + 'static;
|
||||
|
||||
/// Converts an RPC block to a primitive block.
|
||||
///
|
||||
/// This method handles the conversion between the RPC block format and the internal primitive
|
||||
/// block format used by the node's consensus engine.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// For Ethereum nodes, this typically converts from `alloy_rpc_types_eth::Block`
|
||||
/// to the node's internal block representation.
|
||||
fn rpc_to_primitive_block(rpc_block: Self::RpcBlock) -> BlockTy<Self>;
|
||||
}
|
||||
|
||||
/// Node launcher with support for launching various debugging utilities.
|
||||
///
|
||||
/// This launcher wraps an existing launcher and adds debugging capabilities when
|
||||
/// certain debug flags are enabled. It provides two main debugging features:
|
||||
///
|
||||
/// ## RPC Consensus Client
|
||||
///
|
||||
/// When `--debug.rpc-consensus-ws <URL>` is provided, the launcher will:
|
||||
/// - Connect to an external RPC `WebSocket` endpoint
|
||||
/// - Fetch blocks from that endpoint
|
||||
/// - Submit them to the local engine for execution
|
||||
/// - Useful for testing engine behavior with real network data
|
||||
///
|
||||
/// ## Etherscan Consensus Client
|
||||
///
|
||||
/// When `--debug.etherscan [URL]` is provided, the launcher will:
|
||||
/// - Use Etherscan API as a consensus client
|
||||
/// - Fetch recent blocks from Etherscan
|
||||
/// - Submit them to the local engine
|
||||
/// - Requires `ETHERSCAN_API_KEY` environment variable
|
||||
/// - Falls back to default Etherscan URL for the chain if URL not provided
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DebugNodeLauncher<L = EngineNodeLauncher> {
|
||||
inner: L,
|
||||
@@ -66,7 +126,6 @@ where
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: migrate to devmode with https://github.com/paradigmxyz/reth/issues/10104
|
||||
if let Some(maybe_custom_etherscan_url) = config.debug.etherscan.clone() {
|
||||
info!(target: "reth::cli", "Using etherscan as consensus client");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user