Skip to main content

connect_block

Function connect_block 

Source
pub fn connect_block(
    block: &Block,
    witnesses: &[Vec<Vec<Vec<u8>>>],
    utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
    height: u64,
    context: &BlockValidationContext,
) -> Result<(ValidationResult, HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, BlockUndoLog), ConsensusError>
Expand description

ConnectBlock: โ„ฌ ร— ๐’ฒ* ร— ๐’ฐ๐’ฎ ร— โ„• ร— โ„‹* โ†’ {valid, invalid} ร— ๐’ฐ๐’ฎ

For block b = (h, txs) with witnesses ws, UTXO set us at height height, and recent headers:

  1. Validate block header h
  2. For each transaction tx โˆˆ txs:
    • Validate tx structure
    • Check inputs against us
    • Verify scripts (with witness data if available)
  3. Let fees = ฮฃ_{tx โˆˆ txs} fee(tx)
  4. Let subsidy = GetBlockSubsidy(height)
  5. If coinbase output > fees + subsidy: return (invalid, us)
  6. Apply all transactions to us: usโ€™ = ApplyTransactions(txs, us)
  7. Return (valid, usโ€™)

ยงArguments

  • block - The block to validate and connect
  • witnesses - Witness data for each transaction in the block (one Witness per transaction)
  • utxo_set - Current UTXO set (will be modified)
  • height - Current block height
  • context - Block validation context (time, network, fork activation, BIP54 boundary). Build with BlockValidationContext::from_connect_block_ibd_args, from_time_context_and_network, or for_network. ConnectBlock: Validate and apply a block to the UTXO set.