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

chore(op): implement Call for OpEthApi #9502

Merged
merged 24 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0f89de1
feat: API scaffolding
mattsse Jul 10, 2024
758eaf4
Merge branch 'main' into matt/builder3
emhane Jul 10, 2024
57de37f
Add NodeAddOns generic to NodeComponentsBuilder
emhane Jul 10, 2024
1e94e8d
Move eth config and builder ctx to reth-rpc-eth-types & make RpcRegis…
emhane Jul 11, 2024
a4115f2
Remove NodeAddOnBuilders trait and defer instantiation of eth api bui…
emhane Jul 12, 2024
28b7116
fixup! Remove NodeAddOnBuilders trait and defer instantiation of eth …
emhane Jul 12, 2024
a97ba95
Fix conflicts
emhane Jul 12, 2024
5955c2c
Fix lint for lib
emhane Jul 12, 2024
8008698
Fix docs
emhane Jul 12, 2024
2ba7df9
Merge branch 'main' into emhane/node-addons
emhane Jul 12, 2024
8dd44b5
Plug-in OpEthApi to node builder
emhane Jul 12, 2024
4e5ad50
Fix lint remaining targets
emhane Jul 13, 2024
a90a55a
Fix spelling
emhane Jul 13, 2024
9f67cf1
fixup! Fix spelling
emhane Jul 13, 2024
c9a2a7c
Enable optimism feature for reth-optimism-rpc in reth-node-optimism
emhane Jul 13, 2024
dd96713
fixup! Enable optimism feature for reth-optimism-rpc in reth-node-opt…
emhane Jul 13, 2024
31b8a12
Fix doctests
emhane Jul 13, 2024
64f5eee
Merge branch 'main' into emhane/node-addons
emhane Jul 14, 2024
4c23365
Remove unused trait
emhane Jul 14, 2024
86843a6
Remove redundant trait SpawnEthApi
emhane Jul 14, 2024
d726bab
Implement Call for OpEthApi
emhane Jul 15, 2024
83c1928
Remove redundant lint attribute
emhane Jul 15, 2024
14737d4
Merge branch 'main' into emhane/op-ethapi-call
emhane Jul 16, 2024
87569e3
Fix merge conflicts
emhane Jul 16, 2024
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
9 changes: 9 additions & 0 deletions 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 crates/e2e-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ reth-node-builder = { workspace = true, features = ["test-utils"] }
reth-tokio-util.workspace = true
reth-stages-types.workspace = true
reth-network-peers.workspace = true
reth-node-ethereum.workspace = true

jsonrpsee.workspace = true

Expand Down
15 changes: 10 additions & 5 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use std::sync::Arc;

use node::NodeTestContext;
use reth::{
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
builder::{NodeBuilder, NodeConfig, NodeHandle},
rpc::api::eth::{helpers::AddDevSigners, FullEthApiServer},
tasks::TaskManager,
};
use reth_chainspec::ChainSpec;
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_node_builder::{
components::NodeComponentsBuilder, FullNodeTypesAdapter, Node, NodeAdapter, RethFullAdapter,
components::NodeComponentsBuilder, rpc::EthApiBuilderProvider, FullNodeTypesAdapter, Node,
NodeAdapter, NodeAddOns, RethFullAdapter,
};
use reth_provider::providers::BlockchainProvider;
use std::sync::Arc;
use tracing::{span, Level};
use wallet::Wallet;

Expand Down Expand Up @@ -42,9 +45,11 @@ pub async fn setup<N>(
num_nodes: usize,
chain_spec: Arc<ChainSpec>,
is_dev: bool,
) -> eyre::Result<(Vec<NodeHelperType<N>>, TaskManager, Wallet)>
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
where
N: Default + Node<TmpNodeAdapter<N>>,
<N::AddOns as NodeAddOns<Adapter<N>>>::EthApi:
FullEthApiServer + AddDevSigners + EthApiBuilderProvider<Adapter<N>>,
{
let tasks = TaskManager::current();
let exec = tasks.executor();
Expand All @@ -55,7 +60,7 @@ where
};

// Create nodes and peer them
let mut nodes: Vec<NodeTestContext<_>> = Vec::with_capacity(num_nodes);
let mut nodes: Vec<NodeTestContext<_, _>> = Vec::with_capacity(num_nodes);

for idx in 0..num_nodes {
let node_config = NodeConfig::test()
Expand Down Expand Up @@ -106,4 +111,4 @@ type Adapter<N> = NodeAdapter<
>;

/// Type alias for a type of NodeHelper
pub type NodeHelperType<N> = NodeTestContext<Adapter<N>>;
pub type NodeHelperType<N, AO> = NodeTestContext<Adapter<N>, AO>;
33 changes: 20 additions & 13 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
engine_api::EngineApiTestContext, network::NetworkTestContext, payload::PayloadTestContext,
rpc::RpcTestContext, traits::PayloadEnvelopeExt,
};
use std::{marker::PhantomData, pin::Pin};

