Skip to content

Comments

feat: add reth traits to alloy for op-alloy dependency removal#3649

Open
theochap wants to merge 2 commits intoalloy-rs:mainfrom
theochap:theo/add-reth-traits
Open

feat: add reth traits to alloy for op-alloy dependency removal#3649
theochap wants to merge 2 commits intoalloy-rs:mainfrom
theochap:theo/add-reth-traits

Conversation

@theochap
Copy link
Contributor

@theochap theochap commented Feb 5, 2026

Summary

  • Add 10 trait definitions from reth core crates into alloy so that op-alloy can implement them natively without depending on reth
  • alloy-consensus: InMemorySize, SerdeBincodeCompat, SignedTransaction traits + impls for Ethereum types
  • alloy-rpc-types-engine: PayloadAttributes, ExecutionPayload traits + impls for alloy's own structs
  • alloy-network: FromConsensusTx, TryFromTransactionResponse, TryFromReceiptResponse, SignableTxRequest, TryIntoSimTx, RpcTypes traits + Ethereum impls

Motivation

This is part of a multi-repo effort to remove op-alloy-* dependencies from core (non-optimism) reth crates. By moving trait definitions into alloy, op-alloy can implement them natively for OP types without needing to depend on reth, and reth core crates can drop their op-alloy dependencies entirely.

Test plan

  • cargo check --workspace --all-features
  • cargo nextest run --workspace
  • Verify traits are correctly re-exported from each crate's lib.rs

🤖 Generated with Claude Code

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt @onbjerg ?

@theochap
Copy link
Contributor Author

theochap commented Feb 6, 2026

Btw I implemented some new type wrappers for the DB traits in op-reth directly (Compact and such). Here are all the traits that could be cleanly pulled out of op-reth

Move 10 trait definitions from reth core crates into alloy so that
op-alloy can implement them natively without depending on reth:

- alloy-consensus: InMemorySize, SerdeBincodeCompat, SignedTransaction
- alloy-rpc-types-engine: PayloadAttributes, ExecutionPayload
- alloy-network: FromConsensusTx, TryFromTransactionResponse,
  TryFromReceiptResponse, SignableTxRequest, TryIntoSimTx, RpcTypes

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@theochap theochap force-pushed the theo/add-reth-traits branch from 008019b to 8f96b37 Compare February 10, 2026 18:27
Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally supportive, but it seems like a lot of these are because reth is not fully using alloy and instead uses a bunch of wrapper traits/duplicated functionality

///
/// Use unchecked methods only when dealing with historical pre-EIP-2 transactions.
#[auto_impl::auto_impl(&, Arc)]
pub trait SignedTransaction:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have Signed<T>, I'm not sure why this is different in reth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed<T> looks pretty different from SignedTransaction. One is a trait, the other is a struct. I think reth wants to make it possible to generically override transactions with custom types that don't come from alloy

///
/// The recommended way to add bincode compatible serialization is via the
/// [`serde_with`] crate and the `serde_as` macro.
pub trait SerdeBincodeCompat: Sized + 'static {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this belongs in alloy tbh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you think it would be better to integrate?

/// Converts `self` into `T`.
///
/// Should create a fake transaction for simulation using [`TransactionRequest`].
pub trait TryIntoSimTx<T>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these probably belong in alloy-evm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, will move it there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, "these" mean all the traits in this file?

/// RPC types used by the `eth_` RPC API.
///
/// This is a subset of [`Network`] trait with only RPC response types kept.
pub trait RpcTypes: Send + Sync + Clone + Unpin + Debug + 'static {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these already exist in Network, no need to duplicate them.

Comment on lines 75 to 88
pub type RpcTransaction<T> = <T as RpcTypes>::TransactionResponse;

/// Adapter for network specific receipt response.
pub type RpcReceipt<T> = <T as RpcTypes>::Receipt;

/// Adapter for network specific header response.
pub type RpcHeader<T> = <T as RpcTypes>::Header;

/// Adapter for network specific block type.
pub type RpcBlock<T> =
alloy_rpc_types_eth::Block<RpcTransaction<T>, RpcHeader<T>>;

/// Adapter for network specific transaction request.
pub type RpcTxReq<T> = <T as RpcTypes>::TransactionRequest;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be over Network

Comment on lines 44 to 45
// Re-export trait names without the `Trait` suffix inside the traits module for direct use.
// Users can also import from `alloy_rpc_types_engine::traits::{PayloadAttributes, ExecutionPayload}`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure what this comment is doing here?

@github-project-automation github-project-automation bot moved this to In Progress in Alloy Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants