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: implement new RPCs getislocks and add verbose=0 to getbestchainlock #6455

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

knst
Copy link
Collaborator

@knst knst commented Dec 6, 2024

Issue being fixed or feature implemented

#6391

To register an identity in the DashPlatform network, there is a required field of InstantLock or ChainLock buffer in IdentityCreateTransition. You first create and broadcast Core transaction, then wait for InstantLock or ChainLock, and then create and broadcast transaction in the Platform chain with that data.

What was done?

To retrieve information about ChainLocks has been implemented new param verbose=0|1[default] for RPC getbestchainlock which return information in zmq-compatible hex format.
To retrieve information about InstantSend Lock has been implemented a new RPC getrawislocks that return information for list of txids in human-friendly JSON format and zmq-compatible hex format.

How Has This Been Tested?

See new checks in functional test interface_zmq_dash.py

Breaking Changes

N/A

Checklist:

  • 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
  • I have assigned this pull request to a milestone

@knst knst added this to the 22.1 milestone Dec 6, 2024
@knst knst added the guix-build label Dec 6, 2024
@DashCoreAutoGuix
Copy link

Guix Automation has began to build this PR tagged as v22.1.0-devpr6455.a4256c92. A new comment will be made when the image is pushed.

@DashCoreAutoGuix
Copy link

Guix Automation has completed; a release should be present here: https://github.com/dashpay/dash-dev-branches/releases/tag/v22.1.0-devpr6455.a4256c92. The image should be on dockerhub soon.

src/rpc/rawtransaction.cpp Outdated Show resolved Hide resolved
src/rpc/rawtransaction.cpp Outdated Show resolved Hide resolved
@knst knst changed the title feat: implement new RPCs getrawislock and getrawbestchainlock feat: implement new RPCs getrawislocks and getrawbestchainlock Dec 19, 2024
@DashCoreAutoGuix
Copy link

Guix Automation has began to build this PR tagged as v22.1.0-devpr6455.756b7722. A new comment will be made when the image is pushed.

@knst knst removed the guix-build label Jan 7, 2025
@knst knst marked this pull request as ready for review January 7, 2025 13:24
Copy link

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request introduces significant modifications to the RPC interfaces related to blockchain and transaction handling in the Dash cryptocurrency implementation. It updates the getbestchainlock function in src/rpc/blockchain.cpp to include a new verbose parameter, allowing users to specify the output format as either a hex-encoded string or a JSON object. Additionally, a new RPC command getislocks is added in src/rpc/rawtransaction.cpp, which retrieves InstantSend lock data for specified transaction IDs. The vRPCConvertParams array in src/rpc/client.cpp is updated to accommodate these new commands and their parameters. Furthermore, the changes include enhancements to functional tests in test/functional/interface_zmq_dash.py to validate the behavior of the updated and new RPC methods under various scenarios.

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/rpc/rawtransaction.cpp (1)

369-420: LGTM! Implementation looks solid.

The new RPC method is well-structured with proper input validation, error handling, and serialization.

Consider using CHECK_NONFATAL for llmq_ctx.isman

For better error handling consistency with the codebase:

