From 56624f820f287a0eaa38eceac10a3514378c69c7 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 5 Dec 2024 16:58:19 +0100 Subject: [PATCH] chore: add typed2718 to txtype (#13076) --- crates/primitives-traits/src/size.rs | 10 ++--- .../src/transaction/tx_type.rs | 39 ++----------------- crates/primitives/src/transaction/tx_type.rs | 38 ++++++------------ .../transaction-pool/src/blobstore/tracker.rs | 3 +- 4 files changed, 20 insertions(+), 70 deletions(-) diff --git a/crates/primitives-traits/src/size.rs b/crates/primitives-traits/src/size.rs index f9065cda24aa..a1978ff379e0 100644 --- a/crates/primitives-traits/src/size.rs +++ b/crates/primitives-traits/src/size.rs @@ -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. @@ -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 { @@ -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 { diff --git a/crates/primitives-traits/src/transaction/tx_type.rs b/crates/primitives-traits/src/transaction/tx_type.rs index c2f2e04899df..c60cd9cb3af4 100644 --- a/crates/primitives-traits/src/transaction/tx_type.rs +++ b/crates/primitives-traits/src/transaction/tx_type.rs @@ -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; @@ -30,24 +31,10 @@ pub trait TxType: + TryFrom + 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. /// @@ -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 {} diff --git a/crates/primitives/src/transaction/tx_type.rs b/crates/primitives/src/transaction/tx_type.rs index 1d709b902b53..d0a4786dcf16 100644 --- a/crates/primitives/src/transaction/tx_type.rs +++ b/crates/primitives/src/transaction/tx_type.rs @@ -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}; @@ -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] diff --git a/crates/transaction-pool/src/blobstore/tracker.rs b/crates/transaction-pool/src/blobstore/tracker.rs index 3fdcbe8b4eae..817114fcf259 100644 --- a/crates/transaction-pool/src/blobstore/tracker.rs +++ b/crates/transaction-pool/src/blobstore/tracker.rs @@ -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.