Skip to content

Commit

Permalink
chore(rpc): config network specific transaction type in node builder (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Aug 22, 2024
1 parent 7fb9a04 commit 7d8196e
Show file tree
Hide file tree
Showing 54 changed files with 518 additions and 272 deletions.
28 changes: 27 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ alloy-transport-ws = { version = "0.2.1", default-features = false }

# op
op-alloy-rpc-types = "0.1"
op-alloy-network = "0.1"

# misc
aquamarine = "0.5"
Expand Down
4 changes: 4 additions & 0 deletions crates/e2e-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ reth-tokio-util.workspace = true
reth-stages-types.workspace = true
reth-network-peers.workspace = true
reth-node-ethereum.workspace = true
reth-rpc-types.workspace = true
reth-rpc-types-compat.workspace = true

# rpc
jsonrpsee-types.workspace = true
jsonrpsee.workspace = true

futures-util.workspace = true
Expand Down
15 changes: 12 additions & 3 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::sync::Arc;

use alloy_network::Network;
use node::NodeTestContext;
use reth::{
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
Expand Down Expand Up @@ -51,9 +52,17 @@ pub async fn setup<N>(
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
where
N: Default + Node<TmpNodeAdapter<N>> + NodeTypes<ChainSpec = ChainSpec>,
<<N::ComponentsBuilder as NodeComponentsBuilder<TmpNodeAdapter<N>>>::Components as NodeComponents<TmpNodeAdapter<N>>>::Network: PeersHandleProvider,
<N::AddOns as NodeAddOns<Adapter<N>>>::EthApi:
FullEthApiServer + AddDevSigners + EthApiBuilderProvider<Adapter<N>>,
N::ComponentsBuilder: NodeComponentsBuilder<
TmpNodeAdapter<N>,
Components: NodeComponents<TmpNodeAdapter<N>, Network: PeersHandleProvider>,
>,
N::AddOns: NodeAddOns<
Adapter<N>,
EthApi: FullEthApiServer<
NetworkTypes: Network<TransactionResponse = reth_rpc_types::Transaction>,
> + AddDevSigners
+ EthApiBuilderProvider<Adapter<N>>,
>,
{
let tasks = TaskManager::current();
let exec = tasks.executor();
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
@@ -1,5 +1,6 @@
use std::{marker::PhantomData, pin::Pin};

use alloy_network::Network;
use alloy_rpc_types::BlockNumberOrTag;
use eyre::Ok;
use futures_util::Future;
Expand All @@ -14,8 +15,7 @@ use reth::{
types::engine::PayloadStatusEnum,
},
};
use reth_chainspec::ChainSpec;
use reth_node_builder::{NodeAddOns, NodeTypes};
use reth_node_builder::{EthApiTypes, NodeAddOns, NodeTypes};
use reth_primitives::{BlockHash, BlockNumber, Bytes, B256};
use reth_stages_types::StageId;
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -46,7 +46,7 @@ where

impl<Node, AddOns> NodeTestContext<Node, AddOns>
where
Node: FullNodeComponents<ChainSpec = ChainSpec>,
Node: FullNodeComponents,
Node::Network: PeersHandleProvider,
AddOns: NodeAddOns<Node>,
{
Expand Down Expand Up @@ -93,6 +93,8 @@ where
<Node::Engine as EngineTypes>::ExecutionPayloadV3:
From<<Node::Engine as PayloadTypes>::BuiltPayload> + PayloadEnvelopeExt,
AddOns::EthApi: EthApiSpec + EthTransactions + TraceExt,
<AddOns::EthApi as EthApiTypes>::NetworkTypes:
Network<TransactionResponse = alloy_rpc_types::Transaction>,
{
let mut chain = Vec::with_capacity(length as usize);
for i in 0..length {
Expand Down
13 changes: 8 additions & 5 deletions crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use alloy_consensus::TxEnvelope;
use alloy_network::eip2718::Decodable2718;
use alloy_network::{eip2718::Decodable2718, Network};
use reth::{
builder::{rpc::RpcRegistry, FullNodeComponents},
rpc::api::{
eth::helpers::{EthApiSpec, EthTransactions, TraceExt},
DebugApiServer,
},
};
use reth_chainspec::ChainSpec;
use reth_node_builder::EthApiTypes;
use reth_primitives::{Bytes, B256};

#[allow(missing_debug_implementations)]
pub struct RpcTestContext<Node: FullNodeComponents, EthApi> {
pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {
pub inner: RpcRegistry<Node, EthApi>,
}

impl<Node: FullNodeComponents<ChainSpec = ChainSpec>, EthApi> RpcTestContext<Node, EthApi>
impl<Node, EthApi> RpcTestContext<Node, EthApi>
where
EthApi: EthApiSpec + EthTransactions + TraceExt,
Node: FullNodeComponents,
EthApi: EthApiSpec
+ EthTransactions<NetworkTypes: Network<TransactionResponse = alloy_rpc_types::Transaction>>
+ TraceExt,
{
/// Injects a raw transaction into the node tx pool via RPC server
pub async fn inject_tx(&self, raw_tx: Bytes) -> Result<B256, EthApi::Error> {
Expand Down
23 changes: 14 additions & 9 deletions crates/e2e-test-utils/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ use alloy_consensus::{
BlobTransactionSidecar, EnvKzgSettings, SidecarBuilder, SimpleCoder, TxEip4844Variant,
TxEnvelope,
};
use alloy_network::{eip2718::Encodable2718, EthereumWallet, TransactionBuilder};
use alloy_network::{eip2718::Encodable2718, Ethereum, EthereumWallet, TransactionBuilder};
use alloy_rpc_types::{TransactionInput, TransactionRequest};
use alloy_signer_local::PrivateKeySigner;
use eyre::Ok;
use reth_primitives::{hex, Address, Bytes, U256};

use reth_primitives::B256;
use reth_primitives::{hex, Address, Bytes, TxKind, B256, U256};

/// Helper for transaction operations
#[derive(Debug)]
Expand Down Expand Up @@ -38,8 +36,11 @@ impl TransactionTestContext {
builder.ingest(b"dummy blob");
let sidecar: BlobTransactionSidecar = builder.build()?;

tx.set_blob_sidecar(sidecar);
tx.set_max_fee_per_blob_gas(15e9 as u128);
<TransactionRequest as TransactionBuilder<Ethereum>>::set_blob_sidecar(&mut tx, sidecar);
<TransactionRequest as TransactionBuilder<Ethereum>>::set_max_fee_per_blob_gas(
&mut tx,
15e9 as u128,
);

let signed = Self::sign_tx(wallet, tx).await;
Ok(signed)
Expand All @@ -48,7 +49,7 @@ impl TransactionTestContext {
/// Signs an arbitrary [`TransactionRequest`] using the provided wallet
pub async fn sign_tx(wallet: PrivateKeySigner, tx: TransactionRequest) -> TxEnvelope {
let signer = EthereumWallet::from(wallet);
tx.build(&signer).await.unwrap()
<TransactionRequest as TransactionBuilder<Ethereum>>::build(tx, &signer).await.unwrap()
}

/// Creates a tx with blob sidecar and sign it, returning bytes
Expand All @@ -70,7 +71,11 @@ impl TransactionTestContext {
let l1_block_info = Bytes::from_static(&hex!("7ef9015aa044bae9d41b8380d781187b426c6fe43df5fb2fb57bd4466ef6a701e1f01e015694deaddeaddeaddeaddeaddeaddeaddeaddead000194420000000000000000000000000000000000001580808408f0d18001b90104015d8eb900000000000000000000000000000000000000000000000000000000008057650000000000000000000000000000000000000000000000000000000063d96d10000000000000000000000000000000000000000000000000000000000009f35273d89754a1e0387b89520d989d3be9c37c1f32495a88faf1ea05c61121ab0d1900000000000000000000000000000000000000000000000000000000000000010000000000000000000000002d679b567db6187c0c8323fa982cfb88b74dbcc7000000000000000000000000000000000000000000000000000000000000083400000000000000000000000000000000000000000000000000000000000f4240"));
let tx = tx(chain_id, Some(l1_block_info), nonce);
let signer = EthereumWallet::from(wallet);
tx.build(&signer).await.unwrap().encoded_2718().into()
<TransactionRequest as TransactionBuilder<Ethereum>>::build(tx, &signer)
.await
.unwrap()
.encoded_2718()
.into()
}

/// Validates the sidecar of a given tx envelope and returns the versioned hashes
Expand All @@ -95,7 +100,7 @@ fn tx(chain_id: u64, data: Option<Bytes>, nonce: u64) -> TransactionRequest {
TransactionRequest {
nonce: Some(nonce),
value: Some(U256::from(100)),
to: Some(reth_primitives::TxKind::Call(Address::random())),
to: Some(TxKind::Call(Address::random())),
gas: Some(210000),
max_fee_per_gas: Some(20e9 as u128),
max_priority_fee_per_gas: Some(20e9 as u128),
Expand Down
10 changes: 5 additions & 5 deletions crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl EthereumNode {
EthereumConsensusBuilder,
>
where
Node: FullNodeTypes<ChainSpec = ChainSpec>,
Node: FullNodeTypes,
<Node as NodeTypes>::Engine: PayloadTypes<
BuiltPayload = EthBuiltPayload,
PayloadAttributes = EthPayloadAttributes,
Expand Down Expand Up @@ -105,7 +105,7 @@ pub struct EthereumExecutorBuilder;

impl<Node> ExecutorBuilder<Node> for EthereumExecutorBuilder
where
Node: FullNodeTypes<ChainSpec = ChainSpec>,
Node: FullNodeTypes,
{
type EVM = EthEvmConfig;
type Executor = EthExecutorProvider<Self::EVM>;
Expand Down Expand Up @@ -134,7 +134,7 @@ pub struct EthereumPoolBuilder {

impl<Node> PoolBuilder<Node> for EthereumPoolBuilder
where
Node: FullNodeTypes<ChainSpec = ChainSpec>,
Node: FullNodeTypes,
{
type Pool = EthTransactionPool<Node::Provider, DiskFileBlobStore>;

Expand Down Expand Up @@ -212,7 +212,7 @@ impl<EVM> EthereumPayloadBuilder<EVM> {

impl<Node, Evm, Pool> PayloadServiceBuilder<Node, Pool> for EthereumPayloadBuilder<Evm>
where
Node: FullNodeTypes<ChainSpec = ChainSpec>,
Node: FullNodeTypes,
Evm: ConfigureEvm,
Pool: TransactionPool + Unpin + 'static,
<Node as NodeTypes>::Engine: PayloadTypes<
Expand Down Expand Up @@ -284,7 +284,7 @@ pub struct EthereumConsensusBuilder {

impl<Node> ConsensusBuilder<Node> for EthereumConsensusBuilder
where
Node: FullNodeTypes<ChainSpec = ChainSpec>,
Node: FullNodeTypes,
{
type Consensus = Arc<dyn reth_consensus::Consensus>;

Expand Down
1 change: 1 addition & 0 deletions crates/node/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ reth-transaction-pool.workspace = true
reth-payload-builder.workspace = true
reth-payload-primitives.workspace = true
reth-tasks.workspace = true
reth-rpc-eth-api.workspace = true
reth-network-api.workspace = true
2 changes: 2 additions & 0 deletions crates/node/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ pub use node::*;

// re-export for convenience
pub use reth_provider::FullProvider;

pub use reth_rpc_eth_api::EthApiTypes;
9 changes: 5 additions & 4 deletions crates/node/api/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::marker::PhantomData;

use reth_chainspec::EthChainSpec;
use reth_chainspec::{ChainSpec, EthChainSpec};
use reth_db_api::{
database::Database,
database_metrics::{DatabaseMetadata, DatabaseMetrics},
Expand All @@ -11,6 +11,7 @@ use reth_evm::execute::BlockExecutorProvider;
use reth_network_api::FullNetwork;
use reth_payload_builder::PayloadBuilderHandle;
use reth_provider::FullProvider;
use reth_rpc_eth_api::EthApiTypes;
use reth_tasks::TaskExecutor;
use reth_transaction_pool::TransactionPool;

Expand Down Expand Up @@ -64,7 +65,7 @@ where
/// node.
///
/// Its types are configured by node internally and are not intended to be user configurable.
pub trait FullNodeTypes: NodeTypes + 'static {
pub trait FullNodeTypes: NodeTypes<ChainSpec = ChainSpec> + 'static {
/// Underlying database type used by the node to store and retrieve data.
type DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static;
/// The provider type used to interact with the node.
Expand Down Expand Up @@ -114,7 +115,7 @@ where

impl<Types, DB, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
where
Types: NodeTypes,
Types: NodeTypes<ChainSpec = ChainSpec>,
Provider: FullProvider<DB, Types::ChainSpec>,
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
{
Expand Down Expand Up @@ -162,7 +163,7 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
pub trait NodeAddOns<N: FullNodeComponents>: Send + Sync + Unpin + Clone + 'static {
/// The core `eth` namespace API type to install on the RPC server (see
/// `reth_rpc_eth_api::EthApiServer`).
type EthApi: Send + Clone;
type EthApi: EthApiTypes + Send + Clone;
}

impl<N: FullNodeComponents> NodeAddOns<N> for () {
Expand Down
Loading

0 comments on commit 7d8196e

Please sign in to comment.