paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.94k stars 1.17k forks source link

Move more engine API impl logic into type `EngineAPI` #12276

Open mattsse opened 2 hours ago

mattsse commented 2 hours ago

Describe the feature

This type implements the engine API for both ethereum and OP https://github.com/paradigmxyz/reth/blob/c74d2a06f2d84a96f779e62293ef90b3c984c56a/crates/rpc/rpc-engine-api/src/engine_api.rs#L45-L45

via:

https://github.com/paradigmxyz/reth/blob/c74d2a06f2d84a96f779e62293ef90b3c984c56a/crates/rpc/rpc-engine-api/src/engine_api.rs#L635-L636

most of the logic is already directly implemented on EngineApi, but some logic is still part of the trait impl, e.g.:

https://github.com/paradigmxyz/reth/blob/c74d2a06f2d84a96f779e62293ef90b3c984c56a/crates/rpc/rpc-engine-api/src/engine_api.rs#L644-L656

Eventually we want to use a different rpc server implementation for ethereum and OP but it would be nice if this only requires a trait impl and delegation.

for example:

impl EngineApiServer for EngineApi {
       async fn new_payload_v1(&self, payload: ExecutionPayloadV1) -> RpcResult<PayloadStatus> {
        trace!(target: "rpc::engine", "Serving engine_newPayloadV1");
        Ok(Self::new_payload_v1_metered(payload).await?)
      }
}

impl EngineApi {

    async fn new_payload_v1_metered(&self, payload: ExecutionPayloadV1) -> RpcResult<PayloadStatus> {
        let start = Instant::now();
        let res = Self::fork_choice_updated_v3(self, fork_choice_state, payload_attributes).await;
        self.inner.metrics.latency.fork_choice_updated_v3.record(start.elapsed());
        self.inner.metrics.fcu_response.update_response_metrics(&res);
    }
} 

effectively duplicating the function in impl EngineApi

most of this already exists, but we can move even more, like metric updates.

this should be done as 1 PR per function

Additional context

No response

Parikalp-Bhardwaj commented 2 hours ago

Hi @mattsse, can I work on this issue