Skip to content

Commit

Permalink
chore: remove usage of RichBlock (#10538)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 authored Aug 26, 2024
1 parent c4a2313 commit 4138b52
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 116 deletions.
14 changes: 7 additions & 7 deletions crates/consensus/debug-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloy_eips::eip2718::Encodable2718;
use reth_node_api::EngineTypes;
use reth_node_core::{
primitives::B256,
rpc::types::{BlockTransactions, ExecutionPayloadV2, ExecutionPayloadV3, RichBlock},
rpc::types::{Block, BlockTransactions, ExecutionPayloadV2, ExecutionPayloadV3},
};
use reth_rpc_builder::auth::AuthServerHandle;
use reth_rpc_types::ExecutionPayloadV1;
Expand All @@ -19,10 +19,10 @@ pub trait BlockProvider: Send + Sync + 'static {
/// Runs a block provider to send new blocks to the given sender.
///
/// Note: This is expected to be spawned in a separate task.
fn subscribe_blocks(&self, tx: mpsc::Sender<RichBlock>) -> impl Future<Output = ()> + Send;
fn subscribe_blocks(&self, tx: mpsc::Sender<Block>) -> impl Future<Output = ()> + Send;

/// Get a past block by number.
fn get_block(&self, block_number: u64) -> impl Future<Output = eyre::Result<RichBlock>> + Send;
fn get_block(&self, block_number: u64) -> impl Future<Output = eyre::Result<Block>> + Send;

/// Get previous block hash using previous block hash buffer. If it isn't available (buffer
/// started more recently than `offset`), fetch it using `get_block`.
Expand Down Expand Up @@ -78,7 +78,7 @@ impl<P: BlockProvider + Clone> DebugConsensusClient<P> {
let mut previous_block_hashes = AllocRingBuffer::new(64);

let mut block_stream = {
let (tx, rx) = mpsc::channel::<RichBlock>(64);
let (tx, rx) = mpsc::channel::<Block>(64);
let block_provider = self.block_provider.clone();
tokio::spawn(async move {
block_provider.subscribe_blocks(tx).await;
Expand All @@ -87,7 +87,7 @@ impl<P: BlockProvider + Clone> DebugConsensusClient<P> {
};

while let Some(block) = block_stream.recv().await {
let payload = rich_block_to_execution_payload_v3(block);
let payload = block_to_execution_payload_v3(block);

let block_hash = payload.block_hash();
let block_number = payload.block_number();
Expand Down Expand Up @@ -170,9 +170,9 @@ impl ExecutionNewPayload {
}
}

/// Convert a rich block from RPC / Etherscan to params for an execution client's "new payload"
/// Convert a block from RPC / Etherscan to params for an execution client's "new payload"
/// method. Assumes that the block contains full transactions.
pub fn rich_block_to_execution_payload_v3(block: RichBlock) -> ExecutionNewPayload {
pub fn block_to_execution_payload_v3(block: Block) -> ExecutionNewPayload {
let transactions = match &block.transactions {
BlockTransactions::Full(txs) => txs.clone(),
// Empty array gets deserialized as BlockTransactions::Hashes.
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/debug-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
mod client;
mod providers;

pub use client::{rich_block_to_execution_payload_v3, BlockProvider, DebugConsensusClient};
pub use client::{block_to_execution_payload_v3, BlockProvider, DebugConsensusClient};
pub use providers::{EtherscanBlockProvider, RpcBlockProvider};
13 changes: 5 additions & 8 deletions crates/consensus/debug-client/src/providers/etherscan.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::BlockProvider;
use alloy_eips::BlockNumberOrTag;
use reqwest::Client;
use reth_node_core::rpc::types::RichBlock;
use reth_node_core::rpc::types::Block;
use reth_tracing::tracing::warn;
use serde::Deserialize;
use std::time::Duration;
Expand Down Expand Up @@ -31,10 +31,7 @@ impl EtherscanBlockProvider {
/// Load block using Etherscan API. Note: only `BlockNumberOrTag::Latest`,
/// `BlockNumberOrTag::Earliest`, `BlockNumberOrTag::Pending`, `BlockNumberOrTag::Number(u64)`
/// are supported.
pub async fn load_block(
&self,
block_number_or_tag: BlockNumberOrTag,
) -> eyre::Result<RichBlock> {
pub async fn load_block(&self, block_number_or_tag: BlockNumberOrTag) -> eyre::Result<Block> {
let block: EtherscanBlockResponse = self
.http_client
.get(&self.base_url)
Expand All @@ -54,7 +51,7 @@ impl EtherscanBlockProvider {
}

impl BlockProvider for EtherscanBlockProvider {
async fn subscribe_blocks(&self, tx: mpsc::Sender<RichBlock>) {
async fn subscribe_blocks(&self, tx: mpsc::Sender<Block>) {
let mut last_block_number: Option<u64> = None;
let mut interval = interval(self.interval);
loop {
Expand All @@ -80,12 +77,12 @@ impl BlockProvider for EtherscanBlockProvider {
}
}

async fn get_block(&self, block_number: u64) -> eyre::Result<RichBlock> {
async fn get_block(&self, block_number: u64) -> eyre::Result<Block> {
self.load_block(BlockNumberOrTag::Number(block_number)).await
}
}

#[derive(Deserialize, Debug)]
struct EtherscanBlockResponse {
result: RichBlock,
result: Block,
}
13 changes: 6 additions & 7 deletions crates/consensus/debug-client/src/providers/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::BlockProvider;
use alloy_eips::BlockNumberOrTag;
use alloy_provider::{Provider, ProviderBuilder};
use futures::StreamExt;
use reth_node_core::rpc::types::RichBlock;
use reth_node_core::rpc::types::Block;
use reth_rpc_types::BlockTransactionsKind;
use tokio::sync::mpsc::Sender;

Expand All @@ -20,7 +20,7 @@ impl RpcBlockProvider {
}

impl BlockProvider for RpcBlockProvider {
async fn subscribe_blocks(&self, tx: Sender<RichBlock>) {
async fn subscribe_blocks(&self, tx: Sender<Block>) {
let ws_provider = ProviderBuilder::new()
.on_builtin(&self.ws_rpc_url)
.await
Expand All @@ -37,23 +37,22 @@ impl BlockProvider for RpcBlockProvider {
.await
.expect("failed to get block")
.expect("block not found");
if tx.send(full_block.into()).await.is_err() {
if tx.send(full_block).await.is_err() {
// channel closed
break;
}
}
}

async fn get_block(&self, block_number: u64) -> eyre::Result<RichBlock> {
async fn get_block(&self, block_number: u64) -> eyre::Result<Block> {
let ws_provider = ProviderBuilder::new()
.on_builtin(&self.ws_rpc_url)
.await
.expect("failed to create WS provider");
let block: RichBlock = ws_provider
let block: Block = ws_provider
.get_block_by_number(BlockNumberOrTag::Number(block_number), true)
.await?
.ok_or_else(|| eyre::eyre!("block not found by number {}", block_number))?
.into();
.ok_or_else(|| eyre::eyre!("block not found by number {}", block_number))?;
Ok(block)
}
}
4 changes: 2 additions & 2 deletions crates/rpc/rpc-api/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reth_rpc_types::{
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace,
TraceResult,
},
Bundle, RichBlock, StateContext, TransactionRequest,
Block, Bundle, StateContext, TransactionRequest,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -37,7 +37,7 @@ pub trait DebugApi {

/// Returns an array of recent bad blocks that the client has seen on the network.
#[method(name = "getBadBlocks")]
async fn bad_blocks(&self) -> RpcResult<Vec<RichBlock>>;
async fn bad_blocks(&self) -> RpcResult<Vec<Block>>;

/// Returns the structured logs created during the execution of EVM between two blocks
/// (excluding start) as a JSON object.
Expand Down
Loading

0 comments on commit 4138b52

Please sign in to comment.