Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Receipt AT to ReceiptProvider #12890

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
Node: FullNodeComponents<
Types: NodeTypes<
ChainSpec: EthereumHardforks,
Primitives: NodePrimitives<Block: Encodable>,
Primitives: NodePrimitives<Block: Encodable, Receipt = reth_primitives::Receipt>,
>,
>,
EthApi: EthApiSpec + EthTransactions + TraceExt,
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ where
P: DatabaseProviderFactory
+ BlockReader<Block = reth_primitives::Block>
+ StateProviderFactory
+ StateReader
+ StateReader<Receipt = reth_primitives::Receipt>
+ Clone
+ 'static,
<P as DatabaseProviderFactory>::Provider: BlockReader,
Expand Down
6 changes: 5 additions & 1 deletion crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ where

impl<C> NetworkConfig<C>
where
C: BlockReader<Block = reth_primitives::Block> + HeaderProvider + Clone + Unpin + 'static,
C: BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ HeaderProvider
+ Clone
+ Unpin
+ 'static,
{
/// Starts the networking stack given a [`NetworkConfig`] and returns a handle to the network.
pub async fn start_network(self) -> Result<NetworkHandle, NetworkError> {
Expand Down
6 changes: 4 additions & 2 deletions crates/net/network/src/eth_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<C, N: NetworkPrimitives> EthRequestHandler<C, N> {

impl<C> EthRequestHandler<C>
where
C: BlockReader + HeaderProvider + ReceiptProvider,
C: BlockReader + HeaderProvider + ReceiptProvider<Receipt = reth_primitives::Receipt>,
{
/// Returns the list of requested headers
fn get_headers_response(&self, request: GetBlockHeaders) -> Vec<Header> {
Expand Down Expand Up @@ -224,7 +224,9 @@ where
/// This should be spawned or used as part of `tokio::select!`.
impl<C> Future for EthRequestHandler<C>
where
C: BlockReader<Block = reth_primitives::Block> + HeaderProvider + Unpin,
C: BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ HeaderProvider
+ Unpin,
{
type Output = ();

Expand Down
16 changes: 13 additions & 3 deletions crates/net/network/src/test_utils/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ where

impl<C, Pool> Testnet<C, Pool>
where
C: BlockReader<Block = reth_primitives::Block> + HeaderProvider + Clone + Unpin + 'static,
C: BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ HeaderProvider
+ Clone
+ Unpin
+ 'static,
Pool: TransactionPool + Unpin + 'static,
{
/// Spawns the testnet to a separate task
Expand Down Expand Up @@ -253,7 +257,10 @@ impl<C, Pool> fmt::Debug for Testnet<C, Pool> {

impl<C, Pool> Future for Testnet<C, Pool>
where
C: BlockReader<Block = reth_primitives::Block> + HeaderProvider + Unpin + 'static,
C: BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ HeaderProvider
+ Unpin
+ 'static,
Pool: TransactionPool + Unpin + 'static,
{
type Output = ();
Expand Down Expand Up @@ -448,7 +455,10 @@ where

impl<C, Pool> Future for Peer<C, Pool>
where
C: BlockReader<Block = reth_primitives::Block> + HeaderProvider + Unpin + 'static,
C: BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ HeaderProvider
+ Unpin
+ 'static,
Pool: TransactionPool + Unpin + 'static,
{
type Output = ();
Expand Down
6 changes: 4 additions & 2 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
pub fn start_network<Pool>(&self, builder: NetworkBuilder<(), ()>, pool: Pool) -> NetworkHandle
where
Pool: TransactionPool + Unpin + 'static,
Node::Provider: BlockReader<Block = reth_primitives::Block>,
Node::Provider:
BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>,
{
self.start_network_with(builder, pool, Default::default())
}
Expand All @@ -670,7 +671,8 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
) -> NetworkHandle
where
Pool: TransactionPool + Unpin + 'static,
Node::Provider: BlockReader<Block = reth_primitives::Block>,
Node::Provider:
BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>,
{
let (handle, network, txpool, eth) = builder
.transactions(pool, tx_config)
Expand Down
3 changes: 3 additions & 0 deletions crates/node/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,6 @@ pub type BodyTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockBody

/// Helper adapter type for accessing [`NodePrimitives::SignedTx`] on [`NodeTypes`].
pub type TxTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::SignedTx;

/// Helper adapter type for accessing [`NodePrimitives::Receipt`] on [`NodeTypes`].
pub type ReceiptTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::Receipt;
6 changes: 4 additions & 2 deletions crates/optimism/rpc/src/eth/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ impl<N> LoadPendingBlock for OpEthApi<N>
where
Self: SpawnBlocking,
N: RpcNodeCore<
Provider: BlockReaderIdExt<Block = reth_primitives::Block>
+ EvmEnvProvider
Provider: BlockReaderIdExt<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
> + EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
Pool: TransactionPool,
Expand Down
5 changes: 3 additions & 2 deletions crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::RethL1BlockInfo;
use reth_optimism_forks::OpHardforks;
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned, TxType};
use reth_provider::{ChainSpecProvider, TransactionsProvider};
use reth_provider::{ChainSpecProvider, ReceiptProvider, TransactionsProvider};
use reth_rpc_eth_api::{helpers::LoadReceipt, FromEthApiError, RpcReceipt};
use reth_rpc_eth_types::{receipt::build_receipt, EthApiError};

Expand All @@ -21,7 +21,8 @@ impl<N> LoadReceipt for OpEthApi<N>
where
Self: Send + Sync,
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
Self::Provider: TransactionsProvider<Transaction = TransactionSigned>,
Self::Provider:
TransactionsProvider<Transaction = TransactionSigned> + ReceiptProvider<Receipt = Receipt>,
{
async fn build_transaction_receipt(
&self,
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ where

impl<N> TransactionCompat for OpEthApi<N>
where
N: FullNodeComponents,
N: FullNodeComponents<Provider: ReceiptProvider<Receipt = reth_primitives::Receipt>>,
{
type Transaction = Transaction;
type Error = OpEthApiError;
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-builder/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct EthHandlers<Provider, Pool, Network, Events, EthApi: EthApiTypes> {
impl<Provider, Pool, Network, Events, EthApi> EthHandlers<Provider, Pool, Network, Events, EthApi>
where
Provider: StateProviderFactory
+ BlockReader<Block = reth_primitives::Block>
+ BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ EvmEnvProvider
+ Clone
+ Unpin
Expand Down
45 changes: 32 additions & 13 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
//! block_executor: BlockExecutor,
//! consensus: Consensus,
//! ) where
//! Provider: FullRpcProvider<Transaction = TransactionSigned, Block = reth_primitives::Block>
//! + AccountReader
//! Provider: FullRpcProvider<
//! Transaction = TransactionSigned,
//! Block = reth_primitives::Block,
//! Receipt = reth_primitives::Receipt,
//! > + AccountReader
//! + ChangeSetReader,
//! Pool: TransactionPool + Unpin + 'static,
//! Network: NetworkInfo + Peers + Clone + 'static,
Expand Down Expand Up @@ -114,8 +117,11 @@
//! block_executor: BlockExecutor,
//! consensus: Consensus,
//! ) where
//! Provider: FullRpcProvider<Transaction = TransactionSigned, Block = reth_primitives::Block>
//! + AccountReader
//! Provider: FullRpcProvider<
//! Transaction = TransactionSigned,
//! Block = reth_primitives::Block,
//! Receipt = reth_primitives::Receipt,
//! > + AccountReader
//! + ChangeSetReader,
//! Pool: TransactionPool + Unpin + 'static,
//! Network: NetworkInfo + Peers + Clone + 'static,
Expand Down Expand Up @@ -195,7 +201,7 @@ use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers};
use reth_primitives::EthPrimitives;
use reth_provider::{
AccountReader, BlockReader, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
EvmEnvProvider, FullRpcProvider, StateProviderFactory,
EvmEnvProvider, FullRpcProvider, ReceiptProvider, StateProviderFactory,
};
use reth_rpc::{
AdminApi, DebugApi, EngineEthApi, EthBundle, NetApi, OtterscanApi, RPCApi, RethApi, TraceApi,
Expand Down Expand Up @@ -263,7 +269,9 @@ pub async fn launch<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi, B
consensus: Arc<dyn Consensus>,
) -> Result<RpcServerHandle, RpcError>
where
Provider: FullRpcProvider<Block = reth_primitives::Block> + AccountReader + ChangeSetReader,
Provider: FullRpcProvider<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ AccountReader
+ ChangeSetReader,
Pool: TransactionPool + 'static,
Network: NetworkInfo + Peers + Clone + 'static,
Tasks: TaskSpawner + Clone + 'static,
Expand Down Expand Up @@ -646,7 +654,10 @@ where
EngineT: EngineTypes,
EngineApi: EngineApiServer<EngineT>,
EthApi: FullEthApiServer,
Provider: BlockReader<Block = <EthApi::Provider as BlockReader>::Block>,
Provider: BlockReader<
Block = <EthApi::Provider as BlockReader>::Block,
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
>,
{
let Self {
provider,
Expand Down Expand Up @@ -722,7 +733,7 @@ where
) -> RpcRegistryInner<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
where
EthApi: EthApiTypes + 'static,
Provider: BlockReader<Block = reth_primitives::Block>,
Provider: BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>,
{
let Self {
provider,
Expand Down Expand Up @@ -757,7 +768,10 @@ where
) -> TransportRpcModules<()>
where
EthApi: FullEthApiServer,
Provider: BlockReader<Block = <EthApi::Provider as BlockReader>::Block>,
Provider: BlockReader<
Block = <EthApi::Provider as BlockReader>::Block,
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
>,
{
let mut modules = TransportRpcModules::default();

Expand Down Expand Up @@ -916,7 +930,7 @@ impl<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
RpcRegistryInner<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
where
Provider: StateProviderFactory
+ BlockReader<Block = reth_primitives::Block>
+ BlockReader<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>
+ EvmEnvProvider
+ Clone
+ Unpin
Expand Down Expand Up @@ -1125,7 +1139,10 @@ where
pub fn register_debug(&mut self) -> &mut Self
where
EthApi: EthApiSpec + EthTransactions + TraceExt,
Provider: BlockReader<Block = <EthApi::Provider as BlockReader>::Block>,
Provider: BlockReader<
Block = <EthApi::Provider as BlockReader>::Block,
Receipt = reth_primitives::Receipt,
>,
{
let debug_api = self.debug_api();
self.modules.insert(RethRpcModule::Debug, debug_api.into_rpc().into());
Expand Down Expand Up @@ -1279,8 +1296,10 @@ where
impl<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
RpcRegistryInner<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
where
Provider: FullRpcProvider<Block = <EthApi::Provider as BlockReader>::Block>
+ AccountReader
Provider: FullRpcProvider<
Block = <EthApi::Provider as BlockReader>::Block,
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
> + AccountReader
+ ChangeSetReader,
Pool: TransactionPool + 'static,
Network: NetworkInfo + Peers + Clone + 'static,
Expand Down
8 changes: 5 additions & 3 deletions crates/rpc/rpc-eth-api/src/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use alloy_eips::BlockId;
use alloy_rpc_types_eth::{Block, Header, Index};
use futures::Future;
use reth_node_api::BlockBody;
use reth_primitives::{Receipt, SealedBlockFor, SealedBlockWithSenders};
use reth_provider::{BlockIdReader, BlockReader, BlockReaderIdExt, HeaderProvider};
use reth_primitives::{SealedBlockFor, SealedBlockWithSenders};
use reth_provider::{
BlockIdReader, BlockReader, BlockReaderIdExt, HeaderProvider, ProviderReceipt,
};
use reth_rpc_types_compat::block::from_block;

use crate::{
Expand All @@ -24,7 +26,7 @@ pub type BlockReceiptsResult<N, E> = Result<Option<Vec<RpcReceipt<N>>>, E>;
pub type BlockAndReceiptsResult<Eth> = Result<
Option<(
SealedBlockFor<<<Eth as RpcNodeCore>::Provider as BlockReader>::Block>,
Arc<Vec<Receipt>>,
Arc<Vec<ProviderReceipt<<Eth as RpcNodeCore>::Provider>>>,
)>,
<Eth as EthApiTypes>::Error,
>;
Expand Down
13 changes: 9 additions & 4 deletions crates/rpc/rpc-eth-api/src/helpers/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use reth_primitives::{
};
use reth_provider::{
BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ProviderError,
ReceiptProvider, StateProviderFactory,
ProviderReceipt, ReceiptProvider, StateProviderFactory,
};
use reth_revm::{
database::StateProviderDatabase,
Expand All @@ -45,8 +45,10 @@ use tracing::debug;
pub trait LoadPendingBlock:
EthApiTypes
+ RpcNodeCore<
Provider: BlockReaderIdExt<Block = reth_primitives::Block>
+ EvmEnvProvider
Provider: BlockReaderIdExt<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
> + EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
Pool: TransactionPool,
Expand Down Expand Up @@ -119,7 +121,10 @@ pub trait LoadPendingBlock:
&self,
) -> impl Future<
Output = Result<
Option<(SealedBlockWithSenders<<Self::Provider as BlockReader>::Block>, Vec<Receipt>)>,
Option<(
SealedBlockWithSenders<<Self::Provider as BlockReader>::Block>,
Vec<ProviderReceipt<Self::Provider>>,
)>,
Self::Error,
>,
> + Send
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc/rpc-eth-api/src/helpers/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
//! loads receipt data w.r.t. network.

use futures::Future;
use reth_primitives::{Receipt, TransactionMeta};
use reth_provider::TransactionsProvider;
use reth_primitives::TransactionMeta;
use reth_provider::{ProviderReceipt, ProviderTx, ReceiptProvider, TransactionsProvider};

use crate::{EthApiTypes, RpcNodeCoreExt, RpcReceipt};

/// Assembles transaction receipt data w.r.t to network.
///
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` receipts RPC methods.
pub trait LoadReceipt:
EthApiTypes + RpcNodeCoreExt<Provider: TransactionsProvider> + Send + Sync
EthApiTypes + RpcNodeCoreExt<Provider: TransactionsProvider + ReceiptProvider> + Send + Sync
{
/// Helper method for `eth_getBlockReceipts` and `eth_getTransactionReceipt`.
fn build_transaction_receipt(
&self,
tx: <Self::Provider as TransactionsProvider>::Transaction,
tx: ProviderTx<Self::Provider>,
meta: TransactionMeta,
receipt: Receipt,
receipt: ProviderReceipt<Self::Provider>,
) -> impl Future<Output = Result<RpcReceipt<Self::NetworkTypes>, Self::Error>> + Send;
}
7 changes: 4 additions & 3 deletions crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use alloy_network::TransactionBuilder;
use alloy_primitives::{Address, Bytes, TxHash, B256};
use alloy_rpc_types_eth::{transaction::TransactionRequest, BlockNumberOrTag, TransactionInfo};
use futures::Future;
use reth_primitives::{Receipt, SealedBlockWithSenders, TransactionMeta, TransactionSigned};
use reth_primitives::{SealedBlockWithSenders, TransactionMeta, TransactionSigned};
use reth_provider::{
BlockNumReader, BlockReaderIdExt, ProviderTx, ReceiptProvider, TransactionsProvider,
BlockNumReader, BlockReaderIdExt, ProviderReceipt, ProviderTx, ReceiptProvider,
TransactionsProvider,
};
use reth_rpc_eth_types::{
utils::{binary_search, recover_raw_transaction},
Expand Down Expand Up @@ -159,7 +160,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
hash: TxHash,
) -> impl Future<
Output = Result<
Option<(ProviderTx<Self::Provider>, TransactionMeta, Receipt)>,
Option<(ProviderTx<Self::Provider>, TransactionMeta, ProviderReceipt<Self::Provider>)>,
Self::Error,
>,
> + Send
Expand Down
Loading
Loading