Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): gettxchainlocks should return mempool=false when tx not in mempool #5742

Merged
4 changes: 4 additions & 0 deletions doc/release-notes-5742.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RPC changes
-----------

RPC `gettxchainlocks` will also return the status `mempool` indicating wether the transaction is in the mempool or not.
17 changes: 15 additions & 2 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request)
{
RPCHelpMan{
"gettxchainlocks",
"\nReturns the block height each transaction was mined at and whether it is chainlocked or not.\n",
"\nReturns the block height at which each transaction was mined, and indicates whether it is in the mempool, chainlocked, or neither.\n",
{
{"txids", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction ids (no more than 100)",
{
Expand All @@ -281,6 +281,7 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request)
{
{RPCResult::Type::NUM, "height", "The block height"},
{RPCResult::Type::BOOL, "chainlock", "Chainlock status for the block containing the transaction"},
{RPCResult::Type::BOOL, "mempool", "Mempool status for the transaction"},
}},
}
},
Expand Down Expand Up @@ -317,7 +318,15 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request)
int height{-1};
bool chainLock{false};

GetTransaction(nullptr, nullptr, txid, Params().GetConsensus(), hash_block);
const auto tx_ref = GetTransaction(nullptr, node.mempool.get(), txid, Params().GetConsensus(), hash_block);

if (tx_ref == nullptr) {
result.pushKV("height", height);
result.pushKV("chainlock", chainLock);
result.pushKV("mempool", false);
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
result_arr.push_back(result);
continue;
}

if (!hash_block.IsNull()) {
LOCK(cs_main);
Expand All @@ -328,6 +337,10 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request)
}
if (height != -1) {
chainLock = llmq_ctx.clhandler->HasChainLock(height, hash_block);
result.pushKV("mempool", false);
}
else {
result.pushKV("mempool", true);
PastaPastaPasta marked this conversation as resolved.
Show resolved Hide resolved
}
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
result.pushKV("height", height);
result.pushKV("chainlock", chainLock);
Expand Down
11 changes: 8 additions & 3 deletions test/functional/rpc_verifychainlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ def run_test(self):
tx1 = node1.getblock(node1.getbestblockhash())['tx'][0]
locks0 = node0.gettxchainlocks([tx0, tx1])
locks1 = node1.gettxchainlocks([tx0, tx1])
unknown_cl_helper = {'height': -1, 'chainlock': False}
assert_equal(locks0, [{'height': height, 'chainlock': True}, unknown_cl_helper])
assert_equal(locks1, [unknown_cl_helper, {'height': height1, 'chainlock': False}])
unknown_cl_helper = {'height': -1, 'chainlock': False, 'mempool': False}
assert_equal(locks0, [{'mempool': False, 'height': height, 'chainlock': True}, unknown_cl_helper])
assert_equal(locks1, [unknown_cl_helper, {'mempool': False, 'height': height1, 'chainlock': False}])

tx3 = node0.sendtoaddress(node0.getnewaddress(), 1)
locks0 = node0.gettxchainlocks([tx3])
locks1 = node0.gettxchainlocks([tx3])
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
assert_equal(locks0, [{'mempool': True, 'height': -1, 'chainlock': False}])
assert_equal(locks1, [{'mempool': True, 'height': -1, 'chainlock': False}])

if __name__ == '__main__':
RPCVerifyChainLockTest().main()
Loading