Skip to content

Commit badb9b1

Browse files
committed
call SignalsOptInRBF instead of checking all inputs
1 parent e0df41d commit badb9b1

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/util/rbf.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ class CTransaction;
1111

1212
static const uint32_t MAX_BIP125_RBF_SEQUENCE = 0xfffffffd;
1313

14-
// Check whether the sequence numbers on this transaction are signaling
15-
// opt-in to replace-by-fee, according to BIP 125
14+
/** Check whether the sequence numbers on this transaction are signaling
15+
* opt-in to replace-by-fee, according to BIP 125.
16+
* Allow opt-out of transaction replacement by setting
17+
* nSequence > MAX_BIP125_RBF_SEQUENCE (SEQUENCE_FINAL-2) on all inputs.
18+
*
19+
* SEQUENCE_FINAL-1 is picked to still allow use of nLockTime by
20+
* non-replaceable transactions. All inputs rather than just one
21+
* is for the sake of multi-party protocols, where we don't
22+
* want a single party to be able to disable replacement. */
1623
bool SignalsOptInRBF(const CTransaction &tx);
1724

1825
#endif // BITCOIN_UTIL_RBF_H

src/validation.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -605,31 +605,14 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
605605
}
606606
if (!setConflicts.count(ptxConflicting->GetHash()))
607607
{
608-
// Allow opt-out of transaction replacement by setting
609-
// nSequence > MAX_BIP125_RBF_SEQUENCE (SEQUENCE_FINAL-2) on all inputs.
610-
//
611-
// SEQUENCE_FINAL-1 is picked to still allow use of nLockTime by
612-
// non-replaceable transactions. All inputs rather than just one
613-
// is for the sake of multi-party protocols, where we don't
614-
// want a single party to be able to disable replacement.
615-
//
616608
// Transactions that don't explicitly signal replaceability are
617609
// *not* replaceable with the current logic, even if one of their
618610
// unconfirmed ancestors signals replaceability. This diverges
619611
// from BIP125's inherited signaling description (see CVE-2021-31876).
620612
// Applications relying on first-seen mempool behavior should
621613
// check all unconfirmed ancestors; otherwise an opt-in ancestor
622614
// might be replaced, causing removal of this descendant.
623-
bool fReplacementOptOut = true;
624-
for (const CTxIn &_txin : ptxConflicting->vin)
625-
{
626-
if (_txin.nSequence <= MAX_BIP125_RBF_SEQUENCE)
627-
{
628-
fReplacementOptOut = false;
629-
break;
630-
}
631-
}
632-
if (fReplacementOptOut) {
615+
if (!SignalsOptInRBF(*ptxConflicting)) {
633616
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "txn-mempool-conflict");
634617
}
635618

0 commit comments

Comments
 (0)