Skip to content

Commit de10ce3

Browse files
committed
feat(node): apply_block uses activation-aware VerifyFlags via Network helpers
Compute per-block script verification flags from network soft-fork activation heights instead of using the post-taproot mandatory flag set for every block. Op: extend
1 parent 19a8606 commit de10ce3

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

crates/node/src/state.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ impl NodeState {
455455
// stood BEFORE this block's outputs were committed — inputs in this
456456
// block can only spend outputs from earlier blocks. Coinbase txs
457457
// early-return inside `verify_transaction`.
458+
let flags = compute_verify_flags(self.config.network, height);
458459
let view = crate::utxo_view::UtxoSetView::new(Arc::clone(&self.utxo));
459460
for tx in &block.txdata {
460461
if tx.is_coinbase() {
@@ -463,12 +464,7 @@ impl NodeState {
463464
// TODO(perf): drop the per-tx clone once `verify_transaction_borrowed(&bitcoin::Transaction, ...)`
464465
// lands on `bitcoin_rs_consensus`. See DEVIATIONS §7.
465466
let wrapped = bitcoin_rs_primitives::Tx(tx.clone());
466-
bitcoin_rs_consensus::verify_transaction(
467-
&wrapped,
468-
&view,
469-
height,
470-
bitcoin_rs_script::VerifyFlags::MANDATORY,
471-
)?;
467+
bitcoin_rs_consensus::verify_transaction(&wrapped, &view, height, flags)?;
472468
}
473469
Ok(())
474470
}
@@ -525,6 +521,35 @@ impl NodeState {
525521
}
526522
}
527523

524+
#[must_use]
525+
const fn compute_verify_flags(
526+
network: bitcoin_rs_primitives::Network,
527+
height: u32,
528+
) -> bitcoin_rs_script::VerifyFlags {
529+
use bitcoin_rs_script::VerifyFlags;
530+
531+
// P2SH (BIP16) is effectively always-on for supported validation paths.
532+
let mut flags = VerifyFlags::P2SH;
533+
if network.is_bip66_active(height) {
534+
flags = flags.union(VerifyFlags::DERSIG);
535+
}
536+
if network.is_bip65_active(height) {
537+
flags = flags.union(VerifyFlags::CHECKLOCKTIMEVERIFY);
538+
}
539+
if network.is_csv_active(height) {
540+
flags = flags.union(VerifyFlags::CHECKSEQUENCEVERIFY);
541+
}
542+
if network.is_segwit_active(height) {
543+
flags = flags
544+
.union(VerifyFlags::WITNESS)
545+
.union(VerifyFlags::NULLDUMMY);
546+
}
547+
if network.is_taproot_active(height) {
548+
flags = flags.union(VerifyFlags::TAPROOT);
549+
}
550+
flags
551+
}
552+
528553
#[cfg(test)]
529554
mod tests {
530555
use super::*;

0 commit comments

Comments
 (0)