mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat(rpc): rename Client generics to Provider (#3126)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -23,9 +23,9 @@ const MAX_PAYLOAD_BODIES_LIMIT: u64 = 1024;
|
||||
|
||||
/// The Engine API implementation that grants the Consensus layer access to data and
|
||||
/// functions in the Execution layer that are crucial for the consensus process.
|
||||
pub struct EngineApi<Client> {
|
||||
/// The client to interact with the chain.
|
||||
client: Client,
|
||||
pub struct EngineApi<Provider> {
|
||||
/// The provider to interact with the chain.
|
||||
provider: Provider,
|
||||
/// Consensus configuration
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
/// The channel to send messages to the beacon consensus engine.
|
||||
@ -34,18 +34,18 @@ pub struct EngineApi<Client> {
|
||||
payload_store: PayloadStore,
|
||||
}
|
||||
|
||||
impl<Client> EngineApi<Client>
|
||||
impl<Provider> EngineApi<Provider>
|
||||
where
|
||||
Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
|
||||
Provider: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
|
||||
{
|
||||
/// Create new instance of [EngineApi].
|
||||
pub fn new(
|
||||
client: Client,
|
||||
provider: Provider,
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
beacon_consensus: BeaconConsensusEngineHandle,
|
||||
payload_store: PayloadStore,
|
||||
) -> Self {
|
||||
Self { client, chain_spec, beacon_consensus, payload_store }
|
||||
Self { provider, chain_spec, beacon_consensus, payload_store }
|
||||
}
|
||||
|
||||
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/paris.md#engine_newpayloadv1>
|
||||
@ -123,7 +123,7 @@ where
|
||||
/// Caution: This should not return the `withdrawals` field
|
||||
///
|
||||
/// Note:
|
||||
/// > Client software MAY stop the corresponding build process after serving this call.
|
||||
/// > Provider software MAY stop the corresponding build process after serving this call.
|
||||
pub async fn get_payload_v1(&self, payload_id: PayloadId) -> EngineApiResult<ExecutionPayload> {
|
||||
Ok(self
|
||||
.payload_store
|
||||
@ -139,7 +139,7 @@ where
|
||||
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/shanghai.md#engine_getpayloadv2>
|
||||
///
|
||||
/// Note:
|
||||
/// > Client software MAY stop the corresponding build process after serving this call.
|
||||
/// > Provider software MAY stop the corresponding build process after serving this call.
|
||||
async fn get_payload_v2(
|
||||
&self,
|
||||
payload_id: PayloadId,
|
||||
@ -180,7 +180,7 @@ where
|
||||
let end = start.saturating_add(count);
|
||||
for num in start..end {
|
||||
let block = self
|
||||
.client
|
||||
.provider
|
||||
.block(BlockHashOrNumber::Number(num))
|
||||
.map_err(|err| EngineApiError::Internal(Box::new(err)))?;
|
||||
result.push(block.map(Into::into));
|
||||
@ -202,7 +202,7 @@ where
|
||||
let mut result = Vec::with_capacity(hashes.len());
|
||||
for hash in hashes {
|
||||
let block = self
|
||||
.client
|
||||
.provider
|
||||
.block(BlockHashOrNumber::Hash(hash))
|
||||
.map_err(|err| EngineApiError::Internal(Box::new(err)))?;
|
||||
result.push(block.map(Into::into));
|
||||
@ -249,7 +249,7 @@ where
|
||||
|
||||
// Attempt to look up terminal block hash
|
||||
let local_hash = self
|
||||
.client
|
||||
.provider
|
||||
.block_hash(terminal_block_number.as_u64())
|
||||
.map_err(|err| EngineApiError::Internal(Box::new(err)))?;
|
||||
|
||||
@ -302,9 +302,9 @@ where
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<Client> EngineApiServer for EngineApi<Client>
|
||||
impl<Provider> EngineApiServer for EngineApi<Provider>
|
||||
where
|
||||
Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
|
||||
Provider: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
|
||||
{
|
||||
/// Handler for `engine_newPayloadV1`
|
||||
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/paris.md#engine_newpayloadv1>
|
||||
@ -355,7 +355,7 @@ where
|
||||
/// Caution: This should not return the `withdrawals` field
|
||||
///
|
||||
/// Note:
|
||||
/// > Client software MAY stop the corresponding build process after serving this call.
|
||||
/// > Provider software MAY stop the corresponding build process after serving this call.
|
||||
async fn get_payload_v1(&self, payload_id: PayloadId) -> RpcResult<ExecutionPayload> {
|
||||
trace!(target: "rpc::engine", "Serving engine_getPayloadV1");
|
||||
Ok(EngineApi::get_payload_v1(self, payload_id).await?)
|
||||
@ -369,7 +369,7 @@ where
|
||||
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/shanghai.md#engine_getpayloadv2>
|
||||
///
|
||||
/// Note:
|
||||
/// > Client software MAY stop the corresponding build process after serving this call.
|
||||
/// > Provider software MAY stop the corresponding build process after serving this call.
|
||||
async fn get_payload_v2(&self, payload_id: PayloadId) -> RpcResult<ExecutionPayloadEnvelope> {
|
||||
trace!(target: "rpc::engine", "Serving engine_getPayloadV2");
|
||||
Ok(EngineApi::get_payload_v2(self, payload_id).await?)
|
||||
@ -424,7 +424,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Client> std::fmt::Debug for EngineApi<Client> {
|
||||
impl<Provider> std::fmt::Debug for EngineApi<Provider> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("EngineApi").finish_non_exhaustive()
|
||||
}
|
||||
@ -444,22 +444,22 @@ mod tests {
|
||||
|
||||
fn setup_engine_api() -> (EngineApiTestHandle, EngineApi<Arc<MockEthProvider>>) {
|
||||
let chain_spec: Arc<ChainSpec> = MAINNET.clone();
|
||||
let client = Arc::new(MockEthProvider::default());
|
||||
let provider = Arc::new(MockEthProvider::default());
|
||||
let payload_store = spawn_test_payload_service();
|
||||
let (to_engine, engine_rx) = unbounded_channel();
|
||||
let api = EngineApi::new(
|
||||
client.clone(),
|
||||
provider.clone(),
|
||||
chain_spec.clone(),
|
||||
BeaconConsensusEngineHandle::new(to_engine),
|
||||
payload_store.into(),
|
||||
);
|
||||
let handle = EngineApiTestHandle { chain_spec, client, from_api: engine_rx };
|
||||
let handle = EngineApiTestHandle { chain_spec, provider, from_api: engine_rx };
|
||||
(handle, api)
|
||||
}
|
||||
|
||||
struct EngineApiTestHandle {
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
client: Arc<MockEthProvider>,
|
||||
provider: Arc<MockEthProvider>,
|
||||
from_api: UnboundedReceiver<BeaconEngineMessage>,
|
||||
}
|
||||
|
||||
@ -511,7 +511,7 @@ mod tests {
|
||||
|
||||
let (start, count) = (1, 10);
|
||||
let blocks = random_block_range(start..=start + count - 1, H256::default(), 0..2);
|
||||
handle.client.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal())));
|
||||
handle.provider.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal())));
|
||||
|
||||
let expected =
|
||||
blocks.iter().cloned().map(|b| Some(b.unseal().into())).collect::<Vec<_>>();
|
||||
@ -530,7 +530,7 @@ mod tests {
|
||||
// Insert only blocks in ranges 1-25 and 50-75
|
||||
let first_missing_range = 26..=50;
|
||||
let second_missing_range = 76..=100;
|
||||
handle.client.extend_blocks(
|
||||
handle.provider.extend_blocks(
|
||||
blocks
|
||||
.iter()
|
||||
.filter(|b| {
|
||||
@ -611,7 +611,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// Add block and to provider local store and test for mismatch
|
||||
handle.client.add_block(
|
||||
handle.provider.add_block(
|
||||
execution_terminal_block.hash(),
|
||||
execution_terminal_block.clone().unseal(),
|
||||
);
|
||||
@ -638,7 +638,7 @@ mod tests {
|
||||
terminal_block_number: terminal_block_number.into(),
|
||||
};
|
||||
|
||||
handle.client.add_block(terminal_block.hash(), terminal_block.unseal());
|
||||
handle.provider.add_block(terminal_block.hash(), terminal_block.unseal());
|
||||
|
||||
let config =
|
||||
api.exchange_transition_configuration(transition_config.clone()).await.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user