From 2bf18465d708522b865ee3b207c103f128b40aed Mon Sep 17 00:00:00 2001 From: Miguel Tavares Date: Tue, 20 Aug 2024 13:52:04 -0300 Subject: [PATCH 1/5] replace type --- crates/rpc/rpc-eth-api/src/core.rs | 15 +++++---------- crates/rpc/rpc-eth-api/src/helpers/block.rs | 5 +++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/core.rs b/crates/rpc/rpc-eth-api/src/core.rs index 30c51a9f7e86..321dc10ccc08 100644 --- a/crates/rpc/rpc-eth-api/src/core.rs +++ b/crates/rpc/rpc-eth-api/src/core.rs @@ -12,12 +12,7 @@ use reth_primitives::{ }; use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult}; use reth_rpc_types::{ - serde_helpers::JsonStorageKey, - simulate::{SimBlock, SimulatedBlock}, - state::{EvmOverrides, StateOverride}, - AnyTransactionReceipt, BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, - FeeHistory, Header, Index, RichBlock, StateContext, SyncStatus, Transaction, - TransactionRequest, Work, + serde_helpers::JsonStorageKey, simulate::{SimBlock, SimulatedBlock}, state::{EvmOverrides, StateOverride}, AnyTransactionReceipt, Block, BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, FeeHistory, Header, Index, RichBlock, StateContext, SyncStatus, Transaction, TransactionRequest, Work }; use tracing::trace; @@ -102,7 +97,7 @@ pub trait EthApi { &self, hash: B256, index: Index, - ) -> RpcResult>; + ) -> RpcResult>; /// Returns an uncle block of the given block and index. #[method(name = "getUncleByBlockNumberAndIndex")] @@ -110,7 +105,7 @@ pub trait EthApi { &self, number: BlockNumberOrTag, index: Index, - ) -> RpcResult>; + ) -> RpcResult>; /// Returns the EIP-2718 encoded transaction if it exists. /// @@ -449,7 +444,7 @@ where &self, hash: B256, index: Index, - ) -> RpcResult> { + ) -> RpcResult> { trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getUncleByBlockHashAndIndex"); Ok(EthBlocks::ommer_by_block_and_index(self, hash.into(), index).await?) } @@ -459,7 +454,7 @@ where &self, number: BlockNumberOrTag, index: Index, - ) -> RpcResult> { + ) -> RpcResult> { trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex"); Ok(EthBlocks::ommer_by_block_and_index(self, number.into(), index).await?) } diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index 0058ca021cfc..7f3d102fc1ad 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -6,7 +6,7 @@ use futures::Future; use reth_primitives::{BlockId, Receipt, SealedBlock, SealedBlockWithSenders, TransactionMeta}; use reth_provider::{BlockIdReader, BlockReader, BlockReaderIdExt, HeaderProvider}; use reth_rpc_eth_types::{EthApiError, EthStateCache, ReceiptBuilder}; -use reth_rpc_types::{AnyTransactionReceipt, Header, Index, RichBlock}; +use reth_rpc_types::{AnyTransactionReceipt, Block, Header, Index, RichBlock}; use reth_rpc_types_compat::block::{from_block, uncle_block_from_header}; use crate::FromEthApiError; @@ -187,8 +187,9 @@ pub trait EthBlocks: LoadBlock { &self, block_id: BlockId, index: Index, - ) -> impl Future, Self::Error>> + Send { + ) -> impl Future, Self::Error>> + Send { async move { + let uncles = if block_id.is_pending() { // Pending block can be fetched directly without need for caching LoadBlock::provider(self) From dccde63821cb9a886487d7f1e2f03901db637028 Mon Sep 17 00:00:00 2001 From: Miguel Tavares Date: Tue, 20 Aug 2024 13:54:58 -0300 Subject: [PATCH 2/5] run linting --- crates/rpc/rpc-eth-api/src/core.rs | 7 ++++++- crates/rpc/rpc-eth-api/src/helpers/block.rs | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/core.rs b/crates/rpc/rpc-eth-api/src/core.rs index 321dc10ccc08..f5dac6d79169 100644 --- a/crates/rpc/rpc-eth-api/src/core.rs +++ b/crates/rpc/rpc-eth-api/src/core.rs @@ -12,7 +12,12 @@ use reth_primitives::{ }; use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult}; use reth_rpc_types::{ - serde_helpers::JsonStorageKey, simulate::{SimBlock, SimulatedBlock}, state::{EvmOverrides, StateOverride}, AnyTransactionReceipt, Block, BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, FeeHistory, Header, Index, RichBlock, StateContext, SyncStatus, Transaction, TransactionRequest, Work + serde_helpers::JsonStorageKey, + simulate::{SimBlock, SimulatedBlock}, + state::{EvmOverrides, StateOverride}, + AnyTransactionReceipt, Block, BlockOverrides, Bundle, EIP1186AccountProofResponse, + EthCallResponse, FeeHistory, Header, Index, RichBlock, StateContext, SyncStatus, Transaction, + TransactionRequest, Work, }; use tracing::trace; diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index 7f3d102fc1ad..02f0675c7822 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -189,7 +189,6 @@ pub trait EthBlocks: LoadBlock { index: Index, ) -> impl Future, Self::Error>> + Send { async move { - let uncles = if block_id.is_pending() { // Pending block can be fetched directly without need for caching LoadBlock::provider(self) From 0cd2ea8f72e016dfd8b11096a9a883fb87ec3c15 Mon Sep 17 00:00:00 2001 From: Miguel Tavares Date: Tue, 20 Aug 2024 15:43:55 -0300 Subject: [PATCH 3/5] remove .into() --- crates/rpc/rpc-eth-api/src/helpers/block.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index 02f0675c7822..bd3f20756688 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -205,7 +205,7 @@ pub trait EthBlocks: LoadBlock { let uncle = uncles .into_iter() .nth(index.into()) - .map(|header| uncle_block_from_header(header).into()); + .map(|header| uncle_block_from_header(header)); Ok(uncle) } } From 47430a741a01d655dfc8eb909c9f7fc5fcafeeed Mon Sep 17 00:00:00 2001 From: Miguel Tavares Date: Tue, 20 Aug 2024 23:18:39 -0300 Subject: [PATCH 4/5] Update crates/rpc/rpc-eth-api/src/helpers/block.rs Co-authored-by: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> --- crates/rpc/rpc-eth-api/src/helpers/block.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index bd3f20756688..fd76bee8ded8 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -205,7 +205,7 @@ pub trait EthBlocks: LoadBlock { let uncle = uncles .into_iter() .nth(index.into()) - .map(|header| uncle_block_from_header(header)); + .map(uncle_block_from_header); Ok(uncle) } } From ee3642334187059687330eb79491c6f14a09bfd5 Mon Sep 17 00:00:00 2001 From: Miguel Tavares Date: Wed, 21 Aug 2024 13:35:57 -0300 Subject: [PATCH 5/5] lint --- crates/rpc/rpc-eth-api/src/helpers/block.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index fd76bee8ded8..accf5089b422 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -202,11 +202,7 @@ pub trait EthBlocks: LoadBlock { } .unwrap_or_default(); - let uncle = uncles - .into_iter() - .nth(index.into()) - .map(uncle_block_from_header); - Ok(uncle) + Ok(uncles.into_iter().nth(index.into()).map(uncle_block_from_header)) } } }