chore: add typed2718 to txtype (#13076)

This commit is contained in:
Matthias Seitz
2024-12-05 16:58:19 +01:00
committed by GitHub
parent d71a4be982
commit 56624f820f
4 changed files with 20 additions and 70 deletions

View File

@@ -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 {

View File

@@ -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<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.
///
@@ -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)
}
impl TxType for op_alloy_consensus::OpTxType {}
fn is_eip2930(&self) -> bool {
matches!(self, Self::Eip2930)
}
fn is_eip1559(&self) -> bool {
matches!(self, Self::Eip1559)
}
fn is_eip4844(&self) -> bool {
false
}
fn is_eip7702(&self) -> bool {
matches!(self, Self::Eip7702)
}
}
impl TxType for alloy_consensus::TxType {}

View File

@@ -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]

View File

@@ -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.