From 466adc4b14c19b223fd111a197d2c6d937d46366 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Tue, 6 Feb 2024 20:35:33 +0100 Subject: [PATCH] add minor improvements (#6448) --- crates/primitives/src/block.rs | 9 ++++----- crates/primitives/src/storage.rs | 2 +- crates/primitives/src/withdrawal.rs | 8 +++++++- crates/transaction-pool/src/validate/mod.rs | 3 +-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index fd4e6b408..507a85100 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -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::() + self.body.capacity() * std::mem::size_of::() + self.ommers.iter().map(Header::size).sum::() + self.ommers.capacity() * std::mem::size_of::
() + - self.withdrawals.as_ref().map(|w| w.size() + w.capacity() * std::mem::size_of::()).unwrap_or(std::mem::size_of::>()) + self.withdrawals.as_ref().map_or(std::mem::size_of::>(), Withdrawals::total_size) } } @@ -316,7 +316,7 @@ impl SealedBlock { // take into account capacity self.body.iter().map(TransactionSigned::size).sum::() + self.body.capacity() * std::mem::size_of::() + self.ommers.iter().map(Header::size).sum::() + self.ommers.capacity() * std::mem::size_of::
() + - self.withdrawals.as_ref().map(|w| w.size() + w.capacity() * std::mem::size_of::()).unwrap_or(std::mem::size_of::>()) + self.withdrawals.as_ref().map_or(std::mem::size_of::>(), 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::
() + self.withdrawals .as_ref() - .map(|w| w.size() + w.capacity() * std::mem::size_of::()) - .unwrap_or(std::mem::size_of::>()) + .map_or(std::mem::size_of::>(), Withdrawals::total_size) } } diff --git a/crates/primitives/src/storage.rs b/crates/primitives/src/storage.rs index 1c9157fbd..b2f5ab1d9 100644 --- a/crates/primitives/src/storage.rs +++ b/crates/primitives/src/storage.rs @@ -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 } } } diff --git a/crates/primitives/src/withdrawal.rs b/crates/primitives/src/withdrawal.rs index 187525f22..f2eba5586 100644 --- a/crates/primitives/src/withdrawal.rs +++ b/crates/primitives/src/withdrawal.rs @@ -44,7 +44,13 @@ pub struct Withdrawals(Vec); impl Withdrawals { /// Create a new Withdrawals instance. pub fn new(withdrawals: Vec) -> 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::() } /// Calculate a heuristic for the in-memory size of the [Withdrawals]. diff --git a/crates/transaction-pool/src/validate/mod.rs b/crates/transaction-pool/src/validate/mod.rs index 2fb365ca5..ac7c32130 100644 --- a/crates/transaction-pool/src/validate/mod.rs +++ b/crates/transaction-pool/src/validate/mod.rs @@ -118,8 +118,7 @@ impl ValidTransaction { #[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, } }