paradigmxyz / reth

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

Add executionPayload abstraction in PayloadTypes #12670

Open mattsse opened 2 days ago

mattsse commented 2 days ago

Describe the feature

currently we have hardcoded the executionpayload type and sidecar:

https://github.com/paradigmxyz/reth/blob/3408059393bcf03f6727f790ec52f28114e25d02/crates/engine/primitives/src/message.rs#L144-L148

ideally we want this to be configurable.

especially when we want to make custom block types work.

first step would be introducing an associated in the EngineTypes

https://github.com/paradigmxyz/reth/blob/3408059393bcf03f6727f790ec52f28114e25d02/crates/engine/primitives/src/lib.rs#L33-L33

that encapsulates both, for example type ExecutionPayloadRequest

and add a helper type that has the payload and sidecar as fields

Additional context

No response

nils-mathieu commented 2 days ago

I'd like to work on this.

nils-mathieu commented 2 days ago

I'm running into a roadblock.

The create_reorg_head function relies on the internals of the ExecutionPayloadRequest (which is being abstracted out). Specifically, it requires the ExecutionPayloadValidator<Spec> to be coupled with the ExecutionPayloadRequest.

https://github.com/paradigmxyz/reth/blob/3408059393bcf03f6727f790ec52f28114e25d02/crates/engine/util/src/reorg.rs#L250-L257

Currently, I have added an associated type to the EngineTypes trait.

trait EngineTypes {
    type ExecutionPayloadRequest;
}

One thing I could do is to add a dependency on Spec for EngineTypes. This way, we would be able to do the following:

trait EngineTypes<Spec> {
    type ExecutionPayloadRequest: ExecutionPayloadRequest<Spec>;
}

trait ExecutionPayloadRequest<Spec> {
    fn create_reorg_head(
        self,
        provider: &Provider,
        evm_config: &Evm,
        payload_validator: &ExecutionPayloadValidator<Spec>,
        depth: usize,
    ) -> RethResult<Self>;
}

Or one alternative would be:

trait EngineTypes {
    type Spec;
    type ExecutionPayloadRequest: ExecutionPayloadRequest<Self::Spec>;
}

Would that be fine? Or am I missing an obvious thing.


Actually I havn't looked too much into it but it seems like Provider and Evm would both need to be coupled as well. Not sure what would the right thing be for this project.