chore: make block field private (#13628)

This commit is contained in:
Matthias Seitz
2025-01-03 16:10:32 +01:00
committed by GitHub
parent 82013f46da
commit dbd4f0c4fe
67 changed files with 317 additions and 291 deletions

View File

@ -21,11 +21,7 @@ fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> Executi
transformed.header.transactions_root =
proofs::calculate_transaction_root(&transformed.body.transactions);
transformed.header.ommers_hash = proofs::calculate_ommers_root(&transformed.body.ommers);
block_to_payload(SealedBlock {
header: SealedHeader::seal(transformed.header),
body: transformed.body,
})
.0
block_to_payload(SealedBlock::new(SealedHeader::seal(transformed.header), transformed.body)).0
}
#[test]
@ -40,7 +36,7 @@ fn payload_body_roundtrip() {
ExecutionPayloadBodyV1::from_block(block.clone().unseal::<Block>());
assert_eq!(
Ok(block.body.transactions),
Ok(block.body().transactions.clone()),
payload_body
.transactions
.iter()
@ -48,7 +44,7 @@ fn payload_body_roundtrip() {
.collect::<Result<Vec<_>, _>>(),
);
let withdraw = payload_body.withdrawals.map(Withdrawals::new);
assert_eq!(block.body.withdrawals, withdraw);
assert_eq!(block.body().withdrawals.clone(), withdraw);
}
}

View File

@ -88,7 +88,7 @@ pub trait EthBlocks: LoadBlock {
.provider()
.pending_block()
.map_err(Self::Error::from_eth_err)?
.map(|block| block.body.transactions().len()))
.map(|block| block.body().transactions().len()))
}
let block_hash = match self
@ -105,7 +105,7 @@ pub trait EthBlocks: LoadBlock {
.get_sealed_block_with_senders(block_hash)
.await
.map_err(Self::Error::from_eth_err)?
.map(|b| b.body.transactions().len()))
.map(|b| b.body().transactions().len()))
}
}
@ -188,7 +188,7 @@ pub trait EthBlocks: LoadBlock {
self.provider()
.pending_block()
.map_err(Self::Error::from_eth_err)?
.and_then(|block| block.body.ommers().map(|o| o.to_vec()))
.and_then(|block| block.body().ommers().map(|o| o.to_vec()))
} else {
self.provider().ommers_by_id(block_id).map_err(Self::Error::from_eth_err)?
}

View File

@ -314,11 +314,11 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
let mut replay_block_txs = true;
let num_txs =
transaction_index.index().unwrap_or_else(|| block.body.transactions().len());
transaction_index.index().unwrap_or_else(|| block.body().transactions().len());
// but if all transactions are to be replayed, we can use the state at the block itself,
// however only if we're not targeting the pending block, because for pending we can't
// rely on the block's state being available
if !is_block_target_pending && num_txs == block.body.transactions().len() {
if !is_block_target_pending && num_txs == block.body().transactions().len() {
at = block.hash();
replay_block_txs = false;
}

View File

@ -185,7 +185,7 @@ pub trait EthFees: LoadFee {
percentiles,
header.gas_used(),
header.base_fee_per_gas().unwrap_or_default(),
block.body.transactions(),
block.body().transactions(),
&receipts,
)
.unwrap_or_default(),

View File

@ -320,7 +320,7 @@ pub trait Trace:
let Some(block) = block else { return Ok(None) };
if block.body.transactions().is_empty() {
if block.body().transactions().is_empty() {
// nothing to trace
return Ok(Some(Vec::new()))
}
@ -350,7 +350,7 @@ pub trait Trace:
// prepare transactions, we do everything upfront to reduce time spent with open
// state
let max_transactions =
highest_index.map_or(block.body.transactions().len(), |highest| {
highest_index.map_or(block.body().transactions().len(), |highest| {
// we need + 1 because the index is 0-based
highest as usize + 1
});

View File

@ -94,7 +94,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
self.cache()
.get_sealed_block_with_senders(block)
.await
.map(|b| b.map(|b| b.body.transactions().to_vec()))
.map(|b| b.map(|b| b.body().transactions().to_vec()))
.map_err(Self::Error::from_eth_err)
}
}

View File

@ -304,7 +304,7 @@ where
}
Either::Right(transaction_tx) => {
let _ = transaction_tx.send(res.clone().map(|maybe_block| {
maybe_block.map(|block| block.block.body.transactions().to_vec())
maybe_block.map(|block| block.block.body().transactions().to_vec())
}));
}
}
@ -350,7 +350,7 @@ where
}
Either::Right(transaction_tx) => {
let _ = transaction_tx.send(res.clone().map(|maybe_block| {
maybe_block.map(|block| block.block.body.transactions().to_vec())
maybe_block.map(|block| block.block.body().transactions().to_vec())
}));
}
}

View File

