pub fn update_commitments_after_block(
utxo_tree: &mut UtxoMerkleTree,
block: &Block,
block_height: Natural,
spam_filter: Option<&SpamFilter>,
) -> UtxoCommitmentResult<Hash>Expand description
Update UTXO commitments after block connection
This function should be called after successfully connecting a block to keep UTXO commitments synchronized with the blockchain state.
§Arguments
utxo_tree- Mutable reference to the UTXO Merkle treeblock- The block that was just connectedblock_height- Height of the connected blockspam_filter- Optional spam filter (if None, all transactions are included)
§Returns
Returns the new Merkle root hash of the UTXO tree.
§Example
use blvm_consensus::block::connect_block;
use blvm_protocol::utxo_commitments::{UtxoMerkleTree, update_commitments_after_block};
use blvm_consensus::spam_filter::SpamFilter;
use blvm_consensus::types::{Network, ValidationResult};
let (result, new_utxo_set, _) = connect_block(&block, &witnesses, utxo_set, height, None, Network::Regtest)?;
if matches!(result, ValidationResult::Valid) {
let spam_filter = SpamFilter::new();
let root = update_commitments_after_block(
&mut utxo_tree,
&block,
height,
Some(&spam_filter),
)?;
println!("New UTXO commitment root: {:?}", root);
}