diff --git a/base_layer/core/src/chain_storage/blockchain_database.rs b/base_layer/core/src/chain_storage/blockchain_database.rs index 0de3f75c6b..f4e7ceae32 100644 --- a/base_layer/core/src/chain_storage/blockchain_database.rs +++ b/base_layer/core/src/chain_storage/blockchain_database.rs @@ -1262,6 +1262,7 @@ pub fn calculate_mmr_roots(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(); @@ -1275,21 +1276,7 @@ pub fn calculate_mmr_roots(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)); } } @@ -1319,7 +1306,9 @@ pub fn calculate_mmr_roots(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()))?;