mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(rpc): expose ethapi in node builder for op customisation (#9444)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
@ -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()
|
||||
@ -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>;
|
||||
|
||||
@ -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;
|
||||
@ -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 {
|
||||
@ -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;
|
||||
@ -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 {
|
||||
|
||||
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user