Skip to content

Commit 5cac95c

Browse files
committed
disallow_mempool_conflicts -> allow_bip125_replacement and check earlier
1 parent e8ecc62 commit 5cac95c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/validation.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,10 @@ class MemPoolAccept
472472
*/
473473
std::vector<COutPoint>& m_coins_to_uncache;
474474
const bool m_test_accept;
475-
/** Disable BIP125 RBFing; disallow all conflicts with mempool transactions. */
476-
const bool disallow_mempool_conflicts;
475+
/** Whether we allow transactions to replace mempool transactions by BIP125 rules. If false,
476+
* any transaction spending the same inputs as a transaction in the mempool is considered
477+
* a conflict. */
478+
const bool m_allow_bip125_replacement{true};
477479
};
478480

479481
// Single transaction acceptance
@@ -619,6 +621,10 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
619621
{
620622
const CTransaction* ptxConflicting = m_pool.GetConflictTx(txin.prevout);
621623
if (ptxConflicting) {
624+
if (!args.m_allow_bip125_replacement) {
625+
// Transaction conflicts with a mempool tx, but we're not allowing replacements.
626+
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "bip125-replacement-disallowed");
627+
}
622628
if (!setConflicts.count(ptxConflicting->GetHash()))
623629
{
624630
// Allow opt-out of transaction replacement by setting
@@ -642,7 +648,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
642648
break;
643649
}
644650
}
645-
if (fReplacementOptOut || args.disallow_mempool_conflicts) {
651+
if (fReplacementOptOut) {
646652
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "txn-mempool-conflict");
647653
}
648654

@@ -1151,7 +1157,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
11511157
// package to spend. Since we already checked conflicts in the package and we don't allow
11521158
// replacements, we don't need to track the coins spent. Note that this logic will need to be
11531159
// updated if package replace-by-fee is allowed in the future.
1154-
assert(args.disallow_mempool_conflicts);
1160+
assert(!args.m_allow_bip125_replacement);
11551161
m_viewmempool.PackageAddTransaction(ws.m_ptx);
11561162
}
11571163

@@ -1185,7 +1191,7 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp
11851191
{
11861192
std::vector<COutPoint> coins_to_uncache;
11871193
MemPoolAccept::ATMPArgs args { chainparams, nAcceptTime, bypass_limits, coins_to_uncache,
1188-
test_accept, /* disallow_mempool_conflicts */ false };
1194+
test_accept, /* m_allow_bip125_replacement */ true };
11891195

11901196
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
11911197
const MempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptSingleTransaction(tx, args);
@@ -1222,7 +1228,7 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx
12221228
std::vector<COutPoint> coins_to_uncache;
12231229
const CChainParams& chainparams = Params();
12241230
MemPoolAccept::ATMPArgs args { chainparams, GetTime(), /* bypass_limits */ false, coins_to_uncache,
1225-
test_accept, /* disallow_mempool_conflicts */ true };
1231+
test_accept, /* m_allow_bip125_replacement */ false };
12261232
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
12271233
const PackageMempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptMultipleTransactions(package, args);
12281234

test/functional/rpc_packages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ def test_rbf(self):
354354
# This transaction is a valid BIP125 replace-by-fee
355355
assert testres_rbf_single[0]["allowed"]
356356
testres_rbf_package = self.independent_txns_testres_blank + [{
357-
"txid": replacement_tx.rehash(), "wtxid": replacement_tx.getwtxid(), "allowed": False, "reject-reason": "txn-mempool-conflict"
357+
"txid": replacement_tx.rehash(), "wtxid": replacement_tx.getwtxid(), "allowed": False,
358+
"reject-reason": "bip125-replacement-disallowed"
358359
}]
359360
self.assert_testres_equal(self.independent_txns_hex + [signed_replacement_tx["hex"]], testres_rbf_package)
360361

0 commit comments

Comments
 (0)