mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add helpers to obtain the engine API client (#7413)
This commit is contained in:
@ -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;
|
||||
@ -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> {
|
||||
|
||||
@ -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};
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user