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

refactor(simapp,runtime): audit changes #21310

Merged
merged 9 commits into from
Aug 27, 2024
Merged

refactor(simapp,runtime): audit changes #21310

merged 9 commits into from
Aug 27, 2024

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Aug 15, 2024

Description

ref: #20955

  • Abstract unordered tx manager with runtime in app di
  • Abstract indexer wiring in app di with runtime
  • Small docs update
  • Update list of changes between simapp 0.50 wiring -> 0.52 wiring

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 support for unordered transactions, allowing execution in any order without nonce management.
    • Automatic enabling of unordered transactions with the runtime/depinject framework.
    • Enhanced application configuration flexibility with new application options.
    • Improved transaction processing capabilities with the integration of the UnorderedTxManager.
  • Bug Fixes

    • Improved resource management during application shutdown with enhanced error handling.
  • Documentation

    • Updated documentation for clearer guidance on transaction management and application options.

Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Walkthrough

Walkthrough

The changes introduce significant updates to the Cosmos SDK, particularly in transaction handling by supporting unordered transactions, enhancing application configuration flexibility, and refining resource management. Developers are required to adjust transaction submission logic and transition legacy applications to the new unordered transaction management system. Additionally, there are modifications to various struct fields and methods across multiple files, aimed at improving clarity and maintainability.

Changes

Files Change Summary
UPGRADING.md Clarified unordered transaction support, updated transaction submission requirements, and provided transition guidance for legacy applications.
runtime/app.go Added UnorderedTxManager, implemented Close, and introduced GetKey for testing.
simapp/app.go, simapp/ante.go Integrated UnorderedTxManager into setAnteHandler and updated Close for improved error handling.
x/auth/ante/ante.go, x/auth/tx/config/depinject.go Added UnorderedTxManager to HandlerOptions and ModuleInputs, updating ante handler configuration.
testutil/network/network.go Modified DefaultConfigWithAppConfig to include application options with a specified home flag.
simapp/app_config.go, simapp/v2/app_config.go Removed comments related to unused code linting for cleaner code.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AppBuilder
    participant UnorderedTxManager
    participant App

    Client->>AppBuilder: Submit transaction with unordered flag
    AppBuilder->>UnorderedTxManager: Register unordered transaction manager
    UnorderedTxManager->>App: Process transaction
    App->>Client: Return transaction result
Loading

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.

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.

@julienrbrt julienrbrt mentioned this pull request Aug 15, 2024
28 tasks
@hieuvubk hieuvubk mentioned this pull request Aug 15, 2024
12 tasks
@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Aug 16, 2024
@julienrbrt julienrbrt changed the title refactor(simapp): audit changes refactor(simapp,runtime): audit changes Aug 26, 2024
@julienrbrt julienrbrt marked this pull request as ready for review August 26, 2024 13:54
@julienrbrt julienrbrt requested a review from a team as a code owner August 26, 2024 13:54
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, codebase verification and nitpick comments (3)
UPGRADING.md (3)

122-124: Improve grammar for clarity.

The segment can be improved for better readability. Consider this revision:

- The Cosmos SDK now supports unordered transactions. This means that transactions
- can be executed in any order and doesn't require the client to deal with or manage
- nonces. This also means the order of execution is not guaranteed.
+ The Cosmos SDK now supports unordered transactions. This means that transactions
+ can be executed in any order and do not require the client to manage nonces.
+ Consequently, the order of execution is not guaranteed.

Line range hint 125-191: Improve grammar for clarity.

The segment can be improved for better readability. Consider this revision:

- If you are still using the legacy wiring, you must enable unordered transactions manually:
+ If you are still using legacy wiring, you must manually enable unordered transactions:

- * Update the `App` constructor to create, load, and save the unordered transaction
-   manager.
+ * Update the `App` constructor to create, load, and save the unordered transaction manager.

- * Add the decorator to the existing AnteHandler chain, which should be as early
-   as possible.
+ * Add the decorator to the existing AnteHandler chain as early as possible.

- * If the App has a SnapshotManager defined, you must also register the extension
-   for the TxManager.
+ * If the App has a SnapshotManager defined, you must also register the extension for the TxManager.

