diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index e6c021d4261..05b340995d0 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -40,6 +40,10 @@ static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue for (const uint256& conflict : wallet.GetTxConflicts(wtx)) conflicts.push_back(conflict.GetHex()); entry.pushKV("walletconflicts", conflicts); + UniValue mempool_conflicts(UniValue::VARR); + for (const Txid& mempool_conflict : wtx.mempool_conflicts) + mempool_conflicts.push_back(mempool_conflict.GetHex()); + entry.pushKV("mempoolconflicts", mempool_conflicts); entry.pushKV("time", wtx.GetTxTime()); entry.pushKV("timereceived", int64_t{wtx.nTimeReceived}); @@ -417,6 +421,10 @@ static std::vector TransactionDescriptionString() }}, {RPCResult::Type::STR_HEX, "replaced_by_txid", /*optional=*/true, "Only if 'category' is 'send'. The txid if this tx was replaced."}, {RPCResult::Type::STR_HEX, "replaces_txid", /*optional=*/true, "Only if 'category' is 'send'. The txid if this tx replaces another."}, + {RPCResult::Type::ARR, "mempoolconflicts", "Transactions that directly conflict with either this transaction or an ancestor transaction", + { + {RPCResult::Type::STR_HEX, "txid", "The transaction id."}, + }}, {RPCResult::Type::STR, "to", /*optional=*/true, "If a comment to is associated with the transaction."}, {RPCResult::Type::NUM_TIME, "time", "The transaction time expressed in " + UNIX_EPOCH_TIME + "."}, {RPCResult::Type::NUM_TIME, "timereceived", "The time received expressed in " + UNIX_EPOCH_TIME + "."}, diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index f798eee365c..0b52ed79142 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -679,7 +679,7 @@ class WalletTest(BitcoinTestFramework): "category": baz["category"], "vout": baz["vout"]} expected_fields = frozenset({'amount', 'bip125-replaceable', 'confirmations', 'details', 'fee', - 'hex', 'lastprocessedblock', 'time', 'timereceived', 'trusted', 'txid', 'wtxid', 'walletconflicts'}) + 'hex', 'lastprocessedblock', 'time', 'timereceived', 'trusted', 'txid', 'wtxid', 'walletconflicts', 'mempoolconflicts'}) verbose_field = "decoded" expected_verbose_fields = expected_fields | {verbose_field} diff --git a/test/functional/wallet_conflicts.py b/test/functional/wallet_conflicts.py index cb6b1c7eaaf..e5739a6a597 100755 --- a/test/functional/wallet_conflicts.py +++ b/test/functional/wallet_conflicts.py @@ -178,6 +178,8 @@ class TxConflicts(BitcoinTestFramework): assert_equal(alice.listunspent(), [unspents[0]]) assert_equal(alice.getbalance(), 25) + assert_equal(alice.gettransaction(tx1_txid)["mempoolconflicts"], [tx2_txid]) + self.log.info("Test scenario where a mempool conflict is removed") # broadcast tx3, replaces tx2 in mempool @@ -187,6 +189,7 @@ class TxConflicts(BitcoinTestFramework): # tx1 is no longer conflicted. alice.sendrawtransaction(tx3) + assert_equal(alice.gettransaction(tx1_txid)["mempoolconflicts"], []) assert tx1_txid not in self.nodes[0].getrawmempool() # now all of alice's outputs should be considered spent @@ -262,6 +265,10 @@ class TxConflicts(BitcoinTestFramework): assert tx2_txid in bob.getrawmempool() assert tx1_conflict_txid in bob.getrawmempool() + assert_equal(bob.gettransaction(tx1_txid)["mempoolconflicts"], [tx1_conflict_txid]) + assert_equal(bob.gettransaction(tx2_txid)["mempoolconflicts"], []) + assert_equal(bob.gettransaction(tx3_txid)["mempoolconflicts"], [tx1_conflict_txid]) + # check that tx3 is now conflicted, so the output from tx2 can now be spent assert_equal(bob.getbalances()["mine"]["untrusted_pending"], Decimal("24.99990000")) @@ -348,6 +355,8 @@ class TxConflicts(BitcoinTestFramework): assert_equal(alice.getbalance(), 25) assert_equal(bob.getbalances()["mine"]["untrusted_pending"], Decimal("24.99990000")) + assert_equal(bob.gettransaction(tx1_txid)["mempoolconflicts"], []) + raw_tx = bob.createrawtransaction(inputs=[bob.listunspent(minconf=0)[0]], outputs=[{carol.getnewaddress() : 24.999}]) # Bob creates a child to tx1 tx1_child = bob.signrawtransactionwithwallet(raw_tx)['hex'] @@ -356,6 +365,8 @@ class TxConflicts(BitcoinTestFramework): self.sync_mempools() # Currently neither tx1 nor tx1_child should have any conflicts + assert_equal(bob.gettransaction(tx1_txid)["mempoolconflicts"], []) + assert_equal(bob.gettransaction(tx1_child_txid)["mempoolconflicts"], []) assert tx1_txid in bob.getrawmempool() assert tx1_child_txid in bob.getrawmempool() assert_equal(len(bob.getrawmempool()), 2) @@ -378,6 +389,10 @@ class TxConflicts(BitcoinTestFramework): assert tx1_conflict_txid in bob.getrawmempool() assert_equal(len(bob.getrawmempool()), 1) + # Now both tx1 and tx1_child are conflicted by tx1_conflict + assert_equal(bob.gettransaction(tx1_txid)["mempoolconflicts"], [tx1_conflict_txid]) + assert_equal(bob.gettransaction(tx1_child_txid)["mempoolconflicts"], [tx1_conflict_txid]) + # Now create a conflict to tx1_conflict, so that it gets kicked out of the mempool raw_tx = alice.createrawtransaction(inputs=[unspents[1]], outputs=[{carol.getnewaddress() : 24.9895}]) tx1_conflict_conflict = alice.signrawtransactionwithwallet(raw_tx)['hex'] @@ -385,6 +400,10 @@ class TxConflicts(BitcoinTestFramework): self.sync_mempools() + # Now that tx1_conflict has been removed, both tx1 and tx1_child + assert_equal(bob.gettransaction(tx1_txid)["mempoolconflicts"], []) + assert_equal(bob.gettransaction(tx1_child_txid)["mempoolconflicts"], []) + # Both tx1 and tx1_child are still not in the mempool because they have not be re-broadcasted assert tx1_txid not in bob.getrawmempool() assert tx1_child_txid not in bob.getrawmempool()