-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
📝 WalkthroughWalkthroughThe changes in this pull request introduce a new transaction validation handler, Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
ba0df1e
to
bebae75
Compare
@tac0turtle your pull request is missing a changelog! |
There was a problem hiding this 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 theServerOptions
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 explainingcheckTxHandler
fieldTo enhance code readability, consider adding a comment describing the purpose of the
checkTxHandler
field in theConsensus
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 clarityThe 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
📒 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 thenil
initialization ofCheckTxHandler
.Unlike other handlers in
DefaultServerOptions
,CheckTxHandler
is initialized tonil
. This approach might lead to potential issues:
- It's inconsistent with other handlers' initialization.
- It could cause nil pointer dereferences if not properly handled where this handler is used.
Consider the following options:
- Provide a default no-op implementation, similar to other handlers.
- If
nil
is intentional, add a comment explaining why it's different from other handlers.- 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 asnil
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 objectivesThe addition of
checkTxHandler
to theconsensus
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:
- The implementation follows Go naming conventions.
- The assignment is consistent with other handler assignments in this method.
- 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
inserver/v2/cometbft/server.go
aligns with existing usages ofCheckTxHandler
across the codebase. Assigning it froms.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 inCheckTx
methodThe 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 ofcheckTxHandler
The invocation of
c.checkTxHandler(c.app.ValidateTx)
correctly passes the application'sValidateTx
function to the custom handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
(cherry picked from commit a4a0107)
Co-authored-by: Marko <[email protected]>
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...
!
in the type prefix if API or client breaking changeCHANGELOG.md
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...
Summary by CodeRabbit
New Features
Bug Fixes
Documentation