Skip to main content

check_bip30

Function check_bip30 

Source
pub fn check_bip30(
    block: &Block,
    utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
    bip30_index: Option<&HashMap<[u8; 32], usize, FxBuildHasher>>,
    height: u64,
    activation: &impl IsForkActive,
    coinbase_txid: Option<&[u8; 32]>,
) -> Result<bool, ConsensusError>
Expand description

BIP30: Duplicate Coinbase Prevention

Prevents duplicate coinbase transactions (same txid) from being added to the blockchain. Mathematical specification: Orange Paper Section 5.4.1

BIP30Check: ℬ × 𝒰𝒮 × ℕ × Network → {valid, invalid}

For block b = (h, txs) with UTXO set us, height h, and network n:

  • invalid if h ≤ deactivation_height(n) ∧ ∃ tx ∈ txs : IsCoinbase(tx) ∧ txid(tx) ∈ CoinbaseTxids(us)
  • valid otherwise

Deactivation: BIP30 was disabled after block 91722 (mainnet) to allow duplicate coinbases in blocks 91842 and 91880 (historical bug, grandfathered in).

Activation: Block 0 (always active until deactivation)

Optimization: When bip30_index is Some, uses O(1) lookup instead of O(n) iteration over the UTXO set. Caller must maintain the index in sync with UTXO changes. #2: When coinbase_txid is Some, skips calculate_tx_id(coinbase) — caller precomputed.