Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Aug 11, 2022
1 parent 7405126 commit a9655bf
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ pub fn calculate_mmr_roots<T: BlockchainBackend>(db: &T, block: &Block) -> Resul
for kernel in body.kernels().iter() {
kernel_mmr.push(kernel.hash())?;
}
let mut deleted_outputs = Vec::new();

for output in body.outputs().iter() {
let output_hash = output.hash();
Expand All @@ -1275,21 +1276,7 @@ pub fn calculate_mmr_roots<T: BlockchainBackend>(db: &T, block: &Block) -> Resul
field: "hash",
value: output_hash.to_hex(),
})?;
if !output_mmr.delete(index) {
let num_leaves = u32::try_from(output_mmr.get_leaf_count())
.map_err(|_| ChainStorageError::CriticalError("UTXO MMR leaf count overflows u32".to_string()))?;
if index < num_leaves && output_mmr.deleted().contains(index) {
return Err(ChainStorageError::InvalidOperation(format!(
"UTXO {} was already marked as deleted.",
output_hash.to_hex()
)));
}

return Err(ChainStorageError::InvalidOperation(format!(
"Could not delete index {} from the output MMR ({} leaves)",
index, num_leaves
)));
}
deleted_outputs.push((index, output_hash));
}
}

Expand Down Expand Up @@ -1319,7 +1306,9 @@ pub fn calculate_mmr_roots<T: BlockchainBackend>(db: &T, block: &Block) -> Resul
index
},
};

deleted_outputs.push((index, output_hash));
}
for (index, output_hash) in deleted_outputs.into_iter() {
if !output_mmr.delete(index) {
let num_leaves = u32::try_from(output_mmr.get_leaf_count())
.map_err(|_| ChainStorageError::CriticalError("UTXO MMR leaf count overflows u32".to_string()))?;
Expand Down

0 comments on commit a9655bf

Please sign in to comment.