use alloy_rpc_types::BlockNumberOrTag;
use eyre::Ok;
Expand All @@ -11,32 +8,41 @@ use reth::{
builder::FullNode,
payload::PayloadTypes,
providers::{BlockReader, BlockReaderIdExt, CanonStateSubscriptions, StageCheckpointReader},
rpc::types::engine::PayloadStatusEnum,
rpc::{
api::eth::helpers::{EthApiSpec, EthTransactions, TraceExt},
types::engine::PayloadStatusEnum,
},
};
use reth_node_builder::NodeTypes;
use reth_node_builder::{NodeAddOns, NodeTypes};
use reth_primitives::{BlockHash, BlockNumber, Bytes, B256};
use reth_stages_types::StageId;
use std::{marker::PhantomData, pin::Pin};
use tokio_stream::StreamExt;

use crate::{
engine_api::EngineApiTestContext, network::NetworkTestContext, payload::PayloadTestContext,
rpc::RpcTestContext, traits::PayloadEnvelopeExt,
};

/// An helper struct to handle node actions
pub struct NodeTestContext<Node>
pub struct NodeTestContext<Node, AddOns>
where
Node: FullNodeComponents,
AddOns: NodeAddOns<Node>,
{
pub inner: FullNode<Node>,
pub inner: FullNode<Node, AddOns>,
pub payload: PayloadTestContext<Node::Engine>,
pub network: NetworkTestContext,
pub engine_api: EngineApiTestContext<Node::Engine>,
pub rpc: RpcTestContext<Node>,
pub rpc: RpcTestContext<Node, AddOns::EthApi>,
}

