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(server/v2/cometbft): add checktx handler #21985

Merged
merged 6 commits into from
Oct 3, 2024

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Sep 30, 2024

Description

this pr is a follow up to #21979 to add the feature to v2


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a customizable transaction validation handler, enhancing flexibility in transaction processing.
    • Added a new field in server options to specify a transaction check handler.
  • Bug Fixes

    • Improved response consistency in transaction validation regardless of handler usage.
  • Documentation

    • Updated comments to clarify the new handler's usage in the configuration file.

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request introduce a new transaction validation handler, checkTxHandler, to the Consensus struct within the cometbft package. The CheckTx method is modified to conditionally use this handler if it is set, allowing for customizable transaction validation logic. Additionally, the ServerOptions struct is updated to include this handler, enhancing server configurability. Minor adjustments to formatting and structure are also included to ensure consistent response handling.

Changes

File Path Change Summary
server/v2/cometbft/abci.go Added checkTxHandler field to Consensus struct; modified CheckTx method to use this handler.
server/v2/cometbft/handlers/handlers.go Introduced CheckTxHandler function type; added import for server package.
server/v2/cometbft/options.go Added CheckTxHandler field to ServerOptions struct; initialized to nil in DefaultServerOptions.
server/v2/cometbft/server.go Added checkTxHandler field to CometBFTServer struct; integrated into Init method for initialization.

Possibly related PRs

  • refactor(baseapp): create checktx handler #21979: The changes in this PR involve the creation of a checkTxHandler in the BaseApp, which aligns with the introduction of the checkTxHandler in the main PR's Consensus struct, enhancing transaction validation flexibility.
  • chore(server/v2/cometbft): improve code check #21955: This PR modifies the CheckTx method in the Consensus struct, improving error handling, which is relevant to the changes made in the main PR that also focuses on the CheckTx method's logic.
  • chore: remove consensus authority  #21734: Although primarily focused on removing the consensus authority, this PR also modifies the Consensus struct in abci.go, which is directly related to the changes made in the main PR regarding the Consensus struct.

Suggested labels

C:server/v2, stf

Suggested reviewers

  • julienrbrt
  • facundomedica
  • kocubinski
  • sontrinh16

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

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.

@github-actions github-actions bot added C:server/v2 Issues related to server/v2 C:server/v2 cometbft labels Sep 30, 2024
@julienrbrt julienrbrt changed the title feature(cometbft): add checktx handler feat(server/v2/cometbft): add checktx handler Sep 30, 2024
Base automatically changed from marko/checktx_handler to main October 2, 2024 11:45
@tac0turtle tac0turtle force-pushed the marko/checktx_handler_v2 branch from ba0df1e to bebae75 Compare October 3, 2024 10:26
@tac0turtle tac0turtle marked this pull request as ready for review October 3, 2024 10:27
Copy link
Contributor

github-actions bot commented Oct 3, 2024

@tac0turtle your pull request is missing a changelog!

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

🧹 Outside diff range and nitpick comments (4)
server/v2/cometbft/handlers/handlers.go (1)

32-33: LGTM: New CheckTxHandler type added correctly.

The new CheckTxHandler type is well-structured and follows the pattern of existing handlers in the file. It correctly uses generics with transaction.Tx, which aligns with best practices for type-safe code.

Consider adding a brief comment explaining the purpose and usage of this handler, similar to the comments for other handler types in this file. This would improve code readability and maintainability. For example:

// CheckTxHandler is a function type that handles the checking of a transaction.
// It takes a function that executes the transaction check and returns a CheckTxResponse and an error.
server/v2/cometbft/options.go (1)

21-21: LGTM! Consider adding a comment for the new field.

The addition of the CheckTxHandler field is consistent with the structure and naming conventions of the ServerOptions struct. It's correctly typed and placed logically among other handler fields.

Consider adding a brief comment explaining the purpose of the CheckTxHandler field, similar to other fields in the struct. This would improve code documentation and maintainability.

server/v2/cometbft/abci.go (2)

67-67: Add a comment explaining checkTxHandler field

