-
Notifications
You must be signed in to change notification settings - Fork 1.6k
refactor: move ExtendedTxEnvelope to reth-primitives-traits #16102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mattsse
merged 7 commits into
paradigmxyz:main
from
iTranscend:feat/move-ext-tx-envelope
May 8, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1822e12
refactor: move ExtendedTxEnvelope to reth-primitives-traits
iTranscend 1cace77
fix imports
fgimenez 154a54e
move ExtendedOpTxEnvelope alias to example
fgimenez fd97853
feature gate serde-bincode-compat and reth-codec
fgimenez 52aadd4
feature gate op impls and reth-codec import
fgimenez 0b40714
fix
fgimenez 5828f96
fix
fgimenez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
use alloy_consensus::{error::ValueError, Transaction}; | ||
use crate::{ | ||
size::InMemorySize, | ||
transaction::signed::{RecoveryError, SignedTransaction}, | ||
}; | ||
use alloc::vec::Vec; | ||
use alloy_consensus::Transaction; | ||
use alloy_eips::{ | ||
eip2718::{Eip2718Error, Eip2718Result, IsTyped2718}, | ||
eip2930::AccessList, | ||
eip7702::SignedAuthorization, | ||
Decodable2718, Encodable2718, Typed2718, | ||
}; | ||
use alloy_primitives::{bytes::Buf, ChainId, Signature, TxHash}; | ||
use alloy_primitives::{ChainId, TxHash}; | ||
use alloy_rlp::{BufMut, Decodable, Encodable, Result as RlpResult}; | ||
use op_alloy_consensus::{OpPooledTransaction, OpTxEnvelope}; | ||
use reth_codecs::Compact; | ||
use reth_ethereum::primitives::{ | ||
serde_bincode_compat::SerdeBincodeCompat, transaction::signed::RecoveryError, InMemorySize, | ||
SignedTransaction, | ||
}; | ||
use revm_primitives::{Address, Bytes, TxKind, B256, U256}; | ||
|
||
use super::CustomTransactionEnvelope; | ||
#[cfg(feature = "op")] | ||
use op_alloy_consensus::{OpPooledTransaction, OpTxEnvelope}; | ||
|
||
#[cfg(feature = "op")] | ||
use alloy_primitives::Signature; | ||
|
||
#[cfg(feature = "op")] | ||
use alloy_consensus::error::ValueError; | ||
|
||
macro_rules! delegate { | ||
($self:expr => $tx:ident.$method:ident($($arg:expr),*)) => { | ||
|
@@ -33,44 +39,44 @@ macro_rules! delegate { | |
/// | ||
/// Note: The other transaction type variants must not overlap with the builtin one, transaction | ||
/// types must be unique. | ||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Hash, Eq, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
#[derive(Debug, Clone, Hash, Eq, PartialEq)] | ||
pub enum ExtendedTxEnvelope<BuiltIn, Other> { | ||
/// The builtin transaction type. | ||
BuiltIn(BuiltIn), | ||
/// The other transaction type. | ||
Other(Other), | ||
} | ||
|
||
pub type ExtendedOpTxEnvelope<T> = ExtendedTxEnvelope<OpTxEnvelope, T>; | ||
|
||
impl TryFrom<ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>> | ||
for ExtendedTxEnvelope<OpPooledTransaction, CustomTransactionEnvelope> | ||
#[cfg(feature = "op")] | ||
impl<Tx> TryFrom<ExtendedTxEnvelope<OpTxEnvelope, Tx>> | ||
for ExtendedTxEnvelope<OpPooledTransaction, Tx> | ||
{ | ||
type Error = OpTxEnvelope; | ||
|
||
fn try_from( | ||
value: ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>, | ||
) -> Result<Self, Self::Error> { | ||
fn try_from(value: ExtendedTxEnvelope<OpTxEnvelope, Tx>) -> Result<Self, Self::Error> { | ||
match value { | ||
ExtendedTxEnvelope::BuiltIn(tx) => { | ||
let converted_tx: OpPooledTransaction = tx.clone().try_into().map_err(|_| tx)?; | ||
Ok(ExtendedTxEnvelope::BuiltIn(converted_tx)) | ||
Ok(Self::BuiltIn(converted_tx)) | ||
} | ||
ExtendedTxEnvelope::Other(tx) => Ok(ExtendedTxEnvelope::Other(tx)), | ||
ExtendedTxEnvelope::Other(tx) => Ok(Self::Other(tx)), | ||
} | ||
} | ||
} | ||
|
||
impl From<OpPooledTransaction> for ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope> { | ||
#[cfg(feature = "op")] | ||
impl<Tx> From<OpPooledTransaction> for ExtendedTxEnvelope<OpTxEnvelope, Tx> { | ||
fn from(tx: OpPooledTransaction) -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also needs an op feature |
||
ExtendedTxEnvelope::BuiltIn(tx.into()) | ||
Self::BuiltIn(tx.into()) | ||
} | ||
} | ||
|
||
impl TryFrom<ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>> for OpPooledTransaction { | ||
#[cfg(feature = "op")] | ||
impl<Tx> TryFrom<ExtendedTxEnvelope<OpTxEnvelope, Tx>> for OpPooledTransaction { | ||
type Error = ValueError<OpTxEnvelope>; | ||
|
||
fn try_from( | ||
_tx: ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>, | ||
) -> Result<Self, Self::Error> { | ||
fn try_from(_tx: ExtendedTxEnvelope<OpTxEnvelope, Tx>) -> Result<Self, Self::Error> { | ||
match _tx { | ||
ExtendedTxEnvelope::BuiltIn(inner) => inner.try_into(), | ||
ExtendedTxEnvelope::Other(_tx) => Err(ValueError::new( | ||
|
@@ -303,38 +309,49 @@ where | |
} | ||
} | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize)] | ||
pub enum ExtendedTxEnvelopeRepr<'a, B: SerdeBincodeCompat, T: SerdeBincodeCompat> { | ||
BuiltIn(B::BincodeRepr<'a>), | ||
Other(T::BincodeRepr<'a>), | ||
} | ||
#[cfg(feature = "serde-bincode-compat")] | ||
mod serde_bincode_compat { | ||
use super::*; | ||
use crate::serde_bincode_compat::SerdeBincodeCompat; | ||
|
||
impl<B, T> SerdeBincodeCompat for ExtendedTxEnvelope<B, T> | ||
where | ||
B: SerdeBincodeCompat + std::fmt::Debug, | ||
T: SerdeBincodeCompat + std::fmt::Debug, | ||
{ | ||
type BincodeRepr<'a> = ExtendedTxEnvelopeRepr<'a, B, T>; | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
#[derive(Debug)] | ||
pub enum ExtendedTxEnvelopeRepr<'a, B: SerdeBincodeCompat, T: SerdeBincodeCompat> { | ||
BuiltIn(B::BincodeRepr<'a>), | ||
Other(T::BincodeRepr<'a>), | ||
} | ||
|
||
fn as_repr(&self) -> Self::BincodeRepr<'_> { | ||
match self { | ||
Self::BuiltIn(tx) => ExtendedTxEnvelopeRepr::BuiltIn(tx.as_repr()), | ||
Self::Other(tx) => ExtendedTxEnvelopeRepr::Other(tx.as_repr()), | ||
impl<B, T> SerdeBincodeCompat for ExtendedTxEnvelope<B, T> | ||
where | ||
B: SerdeBincodeCompat + core::fmt::Debug, | ||
T: SerdeBincodeCompat + core::fmt::Debug, | ||
{ | ||
type BincodeRepr<'a> = ExtendedTxEnvelopeRepr<'a, B, T>; | ||
|
||
fn as_repr(&self) -> Self::BincodeRepr<'_> { | ||
match self { | ||
Self::BuiltIn(tx) => ExtendedTxEnvelopeRepr::BuiltIn(tx.as_repr()), | ||
Self::Other(tx) => ExtendedTxEnvelopeRepr::Other(tx.as_repr()), | ||
} | ||
} | ||
} | ||
|
||
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self { | ||
match repr { | ||
ExtendedTxEnvelopeRepr::BuiltIn(tx_repr) => Self::BuiltIn(B::from_repr(tx_repr)), | ||
ExtendedTxEnvelopeRepr::Other(tx_repr) => Self::Other(T::from_repr(tx_repr)), | ||
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self { | ||
match repr { | ||
ExtendedTxEnvelopeRepr::BuiltIn(tx_repr) => Self::BuiltIn(B::from_repr(tx_repr)), | ||
ExtendedTxEnvelopeRepr::Other(tx_repr) => Self::Other(T::from_repr(tx_repr)), | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<B, T> Compact for ExtendedTxEnvelope<B, T> | ||
#[cfg(feature = "reth-codec")] | ||
use alloy_primitives::bytes::Buf; | ||
|
||
#[cfg(feature = "reth-codec")] | ||
impl<B, T> reth_codecs::Compact for ExtendedTxEnvelope<B, T> | ||
where | ||
B: Transaction + IsTyped2718 + Compact, | ||
T: Transaction + Compact, | ||
B: Transaction + IsTyped2718 + reth_codecs::Compact, | ||
T: Transaction + reth_codecs::Compact, | ||
{ | ||
fn to_compact<Buf>(&self, buf: &mut Buf) -> usize | ||
where | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we either need to relax this so that this works for any Builtin type or feature gat behind op feature