Skip to content
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

chore: add typed2718 to txtype #13076

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions crates/primitives-traits/src/size.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_consensus::{Header, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy};
use alloy_consensus::{Header, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy, TxType};
use alloy_primitives::{PrimitiveSignature as Signature, TxHash};

/// Trait for calculating a heuristic for the in-memory size of a struct.
Expand Down Expand Up @@ -28,7 +28,7 @@ macro_rules! impl_in_mem_size_size_of {
};
}

impl_in_mem_size_size_of!(Signature, TxHash);
impl_in_mem_size_size_of!(Signature, TxHash, TxType);

/// Implement `InMemorySize` for a type with a native `size` method.
macro_rules! impl_in_mem_size {
Expand All @@ -47,11 +47,7 @@ macro_rules! impl_in_mem_size {
impl_in_mem_size!(Header, TxLegacy, TxEip2930, TxEip1559, TxEip7702, TxEip4844);

#[cfg(feature = "op")]
impl InMemorySize for op_alloy_consensus::OpTxType {
fn size(&self) -> usize {
1
}
}
impl_in_mem_size_size_of!(op_alloy_consensus::OpTxType);

#[cfg(test)]
mod tests {
Expand Down
39 changes: 4 additions & 35 deletions crates/primitives-traits/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Abstraction of transaction envelope type ID.
use crate::{InMemorySize, MaybeArbitrary, MaybeCompact};
use alloy_consensus::Typed2718;
use alloy_primitives::{U64, U8};
use core::fmt;

Expand Down Expand Up @@ -30,24 +31,10 @@ pub trait TxType:
+ TryFrom<U64>
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ Typed2718
+ InMemorySize
+ MaybeArbitrary
{
/// Returns `true` if this is a legacy transaction.
fn is_legacy(&self) -> bool;

/// Returns `true` if this is an eip-2930 transaction.
fn is_eip2930(&self) -> bool;

/// Returns `true` if this is an eip-1559 transaction.
fn is_eip1559(&self) -> bool;

/// Returns `true` if this is an eip-4844 transaction.
fn is_eip4844(&self) -> bool;

/// Returns `true` if this is an eip-7702 transaction.
fn is_eip7702(&self) -> bool;

/// Returns whether this transaction type can be __broadcasted__ as full transaction over the
/// network.
///
Expand All @@ -60,24 +47,6 @@ pub trait TxType:
}

#[cfg(feature = "op")]
impl TxType for op_alloy_consensus::OpTxType {
fn is_legacy(&self) -> bool {
matches!(self, Self::Legacy)
}

fn is_eip2930(&self) -> bool {
matches!(self, Self::Eip2930)
}

fn is_eip1559(&self) -> bool {
matches!(self, Self::Eip1559)
}
impl TxType for op_alloy_consensus::OpTxType {}

fn is_eip4844(&self) -> bool {
false
}

fn is_eip7702(&self) -> bool {
matches!(self, Self::Eip7702)
}
}
impl TxType for alloy_consensus::TxType {}
38 changes: 11 additions & 27 deletions crates/primitives/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloy_consensus::constants::{
EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID,
LEGACY_TX_TYPE_ID,
use alloy_consensus::{
constants::{
EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID,
LEGACY_TX_TYPE_ID,
},
Typed2718,
};
use alloy_primitives::{U64, U8};
use alloy_rlp::{Decodable, Encodable};
Expand Down Expand Up @@ -88,33 +91,14 @@ impl TxType {
}
}

impl reth_primitives_traits::TxType for TxType {
#[inline]
fn is_legacy(&self) -> bool {
matches!(self, Self::Legacy)
}

#[inline]
fn is_eip2930(&self) -> bool {
matches!(self, Self::Eip2930)
}

#[inline]
fn is_eip1559(&self) -> bool {
matches!(self, Self::Eip1559)
}

#[inline]
fn is_eip4844(&self) -> bool {
matches!(self, Self::Eip4844)
}

#[inline]
fn is_eip7702(&self) -> bool {
matches!(self, Self::Eip7702)
impl Typed2718 for TxType {
fn ty(&self) -> u8 {
(*self).into()
}
}

impl reth_primitives_traits::TxType for TxType {}

impl InMemorySize for TxType {
/// Calculates a heuristic for the in-memory size of the [`TxType`].
#[inline]
Expand Down
3 changes: 2 additions & 1 deletion crates/transaction-pool/src/blobstore/tracker.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Support for maintaining the blob pool.
use alloy_consensus::Typed2718;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{BlockNumber, B256};
use reth_execution_types::ChainBlocks;
use reth_primitives_traits::{Block, BlockBody, SignedTransaction, TxType};
use reth_primitives_traits::{Block, BlockBody, SignedTransaction};
use std::collections::BTreeMap;

/// The type that is used to track canonical blob transactions.
Expand Down
Loading