impl<Node> NodeTestContext<Node>
impl<Node, AddOns> NodeTestContext<Node, AddOns>
where
Node: FullNodeComponents,
AddOns: NodeAddOns<Node>,
{
/// Creates a new test node
pub async fn new(node: FullNode<Node>) -> eyre::Result<Self> {
pub async fn new(node: FullNode<Node, AddOns>) -> eyre::Result<Self> {
let builder = node.payload_builder.clone();

Ok(Self {
Expand All @@ -53,7 +59,7 @@ where
}

/// Establish a connection to the node
pub async fn connect(&mut self, node: &mut NodeTestContext<Node>) {
pub async fn connect(&mut self, node: &mut NodeTestContext<Node, AddOns>) {
self.network.add_peer(node.network.record()).await;
node.network.next_session_established().await;
self.network.next_session_established().await;
Expand All @@ -77,6 +83,7 @@ where
where
<Node::Engine as EngineTypes>::ExecutionPayloadV3:
From<<Node::Engine as PayloadTypes>::BuiltPayload> + PayloadEnvelopeExt,
AddOns::EthApi: EthApiSpec + EthTransactions + TraceExt,
{
let mut chain = Vec::with_capacity(length as usize);
for i in 0..length {
Expand Down
14 changes: 10 additions & 4 deletions crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ use alloy_network::eip2718::Decodable2718;
use reth::{
builder::{rpc::RpcRegistry, FullNodeComponents},
rpc::{
api::{eth::helpers::EthTransactions, DebugApiServer},
api::{
eth::helpers::{EthApiSpec, EthTransactions, TraceExt},
DebugApiServer,
},
server_types::eth::EthResult,
},
};
use reth_primitives::{Bytes, B256};

pub struct RpcTestContext<Node: FullNodeComponents> {
pub inner: RpcRegistry<Node>,
pub struct RpcTestContext<Node: FullNodeComponents, EthApi> {
pub inner: RpcRegistry<Node, EthApi>,
}

impl<Node: FullNodeComponents> RpcTestContext<Node> {
impl<Node: FullNodeComponents, EthApi> RpcTestContext<Node, EthApi>
where
EthApi: EthApiSpec + EthTransactions + TraceExt,
{
/// Injects a raw transaction into the node tx pool via RPC server
pub async fn inject_tx(&mut self, raw_tx: Bytes) -> EthResult<B256> {
let eth_api = self.inner.eth_api();
Expand Down
2 changes: 2 additions & 0 deletions crates/ethereum/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ reth-evm-ethereum.workspace = true
reth-consensus.workspace = true
reth-auto-seal-consensus.workspace = true
reth-beacon-consensus.workspace = true
reth-rpc.workspace = true
reth-node-api.workspace = true

# misc
eyre.workspace = true
Expand Down
20 changes: 17 additions & 3 deletions crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Ethereum Node types config.

use crate::{EthEngineTypes, EthEvmConfig};
use std::sync::Arc;

use reth_auto_seal_consensus::AutoSealConsensus;
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
use reth_beacon_consensus::EthBeaconConsensus;
Expand All @@ -9,6 +10,7 @@ use reth_ethereum_engine_primitives::{
};
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_network::NetworkHandle;
use reth_node_api::{FullNodeComponents, NodeAddOns};
use reth_node_builder::{
components::{
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
Expand All @@ -19,12 +21,14 @@ use reth_node_builder::{
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_provider::CanonStateSubscriptions;
use reth_rpc::EthApi;
use reth_tracing::tracing::{debug, info};
use reth_transaction_pool::{
blobstore::DiskFileBlobStore, EthTransactionPool, TransactionPool,
TransactionValidationTaskExecutor,
};
use std::sync::Arc;

use crate::{EthEngineTypes, EthEvmConfig};

/// Type configuration for a regular Ethereum node.
#[derive(Debug, Default, Clone, Copy)]
Expand Down Expand Up @@ -64,6 +68,14 @@ impl NodeTypes for EthereumNode {
type Engine = EthEngineTypes;
}

/// Add-ons w.r.t. l1 ethereum.
#[derive(Debug, Clone)]
pub struct EthereumAddOns;

impl<N: FullNodeComponents> NodeAddOns<N> for EthereumAddOns {
type EthApi = EthApi<N::Provider, N::Pool, NetworkHandle, N::Evm>;
}

impl<N> Node<N> for EthereumNode
where
N: FullNodeTypes<Engine = EthEngineTypes>,
Expand All @@ -77,7 +89,9 @@ where
EthereumConsensusBuilder,
>;

fn components_builder(self) -> Self::ComponentsBuilder {
type AddOns = EthereumAddOns;

fn components_builder(&self) -> Self::ComponentsBuilder {
Self::components()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/node/tests/e2e/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use alloy_genesis::Genesis;
use alloy_primitives::{b256, hex};
use futures::StreamExt;
use reth::rpc::api::eth::helpers::EthTransactions;
use reth::core::rpc::eth::helpers::EthTransactions;
use reth_chainspec::ChainSpec;
use reth_e2e_test_utils::setup;
use reth_provider::CanonStateSubscriptions;
Expand Down
4 changes: 2 additions & 2 deletions crates/ethereum/node/tests/e2e/utils.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use alloy_primitives::{Address, B256};
use reth::rpc::types::engine::PayloadAttributes;
use reth_e2e_test_utils::NodeHelperType;
use reth_node_ethereum::EthereumNode;
use reth_node_ethereum::{node::EthereumAddOns, EthereumNode};
use reth_payload_builder::EthPayloadBuilderAttributes;

/// Ethereum Node Helper type
pub(crate) type EthNode = NodeHelperType<EthereumNode>;
pub(crate) type EthNode = NodeHelperType<EthereumNode, EthereumAddOns>;

/// Helper function to create a new eth payload attributes
pub(crate) fn eth_payload_attributes(timestamp: u64) -> EthPayloadBuilderAttributes {
Expand Down
7 changes: 3 additions & 4 deletions crates/ethereum/node/tests/it/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Node builder setup tests.

use reth_db::test_utils::create_test_rw_db;
use reth_node_api::FullNodeComponents;
use reth_node_builder::{NodeBuilder, NodeConfig};
use reth_node_ethereum::node::EthereumNode;
use reth_node_builder::{FullNodeComponents, NodeBuilder, NodeConfig};
use reth_node_ethereum::node::{EthereumAddOns, EthereumNode};

#[test]
fn test_basic_setup() {
Expand All @@ -14,7 +13,7 @@ fn test_basic_setup() {
let _builder = NodeBuilder::new(config)
.with_database(db)
.with_types::<EthereumNode>()
.with_components(EthereumNode::components())
.with_components::<_, EthereumAddOns>(EthereumNode::components())
.on_component_initialized(move |ctx| {
let _provider = ctx.provider();
println!("{msg}");
Expand Down
4 changes: 2 additions & 2 deletions crates/ethereum/node/tests/it/exex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use reth_db::test_utils::create_test_rw_db;
use reth_exex::ExExContext;
use reth_node_api::FullNodeComponents;
use reth_node_builder::{NodeBuilder, NodeConfig};
use reth_node_ethereum::EthereumNode;
use reth_node_ethereum::{node::EthereumAddOns, EthereumNode};
use std::{
future::Future,
pin::Pin,
Expand Down Expand Up @@ -32,7 +32,7 @@ fn basic_exex() {
let _builder = NodeBuilder::new(config)
.with_database(db)
.with_types::<EthereumNode>()
.with_components(EthereumNode::components())
.with_components::<_, EthereumAddOns>(EthereumNode::components())
.install_exex("dummy", move |ctx| future::ok(DummyExEx { _ctx: ctx }))
.check_launch();
}
5 changes: 3 additions & 2 deletions crates/exex/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use reth_node_builder::{
};
use reth_node_core::node_config::NodeConfig;
use reth_node_ethereum::{
node::{EthereumNetworkBuilder, EthereumPayloadBuilder},
node::{EthereumAddOns, EthereumNetworkBuilder, EthereumPayloadBuilder},
EthEngineTypes, EthEvmConfig,
};
use reth_payload_builder::noop::NoopPayloadBuilderService;
Expand Down Expand Up @@ -125,8 +125,9 @@ where
TestExecutorBuilder,
TestConsensusBuilder,
>;
type AddOns = EthereumAddOns;

fn components_builder(self) -> Self::ComponentsBuilder {
fn components_builder(&self) -> Self::ComponentsBuilder {
ComponentsBuilder::default()
.node_types::<N>()
.pool(TestPoolBuilder::default())
Expand Down
Loading