To enhance code readability, consider adding a comment describing the purpose of the checkTxHandler field in the Consensus struct.

Apply this diff to add the comment:

+     // checkTxHandler handles custom logic for CheckTx if provided.
      checkTxHandler         handlers.CheckTxHandler[T]

142-142: Improve comment capitalization and clarity

The comment should start with a capital letter and form a complete sentence for better readability.

Apply this diff to improve the comment:

-         // we do not want to return a cometbft error, but a check tx response with the error
+         // We do not want to return a CometBFT error but a CheckTx response with the error.
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c5889a4 and bec6312.

📒 Files selected for processing (4)
  • server/v2/cometbft/abci.go (2 hunks)
  • server/v2/cometbft/handlers/handlers.go (2 hunks)
  • server/v2/cometbft/options.go (2 hunks)
  • server/v2/cometbft/server.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
server/v2/cometbft/abci.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/cometbft/handlers/handlers.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/cometbft/options.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/cometbft/server.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (5)
server/v2/cometbft/handlers/handlers.go (1)

8-8: LGTM: New import added correctly.

The new import for "cosmossdk.io/core/server" is correctly placed and follows the Uber Go Style Guide's recommendations for import formatting. This import is necessary for the new CheckTxHandler type.

server/v2/cometbft/options.go (1)

39-39: Clarify the nil initialization of CheckTxHandler.

Unlike other handlers in DefaultServerOptions, CheckTxHandler is initialized to nil. This approach might lead to potential issues:

  1. It's inconsistent with other handlers' initialization.
  2. It could cause nil pointer dereferences if not properly handled where this handler is used.

Consider the following options:

  1. Provide a default no-op implementation, similar to other handlers.
  2. If nil is intentional, add a comment explaining why it's different from other handlers.
  3. If it's truly optional, consider using a pointer type to make the optionality explicit.

To ensure this doesn't cause issues elsewhere in the codebase, let's check for nil checks:

✅ Verification successful

Initialization of CheckTxHandler is safe as nil checks are appropriately handled.

  • No instances found where CheckTxHandler is used without null checks.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of CheckTxHandler without nil checks
rg --type go 'CheckTxHandler' -C 5 | rg -v 'if.*nil'

Length of output: 7303

server/v2/cometbft/server.go (1)

116-116: LGTM: Addition of checkTxHandler aligns with PR objectives

The addition of checkTxHandler to the consensus object is consistent with the PR's objective of adding a CheckTx handler. This change enhances the flexibility of transaction validation within the consensus mechanism.

A few observations:

  1. The implementation follows Go naming conventions.
  2. The assignment is consistent with other handler assignments in this method.
  3. This addition doesn't appear to introduce any breaking changes to existing functionality.

To ensure this change is properly integrated, let's verify its usage:

✅ Verification successful

CheckTxHandler integration is correctly implemented and consistent

The addition of checkTxHandler in server/v2/cometbft/server.go aligns with existing usages of CheckTxHandler across the codebase. Assigning it from s.serverOptions.CheckTxHandler follows established patterns, ensuring proper integration without introducing breaking changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for CheckTxHandler definition and usage
rg --type go 'CheckTxHandler'

Length of output: 1169

server/v2/cometbft/abci.go (2)

140-165: Proper conditional handling in CheckTx method

The conditional statement appropriately checks for the presence of a custom checkTxHandler and falls back to the default validation logic when it's nil. The error handling and response construction are correctly implemented.


168-168: Correct use of checkTxHandler

The invocation of c.checkTxHandler(c.app.ValidateTx) correctly passes the application's ValidateTx function to the custom handler.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 3, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

lgtm

@tac0turtle tac0turtle added this pull request to the merge queue Oct 3, 2024
Merged via the queue into main with commit a4a0107 Oct 3, 2024
77 of 78 checks passed
@tac0turtle tac0turtle deleted the marko/checktx_handler_v2 branch October 3, 2024 11:57
mergify bot pushed a commit that referenced this pull request Oct 3, 2024
julienrbrt pushed a commit that referenced this pull request Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants