Skip to main content

update_commitments_after_block

Function update_commitments_after_block 

Source
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 tree
  • block - The block that was just connected
  • block_height - Height of the connected block
  • spam_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);
}