mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: reduce size of common types (#5304)
This commit is contained in:
@ -11,7 +11,7 @@ pub enum BeaconConsensusEngineEvent {
|
||||
/// A block was added to the canonical chain.
|
||||
CanonicalBlockAdded(Arc<SealedBlock>),
|
||||
/// A canonical chain was committed.
|
||||
CanonicalChainCommitted(SealedHeader, Duration),
|
||||
CanonicalChainCommitted(Box<SealedHeader>, Duration),
|
||||
/// A block was added to the fork chain.
|
||||
ForkBlockAdded(Arc<SealedBlock>),
|
||||
}
|
||||
|
||||
@ -664,8 +664,8 @@ where
|
||||
|
||||
let status = match make_canonical_result {
|
||||
Ok(outcome) => {
|
||||
match outcome {
|
||||
CanonicalOutcome::AlreadyCanonical { ref header } => {
|
||||
match &outcome {
|
||||
CanonicalOutcome::AlreadyCanonical { header } => {
|
||||
// On Optimism, the proposers are allowed to reorg their own chain at will.
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "optimism")] {
|
||||
@ -679,7 +679,7 @@ where
|
||||
let _ = self.update_head(header.clone());
|
||||
self.listeners.notify(
|
||||
BeaconConsensusEngineEvent::CanonicalChainCommitted(
|
||||
header.clone(),
|
||||
Box::new(header.clone()),
|
||||
elapsed,
|
||||
),
|
||||
);
|
||||
@ -701,7 +701,7 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
CanonicalOutcome::Committed { ref head } => {
|
||||
CanonicalOutcome::Committed { head } => {
|
||||
debug!(
|
||||
target: "consensus::engine",
|
||||
hash=?state.head_block_hash,
|
||||
@ -712,7 +712,7 @@ where
|
||||
// new VALID update that moved the canonical chain forward
|
||||
let _ = self.update_head(head.clone());
|
||||
self.listeners.notify(BeaconConsensusEngineEvent::CanonicalChainCommitted(
|
||||
head.clone(),
|
||||
Box::new(head.clone()),
|
||||
elapsed,
|
||||
));
|
||||
}
|
||||
@ -873,7 +873,6 @@ where
|
||||
self.update_head(head)?;
|
||||
self.update_finalized_block(update.finalized_block_hash)?;
|
||||
self.update_safe_block(update.safe_block_hash)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -899,9 +898,7 @@ where
|
||||
|
||||
head_block.total_difficulty =
|
||||
self.blockchain.header_td_by_number(head_block.number)?.ok_or_else(|| {
|
||||
RethError::Provider(ProviderError::TotalDifficultyNotFound {
|
||||
block_number: head_block.number,
|
||||
})
|
||||
RethError::Provider(ProviderError::TotalDifficultyNotFound(head_block.number))
|
||||
})?;
|
||||
self.sync_state_updater.update_status(head_block);
|
||||
|
||||
@ -1562,9 +1559,9 @@ where
|
||||
let elapsed = self.record_make_canonical_latency(start, &make_canonical_result);
|
||||
match make_canonical_result {
|
||||
Ok(outcome) => {
|
||||
if let CanonicalOutcome::Committed { ref head } = outcome {
|
||||
if let CanonicalOutcome::Committed { head } = &outcome {
|
||||
self.listeners.notify(BeaconConsensusEngineEvent::CanonicalChainCommitted(
|
||||
head.clone(),
|
||||
Box::new(head.clone()),
|
||||
elapsed,
|
||||
));
|
||||
}
|
||||
@ -1661,7 +1658,7 @@ where
|
||||
warn!(target: "consensus::engine", invalid_hash=?bad_block.hash, invalid_number=?bad_block.number, "Bad block detected in unwind");
|
||||
|
||||
// update the `invalid_headers` cache with the new invalid headers
|
||||
self.invalid_headers.insert(bad_block);
|
||||
self.invalid_headers.insert(*bad_block);
|
||||
return None
|
||||
}
|
||||
|
||||
|
||||
@ -6,8 +6,9 @@ use reth_primitives::{
|
||||
eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK},
|
||||
},
|
||||
eip4844::calculate_excess_blob_gas,
|
||||
BlockNumber, ChainSpec, Hardfork, Header, InvalidTransactionError, SealedBlock, SealedHeader,
|
||||
Transaction, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxLegacy,
|
||||
BlockNumber, ChainSpec, GotExpected, Hardfork, Header, InvalidTransactionError, SealedBlock,
|
||||
SealedHeader, Transaction, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844,
|
||||
TxLegacy,
|
||||
};
|
||||
use reth_provider::{AccountReader, HeaderProvider, WithdrawalsProvider};
|
||||
use std::collections::{hash_map::Entry, HashMap};
|
||||
@ -203,20 +204,18 @@ pub fn validate_block_standalone(
|
||||
// Check ommers hash
|
||||
let ommers_hash = reth_primitives::proofs::calculate_ommers_root(&block.ommers);
|
||||
if block.header.ommers_hash != ommers_hash {
|
||||
return Err(ConsensusError::BodyOmmersHashDiff {
|
||||
got: ommers_hash,
|
||||
expected: block.header.ommers_hash,
|
||||
})
|
||||
return Err(ConsensusError::BodyOmmersHashDiff(
|
||||
GotExpected { got: ommers_hash, expected: block.header.ommers_hash }.into(),
|
||||
))
|
||||
}
|
||||
|
||||
// Check transaction root
|
||||
// TODO(onbjerg): This should probably be accessible directly on [Block]
|
||||
let transaction_root = reth_primitives::proofs::calculate_transaction_root(&block.body);
|
||||
if block.header.transactions_root != transaction_root {
|
||||
return Err(ConsensusError::BodyTransactionRootDiff {
|
||||
got: transaction_root,
|
||||
expected: block.header.transactions_root,
|
||||
})
|
||||
return Err(ConsensusError::BodyTransactionRootDiff(
|
||||
GotExpected { got: transaction_root, expected: block.header.transactions_root }.into(),
|
||||
))
|
||||
}
|
||||
|
||||
// EIP-4895: Beacon chain push withdrawals as operations
|
||||
@ -227,10 +226,9 @@ pub fn validate_block_standalone(
|
||||
let header_withdrawals_root =
|
||||
block.withdrawals_root.as_ref().ok_or(ConsensusError::WithdrawalsRootMissing)?;
|
||||
if withdrawals_root != *header_withdrawals_root {
|
||||
return Err(ConsensusError::BodyWithdrawalsRootDiff {
|
||||
got: withdrawals_root,
|
||||
expected: *header_withdrawals_root,
|
||||
})
|
||||
return Err(ConsensusError::BodyWithdrawalsRootDiff(
|
||||
GotExpected { got: withdrawals_root, expected: *header_withdrawals_root }.into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,10 +239,10 @@ pub fn validate_block_standalone(
|
||||
let header_blob_gas_used = block.blob_gas_used.ok_or(ConsensusError::BlobGasUsedMissing)?;
|
||||
let total_blob_gas = block.blob_gas_used();
|
||||
if total_blob_gas != header_blob_gas_used {
|
||||
return Err(ConsensusError::BlobGasUsedDiff {
|
||||
header_blob_gas_used,
|
||||
expected_blob_gas_used: total_blob_gas,
|
||||
})
|
||||
return Err(ConsensusError::BlobGasUsedDiff(GotExpected {
|
||||
got: header_blob_gas_used,
|
||||
expected: total_blob_gas,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,10 +298,9 @@ pub fn validate_header_regarding_parent(
|
||||
}
|
||||
|
||||
if parent.hash != child.parent_hash {
|
||||
return Err(ConsensusError::ParentHashMismatch {
|
||||
expected_parent_hash: parent.hash,
|
||||
got_parent_hash: child.parent_hash,
|
||||
})
|
||||
return Err(ConsensusError::ParentHashMismatch(
|
||||
GotExpected { got: child.parent_hash, expected: parent.hash }.into(),
|
||||
))
|
||||
}
|
||||
|
||||
// timestamp in past check
|
||||
@ -343,7 +340,10 @@ pub fn validate_header_regarding_parent(
|
||||
.ok_or(ConsensusError::BaseFeeMissing)?
|
||||
};
|
||||
if expected_base_fee != base_fee {
|
||||
return Err(ConsensusError::BaseFeeDiff { expected: expected_base_fee, got: base_fee })
|
||||
return Err(ConsensusError::BaseFeeDiff(GotExpected {
|
||||
expected: expected_base_fee,
|
||||
got: base_fee,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@ -435,8 +435,7 @@ pub fn validate_4844_header_with_parent(
|
||||
calculate_excess_blob_gas(parent_excess_blob_gas, parent_blob_gas_used);
|
||||
if expected_excess_blob_gas != excess_blob_gas {
|
||||
return Err(ConsensusError::ExcessBlobGasDiff {
|
||||
expected: expected_excess_blob_gas,
|
||||
got: excess_blob_gas,
|
||||
diff: GotExpected { got: excess_blob_gas, expected: expected_excess_blob_gas },
|
||||
parent_excess_blob_gas,
|
||||
parent_blob_gas_used,
|
||||
})
|
||||
@ -843,10 +842,10 @@ mod tests {
|
||||
// validate blob, it should fail blob gas used validation
|
||||
assert_eq!(
|
||||
validate_block_standalone(&block, &chain_spec),
|
||||
Err(ConsensusError::BlobGasUsedDiff {
|
||||
header_blob_gas_used: 1,
|
||||
expected_blob_gas_used
|
||||
})
|
||||
Err(ConsensusError::BlobGasUsedDiff(GotExpected {
|
||||
got: 1,
|
||||
expected: expected_blob_gas_used
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user