feat: check nodes (or peaks) before merge them

This commit is contained in:
Boyu Yang
2022-04-15 13:31:49 +08:00
parent a037309912
commit be20646ac8
7 changed files with 25 additions and 19 deletions
+3 -3
View File
@@ -72,17 +72,17 @@ struct MergeHashWithTD;
impl Merge for MergeHashWithTD {
type Item = HashWithTD;
fn merge(lhs: &Self::Item, rhs: &Self::Item) -> Self::Item {
fn merge(lhs: &Self::Item, rhs: &Self::Item) -> Result<Self::Item> {
let mut hasher = new_blake2b();
let mut hash = [0u8; 32];
hasher.update(&lhs.serialize());
hasher.update(&rhs.serialize());
hasher.finalize(&mut hash);
let td = lhs.td + rhs.td;
HashWithTD {
Ok(HashWithTD {
hash: hash.to_vec().into(),
td,
}
})
}
}