mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
add minor improvements (#6448)
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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].
|
||||
|
||||
Reference in New Issue
Block a user