Skip to content

Conversation

@tuxcanfly
Copy link
Contributor

@tuxcanfly tuxcanfly commented Jul 11, 2024

Overview

This PR restores cometbft compat by allowing optional params for all endpoints, following /block in #1760

Fixes #1761

Summary by CodeRabbit

  • New Features

    • Added support for additional pointer types in various functions, enhancing the versatility of input handling.
  • Bug Fixes

    • Improved safety and robustness in handling query parameters across multiple functions to prevent nil value errors.
  • Tests

    • Updated test cases to reflect changes in request paths and parameter handling for improved accuracy.
  • Refactor

    • Converted several struct fields from non-pointer to pointer types, allowing for nullable values and more flexible data handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2024

Walkthrough

The changes improve the RPC JSON handling by adding support for additional pointer types and ensuring safer handling of query parameters. This involves checking for nil values before assignment in various functions, thus enhancing robustness. Additionally, some struct fields have been converted to pointers, allowing for nullable values. These updates ensure better compatibility with CometBFT RPC methods.

Changes

File(s) Change Summary
rpc/json/handler.go Added support for StrInt, string, bool, and bytes.HexBytes pointer types in setPointerParam.
rpc/json/service.go Added nil checks and conditionally assigned variables for safer query handling in multiple functions.
rpc/json/service_test.go Adjusted request paths, parameters in REST functionality tests, and query handling in subscription tests.
rpc/json/types.go Converted several struct fields from strings to pointers, allowing for nullable values.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RPCHandler
    participant Service

    Client->>+RPCHandler: Request with pointer type parameters
    RPCHandler->>+Service: Forward request with checked pointers
    Service-->>-RPCHandler: Processed response
    RPCHandler-->>-Client: Response with nullable fields
Loading

Assessment against linked issues

Objective Addressed Explanation
Revisit CometBFT RPC Compatibility for methods other than block (#1761)

Poem

In the world of code so bright,
Pointers now dance in the light,
Queries checked with gentle care,
Robust functions everywhere.
CometBFT now sings a tune,
Enhanced RPC, a bright new moon! 🌕


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@tuxcanfly tuxcanfly force-pushed the tux/rpc-optional-params branch 2 times, most recently from 086bccb to 7ab4fa1 Compare July 11, 2024 14:45
@tuxcanfly tuxcanfly force-pushed the tux/rpc-optional-params branch from 7ab4fa1 to cdaf328 Compare July 11, 2024 14:58
@Manav-Aggarwal Manav-Aggarwal marked this pull request as ready for review July 15, 2024 15:50
@RollkitBot RollkitBot requested review from a team, MSevey, gupadhyaya and yarikbratashchuk and removed request for a team July 15, 2024 15:50
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0b7c3ab and cdaf328.

Files selected for processing (4)
  • rpc/json/handler.go (2 hunks)
  • rpc/json/service.go (7 hunks)
  • rpc/json/service_test.go (2 hunks)
  • rpc/json/types.go (3 hunks)
Additional comments not posted (30)
rpc/json/types.go (13)

14-14: LGTM!

The change to make Query a pointer to string aligns with the objective of allowing optional parameters.


18-18: LGTM!

The change to make Query a pointer to string aligns with the objective of allowing optional parameters.


31-32: LGTM!

The change to make MinHeight and MaxHeight pointers to StrInt64 aligns with the objective of allowing optional parameters.


43-43: LGTM!

The change to make Height a pointer to StrInt64 aligns with the objective of allowing optional parameters.


50-50: LGTM!

The change to make Height a pointer to StrInt64 aligns with the objective of allowing optional parameters.


54-54: LGTM!

The change to make Height a pointer to StrInt64 aligns with the objective of allowing optional parameters.


58-58: LGTM!

The change to make Height a pointer to StrInt64 aligns with the objective of allowing optional parameters.


77-79: LGTM!

The change to make Page, PerPage, and OrderBy pointers aligns with the objective of allowing optional parameters.


84-86: LGTM!

The change to make Page, PerPage, and OrderBy pointers aligns with the objective of allowing optional parameters.


90-92: LGTM!

The change to make Height, Page, and PerPage pointers aligns with the objective of allowing optional parameters.


100-100: LGTM!

The change to make Height a pointer to StrInt64 aligns with the objective of allowing optional parameters.


104-104: LGTM!

The change to make Limit a pointer to StrInt aligns with the objective of allowing optional parameters.


126-127: LGTM!

The change to make Height and Prove pointers aligns with the objective of allowing optional parameters.

rpc/json/handler.go (4)

217-218: Add support for StrInt pointer type.

This change allows the function to handle StrInt pointer types, aligning with the objective of supporting additional pointer types.


232-233: Add support for string pointer type.

This change allows the function to handle string pointer types, aligning with the objective of supporting additional pointer types.


234-235: Add support for bool pointer type.

This change allows the function to handle bool pointer types, aligning with the objective of supporting additional pointer types.


240-241: Add support for bytes.HexBytes pointer type.

This change allows the function to handle bytes.HexBytes pointer types, aligning with the objective of supporting additional pointer types.

rpc/json/service.go (12)

99-102: LGTM! Handling optional parameter for query.

The changes correctly handle the optional query parameter.


144-147: LGTM! Handling optional parameter for query.

The changes correctly handle the optional query parameter.


179-187: LGTM! Handling optional parameters for minHeight and maxHeight.

The changes correctly handle the optional minHeight and maxHeight parameters.


213-217: LGTM! Handling optional parameter for height.

The changes correctly handle the optional height parameter.


222-226: LGTM! Handling optional parameter for height.

The changes correctly handle the optional height parameter.


231-235: LGTM! Handling optional parameter for height.

The changes correctly handle the optional height parameter.


252-265: LGTM! Handling optional parameters for page, perPage, and orderBy.

The changes correctly handle the optional page, perPage, and orderBy parameters.


271-284: LGTM! Handling optional parameters for page, perPage, and orderBy.

The changes correctly handle the optional page, perPage, and orderBy parameters.


290-303: LGTM! Handling optional parameters for height, page, and perPage.

The changes correctly handle the optional height, page, and perPage parameters.


318-322: LGTM! Handling optional parameter for height.

The changes correctly handle the optional height parameter.


327-330: LGTM! Handling optional parameter for limit.

The changes correctly handle the optional limit parameter.


354-361: LGTM! Handling optional parameters for options.Height and options.Prove.

The changes correctly handle the optional options.Height and options.Prove parameters.

rpc/json/service_test.go (1)

151-175: LGTM! Testing optional parameters for subscribe and unsubscribe.

The changes correctly test the handling of optional parameters for subscribe and unsubscribe.

Copy link
Member

@Manav-Aggarwal Manav-Aggarwal left a comment

Choose a reason for hiding this comment

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

LGTM

@MSevey MSevey added this pull request to the merge queue Jul 15, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 15, 2024
@Manav-Aggarwal Manav-Aggarwal added this pull request to the merge queue Jul 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 16, 2024
@tzdybal tzdybal added this pull request to the merge queue Jul 16, 2024
Merged via the queue into main with commit 38e9f84 Jul 16, 2024
@tzdybal tzdybal deleted the tux/rpc-optional-params branch July 16, 2024 15:15
@tac0turtle tac0turtle removed this from Evolve Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revisit CometBFT RPC Compatibility for methods other than block

5 participants