-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix(unorderedtx): issues reported in audit #21467
Conversation
WalkthroughWalkthroughThe changes introduce enhancements to transaction management in the application, particularly for unordered transactions. Key updates include the addition of a Changes
Possibly related issues
Possibly related PRs
Suggested labels
Recent review detailsConfiguration used: .coderabbit.yml Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
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
|
@facundomedica 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, codebase verification and nitpick comments (1)
UPGRADING.md (1)
Line range hint
771-772
: Remove the empty code block.The empty code block at the end of the file serves no purpose and should be removed to improve clarity and avoid confusion.
Remove the following lines:
-``` -Tools
LanguageTool
[uncategorized] ~298-~298: Possible missing article found.
Context: ...sures the manager's state is written to file such that when the node restarts, it ...(AI_HYDRA_LEO_MISSING_A)
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (7)
- UPGRADING.md (1 hunks)
- baseapp/abci_utils.go (2 hunks)
- simapp/app.go (2 hunks)
- simapp/app_di.go (5 hunks)
- types/mempool/priority_nonce.go (2 hunks)
- types/mempool/sender_nonce.go (2 hunks)
- x/auth/ante/unorderedtx/manager.go (2 hunks)
Additional context used
Path-based instructions (7)
x/auth/ante/unorderedtx/manager.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.types/mempool/sender_nonce.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/app_di.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.types/mempool/priority_nonce.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.baseapp/abci_utils.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/app.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.UPGRADING.md (1)
Pattern
**/*.md
: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"
Additional comments not posted (23)
x/auth/ante/unorderedtx/manager.go (2)
60-62
: LGTM!The code changes are approved for the following reasons:
- Using
os.MkdirAll
instead ofos.Mkdir
improves robustness by allowing the creation of nested directories and ensuring the entire directory path is created if it doesn't exist.- Panicking with a formatted error message provides clearer feedback on potential issues during initialization.
190-191
: LGTM!The code changes are approved. The updated comment for the
flushToFile
method enhances clarity by specifying that it writes all unordered transactions, including those that are expired but not yet pruned.types/mempool/sender_nonce.go (2)
148-155
: LGTM!The code segment correctly handles unordered transactions by using the gas limit as the nonce and includes appropriate error handling. It also conforms to the Uber Golang style guide.
239-246
: LGTM!The code segment correctly handles unordered transactions by using the gas limit as the nonce during removal and includes appropriate error handling. It also conforms to the Uber Golang style guide.
simapp/app_di.go (4)
9-9
: LGTM!The import of the
filepath
package is approved.
39-39
: LGTM!The import of the
flags
package is approved.
56-56
: LGTM!The import of the
cast
package is approved.
Line range hint
275-344
: Unordered Transaction Manager IntegrationThe changes introduce a robust integration of the unordered transaction manager into the
SimApp
class. Key aspects include:
- Instantiation and startup of the unordered transaction manager.
- Addition of the
Precommiter
method to execute the module manager's precommit logic and signal a new block to the unordered transaction manager.- Introduction of the
Close
method to ensure proper shutdown of the application and the unordered transaction manager.The code follows best practices and adheres to the Uber Go Style Guide.
types/mempool/priority_nonce.go (2)
226-235
: Looks good! The code correctly handles unordered transactions.The changes introduce a new conditional block to handle the case when a transaction is unordered. If the transaction implements the
sdk.TxWithUnordered
interface andGetUnordered()
returns true, the nonce is replaced with the gas limit obtained fromGetGasLimit()
. Error handling is performed to return the error if retrieving the gas limit fails.The code follows the Uber Go Style Guide.
472-480
: LGTM! The changes are consistent with theInsert
method.The code segment introduces the same conditional block as in the
Insert
method to handle unordered transactions. If the transaction is unordered, the nonce is replaced with the gas limit obtained fromGetGasLimit()
. Error handling is performed to return the error if retrieving the gas limit fails.The code is consistent with the changes made in the
Insert
method and follows the Uber Go Style Guide.baseapp/abci_utils.go (4)
295-296
: New check introduced to identify unordered transactions.The code now checks if the transaction implements the
sdk.TxWithUnordered
interface and callsGetUnordered()
to determine its ordering status. This is a crucial change that affects the handling of these transactions in the subsequent logic.
298-328
: Conditional handling of unordered and ordered transactions.The code introduces a conditional flow based on the transaction's ordering status:
- For unordered transactions, the sequence validation is bypassed entirely.
- For ordered transactions, the existing sequence validation logic is followed, checking the sequence against previously seen signers.
This change simplifies the processing of unordered transactions by avoiding unnecessary sequence checks, while maintaining the existing validation for ordered transactions.
346-360
: Selective sequence update for ordered transactions.The code now updates the sender's sequence only for ordered transactions. This change ensures that unordered transactions do not affect the sequence tracking, maintaining consistency in the processing logic.
Additionally, the code checks if a new transaction has been added to the selected transactions before updating the sequence. This helps prevent unnecessary updates and maintains the integrity of the sequence tracking.
Line range hint
295-360
: Conformity with Uber Golang style guide.The changed code segments follow the Uber Golang style guide in terms of naming conventions, formatting, and code structure. No deviations from the style guide were observed.
simapp/app.go (3)
601-601
: LGTM!The code changes are approved.
703-709
: LGTM!The code changes are approved.
601-601
: Skipped duplicate code segment.This code segment is a duplicate and has already been reviewed.
UPGRADING.md (6)
Line range hint
1-4
: Section "Upgrading Cosmos SDK" looks good.The section provides a clear introduction to the purpose of the upgrade guide.
Tools
LanguageTool
[uncategorized] ~298-~298: Possible missing article found.
Context: ...sures the manager's state is written to file such that when the node restarts, it ...(AI_HYDRA_LEO_MISSING_A)
Line range hint
6-296
: Section "[Unreleased]" is well-structured with detailed instructions.The section provides upgrade instructions for an unreleased version of the Cosmos SDK. It is well-organized with clear subsections covering various components like BaseApp, Protobuf, Modules, etc. The instructions seem to be detailed and cover different aspects of the upgrade process.
Tools
LanguageTool
[uncategorized] ~298-~298: Possible missing article found.
Context: ...sures the manager's state is written to file such that when the node restarts, it ...(AI_HYDRA_LEO_MISSING_A)
Line range hint
298-510
: Section "[v0.47.x]" provides comprehensive upgrade instructions.The section offers detailed upgrade instructions for version v0.47.x of the Cosmos SDK. It covers important topics such as migration to CometBFT, simulation, gRPC, AppModule interface changes, and updates to various modules. The instructions provide clear guidance on the necessary modifications for a successful upgrade.
Tools
LanguageTool
[uncategorized] ~298-~298: Possible missing article found.
Context: ...sures the manager's state is written to file such that when the node restarts, it ...(AI_HYDRA_LEO_MISSING_A)
Line range hint
512-729
: Section "[v0.46.x]" provides detailed and well-organized upgrade instructions.The section offers comprehensive upgrade instructions for version v0.46.x of the Cosmos SDK. It covers a wide range of topics, including Go API changes, introduction of new packages, keyring refactoring, IAVL upgrade, and module-specific changes. The instructions are well-structured and provide clear guidance for developers to successfully upgrade to v0.46.x.
Tools
LanguageTool
[uncategorized] ~298-~298: Possible missing article found.
Context: ...sures the manager's state is written to file such that when the node restarts, it ...(AI_HYDRA_LEO_MISSING_A)
Line range hint
731-769
: Section "Protobuf" provides clear instructions on changes.The section offers clear guidance on the changes related to protobuf in the Cosmos SDK. It informs developers about the removal of the
third_party/proto
folder and the adoption ofbuf
for managing proto files. Additionally, it provides instructions on how to extend Cosmos message protobufs withcosmos.msg.v1.signer
. The section is well-written and helps developers understand and adapt to the protobuf changes in the SDK.Tools
LanguageTool
[uncategorized] ~298-~298: Possible missing article found.
Context: ...sures the manager's state is written to file such that when the node restarts, it ...(AI_HYDRA_LEO_MISSING_A)
Line range hint
1-772
: Overall assessment: Comprehensive and well-structured upgrade guide.The UPGRADING.md file provides comprehensive upgrade instructions for different versions of the Cosmos SDK. The instructions are well-structured, detailed, and cover various aspects of the upgrade process, including changes to BaseApp, Protobuf, modules, and more. The file is generally well-written and easy to follow, making it a valuable resource for developers upgrading their Cosmos SDK-based projects. With a few minor improvements, such as removing the empty code block at the end, this file effectively serves its purpose as a clear and comprehensive upgrade guide.
Tools
LanguageTool
[uncategorized] ~298-~298: Possible missing article found.
Context: ...sures the manager's state is written to file such that when the node restarts, it ...(AI_HYDRA_LEO_MISSING_A)
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.
I have only reviewed the app di wiring and I think you've missed that this was moved to runtime for making the app wiring simpler
simapp/app_di.go
Outdated
@@ -268,6 +272,16 @@ func NewSimApp( | |||
// return app.App.InitChainer(ctx, req) | |||
// }) | |||
|
|||
// create, start, and load the unordered tx manager |
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.
This should be deleted, runtime has it.
simapp/app_di.go
Outdated
app.UnorderedTxManager.OnNewBlock(ctx.BlockTime()) | ||
} | ||
|
||
// Close implements the Application interface and closes all necessary application |
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.
Ditto, should be deleted, runtime abstracts it
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.
ah, didn't realize it was there already
simapp/app_di.go
Outdated
@@ -312,6 +326,23 @@ func (app *SimApp) setCustomAnteHandler() { | |||
app.SetAnteHandler(anteHandler) | |||
} | |||
|
|||
func (app *SimApp) Precommiter(ctx sdk.Context) { |
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.
Can we have runtime have this?
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.
EDIT: thinking about it, I don't think we should use this.
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: 2
Outside diff range, codebase verification and nitpick comments (2)
runtime/app.go (1)
176-178
: Methods are implemented, butBlockTime
is deprecated.The
OnNewBlock
method forUnorderedTxManager
is correctly implemented, ensuring that the code changes inruntime/app.go
are valid. However, theBlockTime
method in theContext
type is marked as deprecated. It is advisable to consider using an alternative method if available to avoid potential issues with deprecated functionality.
OnNewBlock
is defined indocs/architecture/adr-070-unordered-transactions.md
.BlockTime
is defined intypes/context.go
and is deprecated.Analysis chain
Conditional check and method call in
PreBlocker
are appropriate.The addition of a conditional check for
UnorderedTxManager
being non-null and the subsequent call toOnNewBlock
aligns with the PR's objectives to enhance transaction management for unordered transactions. This change is crucial for managing transactions that are processed in an unordered manner and helps ensure robustness in transaction processing.However, it's important to verify that the
OnNewBlock
method is properly implemented and thatctx.BlockTime()
is a valid and error-free method call. Additionally, ensure that there are no potential null pointer exceptions or race conditions introduced with this change.Run the following script to verify the method
OnNewBlock
andctx.BlockTime()
:Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the method `OnNewBlock` and `ctx.BlockTime()`. # Test: Search for the method `OnNewBlock` and `ctx.BlockTime()`. Expect: Proper definitions and no errors. ast-grep --lang go --pattern $'func (UnorderedTxManager) OnNewBlock($_) { $$$ }' ast-grep --lang go --pattern $'func (Context) BlockTime() $_ { $$$ }'Length of output: 152
Script:
#!/bin/bash # Search for the definition of the UnorderedTxManager type and its methods ast-grep --lang go --pattern $'type UnorderedTxManager struct { $$$ }' rg 'func \(.*UnorderedTxManager.*\) OnNewBlock' -A 5 # Search for the definition of the Context type and its methods ast-grep --lang go --pattern $'type Context struct { $$$ }' rg 'func \(.*Context.*\) BlockTime' -A 5Length of output: 7077
UPGRADING.md (1)
Line range hint
1-287
: Documentation Review: Clarity and CompletenessThe documentation provides a detailed guide on upgrading the Cosmos SDK, which is essential for developers to adapt their applications to the latest changes. It covers new features, deprecated features, and breaking changes comprehensively.
However, to enhance clarity and ensure developers fully understand the implications of these changes, consider the following improvements:
- Provide examples for complex upgrades or migrations, especially when introducing new concepts or significant changes to existing functionalities.
- Include a section on common pitfalls or issues that developers might encounter during the upgrade process and suggest possible solutions.
Enhancing the documentation with practical examples and troubleshooting tips would make it more actionable and user-friendly, reducing the potential for errors during the upgrade process.
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- UPGRADING.md (1 hunks)
- runtime/app.go (1 hunks)
- x/auth/ante/unordered_test.go (2 hunks)
Additional context used
Path-based instructions (3)
x/auth/ante/unordered_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"runtime/app.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.UPGRADING.md (1)
Pattern
**/*.md
: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"
GitHub Check: tests (02)
x/auth/ante/unordered_test.go
[failure] 11-11:
cannot find module providing package cosmossdk.io/x/auth/ante: import lookup disabled by -mod=readonly
Additional comments not posted (2)
x/auth/ante/unordered_test.go (2)
144-144
: Approved function signature change.The change from
*testing.T
totesting.TB
in the function signature ofgenUnorderedTx
enhances flexibility by allowing it to be used with both testing types. This is a positive change for test maintainability and usability.
20-20
: Test functions are well-implemented.The test functions in this file are well-structured and provide comprehensive coverage for the scenarios involving unordered transactions. The use of the
require
package for assertions is appropriate and follows best practices in Go testing.Also applies to: 30-30, 40-40, 50-50, 60-60, 70-70
x/auth/ante/unordered_test.go
Outdated
"cosmossdk.io/x/auth/ante" | ||
"cosmossdk.io/x/auth/ante/unorderedtx" |
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.
Resolve import path issue.
The static analysis tool reports an issue with the import path cosmossdk.io/x/auth/ante
, indicating that the module providing this package cannot be found. This could be due to a misconfiguration in the module setup or an incorrect import path. Please verify the module configuration and ensure that the import path is correct.
Tools
GitHub Check: tests (02)
[failure] 11-11:
cannot find module providing package cosmossdk.io/x/auth/ante: import lookup disabled by -mod=readonly
func (app *SimApp) PreBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) { | ||
app.UnorderedTxManager.OnNewBlock(ctx.BlockTime()) | ||
return app.ModuleManager.PreBlock(ctx, req) | ||
} |
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.
Review: Integration of Unordered Transaction Manager in PreBlocker()
The integration of the unordered transaction manager within the PreBlocker()
method is crucial for handling unordered transactions effectively. The method now calls OnNewBlock()
on the unordered transaction manager, which is a significant change to ensure that the manager is notified upon each new block. This allows the manager to process transactions that do not require a specific order.
However, the documentation should clarify what specific errors might trigger the panic and under what conditions. This would help developers understand the potential risks and how to mitigate them.
Consider adding more detailed error handling documentation to clarify under what conditions the panic is triggered and how to handle these errors gracefully.
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (1)
- simapp/app.go (1 hunks)
Additional context used
Path-based instructions (1)
simapp/app.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (1)
simapp/app.go (1)
689-689
: Review of the new line inPreBlocker
method.The addition of
app.UnorderedTxManager.OnNewBlock(ctx.BlockTime())
in thePreBlocker
method is a critical update. This line ensures that the unordered transaction manager is updated with the current block time, which is essential for managing transactions that are not ordered. This change aligns with the PR's objective to enhance transaction management, particularly for unordered transactions.The integration of this line appears to be correctly placed within the
PreBlocker
method, ensuring that the transaction manager's state is updated before any other pre-block processing occurs. This is crucial for maintaining the integrity and order of transactions within the block.Code Quality and Best Practices:
- The code change is minimal and directly addresses the issue highlighted by the audit, making it an efficient solution.
- The use of
ctx.BlockTime()
to fetch the current block time is appropriate and ensures that the transaction manager has the most accurate and up-to-date information.Potential Improvements:
- While the current change is sufficient for the immediate needs, future enhancements could include error handling around the
OnNewBlock
method to manage any exceptions that might occur during the block time update process.Conclusion:
- The change is well-integrated and crucial for the functionality it aims to improve. It adheres to the best practices of minimal and direct code modifications to address specific issues.
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.
utACK!
Looks like this one is still failing: https://github.com/cosmos/cosmos-sdk/actions/runs/10793278686/job/29934994553?pr=21467 |
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 (1)
x/auth/ante/unorderedtx/snapshotter_test.go (1)
42-55
: LGTM! The changes enhance the clarity and functionality of the test.The updated comments provide a clear explanation of the expected behavior when restoring with a timestamp greater than the timeout. The use of a specific timestamp value in the
RestoreExtension
test simplifies the test and ensures consistent behavior across test runs.The size verification after the restoration ensures that the expected number of transactions is being handled correctly. The sequence of operations that starts the transaction manager, waits for the background purge loop to execute, and checks the size of the transaction manager after a delay verifies that the transactions are being purged as expected.
Suggestions for further improvement:
Consider adding a test case that specifically verifies the behavior when restoring with a timestamp less than the timeout. This would complement the existing test case and provide more comprehensive coverage of the restoration functionality.
To improve the readability of the test, consider extracting the sequence of operations related to starting the transaction manager and waiting for the background purge loop into a separate helper function. This would make the main test function more concise and easier to understand.
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (2)
- x/auth/ante/unorderedtx/manager.go (5 hunks)
- x/auth/ante/unorderedtx/snapshotter_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- x/auth/ante/unorderedtx/manager.go
Additional context used
Path-based instructions (1)
x/auth/ante/unorderedtx/snapshotter_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
(cherry picked from commit e9eaefa)
Description
This PR aims to fix some concerns raised by an external auditor.
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
Precommiter
method to enhance transaction management.Close
method to ensure proper shutdown of application resources.PreBlocker
method to notify the unordered transaction manager of new blocks.Bug Fixes
Documentation