From f3479777655358fc77dd3fc85597ab2e012d39cc Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 13 Dec 2024 13:28:48 +0100 Subject: [PATCH] chore: use hash fn directly (#13379) --- crates/blockchain-tree/src/blockchain_tree.rs | 10 +++------- crates/blockchain-tree/src/state.rs | 2 +- crates/engine/tree/src/tree/mod.rs | 8 ++++---- crates/rpc/rpc-eth-api/src/helpers/call.rs | 2 +- .../src/providers/blockchain_provider.rs | 16 ++++++++-------- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 2c3e62412f20..5fde2fcbd34a 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -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); } diff --git a/crates/blockchain-tree/src/state.rs b/crates/blockchain-tree/src/state.rs index a8e43240f4fa..2d01293e20f8 100644 --- a/crates/blockchain-tree/src/state.rs +++ b/crates/blockchain-tree/src/state.rs @@ -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(); diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 234a96a47d07..69a0eca16066 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -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) } @@ -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()) } diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index fde88483c63b..8319a3ff67ac 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -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; diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 14cb8108d692..722fb5140d4b 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -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(), @@ -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()) @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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 @@ -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(),