@@ -113,15 +113,43 @@ bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeR
113113 // that we do not treat it as standard as new rules may apply
114114 // in the future due to an upgrade, so we prefer not to treat
115115 // such inputs as standard.
116- const bool seq_is_reserved = (txin.nSequence < CTxIn::SEQUENCE_FINAL-2 ) && (
117- // when sequence is set to disabled, it is reserved for future use
118- ((txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0 ) ||
119- // when sequence has bits set outside of the type flag and locktime mask,
120- // it is reserved for future use.
121- ((~(CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | CTxIn::SEQUENCE_LOCKTIME_MASK) &
122- txin.nSequence ) != 0 )
123- );
124- if (seq_is_reserved) {
116+ bool seq_is_reserved_for_upgrade;
117+ switch (static_cast <CTxIn::SEQUENCE_ROOT_TYPE>(txin.nSequence >> CTxIn::SEQUENCE_ROOT_TYPE_SHIFT)) {
118+ case CTxIn::SEQUENCE_ROOT_TYPE::NORMAL: {
119+ // when sequence has bits set outside of the type flag and locktime mask,
120+ // it is reserved for future use.
121+ // (locktime disable flag is implicitly 0 in SEQUENCE_ROOT_TYPE::NORMAL)
122+ const uint32_t mask = ~(CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | CTxIn::SEQUENCE_LOCKTIME_MASK);
123+ seq_is_reserved_for_upgrade = (mask & txin.nSequence ) != 0 ;
124+ break ;
125+ }
126+ case CTxIn::SEQUENCE_ROOT_TYPE::UNCHECKED_METADATA: {
127+ seq_is_reserved_for_upgrade = false ;
128+ break ;
129+ }
130+ case CTxIn::SEQUENCE_ROOT_TYPE::SPECIAL: {
131+ switch (txin.nSequence ) {
132+ case CTxIn::SEQUENCE_FINAL:
133+ case CTxIn::SEQUENCE_VALUE_RESERVED_NO_RBF_YES_CLTV:
134+ case CTxIn::SEQUENCE_VALUE_RESERVED_YES_RBF_NO_CSV: {
135+ seq_is_reserved_for_upgrade = false ;
136+ break ;
137+ }
138+ default : {
139+ // was not a special reserved value, keep reserved for upgrade.
140+ seq_is_reserved_for_upgrade = true ;
141+ break ;
142+ }
143+ }
144+ break ;
145+ }
146+ default : {
147+ // unknown root type, keep reserved for upgrade.
148+ seq_is_reserved_for_upgrade = true ;
149+ break ;
150+ }
151+ }
152+ if (seq_is_reserved_for_upgrade) {
125153 reason = " sequence-flags-reserved" ;
126154 return false ;
127155 }
0 commit comments