@@ -587,6 +587,16 @@ bool block::is_segregated() const NOEXCEPT
587587 return std::any_of (txs_->begin (), txs_->end (), segregated);
588588}
589589
590+ size_t block::segregated () const NOEXCEPT
591+ {
592+ const auto count_segregated = [](const auto & tx) NOEXCEPT
593+ {
594+ return tx->is_segregated ();
595+ };
596+
597+ return std::count_if (txs_->begin (), txs_->end (), count_segregated);
598+ }
599+
590600// The witness merkle root is obtained from wtxids, subject to malleation just
591601// as the txs commitment. However, since tx duplicates are precluded by the
592602// malleable32 (or complete) block check, there is no opportunity for this.
@@ -600,6 +610,10 @@ bool block::is_invalid_witness_commitment() const NOEXCEPT
600610 if (coinbase->inputs_ptr ()->empty ())
601611 return false ;
602612
613+ // If no block tx has witness data the commitment is optional (bip141).
614+ if (!is_segregated ())
615+ return false ;
616+
603617 // If there is a valid commitment, return false (valid).
604618 // Coinbase input witness must be 32 byte witness reserved value (bip141).
605619 // Last output of commitment pattern holds the committed value (bip141).
@@ -610,10 +624,8 @@ bool block::is_invalid_witness_commitment() const NOEXCEPT
610624 if (committed == sha256::double_hash (
611625 generate_merkle_root (true ), reserved))
612626 return false ;
613-
614- // If no valid commitment, return true (invalid) if segregated.
615- // If no block tx has witness data the commitment is optional (bip141).
616- return is_segregated ();
627+
628+ return true ;
617629}
618630
619631// *****************************************************************************
0 commit comments