mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Refactor Block (#10913)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
@ -365,10 +365,12 @@ impl StorageInner {
|
||||
|
||||
let block = Block {
|
||||
header,
|
||||
body: transactions,
|
||||
ommers: ommers.clone(),
|
||||
withdrawals: withdrawals.clone(),
|
||||
requests: requests.clone(),
|
||||
body: BlockBody {
|
||||
transactions,
|
||||
ommers: ommers.clone(),
|
||||
withdrawals: withdrawals.clone(),
|
||||
requests: requests.clone(),
|
||||
},
|
||||
}
|
||||
.with_recovered_senders()
|
||||
.ok_or(BlockExecutionError::Validation(BlockValidationError::SenderRecoveryError))?;
|
||||
@ -391,7 +393,7 @@ impl StorageInner {
|
||||
// root here
|
||||
|
||||
let Block { mut header, body, .. } = block.block;
|
||||
let body = BlockBody { transactions: body, ommers, withdrawals, requests };
|
||||
let body = BlockBody { transactions: body.transactions, ommers, withdrawals, requests };
|
||||
|
||||
trace!(target: "consensus::auto", ?execution_outcome, ?header, ?body, "executed block, calculating state root and completing header");
|
||||
|
||||
|
||||
@ -2862,7 +2862,7 @@ mod tests {
|
||||
block1 = block1.unseal().seal_slow();
|
||||
let (block2, exec_result2) = data.blocks[1].clone();
|
||||
let mut block2 = block2.unseal().block;
|
||||
block2.withdrawals = None;
|
||||
block2.body.withdrawals = None;
|
||||
block2.header.parent_hash = block1.hash();
|
||||
block2.header.base_fee_per_gas = Some(100);
|
||||
block2.header.difficulty = U256::ZERO;
|
||||
|
||||
@ -44,7 +44,8 @@ pub fn validate_header_base_fee<ChainSpec: EthereumHardforks>(
|
||||
/// [EIP-4895]: https://eips.ethereum.org/EIPS/eip-4895
|
||||
#[inline]
|
||||
pub fn validate_shanghai_withdrawals(block: &SealedBlock) -> Result<(), ConsensusError> {
|
||||
let withdrawals = block.withdrawals.as_ref().ok_or(ConsensusError::BodyWithdrawalsMissing)?;
|
||||
let withdrawals =
|
||||
block.body.withdrawals.as_ref().ok_or(ConsensusError::BodyWithdrawalsMissing)?;
|
||||
let withdrawals_root = reth_primitives::proofs::calculate_withdrawals_root(withdrawals);
|
||||
let header_withdrawals_root =
|
||||
block.withdrawals_root.as_ref().ok_or(ConsensusError::WithdrawalsRootMissing)?;
|
||||
@ -84,13 +85,12 @@ pub fn validate_cancun_gas(block: &SealedBlock) -> Result<(), ConsensusError> {
|
||||
/// [EIP-7685]: https://eips.ethereum.org/EIPS/eip-7685
|
||||
#[inline]
|
||||
pub fn validate_prague_request(block: &SealedBlock) -> Result<(), ConsensusError> {
|
||||
let requests = block.requests.as_ref().ok_or(ConsensusError::BodyRequestsMissing)?;
|
||||
let requests_root = reth_primitives::proofs::calculate_requests_root(&requests.0);
|
||||
let header_requests_root =
|
||||
block.requests_root.as_ref().ok_or(ConsensusError::RequestsRootMissing)?;
|
||||
let requests_root =
|
||||
block.body.calculate_requests_root().ok_or(ConsensusError::BodyRequestsMissing)?;
|
||||
let header_requests_root = block.requests_root.ok_or(ConsensusError::RequestsRootMissing)?;
|
||||
if requests_root != *header_requests_root {
|
||||
return Err(ConsensusError::BodyRequestsRootDiff(
|
||||
GotExpected { got: requests_root, expected: *header_requests_root }.into(),
|
||||
GotExpected { got: requests_root, expected: header_requests_root }.into(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
@ -107,7 +107,7 @@ pub fn validate_block_pre_execution<ChainSpec: EthereumHardforks>(
|
||||
chain_spec: &ChainSpec,
|
||||
) -> Result<(), ConsensusError> {
|
||||
// Check ommers hash
|
||||
let ommers_hash = reth_primitives::proofs::calculate_ommers_root(&block.ommers);
|
||||
let ommers_hash = block.body.calculate_ommers_root();
|
||||
if block.header.ommers_hash != ommers_hash {
|
||||
return Err(ConsensusError::BodyOmmersHashDiff(
|
||||
GotExpected { got: ommers_hash, expected: block.header.ommers_hash }.into(),
|
||||
@ -473,7 +473,7 @@ mod tests {
|
||||
parent.timestamp -= 1;
|
||||
|
||||
let ommers = Vec::new();
|
||||
let body = Vec::new();
|
||||
let transactions = Vec::new();
|
||||
|
||||
let sealed = header.seal_slow();
|
||||
let (header, seal) = sealed.into_parts();
|
||||
@ -481,10 +481,7 @@ mod tests {
|
||||
(
|
||||
SealedBlock {
|
||||
header: SealedHeader::new(header, seal),
|
||||
body,
|
||||
ommers,
|
||||
withdrawals: None,
|
||||
requests: None,
|
||||
body: BlockBody { transactions, ommers, withdrawals: None, requests: None },
|
||||
},
|
||||
parent,
|
||||
)
|
||||
@ -511,8 +508,7 @@ mod tests {
|
||||
|
||||
SealedBlock {
|
||||
header: SealedHeader::new(header, seal),
|
||||
withdrawals: Some(withdrawals),
|
||||
..Default::default()
|
||||
body: BlockBody { withdrawals: Some(withdrawals), ..Default::default() },
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user