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(sims): Integration with app v2 #23013

Merged
merged 4 commits into from
Jan 9, 2025
Merged

feat(sims): Integration with app v2 #23013

merged 4 commits into from
Jan 9, 2025

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Dec 19, 2024

Description

Closes: #20469

Sims integration with App v2

Most run parameters are currently hard coded in the test runner.

make test-v2-sim

TODOs that are done in separate PRs

  • support CLI params
  • cleanup simsx package and find place for new sims runner
  • address or remove todos in code
  • support the previous scenarios from simulation.mk
  • ...

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

Based on the comprehensive summary of changes, here are the release notes:

Release Notes

  • New Features

    • Added integration with application version 2
    • Enhanced simulation framework for blockchain applications
    • Introduced new transaction simulation and validation capabilities
    • Expanded validator set management and history tracking
  • Improvements

    • Refined transaction processing logic
    • Updated dependency management
    • Improved modularity in transaction and simulation handling
    • Enhanced error handling and testing infrastructure
  • Simulation Enhancements

    • New simulation runner with advanced configuration options
    • Introduced weighted validator set management
    • Added future operations registry for block-time scheduling
    • Implemented more flexible transaction building and decoding
  • Database Support

    • Added in-memory database type for simulations
  • Deprecations

    • Marked certain genesis and account state helper functions as deprecated

These release notes provide a high-level overview of the significant changes introduced in this update, focusing on the end-user and developer-facing improvements.

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

📝 Walkthrough

Walkthrough

This pull request introduces significant enhancements to the Cosmos SDK's simulation framework, focusing on the integration with application version 2. The changes span multiple packages, including simapp, server, simsx, and others, to provide a more robust and flexible simulation environment. The modifications include new interfaces, methods for transaction simulation, validator set management, and improvements to the overall simulation infrastructure.

Changes