- * Create or update the App's `Close()` method to close the unordered tx manager.
-   Note, this is critical as it ensures the manager's state is written to file
-   such that when the node restarts, it can recover the state to provide replay
-   protection.
+ * Create or update the App's `Close()` method to close the unordered tx manager.
+   This is critical as it ensures the manager's state is written to a file,
+   allowing the node to recover the state and provide replay protection upon restart.

Line range hint 192-197: Improve grammar for clarity.

The segment can be improved for better readability. Consider this revision:

- To submit an unordered transaction, the client must set the `unordered` flag to
- `true` and ensure a reasonable `timeout_height` is set. The `timeout_height` is
- used as a TTL for the transaction and is used to provide replay protection. See
- [ADR-070](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-070-unordered-transactions.md)
- for more details.
+ To submit an unordered transaction, the client must set the `unordered` flag to `true`
+ and ensure a reasonable `timeout_height` is set. The `timeout_height` serves as a TTL
+ for the transaction and provides replay protection. See
+ [ADR-070](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-070-unordered-transactions.md)
+ for more details.
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 28c792b and 80b9ea9.

Files selected for processing (11)
  • UPGRADING.md (2 hunks)
  • runtime/app.go (4 hunks)
  • runtime/builder.go (3 hunks)
  • runtime/module.go (4 hunks)
  • runtime/v2/builder.go (1 hunks)
  • runtime/v2/module.go (1 hunks)
  • server/util.go (1 hunks)
  • simapp/app_config.go (1 hunks)
  • simapp/app_di.go (7 hunks)
  • simapp/simd/cmd/config.go (1 hunks)
  • simapp/v2/app_config.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • runtime/v2/module.go
  • server/util.go
  • simapp/app_config.go
  • simapp/v2/app_config.go
Additional context used
Path-based instructions (7)
runtime/builder.go (1)

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

simapp/simd/cmd/config.go (1)

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

runtime/v2/builder.go (1)

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

runtime/module.go (1)

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

runtime/app.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.

UPGRADING.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (16)
runtime/builder.go (5)

26-28: LGTM!

The addition of appOptions enhances the flexibility of the configuration options.

The code changes are approved.


53-63: LGTM!

The changes introduce new functionalities and control flows. The error handling is appropriate, and the logic is clear.

The code changes are approved.


73-85: LGTM!

The method correctly initializes and starts the unordered transaction manager. The error handling is appropriate.

The code changes are approved.


87-101: LGTM!

The method correctly handles the registration of the indexer and legacy streaming services based on the configuration options.

The code changes are approved.


103-112: LGTM!

The method correctly retrieves and filters key-value store keys.

The code changes are approved.

simapp/simd/cmd/config.go (1)

Line range hint 1-1: Verify the impact of the change.

The removal of the line disabling the fast node feature simplifies the initialization process but may impact performance or resource usage. Ensure this change aligns with the application's requirements.

runtime/v2/builder.go (1)

128-135: LGTM!

The refactoring improves readability and maintains the overall logic flow. The changes are appropriate.

The code changes are approved.

runtime/module.go (3)

149-149: LGTM!

The initialization of AppBuilder with the named app field improves clarity.

The code changes are approved.


164-164: LGTM!

The addition of the AppOptions field increases flexibility in client wiring.

The code changes are approved.


176-178: LGTM!

The check for AppOptions ensures that the application can utilize provided options if available.

The code changes are approved.

runtime/app.go (3)

46-46: LGTM!

The addition of the UnorderedTxManager field enhances the application's transaction handling capabilities.

The code changes are approved.


162-168: LGTM!

The Close function ensures proper resource management and stability during the shutdown process.

The code changes are approved.


275-285: LGTM!

The GetKey function provides a controlled way for developers to access store keys during testing.

The code changes are approved.

simapp/app_di.go (3)

44-44: LGTM!

The removal of the UnorderedTxManager field indicates a shift in how transactions are managed within the application.

The code changes are approved.


44-44: LGTM!

The removal of the Close function suggests that the application no longer requires this resource management.

The code changes are approved.


44-44: LGTM!

The removal of the GetKey function indicates a broader refactoring of how keys are handled within the application.

The code changes are approved.

runtime/builder.go Dismissed Show dismissed Hide dismissed
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: 1

Outside diff range, codebase verification and nitpick comments (4)
simapp/CHANGELOG.md (4)

35-35: Fix typographical error.

Replace "url" with "URL".

- * Update module path to new vanity url.
+ * Update module path to new vanity URL.

38-38: Fix grammatical issue.

Replace "make use of" with "use".

- * Update `export` function to make use of the new module collections API.
+ * Update `export` function to use the new module collections API.

41-41: Add missing period.

Add a period at the end of the sentence.

- * Update testnet command to match new module APIs
+ * Update testnet command to match new module APIs.

46-46: Fix grammatical issue.

Replace "make use of" with "use".

- * [#20490](https://github.com/cosmos/cosmos-sdk/pull/20490) Refactor simulations to make use of `testutil/sims` instead of `runsims`.
+ * [#20490](https://github.com/cosmos/cosmos-sdk/pull/20490) Refactor simulations to use `testutil/sims` instead of `runsims`.
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 80b9ea9 and 207ccae.

Files selected for processing (8)
  • runtime/app.go (5 hunks)
  • runtime/module.go (5 hunks)
  • simapp/CHANGELOG.md (1 hunks)
  • simapp/ante.go (2 hunks)
  • simapp/app.go (2 hunks)
  • simapp/app_di.go (8 hunks)
  • x/auth/ante/ante.go (3 hunks)
  • x/auth/tx/config/depinject.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • runtime/app.go
  • runtime/module.go
Additional context used
Path-based instructions (6)
simapp/ante.go (1)

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

x/auth/ante/ante.go (1)

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

simapp/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/auth/tx/config/depinject.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.

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 (12)
simapp/ante.go (3)

Line range hint 7-9: Ensure the import path is correct.

The import path for unorderedtx should be verified to ensure it is correct and points to the intended package.


Line range hint 27-27: Ensure the new field is initialized properly.

The new field UnorderedTxManager should be initialized properly when creating an instance of HandlerOptions.


41-41: Verify the new decorator usage.

Ensure that the NewUnorderedTxDecorator is correctly used and that the parameters passed to it are valid.

x/auth/ante/ante.go (3)

7-7: Ensure the import path is correct.

The import path for unorderedtx should be verified to ensure it is correct and points to the intended package.


27-27: Ensure the new field is initialized properly.

The new field UnorderedTxManager should be initialized properly when creating an instance of HandlerOptions.


58-60: Verify the new decorator usage.

Ensure that the NewUnorderedTxDecorator is correctly used and that the parameters passed to it are valid.

x/auth/tx/config/depinject.go (2)

62-62: LGTM!

The addition of the UnorderedTxManager field to the ModuleInputs struct is correctly implemented.

The code changes are approved.


167-173: LGTM!

The integration of the UnorderedTxManager into the ante.NewAnteHandler call is correctly implemented.

The code changes are approved.

simapp/app_di.go (2)

266-266: LGTM!

The removal of the UnorderedTxManager initialization and related functionalities is correctly implemented.

The code changes are approved.


296-302: LGTM!

The removal of the UnorderedTxManager field from the ante.HandlerOptions is correctly implemented.

The code changes are approved.

simapp/app.go (2)

641-641: LGTM!

The integration of the UnorderedTxManager into the ante.HandlerOptions is correctly implemented.

The code changes are approved.


668-671: LGTM!

The addition of error handling for the BaseApp.Close() call is correctly implemented.

The code changes are approved.

Comment on lines +273 to +275
if err := manager.RegisterExtensions(
unorderedtx.NewSnapshotter(app.UnorderedTxManager),
)
if err != nil {
); err != nil {
Copy link
Contributor

@coderabbitai coderabbitai bot Aug 26, 2024

Choose a reason for hiding this comment

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

Remove unused code.

The unorderedtx.NewSnapshotter(app.UnorderedTxManager) call is no longer necessary and should be removed.

Apply this diff to remove the unused code:

- if err := manager.RegisterExtensions(
- 	unorderedtx.NewSnapshotter(app.UnorderedTxManager),
- ); err != nil {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err := manager.RegisterExtensions(
unorderedtx.NewSnapshotter(app.UnorderedTxManager),
)
if err != nil {
); err != nil {

Copy link
Member Author

Choose a reason for hiding this comment

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

Not true, we haven't abstracted that in runtime

Copy link
Contributor

Choose a reason for hiding this comment

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

@julienrbrt, thank you for the clarification. I understand now that the unorderedtx.NewSnapshotter(app.UnorderedTxManager) call is still necessary since it hasn't been abstracted in the runtime. I'll retract my previous suggestion to remove it.


Learnings added
Learnt from: julienrbrt
PR: cosmos/cosmos-sdk#21310
File: simapp/app_di.go:273-275
Timestamp: 2024-08-26T21:27:49.027Z
Learning: When reviewing code related to `unorderedtx.NewSnapshotter(app.UnorderedTxManager)`, remember that it hasn't been abstracted in the runtime, so it should not be removed unless explicitly refactored.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

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.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 207ccae and 90f4aeb.

Files selected for processing (8)
  • UPGRADING.md (2 hunks)
  • runtime/app.go (5 hunks)
  • simapp/app.go (2 hunks)
  • simapp/app_config.go (1 hunks)
  • simapp/v2/app_config.go (1 hunks)
  • testutil/network/network.go (2 hunks)
  • x/auth/ante/ante.go (3 hunks)
  • x/auth/tx/config/depinject.go (3 hunks)
Files skipped from review due to trivial changes (1)
  • simapp/app_config.go
Files skipped from review as they are similar to previous changes (4)
  • simapp/app.go
  • simapp/v2/app_config.go
  • x/auth/ante/ante.go
  • x/auth/tx/config/depinject.go
Additional context used
Path-based instructions (3)
runtime/app.go (1)

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

testutil/network/network.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 (10)
runtime/app.go (3)

45-46: LGTM!

The addition of UnorderedTxManager in the App struct is appropriate for managing unordered transactions.

The code changes are approved.


160-172: LGTM!

The Close function correctly handles the closure of UnorderedTxManager and ensures proper resource management.

The code changes are approved.


277-287: LGTM!

The GetKey function is correctly implemented for retrieving the KVStoreKey for a specified store key, intended for testing purposes.

The code changes are approved.

testutil/network/network.go (1)

214-217: LGTM!

The addition of simtestutil.NewAppOptionsWithFlagHome(val.GetViper().GetString(flags.FlagHome)) in the depinject.Supply function call enhances the configuration capabilities.

The code changes are approved.

UPGRADING.md (6)

Line range hint 5-30: LGTM!

The section is well-written and provides clear instructions for simulating nested messages.

The documentation is clear and correct.


Line range hint 32-202: LGTM!

The section is comprehensive and provides detailed instructions for the changes in the SimApp package.

The documentation is clear and correct.


Line range hint 204-216: LGTM!

The section is well-written and provides clear instructions for the changes in Depinject app_config.go / app.yml.

The documentation is clear and correct.


Line range hint 218-246: LGTM!

The section is comprehensive and provides detailed instructions for the changes in the Protobuf package.

The documentation is clear and correct.


Line range hint 248-418: LGTM!

The section is comprehensive and provides detailed instructions for the changes in various modules.

The documentation is clear and correct.


Line range hint 420-624: LGTM!

The section is well-written and provides clear instructions for the changes in the tooling.

The documentation is clear and correct.

Copy link
Contributor

@hieuvubk hieuvubk left a comment

Choose a reason for hiding this comment

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

LGTM

if err := a.app.ModuleManager.RegisterServices(a.app.configurator); err != nil {
panic(err)
}

return a.app
}

// register unordered tx manager
func (a *AppBuilder) registerUnorderedTxManager() error {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@julienrbrt julienrbrt added this pull request to the merge queue Aug 27, 2024
Merged via the queue into main with commit 03d3a93 Aug 27, 2024
77 checks passed
@julienrbrt julienrbrt deleted the julien/simapp branch August 27, 2024 12:21
mergify bot pushed a commit that referenced this pull request Aug 27, 2024
(cherry picked from commit 03d3a93)

# Conflicts:
#	runtime/v2/builder.go
#	runtime/v2/module.go
julienrbrt added a commit that referenced this pull request Aug 27, 2024
Co-authored-by: Julien Robert <julien@rbrt.fr>
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:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants