feat: implement InMemorySize for TxEnvelope and OpTxEnvelope #14913 (#14922)

This commit is contained in:
VINEET PANT
2025-03-09 17:29:21 +05:30
committed by GitHub
parent 857b069d1a
commit a1ca2dec4c

View File

@@ -1,7 +1,7 @@
use alloc::vec::Vec;
use alloy_consensus::{
transaction::PooledTransaction, Header, TxEip1559, TxEip2930, TxEip4844, TxEip4844WithSidecar,
TxEip7702, TxLegacy, TxType,
transaction::PooledTransaction, Header, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant,
TxEip4844WithSidecar, TxEip7702, TxEnvelope, TxLegacy, TxType,
};
use alloy_eips::eip4895::Withdrawals;
use alloy_primitives::{PrimitiveSignature as Signature, TxHash, B256};
@@ -57,6 +57,7 @@ impl_in_mem_size!(
TxEip1559,
TxEip7702,
TxEip4844,
TxEip4844Variant,
TxEip4844WithSidecar
);
@@ -84,6 +85,18 @@ impl InMemorySize for PooledTransaction {
}
}
impl InMemorySize for TxEnvelope {
fn size(&self) -> usize {
match self {
Self::Legacy(tx) => tx.size(),
Self::Eip2930(tx) => tx.size(),
Self::Eip1559(tx) => tx.size(),
Self::Eip4844(tx) => tx.size(),
Self::Eip7702(tx) => tx.size(),
}
}
}
impl<T: InMemorySize, H: InMemorySize> InMemorySize for alloy_consensus::BlockBody<T, H> {
/// Calculates a heuristic for the in-memory size of the block body
#[inline]
@@ -148,6 +161,18 @@ mod op {
}
}
}
impl InMemorySize for op_alloy_consensus::OpTxEnvelope {
fn size(&self) -> usize {
match self {
Self::Legacy(tx) => tx.size(),
Self::Eip2930(tx) => tx.size(),
Self::Eip1559(tx) => tx.size(),
Self::Eip7702(tx) => tx.size(),
Self::Deposit(tx) => tx.size(),
}
}
}
}
#[cfg(test)]
mod tests {