File Change Summary
CHANGELOG.md Added feature entry for "Integration with app v2"
runtime/v2/app.go Added GetApp() method to App type
scripts/build/simulations.mk Added test-v2-sim target and updated simulation testing configuration
server/v2/appmanager/appmanager.go Introduced TransactionFuzzer interface and DeliverSims method
simapp/v2/sim_runner.go Implemented comprehensive simulation framework with new types and functions
simsx/v2/* Added new packages for advanced simulation capabilities
store/v2/db/db.go Added DBTypeMemDB for in-memory database support

Sequence Diagram

sequenceDiagram
    participant SimApp as Simulation App
    participant AppManager as App Manager
    participant STF as State Transition Function
    participant SimMsgFactory as Simulation Message Factory
    participant Validator as Validator Set

    SimApp->>AppManager: DeliverSims(context, block)
    AppManager->>SimMsgFactory: Generate Transactions
    SimMsgFactory-->>AppManager: Return Transactions
    AppManager->>STF: Process Transactions
    STF->>Validator: Update Validator Set
    STF-->>AppManager: Return Block Response
    AppManager-->>SimApp: Simulation Complete
Loading

Possibly related PRs

Suggested Reviewers

  • alpe
  • julienrbrt
  • tac0turtle
  • kocubinski
  • facundomedica

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 19, 2024
@alpe alpe force-pushed the alex/sims2_v2_dev branch 2 times, most recently from 2877f68 to 4b8d17b Compare January 7, 2025 14:09
@alpe alpe changed the title WIP: feature (sims app v2): Integration with app v2 feature (sims): Integration with app v2 Jan 7, 2025
@alpe alpe force-pushed the alex/sims2_v2_dev branch from 0615dd9 to faae91e Compare January 7, 2025 15:39
scripts/build/simulations.mk Show resolved Hide resolved
@@ -0,0 +1,469 @@
package simapp
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going to refactor and move this into the simsx package in a new PR

server/v2/appmanager/appmanager.go Show resolved Hide resolved
simsCtx := context.WithValue(exCtx, key, hi.Time) //nolint: staticcheck // using string key to decouple
var results []server.TxResult
var i int32
for tx := range simsBuilder(simsCtx) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This calls the sims message factories that were setup in sims_runner.doMainLoop()

if err := isCtxCancelled(simsCtx); err != nil {
return nil, err
}
results = append(results, s.deliverTx(simsCtx, newState, tx, transaction.ExecModeFinalize, hi, i+1))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

and delivered like block TX

hi header.Info,
) ([]server.TxResult, error)

func (s STF[T]) deliverBlock(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

common code used by DeliverBlock and DeliverSims

@alpe alpe changed the title feature (sims): Integration with app v2 (sims): Integration with app v2 Jan 7, 2025
@alpe alpe marked this pull request as ready for review January 7, 2025 15:57
@julienrbrt julienrbrt changed the title (sims): Integration with app v2 feat(sims): Integration with app v2 Jan 7, 2025
runtime/v2/app.go Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to clean all the previous ones, they were commented out waiting for this.
We should indeed append -v2 so when have both in the backport.

Copy link
Member

Choose a reason for hiding this comment

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

We need as well to re-enable it on CI and call the right jobs for main and eventually both in the backport in 0.52 (.github/workflows/sims.yml)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will fix them when the CLI params are integrated (in a new PR)

Copy link
Member

Choose a reason for hiding this comment

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

Can we create a tracking PR for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

simapp/v2/go.mod Outdated Show resolved Hide resolved
x/auth/simulation/genesis.go Outdated Show resolved Hide resolved
simapp/v2/sim_runner.go Outdated Show resolved Hide resolved
simapp/v2/sim_runner.go Outdated Show resolved Hide resolved
scripts/build/simulations.mk Show resolved Hide resolved
server/v2/appmanager/appmanager.go Show resolved Hide resolved
server/v2/appmanager/stf.go Show resolved Hide resolved
server/v2/stf/sims_entry.go Outdated Show resolved Hide resolved
simsx/v2/msg_factory.go Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the C:x/auth label Jan 8, 2025
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: 2

🔭 Outside diff range comments (1)
simapp/v2/go.mod (1)

Line range hint 3-3: Invalid Go version specified

The Go version 1.23.4 is invalid. The latest stable version of Go is 1.22.0. Please update to a valid Go version.

-go 1.23.4
+go 1.22
🧹 Nitpick comments (4)
simsx/v2/txutils.go (3)

71-73: Use lowercase error messages

The error message "unexpected Tx type" should start with a lowercase letter according to Go conventions.

Apply this diff:

-    		return out, errors.New("unexpected Tx type")
+    		return out, errors.New("unexpected tx type")

175-177: Use lowercase error messages

The error message "unexpected Tx type" should start with a lowercase letter according to Go conventions.

Apply this diff:

-    		return out, errors.New("unexpected Tx type")
+    		return out, errors.New("unexpected tx type")

192-194: Use lowercase error messages

The error message "unexpected Tx type" should start with a lowercase letter according to Go conventions.

Apply this diff:

-    		return out, errors.New("unexpected Tx type")
+    		return out, errors.New("unexpected tx type")
server/v2/appmanager/appmanager.go (1)

205-225: Refactor common logic between DeliverBlock and DeliverSims methods

The DeliverBlock and DeliverSims methods share similar logic for retrieving the latest state and validating block height. Consider refactoring the common code into a helper function to reduce code duplication and improve maintainability.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between faae91e and 48b6069.

📒 Files selected for processing (8)
  • scripts/build/simulations.mk (1 hunks)
  • server/v2/appmanager/appmanager.go (4 hunks)
  • server/v2/stf/sims_entry.go (1 hunks)
  • simapp/v2/go.mod (1 hunks)
  • simapp/v2/sim_runner.go (1 hunks)
  • simsx/v2/msg_factory.go (1 hunks)
  • simsx/v2/txutils.go (1 hunks)
  • simsx/v2/valset.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • simsx/v2/msg_factory.go
  • scripts/build/simulations.mk
  • server/v2/stf/sims_entry.go
  • simsx/v2/valset.go
🧰 Additional context used
📓 Path-based instructions (3)
server/v2/appmanager/appmanager.go (1)

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

simsx/v2/txutils.go (1)

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

simapp/v2/sim_runner.go (1)

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

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (3)
simapp/v2/sim_runner.go (1)

65-69: Verify the block time constants for correctness

The constant maxTimePerBlock is set to 10_000 * time.Second, which equals approximately 2.78 hours. This seems unusually long for a block time. Please verify if this is intentional.

simapp/v2/go.mod (2)

53-56: LGTM: Dependencies align with app v2 integration

The new dependencies are appropriate for the PR's purpose and are properly versioned.


Line range hint 271-282: LGTM: Well-structured replace directives

The replace directives are well-organized and properly handle:

  • Security fixes
  • Local development paths
  • Server v2 integration requirements

simsx/v2/txutils.go Show resolved Hide resolved
server/v2/appmanager/appmanager.go Outdated Show resolved Hide resolved
@alpe
Copy link
Contributor Author

alpe commented Jan 8, 2025

Thanks for the feedback! I have applied the changes.

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

♻️ Duplicate comments (1)
simapp/v2/sim_runner.go (1)

145-147: 🛠️ Refactor suggestion

Consider consolidating AppManager and ModuleManager access

Since xapp.GetApp() provides access to the ModuleManager, you might not need both AppManager and ModuleManager in the TestInstance. Consider using one of the following approaches to simplify:

  • Access the ModuleManager through AppManager when needed.
  • Expose the AppManager interface directly if specific functionalities are required.

This can help reduce redundancy and improve maintainability.

🧹 Nitpick comments (5)
server/v2/appmanager/appmanager.go (1)

204-225: Clean and consistent implementation.

The DeliverSims implementation:

  • Follows the same pattern as DeliverBlock for consistency
  • Has comprehensive error handling
  • Properly delegates to the state transition function

However, consider adding a comment explaining the relationship between this method and DeliverBlock, as they share similar patterns.

-// DeliverSims same as DeliverBlock for sims only.
+// DeliverSims processes simulated transactions similar to DeliverBlock, but uses
+// a transaction generator (simsBuilder) instead of a predefined transaction list.
simapp/v2/sim_runner.go (4)

195-195: Assist with reading simulation parameters from disk

There's a TODO comment indicating that simulation parameters should be read from disk as before. I can help implement this functionality to restore the previous behavior.

Do you want me to generate the code to read the simulation parameters from disk or open a GitHub issue to track this task?


240-240: Help replace legacy test data functions

There's a TODO comment suggesting the replacement of legacy test data functions. I can assist in updating this part of the code to use the new testing utilities.

Do you want me to generate the updated code or open a GitHub issue to track this task?


345-348: Offer to implement CLI flags for simulation parameters

The code contains a TODO comment indicating that numBlocks and maxTXPerBlock should be read from the CLI. I can help implement this functionality to make the simulation parameters configurable via command-line flags.

Do you want me to generate the code to add CLI flags for these parameters or open a GitHub issue to track this task?


461-461: Assist with registering legacy and v1 message proposals

There's a TODO comment indicating the need to register legacy and v1 message proposals. I can help implement this functionality to ensure all proposal types are properly registered.

Do you want me to generate the code for registering these proposals or open a GitHub issue to track this task?

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48b6069 and 28caf29.

📒 Files selected for processing (2)
  • server/v2/appmanager/appmanager.go (4 hunks)
  • simapp/v2/sim_runner.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
server/v2/appmanager/appmanager.go (1)

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

simapp/v2/sim_runner.go (1)

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

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: tests (00)
  • GitHub Check: test-store-v2
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (4)
server/v2/appmanager/appmanager.go (3)

9-9: LGTM! Import addition is appropriate.

The "iter" package import is necessary for handling transaction sequences in the new simulation functionality.


20-20: Well-structured interface composition!

The embedding of TransactionFuzzer interface aligns with the previous review discussion and follows the Interface Segregation Principle.


61-70: Clear and well-documented interface definition.

The TransactionFuzzer interface is well-documented and follows Go conventions. The separation of simulation-specific functionality improves modularity.

simapp/v2/sim_runner.go (1)

1-492: Code conforms to Uber Go style and best practices

The implementation in sim_runner.go is well-structured, follows the Uber Golang style guide, and adheres to best practices. The code is clear, readable, and maintainable.

@aljo242
Copy link
Contributor

aljo242 commented Jan 8, 2025

@alpe lgtm - just looks like a formatting lint error

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

🧹 Nitpick comments (1)
CHANGELOG.md (1)

44-44: Add blank lines around lists for better readability

According to markdown best practices, lists should be surrounded by blank lines to improve readability and ensure proper rendering.

 ### Client Breaking Changes
+
 * [#11797](https://github.com/cosmos/cosmos-sdk/pull/11797) Remove all RegisterRESTRoutes (previously deprecated)
 * [#11089](https://github.com/cosmos/cosmos-sdk/pull/11089) interacting with the node through `grpc.Dial` requires clients to pass a codec refer to [doc](https://docs.cosmos.network/main/user/run-node/interact-node).
+
🧰 Tools
🪛 Markdownlint (0.37.0)

44-44: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28caf29 and ff43377.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
CHANGELOG.md (1)

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

🪛 Markdownlint (0.37.0)
CHANGELOG.md

44-44: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-x-staking
  • GitHub Check: test-x-nft
  • GitHub Check: test-x-gov
  • GitHub Check: test-store-v2
  • GitHub Check: test-store
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: test-integration
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: Analyze
  • GitHub Check: runtime-v2
  • GitHub Check: dependency-review
  • GitHub Check: golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (1)
CHANGELOG.md (1)

Line range hint 1-2000: Well-structured and comprehensive changelog

The changelog follows good practices with:

  • Clear version sections with dates
  • Categorized changes (Features, Improvements, Bug Fixes, etc.)
  • Linked PR references
  • Breaking changes clearly marked
  • Detailed descriptions of changes

This makes it easy for users to understand the evolution of the codebase.

🧰 Tools
🪛 Markdownlint (0.37.0)

43-43: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


44-44: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

@alpe alpe mentioned this pull request Jan 9, 2025
6 tasks
@alpe
Copy link
Contributor Author

alpe commented Jan 9, 2025

@aljo242 The file was not touched in this PR. I have triggered a re-run as I can not reproduce the linter issue on my box. Let's fix this in a new PR when it persists

Update:
The make lint-fix did the job. Opened a new PR #23266

@julienrbrt julienrbrt added this pull request to the merge queue Jan 9, 2025
Merged via the queue into main with commit cf721a6 Jan 9, 2025
80 of 82 checks passed
@julienrbrt julienrbrt deleted the alex/sims2_v2_dev branch January 9, 2025 08:26
mergify bot pushed a commit that referenced this pull request Jan 9, 2025
Co-authored-by: Alex | Interchain Labs <[email protected]>
(cherry picked from commit cf721a6)

# Conflicts:
#	CHANGELOG.md
#	runtime/v2/app.go
#	scripts/build/simulations.mk
#	server/v2/appmanager/appmanager.go
#	server/v2/appmanager/stf.go
#	server/v2/stf/stf.go
#	server/v2/streaming/examples/file/file.go
#	simapp/v2/go.mod
#	store/v2/db/db.go
julienrbrt added a commit that referenced this pull request Jan 9, 2025
Co-authored-by: Alexander Peters <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
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.

tests/sims support for runtime/v2