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 getrawislocks and getrawbestchainlock #6455

Draft
wants to merge 4 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?

Implemented 2 new RPC getrawislocks and getrawbestchainlock which output is similar to ZMQ output.

How Has This Been Tested?

See new asserts 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.

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

LLMQContext& llmq_ctx = EnsureLLMQContext(node);
Copy link
Collaborator

@kwvg kwvg Dec 6, 2024

Choose a reason for hiding this comment

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

Consider defining llmq_ctx outside the loop

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 will wait feedback from pshenmic first

const uint256 txid(ParseHashV(txids[idx], "txid"));

LLMQContext& llmq_ctx = EnsureLLMQContext(node);
llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider

if (auto islock = CHECK_NONFATAL(llmq_ctx.isman)->GetInstantSendLockByTxid(txid); islock != nullptr) {
    CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
    ssTx << *islock;
    result_arr.push_back(HexStr(ssTx));
} else {
    result_arr.push_back("None");
}

@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 enhancements to the blockchain and transaction-related RPC interfaces in the Dash cryptocurrency implementation. Specifically, two new RPC methods are added: getrawbestchainlock and getrawislocks.

The getrawbestchainlock method allows retrieval of the raw best ChainLock, providing serialized, hex-encoded data for the most recent ChainLock. The getrawislocks method enables querying of InstantSend lock data for specified transaction IDs.

These additions are accompanied by updates to the RPC command registration process in the relevant source files. The changes include modifying the RegisterBlockchainRPCCommands and RegisterRawTransactionRPCCommands functions to incorporate the new methods.

Corresponding functional tests have been added to the test/functional/interface_zmq_dash.py file to validate the behavior of these new RPC methods under various conditions, such as querying before a ChainLock exists or checking InstantSend lock status for transactions.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants