mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: rm some direct header access (#13633)
This commit is contained in:
@ -18,7 +18,7 @@ use reth_primitives::{
|
|||||||
use reth_primitives_traits::{Block, BlockBody as _, SignedTransaction};
|
use reth_primitives_traits::{Block, BlockBody as _, SignedTransaction};
|
||||||
use reth_storage_api::StateProviderBox;
|
use reth_storage_api::StateProviderBox;
|
||||||
use reth_trie::{updates::TrieUpdates, HashedPostState};
|
use reth_trie::{updates::TrieUpdates, HashedPostState};
|
||||||
use std::{collections::BTreeMap, sync::Arc, time::Instant};
|
use std::{collections::BTreeMap, ops::Deref, sync::Arc, time::Instant};
|
||||||
use tokio::sync::{broadcast, watch};
|
use tokio::sync::{broadcast, watch};
|
||||||
|
|
||||||
/// Size of the broadcast channel used to notify canonical state events.
|
/// Size of the broadcast channel used to notify canonical state events.
|
||||||
@ -183,7 +183,7 @@ impl<N: NodePrimitives> CanonicalInMemoryState<N> {
|
|||||||
let in_memory_state = InMemoryState::new(blocks, numbers, pending);
|
let in_memory_state = InMemoryState::new(blocks, numbers, pending);
|
||||||
let header = in_memory_state
|
let header = in_memory_state
|
||||||
.head_state()
|
.head_state()
|
||||||
.map_or_else(SealedHeader::default, |state| state.block_ref().block().header.clone());
|
.map_or_else(SealedHeader::default, |state| state.block_ref().block().deref().clone());
|
||||||
let chain_info_tracker = ChainInfoTracker::new(header, finalized, safe);
|
let chain_info_tracker = ChainInfoTracker::new(header, finalized, safe);
|
||||||
let (canon_state_notification_sender, _) =
|
let (canon_state_notification_sender, _) =
|
||||||
broadcast::channel(CANON_STATE_NOTIFICATION_CHANNEL_SIZE);
|
broadcast::channel(CANON_STATE_NOTIFICATION_CHANNEL_SIZE);
|
||||||
@ -462,7 +462,7 @@ impl<N: NodePrimitives> CanonicalInMemoryState<N> {
|
|||||||
|
|
||||||
/// Returns the `SealedHeader` corresponding to the pending state.
|
/// Returns the `SealedHeader` corresponding to the pending state.
|
||||||
pub fn pending_sealed_header(&self) -> Option<SealedHeader<N::BlockHeader>> {
|
pub fn pending_sealed_header(&self) -> Option<SealedHeader<N::BlockHeader>> {
|
||||||
self.pending_state().map(|h| h.block_ref().block().header.clone())
|
self.pending_state().map(|h| h.block_ref().block().deref().clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `Header` corresponding to the pending state.
|
/// Returns the `Header` corresponding to the pending state.
|
||||||
@ -584,7 +584,7 @@ impl<N: NodePrimitives> CanonicalInMemoryState<N> {
|
|||||||
index: index as u64,
|
index: index as u64,
|
||||||
block_hash: block_state.hash(),
|
block_hash: block_state.hash(),
|
||||||
block_number: block_state.block_ref().block.number(),
|
block_number: block_state.block_ref().block.number(),
|
||||||
base_fee: block_state.block_ref().block.header.base_fee_per_gas(),
|
base_fee: block_state.block_ref().block.base_fee_per_gas(),
|
||||||
timestamp: block_state.block_ref().block.timestamp(),
|
timestamp: block_state.block_ref().block.timestamp(),
|
||||||
excess_blob_gas: block_state.block_ref().block.excess_blob_gas(),
|
excess_blob_gas: block_state.block_ref().block.excess_blob_gas(),
|
||||||
};
|
};
|
||||||
@ -664,7 +664,7 @@ impl<N: NodePrimitives> BlockState<N> {
|
|||||||
/// Returns the state root after applying the executed block that determines
|
/// Returns the state root after applying the executed block that determines
|
||||||
/// the state.
|
/// the state.
|
||||||
pub fn state_root(&self) -> B256 {
|
pub fn state_root(&self) -> B256 {
|
||||||
self.block.block().header.state_root()
|
self.block.block().state_root()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `Receipts` of executed block that determines the state.
|
/// Returns the `Receipts` of executed block that determines the state.
|
||||||
@ -789,7 +789,7 @@ impl<N: NodePrimitives> BlockState<N> {
|
|||||||
index: index as u64,
|
index: index as u64,
|
||||||
block_hash: block_state.hash(),
|
block_hash: block_state.hash(),
|
||||||
block_number: block_state.block_ref().block.number(),
|
block_number: block_state.block_ref().block.number(),
|
||||||
base_fee: block_state.block_ref().block.header.base_fee_per_gas(),
|
base_fee: block_state.block_ref().block.base_fee_per_gas(),
|
||||||
timestamp: block_state.block_ref().block.timestamp(),
|
timestamp: block_state.block_ref().block.timestamp(),
|
||||||
excess_blob_gas: block_state.block_ref().block.excess_blob_gas(),
|
excess_blob_gas: block_state.block_ref().block.excess_blob_gas(),
|
||||||
};
|
};
|
||||||
@ -1318,7 +1318,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check the pending header
|
// Check the pending header
|
||||||
assert_eq!(state.pending_header().unwrap(), block2.block().header.header().clone());
|
assert_eq!(state.pending_header().unwrap(), block2.block().header().clone());
|
||||||
|
|
||||||
// Check the pending sealed header
|
// Check the pending sealed header
|
||||||
assert_eq!(state.pending_sealed_header().unwrap(), block2.block().header.clone());
|
assert_eq!(state.pending_sealed_header().unwrap(), block2.block().header.clone());
|
||||||
|
|||||||
@ -140,11 +140,11 @@ where
|
|||||||
{
|
{
|
||||||
// Check ommers hash
|
// Check ommers hash
|
||||||
let ommers_hash = block.body().calculate_ommers_root();
|
let ommers_hash = block.body().calculate_ommers_root();
|
||||||
if Some(block.header.ommers_hash()) != ommers_hash {
|
if Some(block.ommers_hash()) != ommers_hash {
|
||||||
return Err(ConsensusError::BodyOmmersHashDiff(
|
return Err(ConsensusError::BodyOmmersHashDiff(
|
||||||
GotExpected {
|
GotExpected {
|
||||||
got: ommers_hash.unwrap_or(EMPTY_OMMER_ROOT_HASH),
|
got: ommers_hash.unwrap_or(EMPTY_OMMER_ROOT_HASH),
|
||||||
expected: block.header.ommers_hash(),
|
expected: block.ommers_hash(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
))
|
))
|
||||||
|
|||||||
@ -710,10 +710,10 @@ mod tests {
|
|||||||
let mut block3 = block.clone();
|
let mut block3 = block.clone();
|
||||||
let mut block4 = block;
|
let mut block4 = block;
|
||||||
|
|
||||||
block1.block.header.set_hash(block1_hash);
|
block1.block.set_hash(block1_hash);
|
||||||
block2.block.header.set_hash(block2_hash);
|
block2.block.set_hash(block2_hash);
|
||||||
block3.block.header.set_hash(block3_hash);
|
block3.block.set_hash(block3_hash);
|
||||||
block4.block.header.set_hash(block4_hash);
|
block4.block.set_hash(block4_hash);
|
||||||
|
|
||||||
block3.set_parent_hash(block2_hash);
|
block3.set_parent_hash(block2_hash);
|
||||||
|
|
||||||
|
|||||||
@ -709,7 +709,7 @@ mod tests {
|
|||||||
assert_eq!(received.len(), 10);
|
assert_eq!(received.len(), 10);
|
||||||
for (i, block) in received.iter().enumerate() {
|
for (i, block) in received.iter().enumerate() {
|
||||||
let expected_number = header.number - i as u64;
|
let expected_number = header.number - i as u64;
|
||||||
assert_eq!(block.header.number, expected_number);
|
assert_eq!(block.number, expected_number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,7 +728,7 @@ mod tests {
|
|||||||
assert_eq!(received.len(), 50);
|
assert_eq!(received.len(), 50);
|
||||||
for (i, block) in received.iter().enumerate() {
|
for (i, block) in received.iter().enumerate() {
|
||||||
let expected_number = header.number - i as u64;
|
let expected_number = header.number - i as u64;
|
||||||
assert_eq!(block.header.number, expected_number);
|
assert_eq!(block.number, expected_number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -748,7 +748,7 @@ mod tests {
|
|||||||
assert_eq!(received.len(), range_length);
|
assert_eq!(received.len(), range_length);
|
||||||
for (i, block) in received.iter().enumerate() {
|
for (i, block) in received.iter().enumerate() {
|
||||||
let expected_number = header.number - i as u64;
|
let expected_number = header.number - i as u64;
|
||||||
assert_eq!(block.header.number, expected_number);
|
assert_eq!(block.number, expected_number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,9 +75,9 @@ impl Consensus<Header, OpBlockBody> for OpBeaconConsensus {
|
|||||||
) -> Result<(), ConsensusError> {
|
) -> Result<(), ConsensusError> {
|
||||||
// Check ommers hash
|
// Check ommers hash
|
||||||
let ommers_hash = block.body().calculate_ommers_root();
|
let ommers_hash = block.body().calculate_ommers_root();
|
||||||
if block.header.ommers_hash != ommers_hash {
|
if block.ommers_hash != ommers_hash {
|
||||||
return Err(ConsensusError::BodyOmmersHashDiff(
|
return Err(ConsensusError::BodyOmmersHashDiff(
|
||||||
GotExpected { got: ommers_hash, expected: block.header.ommers_hash }.into(),
|
GotExpected { got: ommers_hash, expected: block.ommers_hash }.into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -543,11 +543,11 @@ mod tests {
|
|||||||
let mut block2 = block;
|
let mut block2 = block;
|
||||||
|
|
||||||
// Set the hashes of block1 and block2
|
// Set the hashes of block1 and block2
|
||||||
block1.block.header.set_block_number(10);
|
block1.block.set_block_number(10);
|
||||||
block1.block.header.set_hash(block1_hash);
|
block1.block.set_hash(block1_hash);
|
||||||
|
|
||||||
block2.block.header.set_block_number(11);
|
block2.block.set_block_number(11);
|
||||||
block2.block.header.set_hash(block2_hash);
|
block2.block.set_hash(block2_hash);
|
||||||
|
|
||||||
// Create a random receipt object, receipt1
|
// Create a random receipt object, receipt1
|
||||||
let receipt1 = OpReceipt::Legacy(Receipt {
|
let receipt1 = OpReceipt::Legacy(Receipt {
|
||||||
|
|||||||
@ -131,11 +131,11 @@ impl<ChainSpec: EthereumHardforks> ExecutionPayloadValidator<ChainSpec> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.is_cancun_active_at_timestamp(sealed_block.timestamp) {
|
if self.is_cancun_active_at_timestamp(sealed_block.timestamp) {
|
||||||
if sealed_block.header.blob_gas_used.is_none() {
|
if sealed_block.blob_gas_used.is_none() {
|
||||||
// cancun active but blob gas used not present
|
// cancun active but blob gas used not present
|
||||||
return Err(PayloadError::PostCancunBlockWithoutBlobGasUsed)
|
return Err(PayloadError::PostCancunBlockWithoutBlobGasUsed)
|
||||||
}
|
}
|
||||||
if sealed_block.header.excess_blob_gas.is_none() {
|
if sealed_block.excess_blob_gas.is_none() {
|
||||||
// cancun active but excess blob gas not present
|
// cancun active but excess blob gas not present
|
||||||
return Err(PayloadError::PostCancunBlockWithoutExcessBlobGas)
|
return Err(PayloadError::PostCancunBlockWithoutExcessBlobGas)
|
||||||
}
|
}
|
||||||
@ -148,11 +148,11 @@ impl<ChainSpec: EthereumHardforks> ExecutionPayloadValidator<ChainSpec> {
|
|||||||
// cancun not active but blob transactions present
|
// cancun not active but blob transactions present
|
||||||
return Err(PayloadError::PreCancunBlockWithBlobTransactions)
|
return Err(PayloadError::PreCancunBlockWithBlobTransactions)
|
||||||
}
|
}
|
||||||
if sealed_block.header.blob_gas_used.is_some() {
|
if sealed_block.blob_gas_used.is_some() {
|
||||||
// cancun not active but blob gas used present
|
// cancun not active but blob gas used present
|
||||||
return Err(PayloadError::PreCancunBlockWithBlobGasUsed)
|
return Err(PayloadError::PreCancunBlockWithBlobGasUsed)
|
||||||
}
|
}
|
||||||
if sealed_block.header.excess_blob_gas.is_some() {
|
if sealed_block.excess_blob_gas.is_some() {
|
||||||
// cancun not active but excess blob gas present
|
// cancun not active but excess blob gas present
|
||||||
return Err(PayloadError::PreCancunBlockWithExcessBlobGas)
|
return Err(PayloadError::PreCancunBlockWithExcessBlobGas)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ pub fn block_to_payload<T: SignedTransaction>(
|
|||||||
_ => ExecutionPayloadSidecar::none(),
|
_ => ExecutionPayloadSidecar::none(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let execution_payload = if value.header.parent_beacon_block_root.is_some() {
|
let execution_payload = if value.parent_beacon_block_root.is_some() {
|
||||||
// block with parent beacon block root: V3
|
// block with parent beacon block root: V3
|
||||||
ExecutionPayload::V3(block_to_payload_v3(value))
|
ExecutionPayload::V3(block_to_payload_v3(value))
|
||||||
} else if value.body().withdrawals.is_some() {
|
} else if value.body().withdrawals.is_some() {
|
||||||
|
|||||||
@ -263,7 +263,7 @@ pub fn random_block_range<R: Rng>(
|
|||||||
idx,
|
idx,
|
||||||
BlockParams {
|
BlockParams {
|
||||||
parent: Some(
|
parent: Some(
|
||||||
blocks.last().map(|block: &SealedBlock| block.header.hash()).unwrap_or(parent),
|
blocks.last().map(|block: &SealedBlock| block.hash()).unwrap_or(parent),
|
||||||
),
|
),
|
||||||
tx_count: Some(tx_count),
|
tx_count: Some(tx_count),
|
||||||
ommers_count: None,
|
ommers_count: None,
|
||||||
|
|||||||
Reference in New Issue
Block a user