diff --git a/zebra-chain/src/orchard/tree.rs b/zebra-chain/src/orchard/tree.rs index 9862bd8f7..8a2acf5b8 100644 --- a/zebra-chain/src/orchard/tree.rs +++ b/zebra-chain/src/orchard/tree.rs @@ -428,7 +428,13 @@ impl Eq for NoteCommitmentTree {} impl PartialEq for NoteCommitmentTree { fn eq(&self, other: &Self) -> bool { - self.hash() == other.hash() + if let (Some(root), Some(other_root)) = (self.cached_root(), other.cached_root()) { + // Use cached roots if available + root == other_root + } else { + // Avoid expensive root recalculations which use multiple cryptographic hashes + self.inner == other.inner + } } } diff --git a/zebra-chain/src/sapling/tree.rs b/zebra-chain/src/sapling/tree.rs index 5b5bed239..75eea88e1 100644 --- a/zebra-chain/src/sapling/tree.rs +++ b/zebra-chain/src/sapling/tree.rs @@ -423,7 +423,13 @@ impl Eq for NoteCommitmentTree {} impl PartialEq for NoteCommitmentTree { fn eq(&self, other: &Self) -> bool { - self.hash() == other.hash() + if let (Some(root), Some(other_root)) = (self.cached_root(), other.cached_root()) { + // Use cached roots if available + root == other_root + } else { + // Avoid expensive root recalculations which use multiple cryptographic hashes + self.inner == other.inner + } } } diff --git a/zebra-chain/src/sprout/tree.rs b/zebra-chain/src/sprout/tree.rs index 2b70b0a36..5c9269283 100644 --- a/zebra-chain/src/sprout/tree.rs +++ b/zebra-chain/src/sprout/tree.rs @@ -377,7 +377,13 @@ impl Eq for NoteCommitmentTree {} impl PartialEq for NoteCommitmentTree { fn eq(&self, other: &Self) -> bool { - self.hash() == other.hash() + if let (Some(root), Some(other_root)) = (self.cached_root(), other.cached_root()) { + // Use cached roots if available + root == other_root + } else { + // Avoid expensive root recalculations which use multiple cryptographic hashes + self.inner == other.inner + } } }