Skip to content

Commit 6516b36

Browse files
committed
Merge #12676: Show "bip125-replaceable" flag, when retrieving mempool entries
870bd4c Update functional RBF test to check replaceable flag (dexX7) 820d31f Add "bip125-replaceable" flag to mempool RPCs (dexX7) Pull request description: This pull request adds a flag "bip125-replaceable" to the mempool RPCs getrawmempool, getmempoolentry, getmempoolancestors and getmempooldescendants, which indicates whether an unconfirmed transaction might be replaced. Initially the flag was added to the raw transaction RPCs, but thanks to @conscott, it was moved to the mempool RPCs, which actually have access to the mempool. ~~This pull request adds a flag "bip125-replaceable" to the RPCs "getrawtransaction" and "decoderawtransaction", which indicates, whether a transaction signals BIP 125 replaceability.~~ There was some discussion in #7817, whether showing replaceability in the UI could lead to the false assumption that transactions that don't signal BIP 125 are truely non-replaceable, but given that this PR tackles the raw transaction interface, which is a rather low level tool, I believe having this extra piece of information isn't bad. Tree-SHA512: 1f5511957af2c20a9a6c79d80a335c3be37a2402dbf829c40cceaa01a24868eab81a9c1cdb0b3d77198fa3bb82799e3540a5c0ce7f35bbac80d73f7133ff7cbc
2 parents f6eb85d + 870bd4c commit 6516b36

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/rpc/blockchain.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <key_io.h>
1919
#include <policy/feerate.h>
2020
#include <policy/policy.h>
21+
#include <policy/rbf.h>
2122
#include <primitives/transaction.h>
2223
#include <rpc/server.h>
2324
#include <script/descriptor.h>
@@ -379,7 +380,8 @@ static std::string EntryDescriptionString()
379380
" ... ]\n"
380381
" \"spentby\" : [ (array) unconfirmed transactions spending outputs from this transaction\n"
381382
" \"transactionid\", (string) child transaction id\n"
382-
" ... ]\n";
383+
" ... ]\n"
384+
" \"bip125-replaceable\" : true|false, (boolean) Whether this transaction could be replaced due to BIP125 (replace-by-fee)\n";
383385
}
384386

385387
static void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) EXCLUSIVE_LOCKS_REQUIRED(::mempool.cs)
@@ -429,6 +431,17 @@ static void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) EXCLUSIVE_LOCK
429431
}
430432

431433
info.pushKV("spentby", spent);
434+
435+
// Add opt-in RBF status
436+
bool rbfStatus = false;
437+
RBFTransactionState rbfState = IsRBFOptIn(tx, mempool);
438+
if (rbfState == RBFTransactionState::UNKNOWN) {
439+
throw JSONRPCError(RPC_MISC_ERROR, "Transaction is not in mempool");
440+
} else if (rbfState == RBFTransactionState::REPLACEABLE_BIP125) {
441+
rbfStatus = true;
442+
}
443+
444+
info.pushKV("bip125-replaceable", rbfStatus);
432445
}
433446

434447
UniValue mempoolToJSON(bool fVerbose)

test/functional/feature_rbf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ def test_opt_in(self):
429429
tx1a_hex = txToHex(tx1a)
430430
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
431431

432+
# This transaction isn't shown as replaceable
433+
assert_equal(self.nodes[0].getmempoolentry(tx1a_txid)['bip125-replaceable'], False)
434+
432435
# Shouldn't be able to double-spend
433436
tx1b = CTransaction()
434437
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
@@ -469,7 +472,10 @@ def test_opt_in(self):
469472
tx3a.vout = [CTxOut(int(0.9*COIN), CScript([b'c'])), CTxOut(int(0.9*COIN), CScript([b'd']))]
470473
tx3a_hex = txToHex(tx3a)
471474

472-
self.nodes[0].sendrawtransaction(tx3a_hex, True)
475+
tx3a_txid = self.nodes[0].sendrawtransaction(tx3a_hex, True)
476+
477+
# This transaction is shown as replaceable
478+
assert_equal(self.nodes[0].getmempoolentry(tx3a_txid)['bip125-replaceable'], True)
473479

474480
tx3b = CTransaction()
475481
tx3b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]

0 commit comments

Comments
 (0)