From 147267c3ad227ffda78ff827346c2bc71411e74a Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Tue, 28 Nov 2023 19:16:35 +0200 Subject: [PATCH 01/13] return null when tx not in mempool --- src/rpc/rawtransaction.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index ea81ace82fe44..1f9d2b173c657 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -317,7 +317,13 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request) int height{-1}; bool chainLock{false}; - GetTransaction(nullptr, nullptr, txid, Params().GetConsensus(), hash_block); + auto tx_ref = GetTransaction(nullptr, node.mempool.get(), txid, Params().GetConsensus(), hash_block); + + if (tx_ref == nullptr) { + UniValue r(UniValue::VNULL); + result_arr.push_back(r); + continue; + } if (!hash_block.IsNull()) { LOCK(cs_main); From 7280af50fa3b64059a3370194eef5ec9594b88b9 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Wed, 29 Nov 2023 11:16:34 +0200 Subject: [PATCH 02/13] adapted rpc_verifychainlock to change --- test/functional/rpc_verifychainlock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/rpc_verifychainlock.py b/test/functional/rpc_verifychainlock.py index a11aba3adc171..6372eddaa1f6c 100755 --- a/test/functional/rpc_verifychainlock.py +++ b/test/functional/rpc_verifychainlock.py @@ -65,7 +65,7 @@ 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} + unknown_cl_helper = None assert_equal(locks0, [{'height': height, 'chainlock': True}, unknown_cl_helper]) assert_equal(locks1, [unknown_cl_helper, {'height': height1, 'chainlock': False}]) From 3c4fef54d8f47fc4f1db065a348a9e4a9067dfe1 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Wed, 29 Nov 2023 11:18:40 +0200 Subject: [PATCH 03/13] suggestions --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 1f9d2b173c657..30cf042a7a295 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -317,7 +317,7 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request) int height{-1}; bool chainLock{false}; - auto tx_ref = GetTransaction(nullptr, node.mempool.get(), txid, Params().GetConsensus(), hash_block); + const auto tx_ref = GetTransaction(nullptr, node.mempool.get(), txid, Params().GetConsensus(), hash_block); if (tx_ref == nullptr) { UniValue r(UniValue::VNULL); From 4b68535d5afd5cf667ccd26b07d12d12c8d9e377 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Tue, 19 Dec 2023 16:32:11 +0200 Subject: [PATCH 04/13] backward compatibility change --- src/rpc/rawtransaction.cpp | 6 ++++-- test/functional/rpc_verifychainlock.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 30cf042a7a295..5cb2ee4574ab5 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -320,8 +320,10 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request) const auto tx_ref = GetTransaction(nullptr, node.mempool.get(), txid, Params().GetConsensus(), hash_block); if (tx_ref == nullptr) { - UniValue r(UniValue::VNULL); - result_arr.push_back(r); + result.pushKV("height", height); + result.pushKV("chainlock", chainLock); + result.pushKV("mempool", false); + result_arr.push_back(result); continue; } diff --git a/test/functional/rpc_verifychainlock.py b/test/functional/rpc_verifychainlock.py index 6372eddaa1f6c..3fbfcc9f3ce07 100755 --- a/test/functional/rpc_verifychainlock.py +++ b/test/functional/rpc_verifychainlock.py @@ -65,7 +65,7 @@ def run_test(self): tx1 = node1.getblock(node1.getbestblockhash())['tx'][0] locks0 = node0.gettxchainlocks([tx0, tx1]) locks1 = node1.gettxchainlocks([tx0, tx1]) - unknown_cl_helper = None + unknown_cl_helper = {'height': -1, 'chainlock': False, 'mempool': False} assert_equal(locks0, [{'height': height, 'chainlock': True}, unknown_cl_helper]) assert_equal(locks1, [unknown_cl_helper, {'height': height1, 'chainlock': False}]) From 68a1dc4ae6196d22a456efdf9fef954d0d050dc0 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Wed, 20 Dec 2023 11:32:25 +0200 Subject: [PATCH 05/13] Adjusted help text --- src/rpc/rawtransaction.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 5cb2ee4574ab5..eccb23286a919 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -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)", { @@ -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"}, }}, } }, From 74bb167709d090e1f2c2a390d2c3413bb8063614 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Wed, 20 Dec 2023 11:47:32 +0200 Subject: [PATCH 06/13] Create release-notes-5742.md --- doc/release-notes-5742.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 doc/release-notes-5742.md diff --git a/doc/release-notes-5742.md b/doc/release-notes-5742.md new file mode 100644 index 0000000000000..6fa741c29323c --- /dev/null +++ b/doc/release-notes-5742.md @@ -0,0 +1,4 @@ +RPC changes +----------- + +RPC `gettxchainlocks` will also return the status `mempool` indicating wether the transaction is in the mempool or not. From 3ec6c44490e3f2b36e110bdab90a81914541dccf Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Wed, 20 Dec 2023 12:16:46 +0200 Subject: [PATCH 07/13] added mempool=true case --- src/rpc/rawtransaction.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index eccb23286a919..545e27bde052a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -338,6 +338,9 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request) if (height != -1) { chainLock = llmq_ctx.clhandler->HasChainLock(height, hash_block); } + else { + result.pushKV("mempool", true); + } result.pushKV("height", height); result.pushKV("chainlock", chainLock); result_arr.push_back(result); From a7a543d47c49a230a468089cc1e84c9250560de5 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 22 Dec 2023 10:42:13 +0200 Subject: [PATCH 08/13] suggestions --- src/rpc/rawtransaction.cpp | 1 + test/functional/rpc_verifychainlock.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 545e27bde052a..485a0120aa0d1 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -337,6 +337,7 @@ 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); diff --git a/test/functional/rpc_verifychainlock.py b/test/functional/rpc_verifychainlock.py index 3fbfcc9f3ce07..1505d47f482ca 100755 --- a/test/functional/rpc_verifychainlock.py +++ b/test/functional/rpc_verifychainlock.py @@ -66,9 +66,14 @@ def run_test(self): locks0 = node0.gettxchainlocks([tx0, tx1]) locks1 = node1.gettxchainlocks([tx0, tx1]) unknown_cl_helper = {'height': -1, 'chainlock': False, 'mempool': False} - assert_equal(locks0, [{'height': height, 'chainlock': True}, unknown_cl_helper]) - assert_equal(locks1, [unknown_cl_helper, {'height': height1, 'chainlock': 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]) + assert_equal(locks0, [{'mempool': True, 'height': -1, 'chainlock': False}]) + assert_equal(locks1, [{'mempool': True, 'height': -1, 'chainlock': False}]) if __name__ == '__main__': RPCVerifyChainLockTest().main() From 55ecb41d44ee4dbb4c2f4765c221aa899d327678 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 22 Dec 2023 10:57:18 +0200 Subject: [PATCH 09/13] Update test/functional/rpc_verifychainlock.py Co-authored-by: Konstantin Akimov --- test/functional/rpc_verifychainlock.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functional/rpc_verifychainlock.py b/test/functional/rpc_verifychainlock.py index 1505d47f482ca..15dcc3852d621 100755 --- a/test/functional/rpc_verifychainlock.py +++ b/test/functional/rpc_verifychainlock.py @@ -71,7 +71,8 @@ def run_test(self): tx3 = node0.sendtoaddress(node0.getnewaddress(), 1) locks0 = node0.gettxchainlocks([tx3]) - locks1 = node0.gettxchainlocks([tx3]) + self.sync_mempools() + locks1 = node1.gettxchainlocks([tx3]) assert_equal(locks0, [{'mempool': True, 'height': -1, 'chainlock': False}]) assert_equal(locks1, [{'mempool': True, 'height': -1, 'chainlock': False}]) From 63b75271625e929ce10d525fbc7738685bcbf9d5 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 22 Dec 2023 14:50:34 +0200 Subject: [PATCH 10/13] suggestions --- src/rpc/rawtransaction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 485a0120aa0d1..beac7461b48f3 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -317,13 +317,14 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request) uint256 hash_block; int height{-1}; bool chainLock{false}; + bool mempool{false}; 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); + result.pushKV("mempool", mempool); result_arr.push_back(result); continue; } @@ -337,13 +338,13 @@ 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); } result.pushKV("height", height); result.pushKV("chainlock", chainLock); + result.pushKV("mempool", mempool); result_arr.push_back(result); } return result_arr; From 717edda9592cfb90b7042aca4793e7c83a5cc64e Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 22 Dec 2023 15:03:00 +0200 Subject: [PATCH 11/13] Apply suggestions from code review Co-authored-by: UdjinM6 --- src/rpc/rawtransaction.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index beac7461b48f3..2ec28580ce8c0 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -317,14 +317,13 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request) uint256 hash_block; int height{-1}; bool chainLock{false}; - bool mempool{false}; 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", mempool); + result.pushKV("height", -1); + result.pushKV("chainlock", false); + result.pushKV("mempool", false); result_arr.push_back(result); continue; } @@ -339,12 +338,9 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request) if (height != -1) { chainLock = llmq_ctx.clhandler->HasChainLock(height, hash_block); } - else { - result.pushKV("mempool", true); - } result.pushKV("height", height); result.pushKV("chainlock", chainLock); - result.pushKV("mempool", mempool); + result.pushKV("mempool", height == -1); result_arr.push_back(result); } return result_arr; From 21b632691249d40f5a0393f4d1ecccc67c84fce3 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 22 Dec 2023 18:28:10 +0200 Subject: [PATCH 12/13] Update rpc_verifychainlock.py --- test/functional/rpc_verifychainlock.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/functional/rpc_verifychainlock.py b/test/functional/rpc_verifychainlock.py index 15dcc3852d621..7cb5bfe5dce7f 100755 --- a/test/functional/rpc_verifychainlock.py +++ b/test/functional/rpc_verifychainlock.py @@ -71,10 +71,7 @@ def run_test(self): tx3 = node0.sendtoaddress(node0.getnewaddress(), 1) locks0 = node0.gettxchainlocks([tx3]) - self.sync_mempools() - locks1 = node1.gettxchainlocks([tx3]) - assert_equal(locks0, [{'mempool': True, 'height': -1, 'chainlock': False}]) - assert_equal(locks1, [{'mempool': True, 'height': -1, 'chainlock': False}]) + assert_equal(locks0, [{'height': -1, 'chainlock': False, 'mempool': True}]) if __name__ == '__main__': RPCVerifyChainLockTest().main() From 25283332ab495b932e2900ec815d001bfc5204af Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 22 Dec 2023 19:57:46 +0300 Subject: [PATCH 13/13] suggestions --- test/functional/rpc_verifychainlock.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/functional/rpc_verifychainlock.py b/test/functional/rpc_verifychainlock.py index 7cb5bfe5dce7f..31df77c467e69 100755 --- a/test/functional/rpc_verifychainlock.py +++ b/test/functional/rpc_verifychainlock.py @@ -22,6 +22,9 @@ def set_test_params(self): self.set_dash_test_params(5, 3, [["-whitelist=127.0.0.1"], [], [], [], []], fast_dip3_enforcement=True) self.set_dash_llmq_test_params(3, 2) + def cl_helper(self, height, chainlock, mempool): + return {'height': height, 'chainlock': chainlock, 'mempool': mempool} + def run_test(self): node0 = self.nodes[0] node1 = self.nodes[1] @@ -63,15 +66,12 @@ def run_test(self): height1 = node1.getblockcount() tx0 = node0.getblock(node0.getbestblockhash())['tx'][0] tx1 = node1.getblock(node1.getbestblockhash())['tx'][0] - locks0 = node0.gettxchainlocks([tx0, tx1]) - locks1 = node1.gettxchainlocks([tx0, tx1]) - 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]) - assert_equal(locks0, [{'height': -1, 'chainlock': False, 'mempool': True}]) + tx2 = node0.sendtoaddress(node0.getnewaddress(), 1) + locks0 = node0.gettxchainlocks([tx0, tx1, tx2]) + locks1 = node1.gettxchainlocks([tx0, tx1, tx2]) + unknown_cl_helper = self.cl_helper(-1, False, False) + assert_equal(locks0, [self.cl_helper(height, True, False), unknown_cl_helper, self.cl_helper(-1, False, True)]) + assert_equal(locks1, [unknown_cl_helper, self.cl_helper(height1, False, False), unknown_cl_helper]) if __name__ == '__main__': RPCVerifyChainLockTest().main()