mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: impl InMemorySize for PooledTx (#12791)
This commit is contained in:
@ -10,15 +10,32 @@ pub trait InMemorySize {
|
|||||||
|
|
||||||
impl<T: InMemorySize> InMemorySize for alloy_consensus::Signed<T> {
|
impl<T: InMemorySize> InMemorySize for alloy_consensus::Signed<T> {
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
T::size(self.tx()) + core::mem::size_of::<Signature>() + core::mem::size_of::<TxHash>()
|
T::size(self.tx()) + self.signature().size() + self.hash().size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implement `InMemorySize` for a type with `size_of`
|
||||||
|
macro_rules! impl_in_mem_size_size_of {
|
||||||
|
($($ty:ty),*) => {
|
||||||
|
$(
|
||||||
|
impl InMemorySize for $ty {
|
||||||
|
#[inline]
|
||||||
|
fn size(&self) -> usize {
|
||||||
|
core::mem::size_of::<Self>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_in_mem_size_size_of!(Signature, TxHash);
|
||||||
|
|
||||||
/// Implement `InMemorySize` for a type with a native `size` method.
|
/// Implement `InMemorySize` for a type with a native `size` method.
|
||||||
macro_rules! impl_in_mem_size {
|
macro_rules! impl_in_mem_size {
|
||||||
($($ty:ty),*) => {
|
($($ty:ty),*) => {
|
||||||
$(
|
$(
|
||||||
impl InMemorySize for $ty {
|
impl InMemorySize for $ty {
|
||||||
|
#[inline]
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
Self::size(self)
|
Self::size(self)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ use alloy_primitives::{
|
|||||||
use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header};
|
use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header};
|
||||||
use bytes::Buf;
|
use bytes::Buf;
|
||||||
use derive_more::{AsRef, Deref};
|
use derive_more::{AsRef, Deref};
|
||||||
|
use reth_primitives_traits::InMemorySize;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A response to `GetPooledTransactions`. This can include either a blob transaction, or a
|
/// A response to `GetPooledTransactions`. This can include either a blob transaction, or a
|
||||||
@ -559,6 +560,18 @@ impl alloy_consensus::Transaction for PooledTransactionsElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl InMemorySize for PooledTransactionsElement {
|
||||||
|
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::BlobTransaction(tx) => tx.size(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<TransactionSigned> for PooledTransactionsElement {
|
impl TryFrom<TransactionSigned> for PooledTransactionsElement {
|
||||||
type Error = TransactionConversionError;
|
type Error = TransactionConversionError;
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use crate::{Transaction, TransactionSigned};
|
|||||||
use alloy_consensus::{transaction::RlpEcdsaTx, Signed, TxEip4844WithSidecar};
|
use alloy_consensus::{transaction::RlpEcdsaTx, Signed, TxEip4844WithSidecar};
|
||||||
use alloy_eips::eip4844::BlobTransactionSidecar;
|
use alloy_eips::eip4844::BlobTransactionSidecar;
|
||||||
use derive_more::Deref;
|
use derive_more::Deref;
|
||||||
|
use reth_primitives_traits::InMemorySize;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A response to `GetPooledTransactions` that includes blob data, their commitments, and their
|
/// A response to `GetPooledTransactions` that includes blob data, their commitments, and their
|
||||||
@ -73,6 +74,16 @@ impl BlobTransaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl InMemorySize for BlobTransaction {
|
||||||
|
fn size(&self) -> usize {
|
||||||
|
// TODO(mattsse): replace with next alloy bump
|
||||||
|
self.0.hash().size() +
|
||||||
|
self.0.signature().size() +
|
||||||
|
self.0.tx().tx().size() +
|
||||||
|
self.0.tx().sidecar.size()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(test, feature = "c-kzg"))]
|
#[cfg(all(test, feature = "c-kzg"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user