-if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
+if (const llmq::CInstantSendLockPtr islock = CHECK_NONFATAL(llmq_ctx.isman)->GetInstantSendLockByTxid(txid); islock != nullptr) {
src/rpc/blockchain.cpp (1)

272-301: LGTM! Implementation looks solid.

The new RPC method is well-structured with proper error handling and serialization.

Consider using RPC_INVALID_REQUEST for consistency

For better error code consistency with other RPC methods:

-        throw JSONRPCError(RPC_MISC_ERROR, "Unable to find any ChainLock");
+        throw JSONRPCError(RPC_INVALID_REQUEST, "Unable to find any ChainLock");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8decb8 and 756b772.

📒 Files selected for processing (4)
  • src/rpc/blockchain.cpp (2 hunks)
  • src/rpc/client.cpp (1 hunks)
  • src/rpc/rawtransaction.cpp (3 hunks)
  • test/functional/interface_zmq_dash.py (4 hunks)
🔇 Additional comments (4)
src/rpc/client.cpp (1)

118-118: LGTM!

The new entry for getrawislocks is correctly added to the vRPCConvertParams array, maintaining alphabetical order and following the established pattern.

test/functional/interface_zmq_dash.py (1)

139-140: LGTM! Test coverage looks good.

The added test assertions provide good coverage for both the new RPC methods:

  • Tests error case for getrawbestchainlock when no ChainLock exists
  • Tests both negative and positive cases for getrawislocks (before and after InstantSend lock)

Also applies to: 291-291, 311-311

src/rpc/rawtransaction.cpp (1)

1984-1984: LGTM! Command registration looks good.

The new RPC command is properly registered in the command table.

src/rpc/blockchain.cpp (1)

2705-2705: LGTM! Command registration looks good.

The new RPC command is properly registered in the command table.

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rework to combine with getbestchainlock and add json to islock

@knst
Copy link
Collaborator Author

knst commented Jan 7, 2025

Let's rework to combine with getbestchainlock and add json to islock

as discussed, RPC will be changed:

  • getbestchainlock will have an argument "verbose=0|1[default]" which return raw for verbose=0
  • getrawislock will have same verbose argument to return result as a JSON

@knst knst marked this pull request as draft January 7, 2025 14:06
@DashCoreAutoGuix
Copy link

Guix Automation has completed; a release should be present here: https://github.com/dashpay/dash-dev-branches/releases/tag/v22.1.0-devpr6455.756b7722. The image should be on dockerhub soon.

@thephez thephez added the RPC Some notable changes to RPC params/behaviour/descriptions label Jan 9, 2025
It adds ability to receive raw chainlock in hex format (compatible with ZMQ subscription)
@knst knst changed the title feat: implement new RPCs getrawislocks and getrawbestchainlock feat: implement new RPCs getislocks and add verbose=0 to getbestchainlock Jan 9, 2025
@knst knst marked this pull request as ready for review January 9, 2025 15:29
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/rpc/blockchain.cpp (1)

274-289: Consider adding error handling for serialization.

The core logic is correct, but consider:

  1. Using a named constant for PROTOCOL_VERSION to improve maintainability
  2. Adding error handling for potential serialization failures
-        CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
+        try {
+            CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
+            ssTx << clsig;
+            return HexStr(ssTx);
+        } catch (const std::exception& e) {
+            throw JSONRPCError(RPC_INTERNAL_ERROR, 
+                std::string("Failed to serialize ChainLock: ") + e.what());
+        }
-        ssTx << clsig;
-        return HexStr(ssTx);
src/rpc/rawtransaction.cpp (2)

431-432: Move llmq_ctx declaration outside the loop for better performance.

The LLMQContext is retrieved inside the loop but it could be moved outside since it's used for all transactions.

Apply this diff to improve performance:

    const NodeContext& node = EnsureAnyNodeContext(request.context);
+   const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
    for (const auto idx : irange::range(txids.size())) {
        const uint256 txid(ParseHashV(txids[idx], "txid"));
-       const LLMQContext& llmq_ctx = EnsureLLMQContext(node);

435-456: Consider using structured bindings for better readability.

The code can be made more readable by using C++17's structured bindings and early returns.

Apply this diff to improve readability:

-   if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
+   if (auto islock = CHECK_NONFATAL(llmq_ctx.isman)->GetInstantSendLockByTxid(txid); islock != nullptr) {
        if (verbose == 1) {
            UniValue objIS(UniValue::VOBJ);
            objIS.pushKV("txid", islock->txid.ToString());
            UniValue outputs(UniValue::VARR);
            for (const auto& out : islock->inputs) {
                UniValue outpoint(UniValue::VOBJ);
                outpoint.pushKV("txid", out.hash.ToString());
                outpoint.pushKV("vout", static_cast<int64_t>(out.n));
                outputs.push_back(outpoint);
            }
            objIS.pushKV("cycleHash", islock->cycleHash.ToString());
            objIS.pushKV("sig", islock->sig.ToString());
            result_arr.push_back(objIS);
        } else {
            CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
            ssTx << *islock;
            result_arr.push_back(HexStr(ssTx));
        }
    } else {
        result_arr.push_back("None");
    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 756b772 and 2346aa7.

📒 Files selected for processing (4)
  • src/rpc/blockchain.cpp (1 hunks)
  • src/rpc/client.cpp (1 hunks)
  • src/rpc/rawtransaction.cpp (3 hunks)
  • test/functional/interface_zmq_dash.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/rpc/client.cpp
  • test/functional/interface_zmq_dash.py
🔇 Additional comments (5)
src/rpc/blockchain.cpp (2)

235-251: LGTM! Documentation and parameter definition are clear and comprehensive.

The updated documentation clearly describes:

  • The new verbose parameter and its default value
  • The different return formats based on the verbose flag
  • The error condition when no ChainLock exists

259-266: LGTM! Parameter handling is robust and maintains backward compatibility.

The code properly handles:

  • Both boolean and numeric input types for the verbose parameter
  • Default value of 1 for backward compatibility
src/rpc/rawtransaction.cpp (3)

2186-2186: LGTM!

The new command is properly registered in the RPC table.


382-407: LGTM!

The RPCResult documentation is comprehensive and well-structured, covering both output formats and error cases.


370-462: Implementation aligns with PR objectives.

The getislocks implementation successfully:

  1. Provides InstantSend lock data in both verbose and raw formats
  2. Matches ZMQ output format when verbose=0
  3. Supports the IdentityCreateTransition process by providing InstantLock data

@knst knst requested a review from PastaPastaPasta January 9, 2025 15:35
@knst knst added the guix-build label Jan 9, 2025
@DashCoreAutoGuix
Copy link

Guix Automation has began to build this PR tagged as v22.1.0-devpr6455.2346aa72. A new comment will be made when the image is pushed.

@knst knst removed the guix-build label Jan 9, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/rpc/rawtransaction.cpp (1)

431-457: Consider performance optimization by moving context outside the loop.

The llmq_ctx is accessed within the loop for each transaction. Consider moving it outside to avoid repeated context retrieval.

 const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
+const auto& isman = llmq_ctx.isman;
 for (const auto idx : irange::range(txids.size())) {
     const uint256 txid(ParseHashV(txids[idx], "txid"));
 
-    if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
+    if (const llmq::CInstantSendLockPtr islock = isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2346aa7 and 9cbd1c6.

📒 Files selected for processing (3)
  • src/rpc/client.cpp (1 hunks)
  • src/rpc/rawtransaction.cpp (3 hunks)
  • test/functional/interface_zmq_dash.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/functional/interface_zmq_dash.py
  • src/rpc/client.cpp
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Dependencies (linux64, x86_64-pc-linux-gnu)
  • GitHub Check: Build Dependencies (arm-linux, arm-linux-gnueabihf)
🔇 Additional comments (2)
src/rpc/rawtransaction.cpp (2)

2186-2186: LGTM!

The command registration follows the established pattern and is correctly placed in the command table.


435-435: ⚠️ Potential issue

Add nullptr check for InstantSend manager.

Add a CHECK_NONFATAL for the InstantSend manager to ensure it's not null before dereferencing.

-    if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
+    if (const llmq::CInstantSendLockPtr islock = CHECK_NONFATAL(llmq_ctx.isman)->GetInstantSendLockByTxid(txid); islock != nullptr) {

Likely invalid or redundant comment.

@DashCoreAutoGuix
Copy link

Guix Automation has completed; a release should be present here: https://github.com/dashpay/dash-dev-branches/releases/tag/v22.1.0-devpr6455.2346aa72. The image should be on dockerhub soon.

"If verbose is 1, returns information about the best ChainLock.\n"
"Throws an error if there is no known ChainLock yet.",
{
{"verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could be bool instead (unless there are plans to allow greater verbosity in the future)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see RPC getblock.

It's done for convinience, so, you can call getbestchainlock true or gestbestchainlock 1 - both ways will work

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verbose should be bool. If you want int it should be verbosity.

You can achieve the same effect (true/1) for bool by doing it the way it's done in getrawtransaction i.e.

bool fVerbose = false;
if (!request.params[0].isNull()) {
    fVerbose = request.params[0].isNum() ? (request.params[0].get_int() != 0) : request.params[0].get_bool();
}

for (const auto idx : irange::range(txids.size())) {
const uint256 txid(ParseHashV(txids[idx], "txid"));

if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could use const auto here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to see a type here 🤷 but I have no strong opinion to remove it

src/rpc/rawtransaction.cpp Show resolved Hide resolved
},
}},
{RPCResult::Type::STR_HEX, "cycleHash", "The Cycle Hash"},
{RPCResult::Type::STR_HEX, "signature", "The InstantSend's BLS signature"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we should mention the algorithm used to generate the signature in the help text.

Suggested change
{RPCResult::Type::STR_HEX, "signature", "The InstantSend's BLS signature"},
{RPCResult::Type::STR_HEX, "signature", "The InstantSend lock's signature"},

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unified with getbestchainlock

                {RPCResult::Type::STR_HEX, "signature", "The ChainLock's BLS signature"},

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be changed too IMO but change could be out-of-scope for this PR.

{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A transaction hash"},
},
},
{"verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could be bool

Copy link
Collaborator Author

@knst knst Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion like for getbestchainlock

It return InstantSend Lock as JSON or as hex-string depends on verbose=0|1

Hex format is compatible with zmq-subscription
@knst knst requested a review from kwvg January 9, 2025 17:14
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/rpc/rawtransaction.cpp (3)

380-380: Use bool type for verbose parameter to maintain consistency.

The verbose parameter is defined as RPCArg::Type::NUM, but other RPCs in the codebase use RPCArg::Type::BOOL for verbose flags. Consider changing to maintain consistency.

-            {"verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object"},
+            {"verbose", RPCArg::Type::BOOL, RPCArg::Default{true}, "false for hex-encoded data, true for a json object"},

435-435: Use const auto for better readability and const correctness.

The islock variable should be declared with const auto to improve readability and enforce const correctness.

-        if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
+        if (const auto islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {

402-402: Update signature field name to match help text.

The help text refers to "signature" but the code uses "sig". Consider updating for consistency.

-                        {RPCResult::Type::STR_HEX, "signature", "The InstantSend's BLS signature"},
+                        {RPCResult::Type::STR_HEX, "sig", "The InstantSend's BLS signature"},
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cbd1c6 and c9a82ba.

📒 Files selected for processing (3)
  • src/rpc/client.cpp (1 hunks)
  • src/rpc/rawtransaction.cpp (3 hunks)
  • test/functional/interface_zmq_dash.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/rpc/client.cpp
  • test/functional/interface_zmq_dash.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Dependencies (linux64, x86_64-pc-linux-gnu)
  • GitHub Check: Build Dependencies (arm-linux, arm-linux-gnueabihf)
🔇 Additional comments (2)
src/rpc/rawtransaction.cpp (2)

2187-2188: LGTM! Command registration follows the established pattern.

The registration of the new getislocks command is properly implemented and follows the existing pattern in the codebase.


445-445: ⚠️ Potential issue

Add missing inputs array to object.

The inputs array is not being pushed to the object in the JSON output.

                 }
+                objIS.pushKV("inputs", inputs);

Likely invalid or redundant comment.

Comment on lines +433 to +435
const uint256 txid(ParseHashV(txids[idx], "txid"));

if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for invalid transaction IDs.

The function should validate transaction IDs before attempting to retrieve InstantSend locks.

         const uint256 txid(ParseHashV(txids[idx], "txid"));
+        if (txid.IsNull()) {
+            throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid txid at index %d", idx));
+        }
 
         if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const uint256 txid(ParseHashV(txids[idx], "txid"));
if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {
const uint256 txid(ParseHashV(txids[idx], "txid"));
if (txid.IsNull()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid txid at index %d", idx));
}
if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) {

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK c9a82ba

Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK c9a82ba

"If verbose is 1, returns information about the best ChainLock.\n"
"Throws an error if there is no known ChainLock yet.",
{
{"verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object"},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verbose should be bool. If you want int it should be verbosity.

You can achieve the same effect (true/1) for bool by doing it the way it's done in getrawtransaction i.e.

bool fVerbose = false;
if (!request.params[0].isNull()) {
    fVerbose = request.params[0].isNum() ? (request.params[0].get_int() != 0) : request.params[0].get_bool();
}

},
{
RPCResult{"for verbose = 0",
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for best ChainLock"},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for best ChainLock"},
RPCResult::Type::STR_HEX, "data", "The serialized, hex-encoded data for best ChainLock"},

Do we need known_block here too? In this case we could probably just add a new hex field to the old RPC results instead of adding a new param.

{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A transaction hash"},
},
},
{"verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object"},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion like for getbestchainlock

RPCResult::Type::ARR, "", "Response is an array with the same size as the input txids",
{
RPCResult{"for verbose = 0 if InstantSend Lock is known for specified txid",
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for 'txid'"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for 'txid'"
RPCResult::Type::STR_HEX, "data", "The serialized, hex-encoded data for 'txid'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RPC Some notable changes to RPC params/behaviour/descriptions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants