chore: relax bounds on RPC types (#14529)

This commit is contained in:
Arsenii Kulikov
2025-02-17 13:33:59 +04:00
committed by GitHub
parent 25579ce8a3
commit c341ee3431
6 changed files with 40 additions and 17 deletions

View File

@ -2,10 +2,9 @@
//! RPC methods.
use super::SpawnBlocking;
use crate::{EthApiTypes, FromEthApiError, FromEvmError, RpcNodeCore};
use crate::{types::RpcTypes, EthApiTypes, FromEthApiError, FromEvmError, RpcNodeCore};
use alloy_consensus::{BlockHeader, Transaction};
use alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK;
use alloy_network::Network;
use alloy_primitives::B256;
use alloy_rpc_types_eth::BlockNumberOrTag;
use futures::Future;
@ -41,8 +40,8 @@ use tracing::debug;
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` blocks RPC methods.
pub trait LoadPendingBlock:
EthApiTypes<
NetworkTypes: Network<
HeaderResponse = alloy_rpc_types_eth::Header<ProviderHeader<Self::Provider>>,
NetworkTypes: RpcTypes<
Header = alloy_rpc_types_eth::Header<ProviderHeader<Self::Provider>>,
>,
Error: FromEvmError<Self::Evm>,
> + RpcNodeCore<

View File

@ -1,7 +1,8 @@
//! Trait for specifying `eth` network dependent API types.
use crate::{AsEthApiError, FromEthApiError, RpcNodeCore};
use alloy_network::Network;
use alloy_json_rpc::RpcObject;
use alloy_network::{Network, ReceiptResponse, TransactionResponse};
use alloy_rpc_types_eth::Block;
use reth_provider::{ProviderTx, ReceiptProvider, TransactionsProvider};
use reth_rpc_types_compat::TransactionCompat;
@ -11,6 +12,27 @@ use std::{
fmt::{self},
};
/// RPC types used by the `eth_` RPC API.
///
/// This is a subset of [`alloy_network::Network`] trait with only RPC response types kept.
pub trait RpcTypes {
/// Header response type.
type Header: RpcObject;
/// Receipt response type.
type Receipt: RpcObject + ReceiptResponse;
/// Transaction response type.
type Transaction: RpcObject + TransactionResponse;
}
impl<T> RpcTypes for T
where
T: Network,
{
type Header = T::HeaderResponse;
type Receipt = T::ReceiptResponse;
type Transaction = T::TransactionResponse;
}
/// Network specific `eth` API types.
///
/// This trait defines the network specific rpc types and helpers required for the `eth_` and
@ -28,7 +50,7 @@ pub trait EthApiTypes: Send + Sync + Clone {
+ Send
+ Sync;
/// Blockchain primitive types, specific to network, e.g. block and transaction.
type NetworkTypes: Network;
type NetworkTypes: RpcTypes;
/// Conversion methods for transaction RPC type.
type TransactionCompat: Send + Sync + Clone + fmt::Debug;
@ -37,16 +59,16 @@ pub trait EthApiTypes: Send + Sync + Clone {
}
/// Adapter for network specific transaction type.
pub type RpcTransaction<T> = <T as Network>::TransactionResponse;
pub type RpcTransaction<T> = <T as RpcTypes>::Transaction;
/// Adapter for network specific block type.
pub type RpcBlock<T> = Block<RpcTransaction<T>, <T as Network>::HeaderResponse>;
pub type RpcBlock<T> = Block<RpcTransaction<T>, RpcHeader<T>>;
/// Adapter for network specific receipt type.
pub type RpcReceipt<T> = <T as Network>::ReceiptResponse;
pub type RpcReceipt<T> = <T as RpcTypes>::Receipt;
/// Adapter for network specific header type.
pub type RpcHeader<T> = <T as Network>::HeaderResponse;
pub type RpcHeader<T> = <T as RpcTypes>::Header;
/// Adapter for network specific error type.
pub type RpcError<T> = <T as EthApiTypes>::Error;

View File

@ -7,6 +7,7 @@ use reth_primitives_traits::{BlockBody, SignedTransaction};
use reth_provider::{BlockReader, ChainSpecProvider};
use reth_rpc_eth_api::{
helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
types::RpcTypes,
RpcNodeCoreExt, RpcReceipt,
};
use reth_rpc_eth_types::{EthApiError, EthReceiptBuilder};
@ -17,7 +18,7 @@ impl<Provider, Pool, Network, EvmConfig> EthBlocks for EthApi<Provider, Pool, Ne
where
Self: LoadBlock<
Error = EthApiError,
NetworkTypes: alloy_network::Network<ReceiptResponse = TransactionReceipt>,
NetworkTypes: RpcTypes<Receipt = TransactionReceipt>,
Provider: BlockReader<
Transaction = reth_primitives::TransactionSigned,
Receipt = reth_primitives::Receipt,

View File

@ -13,6 +13,7 @@ use reth_provider::{
};
use reth_rpc_eth_api::{
helpers::{LoadPendingBlock, SpawnBlocking},
types::RpcTypes,
FromEvmError, RpcNodeCore,
};
use reth_rpc_eth_types::PendingBlock;
@ -25,7 +26,7 @@ impl<Provider, Pool, Network, EvmConfig> LoadPendingBlock
for EthApi<Provider, Pool, Network, EvmConfig>
where
Self: SpawnBlocking<
NetworkTypes: alloy_network::Network<HeaderResponse = alloy_rpc_types_eth::Header>,
NetworkTypes: RpcTypes<Header = alloy_rpc_types_eth::Header>,
Error: FromEvmError<Self::Evm>,
> + RpcNodeCore<
Provider: BlockReaderIdExt<