pub fn update_mempool_after_block(
mempool: &mut HashSet<[u8; 32]>,
block: &Block,
_utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
) -> Result<Vec<[u8; 32]>, ConsensusError>Expand description
Update mempool after block connection
Removes transactions that were included in the block and transactions that became invalid due to spent inputs.
This function should be called after successfully connecting a block to keep the mempool synchronized with the blockchain state.
§Arguments
mempool- Mutable reference to the mempoolblock- The block that was just connectedutxo_set- The updated UTXO set after block connection
§Returns
Returns a vector of transaction IDs that were removed from the mempool.
§Example
use blvm_consensus::mempool::{Mempool, update_mempool_after_block};
use blvm_consensus::block::{connect_block, BlockValidationContext};
use blvm_consensus::ValidationResult;
// One `Vec<Witness>` per tx; coinbase has one input → one empty witness stack.
let ctx = BlockValidationContext::for_network(Network::Regtest);
let (result, new_utxo_set, _) = connect_block(&block, &witnesses, utxo_set, height, &ctx)?;
if matches!(result, ValidationResult::Valid) {
let removed = update_mempool_after_block(&mut mempool, &block, &new_utxo_set)?;
println!("Removed {} transactions from mempool", removed.len());
}