reth icon indicating copy to clipboard operation
reth copied to clipboard

Remove multi provider trait functions in rpc helper traits

Open mattsse opened this issue 1 year ago • 1 comments
trafficstars

Describe the feature

we compose various rpc traits with default impls

like:

https://github.com/paradigmxyz/reth/blob/a07efa7b5b83b9821631a9191e225a8c0bc42f0b/crates/rpc/rpc-eth-api/src/helpers/trace.rs#L22-L22

these are effective stacked traits. currently we have some functions multiple times:

https://github.com/paradigmxyz/reth/blob/a07efa7b5b83b9821631a9191e225a8c0bc42f0b/crates/rpc/rpc-eth-api/src/helpers/trace.rs#L26-L26

https://github.com/paradigmxyz/reth/blob/a07efa7b5b83b9821631a9191e225a8c0bc42f0b/crates/rpc/rpc-eth-api/src/helpers/call.rs#L459-L459

or

https://github.com/paradigmxyz/reth/blob/a07efa7b5b83b9821631a9191e225a8c0bc42f0b/crates/rpc/rpc-eth-api/src/helpers/transaction.rs#L56-L56

https://github.com/paradigmxyz/reth/blob/a07efa7b5b83b9821631a9191e225a8c0bc42f0b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs#L47-L52

resulting in some inconvenient usage and restrictions.

like:

https://github.com/paradigmxyz/reth/blob/a07efa7b5b83b9821631a9191e225a8c0bc42f0b/crates/rpc/rpc-eth-api/src/helpers/block.rs#L154-L154

ideally we only have one evm_config and one provider function, perhaps in a single trait that sits at the bottom of the stack, these should like by an associated type and we can easily implement this because we have this generic:

https://github.com/paradigmxyz/reth/blob/a07efa7b5b83b9821631a9191e225a8c0bc42f0b/crates/rpc/rpc/src/eth/helpers/transaction.rs#L13-L23

and it is expected that the final provider is then the full provider that satisfies all traits.

the stacked traits can then add the required bounds

trait EthCore // naming tbd {
  type Provider;
  type Evm;

  fn provider(&self) -> &Self::Provider;
  fn evm_config...
}

then we can force the required trait bounds on Trace for example

trait Trace: EthCore<Provider: ....> {

}

Additional context

No response

mattsse avatar Oct 02 '24 12:10 mattsse