-
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(sims): Add sims2 framework and factory methods #21613
Conversation
WalkthroughWalkthroughThis pull request introduces significant updates to the API, including the addition of a new method Changes
Possibly related issues
Possibly related PRs
Suggested labels
Recent review detailsConfiguration used: .coderabbit.yml Files selected for processing (2)
Additional context usedPath-based instructions (2)
Additional comments not posted (2)
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
|
64821b2
to
c220ca1
Compare
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.
nice job, love we got this cleanup
(cherry picked from commit b75bab14bb9bf529529d49bd78622e0e046171e5)
* main: test: fix sims (#21735) build: bump proto-builder (#21730) refactor(schema)!: rename IntegerStringKind and DecimalStringKind (#21694) feat(types/collections): add `LegacyDec` collection value (#21693) refactor(server): alias AppOptions to coreserver.DynamicConfig (#21711) refactor(simapp): simplify simapp di (#21718) feat: replace the cosmos-db usecases in the tests with `core/testing` (#21525) feat(runtime/v2): store loader on simappv2 (#21704) docs(x/auth): vesting (#21715) build(deps): Bump google.golang.org/grpc from 1.66.1 to 1.66.2 (#21670) refactor(systemtest): Add cli.RunAndWait for common operations (#21689) fix(runtime/v2): provide default factory options if unset in app builder (#21690) chore: remove duplicate proto files for the same proto file (#21648) feat(x/genutil): add better error messages for genesis validation (#21701) build(deps): Bump cosmossdk.io/core from 1.0.0-alpha.1 to 1.0.0-alpha.2 (#21698) test: migrate e2e/bank to system tests (#21607) chore: fix the gci lint issue in testutil (#21695) docs(x/authz): update grant docs (#21677)
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)
simsx/delivery.go (1)
28-98
: Excellent implementation of the simulation delivery mechanism!The
DeliverSimsMsg
function is well-structured and documented, making it easy to understand its purpose and behavior. The error handling and reporting flow is robust, ensuring that failures are logged with relevant details.A few suggestions for improvement:
- Consider adding a comment explaining the purpose of the
Collect
function used on line 81, as it may not be immediately clear to readers.- The error variable on line 88 is named
err2
, which could be more descriptive. Consider renaming it to something likehandlerErr
orresultHandlerErr
.- The comment generation on lines 89-92 could be extracted into a separate function for better readability and reusability.
Overall, the function is well-implemented and follows good practices for error handling and reporting.
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (1)
x/params/go.sum
is excluded by!**/*.sum
Files selected for processing (10)
- CHANGELOG.md (1 hunks)
- go.mod (1 hunks)
- simsx/delivery.go (1 hunks)
- simsx/runner.go (1 hunks)
- tests/go.mod (1 hunks)
- testutil/sims/simulation_helpers.go (1 hunks)
- x/gov/go.mod (1 hunks)
- x/params/go.mod (0 hunks)
- x/protocolpool/go.mod (1 hunks)
- x/staking/go.mod (1 hunks)
Files not reviewed due to no reviewable changes (1)
- x/params/go.mod
Files skipped from review due to trivial changes (2)
- tests/go.mod
- x/staking/go.mod
Files skipped from review as they are similar to previous changes (3)
- go.mod
- x/gov/go.mod
- x/protocolpool/go.mod
Additional context used
Path-based instructions (4)
simsx/delivery.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.testutil/sims/simulation_helpers.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simsx/runner.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.CHANGELOG.md (1)
Pattern
**/*.md
: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"
Markdownlint
CHANGELOG.md
57-57: null
Lists should be surrounded by blank lines(MD032, blanks-around-lists)
Additional comments not posted (13)
simsx/delivery.go (3)
1-15
: LGTM!The package declaration and imports are correctly organized and formatted. The package name
simsx
is acceptable for now, but open for renaming suggestions as per the PR objectives.
16-26
: LGTM!The type definitions are clear and serve their intended purposes:
AppEntrypoint
alias provides a convenient way to refer to the simulation entry point interface.AccountSource
interface encapsulates the retrieval of account information, which is necessary for generating mock transactions.SimDeliveryResultHandler
function type allows for flexible handling of delivery errors, as some simulations may expect certain errors.
45-45
: Past review comment addressed.The
DeliverSimsMsg
function now takes acontext.Context
parameter, resolving the suggestion from the previous review.testutil/sims/simulation_helpers.go (1)
53-56
: LGTM!The changes to the
PrintStats
function look good. The newlogLine
parameter allows for a more flexible logging approach, which is a nice improvement.Just make sure to update the callers of this function to provide a
logLine
function.simsx/runner.go (7)
53-59
: LGTM!The
SimStateFactory
struct is well-defined with clear field names and types. The addition ofAccountSource
andBalanceSource
fields enhances the functionality by providing sources for accounts and balances. The fields have appropriate documentation comments explaining their purpose.
70-89
: LGTM!The
Run
function provides a convenient way to run simulation tests with default settings. It leverages theRunWithSeeds
function to perform the actual simulation. The function signature and documentation comments are clear and informative.
91-125
: LGTM!The
RunWithSeeds
function provides a flexible way to run simulation tests with custom seeds and parameters. It sets up the environment and creates an instance of the simulation app for each seed. The parallel execution of tests for each seed improves performance. The function signature and documentation comments are clear and informative.
127-170
: LGTM!The
RunWithSeed
function provides a detailed implementation of running a simulation test for a single seed. It sets up the environment, creates an instance of the simulation app, and performs the simulation using theSimulateFromSeedX
function. The function checks the simulation results, prints stats, and performs post-run actions. The function signature and documentation comments are clear and informative.
172-203
: LGTM!The new interfaces (
HasWeightedOperationsX
,HasWeightedOperationsXWithProposals
,HasProposalMsgsX
) provide a more structured and extensible way to define weighted operations and proposal messages for simulations. The legacy interfaces (HasLegacyWeightedOperations
,HasLegacyProposalMsgs
,HasLegacyProposalContents
) are deprecated, indicating a transition to the new interface structure. The interface definitions are clear and well-documented.
205-220
: LGTM!The
TestInstance
struct provides a convenient way to encapsulate the necessary components for testing simulations. It includes fields for the app instance, database, working directory, configuration, logger, and execution log writer. The struct is well-documented, making it easy to understand its purpose and usage.
294-339
: LGTM!The
NewSimulationAppInstance
function provides a convenient way to initialize aTestInstance
for aSimulationApp
. It sets up the necessary components, such as the working directory, database, logger, and app options. The function handles the cleanup of the database on test completion. The function is well-documented, making it easy to understand its purpose and usage.CHANGELOG.md (2)
57-57
: The v0.50.x changes section looks good!The content in this section follows the Keep A Changelog format consistently, with clear subsections for each category of change.
The markdownlint warnings about blank lines around lists can be safely ignored, as they are just minor formatting nits that don't impact the meaning or readability.
Nice work documenting the changes thoroughly and consistently!
Tools
Markdownlint
57-57: null
Lists should be surrounded by blank lines(MD032, blanks-around-lists)
Line range hint
1000-1002
: Good call linking to the previous changelog.For a project with a long history of releases, it makes sense to link to the previous changelog rather than copying all that content into this file. It keeps this changelog focused and readable.
No changes needed here!
Tools
Markdownlint
56-56: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines(MD022, blanks-around-headings)
57-57: null
Lists should be surrounded by blank lines(MD032, blanks-around-lists)
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 (2)
CHANGELOG.md (2)
59-59
: Consider adding a blank line before and after the list to improve readability.According to Markdown best practices, it's recommended to surround lists with blank lines to visually separate them from the surrounding text. This helps improve the readability of the document.
Tools
Markdownlint
59-59: null
Lists should be surrounded by blank lines(MD032, blanks-around-lists)
Line range hint
1-1
: The CHANGELOG looks comprehensive and well-structured overall. Good job!The categorization of changes into clear sections, references to relevant issues/PRs, and level of detail provided for each entry makes this an excellent changelog. It gives a good high-level overview of the major changes between SDK versions.
Just one minor nitpick around list formatting, otherwise looks great! Let me know if you would like me to submit a PR to fix the list formatting.
Tools
Markdownlint
58-58: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines(MD022, blanks-around-headings)
59-59: null
Lists should be surrounded by blank lines(MD032, blanks-around-lists)
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
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
CHANGELOG.md
59-59: null
Lists should be surrounded by blank lines(MD032, blanks-around-lists)
(cherry picked from commit bf77680) # Conflicts: # CHANGELOG.md # go.mod # simapp/sim_bench_test.go # testutil/sims/state_helpers.go # x/params/go.mod # x/staking/go.mod
Description
This PR introduces some new helper types to simplify message construction for simulations (sims). The focus is on better dev UX for new message factories.
Technically, they are adapters that build upon the existing sims framework.
This PR also included the refactoring for all
x</module>/simulation/operations
into the new factory structures.(Reviewer note at the end)
* Message factory
Simple functions as factories for dedicated sdk.Msgs. They have access to the context, reporter and test data environment. For example:
* Sims registry
A new helper to register message factories with a default weight value. They can be overwritten by a parameters file as before. The registry is passed to the AppModule type. For example:
* Reporter
The reporter is a flow control structure that can be used in message factories to skip execution at any point. The idea is similar to the testing.T Skip in Go stdlib. Internally, it converts skip, success and failure events to legacy sim messages.
The reporter also provides some capability to print an execution summary.
It is also used to interact with the test data environment to not have errors checked all the time.
Message factories may want to abort early via
* Test data environment
The test data environment provides simple access to accounts and other test data used in most message factories. It also encapsulates some app internals like bank keeper or address codec.
Note to the reviewers
Apologies for this big PR. 🙈 It created too much extra work to keep the smaller PRs updated with changes in main as they pile up.
Please note. the
gov
module is the most complex one compared to the others due to the proposal and legacy support.simsx
is not necessarily the best name. If somebody would come up with a better name, I would refactor this in a new PR. Naming is hardSummary by CodeRabbit
New Features
SelectBy
method in the API for enhanced thread-safe operations.sims2
framework with factory methods for simplified message creation.Bug Fixes
Refactor
Documentation
Tests