@ -89,7 +89,7 @@ impl FeeHistoryCache {
&percentiles,
fee_history_entry.gas_used,
fee_history_entry.base_fee_per_gas,
block.body.transactions(),
block.body().transactions(),
&receipts,
)
.unwrap_or_default();
@ -370,7 +370,7 @@ impl FeeHistoryEntry {
base_fee_per_blob_gas: block
.excess_blob_gas()
.map(alloy_eips::eip4844::calc_blob_gasprice),
blob_gas_used_ratio: block.body.blob_gas_used() as f64 /
blob_gas_used_ratio: block.body().blob_gas_used() as f64 /
alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK as f64,
excess_blob_gas: block.excess_blob_gas(),
blob_gas_used: block.blob_gas_used(),

View File

@ -226,7 +226,7 @@ where
let parent_hash = block.parent_hash();
// sort the functions by ascending effective tip first
let sorted_transactions = block.body.transactions().iter().sorted_by_cached_key(|tx| {
let sorted_transactions = block.body().transactions().iter().sorted_by_cached_key(|tx| {
if let Some(base_fee) = base_fee_per_gas {
(*tx).effective_tip_per_gas(base_fee)
} else {

View File

@ -92,7 +92,7 @@ where
if transaction_hash.is_none() {
transaction_hash = match &provider_or_block {
ProviderOrBlock::Block(block) => {
block.body.transactions().get(receipt_idx).map(|t| t.trie_hash())
block.body().transactions().get(receipt_idx).map(|t| t.trie_hash())
}
ProviderOrBlock::Provider(provider) => {
let first_tx_num = match loaded_first_tx_num {

View File

@ -16,14 +16,11 @@ use reth_primitives_traits::{BlockBody as _, SignedTransaction};
pub fn block_to_payload<T: SignedTransaction>(
value: SealedBlock<Header, BlockBody<T>>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
let cancun = if let Some(parent_beacon_block_root) = value.parent_beacon_block_root {
Some(CancunPayloadFields {
let cancun =
value.parent_beacon_block_root.map(|parent_beacon_block_root| CancunPayloadFields {
parent_beacon_block_root,
versioned_hashes: value.body.blob_versioned_hashes_iter().copied().collect(),
})
} else {
None
};
versioned_hashes: value.body().blob_versioned_hashes_iter().copied().collect(),
});
let prague = value
.requests_hash
@ -38,7 +35,7 @@ pub fn block_to_payload<T: SignedTransaction>(
let execution_payload = if value.header.parent_beacon_block_root.is_some() {
// block with parent beacon block root: V3
ExecutionPayload::V3(block_to_payload_v3(value))
} else if value.body.withdrawals.is_some() {
} else if value.body().withdrawals.is_some() {
// block with withdrawals: V2
ExecutionPayload::V2(block_to_payload_v2(value))
} else {
@ -54,7 +51,7 @@ pub fn block_to_payload_v1<T: Encodable2718>(
value: SealedBlock<Header, BlockBody<T>>,
) -> ExecutionPayloadV1 {
let transactions =
value.body.transactions.iter().map(|tx| tx.encoded_2718().into()).collect::<Vec<_>>();
value.body().transactions.iter().map(|tx| tx.encoded_2718().into()).collect::<Vec<_>>();
ExecutionPayloadV1 {
parent_hash: value.parent_hash,
fee_recipient: value.beneficiary,
@ -75,10 +72,10 @@ pub fn block_to_payload_v1<T: Encodable2718>(
/// Converts [`SealedBlock`] to [`ExecutionPayloadV2`]
pub fn block_to_payload_v2<T: Encodable2718>(
mut value: SealedBlock<Header, BlockBody<T>>,
value: SealedBlock<Header, BlockBody<T>>,
) -> ExecutionPayloadV2 {
ExecutionPayloadV2 {
withdrawals: value.body.withdrawals.take().unwrap_or_default().into_inner(),
withdrawals: value.body().withdrawals.clone().unwrap_or_default().into_inner(),
payload_inner: block_to_payload_v1(value),
}
}
@ -99,7 +96,7 @@ pub fn convert_block_to_payload_field_v2<T: Encodable2718>(
value: SealedBlock<Header, BlockBody<T>>,
) -> ExecutionPayloadFieldV2 {
// if there are withdrawals, return V2
if value.body.withdrawals.is_some() {
if value.body().withdrawals.is_some() {
ExecutionPayloadFieldV2::V2(block_to_payload_v2(value))
} else {
ExecutionPayloadFieldV2::V1(block_to_payload_v1(value))

View File

@ -103,7 +103,7 @@ where
let this = self.clone();
self.eth_api()
.spawn_with_state_at_block(block.parent_hash().into(), move |state| {
let mut results = Vec::with_capacity(block.body.transactions().len());
let mut results = Vec::with_capacity(block.body().transactions().len());
let mut db = CacheDB::new(StateProviderDatabase::new(state));
this.eth_api().apply_pre_execution_changes(&block, &mut db, &cfg, &block_env)?;
@ -527,11 +527,12 @@ where
let mut replay_block_txs = true;
// if a transaction index is provided, we need to replay the transactions until the index
let num_txs = transaction_index.index().unwrap_or_else(|| block.body.transactions().len());
let num_txs =
transaction_index.index().unwrap_or_else(|| block.body().transactions().len());
// but if all transactions are to be replayed, we can use the state at the block itself
// this works with the exception of the PENDING block, because its state might not exist if
// built locally
if !target_block.is_pending() && num_txs == block.body.transactions().len() {
if !target_block.is_pending() && num_txs == block.body().transactions().len() {
at = block.hash();
replay_block_txs = false;
}

View File

@ -40,7 +40,7 @@ where
let timestamp = block.timestamp();
return block
.body
.body()
.transactions()
.iter()
.zip(receipts.iter())

View File

@ -315,7 +315,7 @@ where
all_traces.extend(
self.extract_reward_traces(
block.header.header(),
block.body.ommers(),
block.body().ommers(),
base_block_reward,
)
.into_iter()
@ -396,7 +396,7 @@ where
{
traces.extend(self.extract_reward_traces(
block.block.header(),
block.body.ommers(),
block.body().ommers(),
base_block_reward,
));
}