Skip to content

Commit

Permalink
chore: use hash fn directly (#13379)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 13, 2024
1 parent fb64997 commit f347977
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
10 changes: 3 additions & 7 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,21 +698,17 @@ where
if let Err(e) =
self.externals.consensus.validate_header_with_total_difficulty(block, U256::MAX)
{
error!(
?block,
"Failed to validate total difficulty for block {}: {e}",
block.header.hash()
);
error!(?block, "Failed to validate total difficulty for block {}: {e}", block.hash());
return Err(e);
}

if let Err(e) = self.externals.consensus.validate_header(block) {
error!(?block, "Failed to validate header {}: {e}", block.header.hash());
error!(?block, "Failed to validate header {}: {e}", block.hash());
return Err(e);
}

if let Err(e) = self.externals.consensus.validate_block_pre_execution(block) {
error!(?block, "Failed to validate block {}: {e}", block.header.hash());
error!(?block, "Failed to validate block {}: {e}", block.hash());
return Err(e);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ mod tests {
// Test lowest_buffered_ancestor for the descendant block
let lowest_ancestor = tree_state.lowest_buffered_ancestor(&descendant_hash);
assert!(lowest_ancestor.is_some());
assert_eq!(lowest_ancestor.unwrap().block.header.hash(), ancestor_hash);
assert_eq!(lowest_ancestor.unwrap().block.hash(), ancestor_hash);

// Test lowest_buffered_ancestor with a non-existent hash
let non_existent_hash = B256::random();
Expand Down
8 changes: 4 additions & 4 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,18 +1762,18 @@ where
target: "engine::tree",
?block,
"Failed to validate total difficulty for block {}: {e}",
block.header.hash()
block.hash()
);
return Err(e)
}

if let Err(e) = self.consensus.validate_header(block) {
error!(target: "engine::tree", ?block, "Failed to validate header {}: {e}", block.header.hash());
error!(target: "engine::tree", ?block, "Failed to validate header {}: {e}", block.hash());
return Err(e)
}

if let Err(e) = self.consensus.validate_block_pre_execution(block) {
error!(target: "engine::tree", ?block, "Failed to validate block {}: {e}", block.header.hash());
error!(target: "engine::tree", ?block, "Failed to validate block {}: {e}", block.hash());
return Err(e)
}

Expand Down Expand Up @@ -2210,7 +2210,7 @@ where
))
})?;
if let Err(e) = self.consensus.validate_header_against_parent(&block, &parent_block) {
warn!(target: "engine::tree", ?block, "Failed to validate header {} against parent: {e}", block.header.hash());
warn!(target: "engine::tree", ?block, "Failed to validate header {} against parent: {e}", block.hash());
return Err(e.into())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA

let base_block =
self.block_with_senders(block).await?.ok_or(EthApiError::HeaderNotFound(block))?;
let mut parent_hash = base_block.header.hash();
let mut parent_hash = base_block.hash();

// Only enforce base fee if validation is enabled
cfg.disable_base_fee = !validation;
Expand Down
16 changes: 8 additions & 8 deletions crates/storage/provider/src/providers/blockchain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ mod tests {
let in_memory_block = in_memory_blocks.last().unwrap().clone();

let block_number = database_block.number;
let block_hash = database_block.header.hash();
let block_hash = database_block.hash();

assert_eq!(
provider.block_by_id(block_number.into()).unwrap(),
Expand All @@ -1544,7 +1544,7 @@ mod tests {
assert_eq!(provider.block_by_id(block_hash.into()).unwrap(), Some(database_block.unseal()));

let block_number = in_memory_block.number;
let block_hash = in_memory_block.header.hash();
let block_hash = in_memory_block.hash();
assert_eq!(
provider.block_by_id(block_number.into()).unwrap(),
Some(in_memory_block.clone().unseal())
Expand Down Expand Up @@ -1628,7 +1628,7 @@ mod tests {
let in_memory_block = in_memory_blocks.last().unwrap().clone();

let block_number = database_block.number;
let block_hash = database_block.header.hash();
let block_hash = database_block.hash();

assert_eq!(
provider.header_by_id(block_number.into()).unwrap(),
Expand All @@ -1649,7 +1649,7 @@ mod tests {
);

let block_number = in_memory_block.number;
let block_hash = in_memory_block.header.hash();
let block_hash = in_memory_block.hash();

assert_eq!(
provider.header_by_id(block_number.into()).unwrap(),
Expand Down Expand Up @@ -1686,7 +1686,7 @@ mod tests {
let in_memory_block = in_memory_blocks.last().unwrap().clone();

let block_number = database_block.number;
let block_hash = database_block.header.hash();
let block_hash = database_block.hash();

assert_eq!(
provider.ommers_by_id(block_number.into()).unwrap().unwrap_or_default(),
Expand All @@ -1698,7 +1698,7 @@ mod tests {
);

let block_number = in_memory_block.number;
let block_hash = in_memory_block.header.hash();
let block_hash = in_memory_block.hash();

assert_eq!(
provider.ommers_by_id(block_number.into()).unwrap().unwrap_or_default(),
Expand Down Expand Up @@ -1726,7 +1726,7 @@ mod tests {
let in_memory_block = in_memory_blocks.last().unwrap().clone();

let block_number = database_block.number;
let block_hash = database_block.header.hash();
let block_hash = database_block.hash();

assert!(!receipts.get(database_block.number as usize).unwrap().is_empty());
assert!(!provider
Expand All @@ -1744,7 +1744,7 @@ mod tests {
);

let block_number = in_memory_block.number;
let block_hash = in_memory_block.header.hash();
let block_hash = in_memory_block.hash();

assert_eq!(
provider.receipts_by_block_id(block_number.into())?.unwrap(),
Expand Down

0 comments on commit f347977

Please sign in to comment.