add minor improvements (#6448)

This commit is contained in:
Thomas Coratger
2024-02-06 20:35:33 +01:00
committed by GitHub
parent 2c119b8d0b
commit 466adc4b14
4 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,6 @@
use crate::{
Address, Bytes, GotExpected, Header, SealedHeader, TransactionSigned,
TransactionSignedEcRecovered, Withdrawal, Withdrawals, B256,
TransactionSignedEcRecovered, Withdrawals, B256,
};
use alloy_rlp::{RlpDecodable, RlpEncodable};
use reth_codecs::derive_arbitrary;
@ -119,7 +119,7 @@ impl Block {
// take into account capacity
self.body.iter().map(TransactionSigned::size).sum::<usize>() + self.body.capacity() * std::mem::size_of::<TransactionSigned>() +
self.ommers.iter().map(Header::size).sum::<usize>() + self.ommers.capacity() * std::mem::size_of::<Header>() +
self.withdrawals.as_ref().map(|w| w.size() + w.capacity() * std::mem::size_of::<Withdrawal>()).unwrap_or(std::mem::size_of::<Option<Withdrawals>>())
self.withdrawals.as_ref().map_or(std::mem::size_of::<Option<Withdrawals>>(), Withdrawals::total_size)
}
}
@ -316,7 +316,7 @@ impl SealedBlock {
// take into account capacity
self.body.iter().map(TransactionSigned::size).sum::<usize>() + self.body.capacity() * std::mem::size_of::<TransactionSigned>() +
self.ommers.iter().map(Header::size).sum::<usize>() + self.ommers.capacity() * std::mem::size_of::<Header>() +
self.withdrawals.as_ref().map(|w| w.size() + w.capacity() * std::mem::size_of::<Withdrawal>()).unwrap_or(std::mem::size_of::<Option<Withdrawals>>())
self.withdrawals.as_ref().map_or(std::mem::size_of::<Option<Withdrawals>>(), Withdrawals::total_size)
}
/// Calculates the total gas used by blob transactions in the sealed block.
@ -515,8 +515,7 @@ impl BlockBody {
self.ommers.capacity() * std::mem::size_of::<Header>() +
self.withdrawals
.as_ref()
.map(|w| w.size() + w.capacity() * std::mem::size_of::<Withdrawal>())
.unwrap_or(std::mem::size_of::<Option<Withdrawals>>())
.map_or(std::mem::size_of::<Option<Withdrawals>>(), Withdrawals::total_size)
}
}

View File

@ -23,7 +23,7 @@ impl StorageEntry {
impl From<(B256, U256)> for StorageEntry {
fn from((key, value): (B256, U256)) -> Self {
StorageEntry { key, value }
Self { key, value }
}
}

View File

@ -44,7 +44,13 @@ pub struct Withdrawals(Vec<Withdrawal>);
impl Withdrawals {
/// Create a new Withdrawals instance.
pub fn new(withdrawals: Vec<Withdrawal>) -> Self {
Withdrawals(withdrawals)
Self(withdrawals)
}
/// Calculate the total size, including capacity, of the Withdrawals.
#[inline]
pub fn total_size(&self) -> usize {
self.size() + self.capacity() * std::mem::size_of::<Withdrawal>()
}
/// Calculate a heuristic for the in-memory size of the [Withdrawals].

View File

@ -118,8 +118,7 @@ impl<T: PoolTransaction> ValidTransaction<T> {
#[inline]
pub(crate) const fn transaction(&self) -> &T {
match self {
Self::Valid(transaction) => transaction,
Self::ValidWithSidecar { transaction, .. } => transaction,
Self::Valid(transaction) | Self::ValidWithSidecar { transaction, .. } => transaction,
}
}