Skip to content

Commit 4138b52

Browse files
authored
chore: remove usage of RichBlock (#10538)
1 parent c4a2313 commit 4138b52

File tree

10 files changed

+90
-116
lines changed

10 files changed

+90
-116
lines changed

crates/consensus/debug-client/src/client.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use alloy_eips::eip2718::Encodable2718;
33
use reth_node_api::EngineTypes;
44
use reth_node_core::{
55
primitives::B256,
6-
rpc::types::{BlockTransactions, ExecutionPayloadV2, ExecutionPayloadV3, RichBlock},
6+
rpc::types::{Block, BlockTransactions, ExecutionPayloadV2, ExecutionPayloadV3},
77
};
88
use reth_rpc_builder::auth::AuthServerHandle;
99
use reth_rpc_types::ExecutionPayloadV1;
@@ -19,10 +19,10 @@ pub trait BlockProvider: Send + Sync + 'static {
1919
/// Runs a block provider to send new blocks to the given sender.
2020
///
2121
/// Note: This is expected to be spawned in a separate task.
22-
fn subscribe_blocks(&self, tx: mpsc::Sender<RichBlock>) -> impl Future<Output = ()> + Send;
22+
fn subscribe_blocks(&self, tx: mpsc::Sender<Block>) -> impl Future<Output = ()> + Send;
2323

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

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

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

8989
while let Some(block) = block_stream.recv().await {
90-
let payload = rich_block_to_execution_payload_v3(block);
90+
let payload = block_to_execution_payload_v3(block);
9191

9292
let block_hash = payload.block_hash();
9393
let block_number = payload.block_number();
@@ -170,9 +170,9 @@ impl ExecutionNewPayload {
170170
}
171171
}
172172

173-
/// Convert a rich block from RPC / Etherscan to params for an execution client's "new payload"
173+
/// Convert a block from RPC / Etherscan to params for an execution client's "new payload"
174174
/// method. Assumes that the block contains full transactions.
175-
pub fn rich_block_to_execution_payload_v3(block: RichBlock) -> ExecutionNewPayload {
175+
pub fn block_to_execution_payload_v3(block: Block) -> ExecutionNewPayload {
176176
let transactions = match &block.transactions {
177177
BlockTransactions::Full(txs) => txs.clone(),
178178
// Empty array gets deserialized as BlockTransactions::Hashes.

crates/consensus/debug-client/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
mod client;
1616
mod providers;
1717

18-
pub use client::{rich_block_to_execution_payload_v3, BlockProvider, DebugConsensusClient};
18+
pub use client::{block_to_execution_payload_v3, BlockProvider, DebugConsensusClient};
1919
pub use providers::{EtherscanBlockProvider, RpcBlockProvider};

crates/consensus/debug-client/src/providers/etherscan.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::BlockProvider;
22
use alloy_eips::BlockNumberOrTag;
33
use reqwest::Client;
4-
use reth_node_core::rpc::types::RichBlock;
4+
use reth_node_core::rpc::types::Block;
55
use reth_tracing::tracing::warn;
66
use serde::Deserialize;
77
use std::time::Duration;
@@ -31,10 +31,7 @@ impl EtherscanBlockProvider {
3131
/// Load block using Etherscan API. Note: only `BlockNumberOrTag::Latest`,
3232
/// `BlockNumberOrTag::Earliest`, `BlockNumberOrTag::Pending`, `BlockNumberOrTag::Number(u64)`
3333
/// are supported.
34-
pub async fn load_block(
35-
&self,
36-
block_number_or_tag: BlockNumberOrTag,
37-
) -> eyre::Result<RichBlock> {
34+
pub async fn load_block(&self, block_number_or_tag: BlockNumberOrTag) -> eyre::Result<Block> {
3835
let block: EtherscanBlockResponse = self
3936
.http_client
4037
.get(&self.base_url)
@@ -54,7 +51,7 @@ impl EtherscanBlockProvider {
5451
}
5552

5653
impl BlockProvider for EtherscanBlockProvider {
57-
async fn subscribe_blocks(&self, tx: mpsc::Sender<RichBlock>) {
54+
async fn subscribe_blocks(&self, tx: mpsc::Sender<Block>) {
5855
let mut last_block_number: Option<u64> = None;
5956
let mut interval = interval(self.interval);
6057
loop {
@@ -80,12 +77,12 @@ impl BlockProvider for EtherscanBlockProvider {
8077
}
8178
}
8279

83-
async fn get_block(&self, block_number: u64) -> eyre::Result<RichBlock> {
80+
async fn get_block(&self, block_number: u64) -> eyre::Result<Block> {
8481
self.load_block(BlockNumberOrTag::Number(block_number)).await
8582
}
8683
}
8784

8885
#[derive(Deserialize, Debug)]
8986
struct EtherscanBlockResponse {
90-
result: RichBlock,
87+
result: Block,
9188
}

crates/consensus/debug-client/src/providers/rpc.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::BlockProvider;
22
use alloy_eips::BlockNumberOrTag;
33
use alloy_provider::{Provider, ProviderBuilder};
44
use futures::StreamExt;
5-
use reth_node_core::rpc::types::RichBlock;
5+
use reth_node_core::rpc::types::Block;
66
use reth_rpc_types::BlockTransactionsKind;
77
use tokio::sync::mpsc::Sender;
88

@@ -20,7 +20,7 @@ impl RpcBlockProvider {
2020
}
2121

2222
impl BlockProvider for RpcBlockProvider {
23-
async fn subscribe_blocks(&self, tx: Sender<RichBlock>) {
23+
async fn subscribe_blocks(&self, tx: Sender<Block>) {
2424
let ws_provider = ProviderBuilder::new()
2525
.on_builtin(&self.ws_rpc_url)
2626
.await
@@ -37,23 +37,22 @@ impl BlockProvider for RpcBlockProvider {
3737
.await
3838
.expect("failed to get block")
3939
.expect("block not found");
40-
if tx.send(full_block.into()).await.is_err() {
40+
if tx.send(full_block).await.is_err() {
4141
// channel closed
4242
break;
4343
}
4444
}
4545
}
4646

47-
async fn get_block(&self, block_number: u64) -> eyre::Result<RichBlock> {
47+
async fn get_block(&self, block_number: u64) -> eyre::Result<Block> {
4848
let ws_provider = ProviderBuilder::new()
4949
.on_builtin(&self.ws_rpc_url)
5050
.await
5151
.expect("failed to create WS provider");
52-
let block: RichBlock = ws_provider
52+
let block: Block = ws_provider
5353
.get_block_by_number(BlockNumberOrTag::Number(block_number), true)
5454
.await?
55-
.ok_or_else(|| eyre::eyre!("block not found by number {}", block_number))?
56-
.into();
55+
.ok_or_else(|| eyre::eyre!("block not found by number {}", block_number))?;
5756
Ok(block)
5857
}
5958
}

crates/rpc/rpc-api/src/debug.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use reth_rpc_types::{
55
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace,
66
TraceResult,
77
},
8-
Bundle, RichBlock, StateContext, TransactionRequest,
8+
Block, Bundle, StateContext, TransactionRequest,
99
};
1010
use std::collections::HashMap;
1111

@@ -37,7 +37,7 @@ pub trait DebugApi {
3737

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

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

0 commit comments

Comments
 (0)