From 3e5a6ef649c368be417b9d461cfa78c8a7e2564b Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 19 Dec 2023 16:43:36 +0300 Subject: [PATCH] fix(rpc): pass blockhash into `TxToJSON` so that `getspecialtxes` could show correct `instantlock`/`chainlock` values (#5774) ## Issue being fixed or feature implemented `instantlock` and `chainlock` are broken in `getspecialtxes` kudos to @thephez for finding the issue ## What was done? pass the hash and also rename the variable to self-describing ## How Has This Been Tested? run `getspecialtxes` on a node with and without the patch ## Breaking Changes `instantlock` and `chainlock` will show actual values and not just `false` all the time now (not sure if that qualifies for "breaking" though) ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ --- doc/release-notes-5774.md | 4 ++++ src/rpc/blockchain.cpp | 6 +++--- test/functional/feature_llmq_chainlocks.py | 13 ++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 doc/release-notes-5774.md diff --git a/doc/release-notes-5774.md b/doc/release-notes-5774.md new file mode 100644 index 0000000000..4ceafc25ff --- /dev/null +++ b/doc/release-notes-5774.md @@ -0,0 +1,4 @@ +RPC changes +----------- + +In `getspecialtxes` `instantlock` and `chainlock` fields were always `false`. They should show actual values now. diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0f3c3a2caa..2d6281c31b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2462,7 +2462,7 @@ static UniValue getspecialtxes(const JSONRPCRequest& request) CTxMemPool& mempool = EnsureMemPool(node); LLMQContext& llmq_ctx = EnsureLLMQContext(node); - uint256 hash(ParseHashV(request.params[0], "blockhash")); + uint256 blockhash(ParseHashV(request.params[0], "blockhash")); int nTxType = -1; if (!request.params[1].isNull()) { @@ -2491,7 +2491,7 @@ static UniValue getspecialtxes(const JSONRPCRequest& request) } } - const CBlockIndex* pblockindex = chainman.m_blockman.LookupBlockIndex(hash); + const CBlockIndex* pblockindex = chainman.m_blockman.LookupBlockIndex(blockhash); if (!pblockindex) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); } @@ -2519,7 +2519,7 @@ static UniValue getspecialtxes(const JSONRPCRequest& request) case 2 : { UniValue objTx(UniValue::VOBJ); - TxToJSON(*tx, uint256(), mempool, chainman.ActiveChainstate(), *llmq_ctx.clhandler, *llmq_ctx.isman, objTx); + TxToJSON(*tx, blockhash, mempool, chainman.ActiveChainstate(), *llmq_ctx.clhandler, *llmq_ctx.isman, objTx); result.push_back(objTx); break; } diff --git a/test/functional/feature_llmq_chainlocks.py b/test/functional/feature_llmq_chainlocks.py index 93959bc154..f4981a61d0 100755 --- a/test/functional/feature_llmq_chainlocks.py +++ b/test/functional/feature_llmq_chainlocks.py @@ -40,8 +40,13 @@ class LLMQChainLocksTest(DashTestFramework): self.test_coinbase_best_cl(self.nodes[0], expected_cl_in_cb=False) # v20 is active, no quorums, no CLs - null CL in CbTx - self.nodes[0].generate(1) + nocl_block_hash = self.nodes[0].generate(1)[0] self.test_coinbase_best_cl(self.nodes[0], expected_cl_in_cb=True, expected_null_cl=True) + cbtx = self.nodes[0].getspecialtxes(nocl_block_hash, 5, 1, 0, 2)[0] + assert_equal(cbtx["instantlock"], False) + assert_equal(cbtx["instantlock_internal"], False) + assert_equal(cbtx["chainlock"], False) + self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.wait_for_sporks_same() @@ -55,6 +60,12 @@ class LLMQChainLocksTest(DashTestFramework): self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.test_coinbase_best_cl(self.nodes[0]) + # ChainLock locks all the blocks below it so nocl_block_hash should be locked too + cbtx = self.nodes[0].getspecialtxes(nocl_block_hash, 5, 1, 0, 2)[0] + assert_equal(cbtx["instantlock"], True) + assert_equal(cbtx["instantlock_internal"], False) + assert_equal(cbtx["chainlock"], True) + self.log.info("Mine many blocks, wait for chainlock") self.nodes[0].generate(20) # We need more time here due to 20 blocks being generated at once