Skip to content

Commit

Permalink
feat: add helpers to obtain the engine API client (paradigmxyz#7413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and Ruteri committed Apr 17, 2024
1 parent e226b38 commit c22ae83
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
19 changes: 18 additions & 1 deletion crates/node-builder/src/node.rs
Expand Up @@ -9,7 +9,10 @@ pub use reth_node_api::NodeTypes;
use reth_node_core::{
dirs::{ChainPath, DataDirPath},
node_config::NodeConfig,
rpc::builder::{auth::AuthServerHandle, RpcServerHandle},
rpc::{
api::EngineApiClient,
builder::{auth::AuthServerHandle, RpcServerHandle},
},
};
use reth_payload_builder::PayloadBuilderHandle;
use reth_primitives::ChainSpec;
Expand Down Expand Up @@ -124,6 +127,20 @@ impl<Node: FullNodeComponents> FullNode<Node> {
pub fn auth_server_handle(&self) -> &AuthServerHandle {
&self.rpc_server_handles.auth
}

/// Returns the [EngineApiClient] interface for the authenticated engine API.
///
/// This will send authenticated http requests to the node's auth server.
pub fn engine_http_client(&self) -> impl EngineApiClient<Node::Engine> {
self.auth_server_handle().http_client()
}

/// Returns the [EngineApiClient] interface for the authenticated engine API.
///
/// This will send authenticated ws requests to the node's auth server.
pub async fn engine_ws_client(&self) -> impl EngineApiClient<Node::Engine> {
self.auth_server_handle().ws_client().await
}
}

impl<Node: FullNodeComponents> Clone for FullNode<Node> {
Expand Down
38 changes: 18 additions & 20 deletions crates/node-e2e-tests/tests/it/eth.rs
Expand Up @@ -12,7 +12,7 @@ use reth::{
tasks::TaskManager,
};
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
use reth_node_ethereum::{EthEngineTypes, EthereumNode};
use reth_node_ethereum::EthereumNode;
use reth_primitives::{Address, BlockNumberOrTag, B256};
use std::time::{SystemTime, UNIX_EPOCH};

Expand Down Expand Up @@ -46,8 +46,10 @@ async fn can_run_eth_node() -> eyre::Result<()> {
let payload_id = node.payload_builder.new_payload(eth_attr.clone()).await?;

// resolve best payload via engine api
let client = node.auth_server_handle().http_client();
EngineApiClient::<EthEngineTypes>::get_payload_v3(&client, payload_id).await?;
let client = node.engine_http_client();

// ensure we can get the payload over the engine api
let _payload = client.get_payload_v3(payload_id).await?;

let mut payload_event_stream = payload_events.into_stream();

Expand All @@ -67,29 +69,25 @@ async fn can_run_eth_node() -> eyre::Result<()> {
let payload_v3 = envelope_v3.execution_payload;

// submit payload to engine api
let submission = EngineApiClient::<EthEngineTypes>::new_payload_v3(
&client,
payload_v3,
vec![],
eth_attr.parent_beacon_block_root.unwrap(),
)
.await?;
let submission = client
.new_payload_v3(payload_v3, vec![], eth_attr.parent_beacon_block_root.unwrap())
.await?;
assert!(submission.is_valid());

// get latest valid hash from blockchain tree
let hash = submission.latest_valid_hash.unwrap();

// trigger forkchoice update via engine api to commit the block to the blockchain
let fcu = EngineApiClient::<EthEngineTypes>::fork_choice_updated_v2(
&client,
ForkchoiceState {
head_block_hash: hash,
safe_block_hash: hash,
finalized_block_hash: hash,
},
None,
)
.await?;
let fcu = client
.fork_choice_updated_v2(
ForkchoiceState {
head_block_hash: hash,
safe_block_hash: hash,
finalized_block_hash: hash,
},
None,
)
.await?;
assert!(fcu.is_valid());

// get head block from notifications stream and verify the tx has been pushed to the pool
Expand Down

0 comments on commit c22ae83

Please sign in to comment.