mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
feat: implement clientVersionV1 in engine API (#8016)
This commit is contained in:
@@ -11,9 +11,10 @@ use reth_primitives::{BlockHash, BlockHashOrNumber, BlockNumber, ChainSpec, Hard
|
||||
use reth_provider::{BlockReader, EvmEnvProvider, HeaderProvider, StateProviderFactory};
|
||||
use reth_rpc_api::EngineApiServer;
|
||||
use reth_rpc_types::engine::{
|
||||
CancunPayloadFields, ExecutionPayload, ExecutionPayloadBodiesV1, ExecutionPayloadInputV2,
|
||||
ExecutionPayloadV1, ExecutionPayloadV3, ExecutionPayloadV4, ForkchoiceState, ForkchoiceUpdated,
|
||||
PayloadId, PayloadStatus, TransitionConfiguration, CAPABILITIES,
|
||||
CancunPayloadFields, ClientVersionV1, ExecutionPayload, ExecutionPayloadBodiesV1,
|
||||
ExecutionPayloadInputV2, ExecutionPayloadV1, ExecutionPayloadV3, ExecutionPayloadV4,
|
||||
ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus, TransitionConfiguration,
|
||||
CAPABILITIES,
|
||||
};
|
||||
use reth_rpc_types_compat::engine::payload::{
|
||||
convert_payload_input_v2_to_payload, convert_to_payload_body_v1,
|
||||
@@ -48,6 +49,8 @@ struct EngineApiInner<Provider, EngineT: EngineTypes> {
|
||||
task_spawner: Box<dyn TaskSpawner>,
|
||||
/// The latency and response type metrics for engine api calls
|
||||
metrics: EngineApiMetrics,
|
||||
/// Identification of the execution client used by the consensus client
|
||||
client: ClientVersionV1,
|
||||
}
|
||||
|
||||
impl<Provider, EngineT> EngineApi<Provider, EngineT>
|
||||
@@ -62,6 +65,7 @@ where
|
||||
beacon_consensus: BeaconConsensusEngineHandle<EngineT>,
|
||||
payload_store: PayloadStore<EngineT>,
|
||||
task_spawner: Box<dyn TaskSpawner>,
|
||||
client: ClientVersionV1,
|
||||
) -> Self {
|
||||
let inner = Arc::new(EngineApiInner {
|
||||
provider,
|
||||
@@ -70,10 +74,18 @@ where
|
||||
payload_store,
|
||||
task_spawner,
|
||||
metrics: EngineApiMetrics::default(),
|
||||
client,
|
||||
});
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
/// Fetches the client version.
|
||||
async fn get_client_version_v1(
|
||||
&self,
|
||||
_client: ClientVersionV1,
|
||||
) -> EngineApiResult<Vec<ClientVersionV1>> {
|
||||
Ok(vec![self.inner.client.clone()])
|
||||
}
|
||||
/// Fetches the attributes for the payload with the given id.
|
||||
async fn get_payload_attributes(
|
||||
&self,
|
||||
@@ -749,6 +761,18 @@ where
|
||||
self.inner.metrics.latency.exchange_transition_configuration.record(start.elapsed());
|
||||
Ok(res?)
|
||||
}
|
||||
/// Handler for `engine_getClientVersionV1`
|
||||
///
|
||||
/// See also <https://github.com/ethereum/execution-apis/blob/03911ffc053b8b806123f1fc237184b0092a485a/src/engine/identification.md>
|
||||
async fn get_client_version_v1(
|
||||
&self,
|
||||
client: ClientVersionV1,
|
||||
) -> RpcResult<Vec<ClientVersionV1>> {
|
||||
trace!(target: "rpc::engine", "Serving engine_getClientVersionV1");
|
||||
let res = EngineApi::get_client_version_v1(self, client).await;
|
||||
|
||||
Ok(res?)
|
||||
}
|
||||
|
||||
/// Handler for `engine_exchangeCapabilitiesV1`
|
||||
/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/common.md#capabilities>
|
||||
@@ -773,9 +797,11 @@ mod tests {
|
||||
use reth_beacon_consensus::{BeaconConsensusEngineEvent, BeaconEngineMessage};
|
||||
use reth_ethereum_engine_primitives::EthEngineTypes;
|
||||
use reth_interfaces::test_utils::generators::random_block;
|
||||
|
||||
use reth_payload_builder::test_utils::spawn_test_payload_service;
|
||||
use reth_primitives::{SealedBlock, B256, MAINNET};
|
||||
use reth_provider::test_utils::MockEthProvider;
|
||||
use reth_rpc_types::engine::{ClientCode, ClientVersionV1};
|
||||
use reth_rpc_types_compat::engine::payload::execution_payload_from_sealed_block;
|
||||
use reth_tasks::TokioTaskExecutor;
|
||||
use reth_tokio_util::EventSender;
|
||||
@@ -783,6 +809,13 @@ mod tests {
|
||||
|
||||
fn setup_engine_api() -> (EngineApiTestHandle, EngineApi<Arc<MockEthProvider>, EthEngineTypes>)
|
||||
{
|
||||
let client = ClientVersionV1 {
|
||||
code: ClientCode::RH,
|
||||
name: "Reth".to_string(),
|
||||
version: "v0.2.0-beta.5".to_string(),
|
||||
commit: "defa64b2".to_string(),
|
||||
};
|
||||
|
||||
let chain_spec: Arc<ChainSpec> = MAINNET.clone();
|
||||
let provider = Arc::new(MockEthProvider::default());
|
||||
let payload_store = spawn_test_payload_service();
|
||||
@@ -795,11 +828,25 @@ mod tests {
|
||||
BeaconConsensusEngineHandle::new(to_engine, event_sender),
|
||||
payload_store.into(),
|
||||
task_executor,
|
||||
client,
|
||||
);
|
||||
let handle = EngineApiTestHandle { chain_spec, provider, from_api: engine_rx };
|
||||
(handle, api)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn engine_client_version_v1() {
|
||||
let client = ClientVersionV1 {
|
||||
code: ClientCode::RH,
|
||||
name: "Reth".to_string(),
|
||||
version: "v0.2.0-beta.5".to_string(),
|
||||
commit: "defa64b2".to_string(),
|
||||
};
|
||||
let (_, api) = setup_engine_api();
|
||||
let res = api.get_client_version_v1(client.clone()).await;
|
||||
assert_eq!(res.unwrap(), vec![client]);
|
||||
}
|
||||
|
||||
struct EngineApiTestHandle {
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
provider: Arc<MockEthProvider>,
|
||||
|
||||
Reference in New Issue
Block a user