Skip to content

Commit

Permalink
feat: remove constraint of concrete type AnyTransactionReceipt for Et…
Browse files Browse the repository at this point in the history
…hApiTypes::NetworkType (#10693)

Co-authored-by: Emilia Hane <[email protected]>
  • Loading branch information
nkysg and emhane authored Sep 9, 2024
1 parent 1ea8cca commit b78e0f6
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use reth::{
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
builder::{NodeBuilder, NodeConfig, NodeHandle},
network::PeersHandleProvider,
rpc::api::eth::{helpers::AddDevSigners, FullEthApiServer},
rpc::{
api::eth::{helpers::AddDevSigners, FullEthApiServer},
types::AnyTransactionReceipt,
},
tasks::TaskManager,
};
use reth_chainspec::ChainSpec;
Expand Down Expand Up @@ -62,6 +65,7 @@ where
EthApi: FullEthApiServer<
NetworkTypes: Network<
TransactionResponse = reth_rpc_types::WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
> + AddDevSigners
+ EthApiBuilderProvider<Adapter<N>>,
Expand Down
8 changes: 5 additions & 3 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth::{
providers::{BlockReader, BlockReaderIdExt, CanonStateSubscriptions, StageCheckpointReader},
rpc::{
api::eth::helpers::{EthApiSpec, EthTransactions, TraceExt},
types::engine::PayloadStatusEnum,
types::{engine::PayloadStatusEnum, AnyTransactionReceipt},
},
};
use reth_chainspec::ChainSpec;
Expand Down Expand Up @@ -90,8 +90,10 @@ where
<Engine as EngineTypes>::ExecutionPayloadV3:
From<Engine::BuiltPayload> + PayloadEnvelopeExt,
AddOns::EthApi: EthApiSpec + EthTransactions + TraceExt,
<AddOns::EthApi as EthApiTypes>::NetworkTypes:
Network<TransactionResponse = WithOtherFields<alloy_rpc_types::Transaction>>,
<AddOns::EthApi as EthApiTypes>::NetworkTypes: Network<
TransactionResponse = WithOtherFields<alloy_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
{
let mut chain = Vec::with_capacity(length as usize);
for i in 0..length {
Expand Down
3 changes: 2 additions & 1 deletion crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth::{
use reth_chainspec::ChainSpec;
use reth_node_builder::{EthApiTypes, NodeTypes};
use reth_primitives::{Bytes, B256};
use reth_rpc_types::WithOtherFields;
use reth_rpc_types::{AnyTransactionReceipt, WithOtherFields};

#[allow(missing_debug_implementations)]
pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {
Expand All @@ -24,6 +24,7 @@ where
+ EthTransactions<
NetworkTypes: Network<
TransactionResponse = WithOtherFields<alloy_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
> + TraceExt,
{
Expand Down
7 changes: 6 additions & 1 deletion crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use reth_node_core::{
dirs::{ChainPath, DataDirPath},
node_config::NodeConfig,
primitives::Head,
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
rpc::{
eth::{helpers::AddDevSigners, FullEthApiServer},
types::AnyTransactionReceipt,
},
};
use reth_primitives::revm_primitives::EnvKzgSettings;
use reth_provider::{providers::BlockchainProvider, ChainSpecProvider, FullProvider};
Expand Down Expand Up @@ -341,6 +344,7 @@ where
+ FullEthApiServer<
NetworkTypes: alloy_network::Network<
TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
>
+ AddDevSigners
Expand Down Expand Up @@ -491,6 +495,7 @@ where
+ FullEthApiServer<
NetworkTypes: alloy_network::Network<
TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
> + AddDevSigners,
>,
Expand Down
6 changes: 5 additions & 1 deletion crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use reth_node_core::{
dirs::{ChainPath, DataDirPath},
exit::NodeExitFuture,
primitives::Head,
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
rpc::{
eth::{helpers::AddDevSigners, FullEthApiServer},
types::AnyTransactionReceipt,
},
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
};
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
Expand Down Expand Up @@ -71,6 +74,7 @@ where
+ FullEthApiServer<
NetworkTypes: alloy_network::Network<
TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
> + AddDevSigners,
>,
Expand Down
6 changes: 5 additions & 1 deletion crates/node/builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use reth_node_api::{
use reth_node_core::{
dirs::{ChainPath, DataDirPath},
exit::NodeExitFuture,
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
rpc::{
eth::{helpers::AddDevSigners, FullEthApiServer},
types::AnyTransactionReceipt,
},
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
};
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
Expand Down Expand Up @@ -113,6 +116,7 @@ where
+ FullEthApiServer<
NetworkTypes: alloy_network::Network<
TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
> + AddDevSigners,
>,
Expand Down
2 changes: 2 additions & 0 deletions crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use reth_node_core::{
rpc::{
api::EngineApiServer,
eth::{EthApiTypes, FullEthApiServer},
types::AnyTransactionReceipt,
},
};
use reth_payload_builder::PayloadBuilderHandle;
Expand Down Expand Up @@ -306,6 +307,7 @@ where
+ FullEthApiServer<
NetworkTypes: alloy_network::Network<
TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
>,
{
Expand Down
3 changes: 3 additions & 0 deletions crates/rpc/rpc-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ reth-evm.workspace = true
reth-engine-primitives.workspace = true
reth-rpc-types.workspace = true

# ethereum
alloy-network.workspace = true

# rpc/net
jsonrpsee = { workspace = true, features = ["server"] }
tower-http = { workspace = true, features = ["full"] }
Expand Down
37 changes: 26 additions & 11 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ use reth_rpc::{
use reth_rpc_api::servers::*;
use reth_rpc_eth_api::{
helpers::{Call, EthApiSpec, EthTransactions, LoadPendingBlock, TraceExt},
EthApiServer, FullEthApiServer,
EthApiServer, EthApiTypes, FullEthApiServer, RpcReceipt,
};
use reth_rpc_eth_types::{EthConfig, EthStateCache, EthSubscriptionIdProvider};
use reth_rpc_layer::{AuthLayer, Claims, JwtAuthValidator, JwtSecret};
Expand Down Expand Up @@ -207,6 +207,7 @@ pub use eth::EthHandlers;
// Rpc server metrics
mod metrics;
pub use metrics::{MeteredRequestFuture, RpcRequestMetricsService};
use reth_node_core::rpc::types::AnyTransactionReceipt;

/// Convenience function for starting a server in one step.
#[allow(clippy::too_many_arguments)]
Expand All @@ -228,7 +229,9 @@ where
Tasks: TaskSpawner + Clone + 'static,
Events: CanonStateSubscriptions + Clone + 'static,
EvmConfig: ConfigureEvm,
EthApi: FullEthApiServer,
EthApi: FullEthApiServer<
NetworkTypes: alloy_network::Network<ReceiptResponse = AnyTransactionReceipt>,
>,
{
let module_config = module_config.into();
server_config
Expand Down Expand Up @@ -435,7 +438,9 @@ where
where
EngineT: EngineTypes,
EngineApi: EngineApiServer<EngineT>,
EthApi: FullEthApiServer,
EthApi: FullEthApiServer<
NetworkTypes: alloy_network::Network<ReceiptResponse = AnyTransactionReceipt>,
>,
{
let Self { provider, pool, network, executor, events, evm_config } = self;

Expand Down Expand Up @@ -501,7 +506,9 @@ where
eth: DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi>,
) -> TransportRpcModules<()>
where
EthApi: FullEthApiServer,
EthApi: FullEthApiServer<
NetworkTypes: alloy_network::Network<ReceiptResponse = AnyTransactionReceipt>,
>,
{
let mut modules = TransportRpcModules::default();

Expand Down Expand Up @@ -792,10 +799,12 @@ where
pub fn register_eth(&mut self) -> &mut Self
where
EthApi: EthApiServer<
reth_rpc_types::Transaction,
reth_rpc_types::Block,
reth_rpc_types::AnyTransactionReceipt,
>,
reth_rpc_types::Transaction,
reth_rpc_types::Block,
RpcReceipt<EthApi::NetworkTypes>,
> + EthApiTypes<
NetworkTypes: alloy_network::Network<ReceiptResponse = AnyTransactionReceipt>,
>,
{
let eth_api = self.eth_api().clone();
self.modules.insert(RethRpcModule::Eth, eth_api.into_rpc().into());
Expand All @@ -812,7 +821,9 @@ where
EthApi: EthApiServer<
WithOtherFields<reth_rpc_types::Transaction>,
reth_rpc_types::Block<WithOtherFields<reth_rpc_types::Transaction>>,
reth_rpc_types::AnyTransactionReceipt,
RpcReceipt<EthApi::NetworkTypes>,
> + EthApiTypes<
NetworkTypes: alloy_network::Network<ReceiptResponse = AnyTransactionReceipt>,
> + TraceExt
+ EthTransactions,
{
Expand Down Expand Up @@ -917,7 +928,9 @@ where
EthApi: EthApiServer<
WithOtherFields<reth_rpc_types::Transaction>,
reth_rpc_types::Block<WithOtherFields<reth_rpc_types::Transaction>>,
reth_rpc_types::AnyTransactionReceipt,
RpcReceipt<EthApi::NetworkTypes>,
> + EthApiTypes<
NetworkTypes: alloy_network::Network<ReceiptResponse = AnyTransactionReceipt>,
> + TraceExt
+ EthTransactions,
{
Expand Down Expand Up @@ -965,7 +978,9 @@ where
Network: NetworkInfo + Peers + Clone + 'static,
Tasks: TaskSpawner + Clone + 'static,
Events: CanonStateSubscriptions + Clone + 'static,
EthApi: FullEthApiServer,
EthApi: FullEthApiServer<
NetworkTypes: alloy_network::Network<ReceiptResponse = AnyTransactionReceipt>,
>,
{
/// Configures the auth module that includes the
/// * `engine_` namespace
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc/rpc-eth-api/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Implementation of the [`jsonrpsee`] generated [`EthApiServer`] trait. Handles RPC requests for
//! the `eth_` namespace.

use alloy_dyn_abi::TypedData;
use alloy_json_rpc::RpcObject;
use alloy_network::Network;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::{
transaction::AccessListResult, Address, BlockId, BlockNumberOrTag, Bytes, B256, B64, U256, U64,
Expand All @@ -12,8 +12,8 @@ use reth_rpc_types::{
serde_helpers::JsonStorageKey,
simulate::{SimBlock, SimulatedBlock},
state::{EvmOverrides, StateOverride},
BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, FeeHistory, Header,
Index, StateContext, SyncStatus, TransactionRequest, Work,
AnyTransactionReceipt, BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse,
FeeHistory, Header, Index, StateContext, SyncStatus, TransactionRequest, Work,
};
use tracing::trace;

Expand Down Expand Up @@ -369,7 +369,7 @@ impl<T>
RpcReceipt<T::NetworkTypes>,
> for T
where
T: FullEthApi,
T: FullEthApi<NetworkTypes: Network<ReceiptResponse = AnyTransactionReceipt>>,
jsonrpsee_types::error::ErrorObject<'static>: From<T::Error>,
{
/// Handler for: `eth_protocolVersion`
Expand Down
4 changes: 1 addition & 3 deletions crates/rpc/rpc-eth-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::error::Error;

use alloy_network::{AnyNetwork, Network};
use reth_rpc_eth_types::EthApiError;
use reth_rpc_types::{AnyTransactionReceipt, Block, Transaction, WithOtherFields};
use reth_rpc_types::{Block, Transaction, WithOtherFields};

use crate::{AsEthApiError, FromEthApiError, FromEvmError};

Expand All @@ -20,11 +20,9 @@ pub trait EthApiTypes: Send + Sync + Clone {
+ Sync;
/// Blockchain primitive types, specific to network, e.g. block and transaction.
// todo: remove restriction [`reth_rpc_types::Transaction`]
// todo: remove restriction [`reth_rpc_types::AnyTransactionReceipt`]
type NetworkTypes: Network<
TransactionResponse = WithOtherFields<Transaction>,
HeaderResponse = reth_rpc_types::Header,
ReceiptResponse = AnyTransactionReceipt,
>;
}

Expand Down
8 changes: 6 additions & 2 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ impl<Eth> OtterscanApi<Eth> {
impl<Eth> OtterscanApi<Eth>
where
Eth: EthApiTypes<
NetworkTypes: Network<TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>>,
NetworkTypes: Network<
TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
>,
{
/// Constructs a `BlockDetails` from a block and its receipts.
fn block_details(
&self,
block: RpcBlock<Eth::NetworkTypes>,
receipts: Vec<AnyTransactionReceipt>,
receipts: Vec<RpcReceipt<Eth::NetworkTypes>>,
) -> RpcResult<BlockDetails> {
// blob fee is burnt, so we don't need to calculate it
let total_fees = receipts
Expand All @@ -73,6 +76,7 @@ where
> + EthApiTypes<
NetworkTypes: Network<
TransactionResponse = WithOtherFields<reth_rpc_types::Transaction>,
ReceiptResponse = AnyTransactionReceipt,
>,
> + TraceExt
+ EthTransactions
Expand Down

0 comments on commit b78e0f6

Please sign in to comment.