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

fix(sims): TestAppSimulationAfterImport and legacy proposal handling #21800

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Sep 18, 2024

Description

The make test-sim-after-import run was failing after sims2 were merged. This PR includes a fix that takes the startup height into account and ensures that the bech32 addresses for the test accounts are set. For this the accounts from the initial run are forwarded instead of parsing genesis with new (non matching) private keys.

includes #21784

Please note the changes to the x/simulation package that are api breaking. This does not affect module code and should be covered by the original changelog


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

  • Bug Fixes

    • Improved error handling in simulation functions to prevent abrupt test failures and ensure data integrity.
  • New Features

    • Enhanced simulation initialization with the option to set an initial block height.
    • Added account data return in simulation functions for better context and error reporting.
  • Refactor

    • Streamlined function signatures and internal logic for clarity and performance, particularly in message factory handling.
    • Restructured message factory management to improve functionality and clarity.
  • Tests

    • Expanded test coverage for unique type registries and weighted factory methods, ensuring robust validation of logic.
    • Introduced new tests for weighted factory methods and iterator functionalities.

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

Walkthrough

The pull request encompasses a series of changes across multiple files, primarily focusing on the removal of a specific test target related to v2 simulation tests, modifications to function signatures to include account parameters, enhancements to error handling, and restructuring of message factory management. The changes aim to improve clarity, robustness, and functionality within the simulation framework and related testing processes.

Changes

File Path Change Summary
scripts/build/simulations.mk Removed the test-v2-sim-wip target, indicating a shift away from v2 simulation tests.
simapp/sim_test.go Modified test function signatures to include accounts parameter for better account management.
simsx/environment.go Added a validation check in NewChainDataSource to ensure valid account addresses.
simsx/registry.go Restructured message factory handling, introducing new types and methods for weighted factories.
simsx/registry_test.go Updated tests to reflect changes in factory methods and added new tests for weighted factories.
simsx/reporter.go Enhanced the String() method of ExecutionSummary to include skip reasons in the output.
simsx/runner.go Updated function signatures to pass account information to post-run actions and refined proposal handling.
x/gov/simulation/msg_factory.go Changed payloadFactory parameter type to simplify invocation in MsgSubmitProposalFactory.
x/simulation/mock_cometbft.go Improved error handling in updateValidators and refined logic in RandomRequestFinalizeBlock.
x/simulation/simulate.go Modified initChain and SimulateFromSeed functions to include initial height and account return values.

Possibly related PRs

Suggested labels

C:x/genutil, C:x/auth

Suggested reviewers

  • kocubinski
  • sontrinh16
  • testinginprod
  • julienrbrt
  • facundomedica

Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c70a08c and df2d7fb.

Files selected for processing (1)
  • simsx/msg_factory.go (1 hunks)
Additional context used
Path-based instructions (1)
simsx/msg_factory.go (1)

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

Additional comments not posted (2)
simsx/msg_factory.go (2)

9-25: Excellent documentation improvements!

The added comments for the SimMsgFactoryX interface methods provide clear explanations of their purpose and functionality. This enhances the clarity and usability of the interface for developers working with simulation messages.


28-43: Great job documenting the FactoryMethod function signature!

The added comments thoroughly explain the purpose, parameters, and return values of the factory method. This level of detail will greatly assist developers in understanding and implementing concrete message factories for SimMsgFactoryX.


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 generate interesting stats about this repository and render them as a table.
    -- @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 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.

@alpe alpe changed the title Fix: TestAppSimulationAfterImport and legacy proposal handling fix(sims): TestAppSimulationAfterImport and legacy proposal handling Sep 18, 2024
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 and nitpick comments (1)
simapp/sim_test.go (1)

198-198: Remove the unused parameter from the function signature.

The _ []simtypes.Account parameter has been added to the function signature but is not being used within the function. Consider removing it to keep the function signature clean.

Apply this diff to remove the unused parameter:

-func captureAndCheckHash(t testing.TB, ti simsx.TestInstance[*SimApp], _ []simtypes.Account) {
+func captureAndCheckHash(t testing.TB, ti simsx.TestInstance[*SimApp]) {
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0c8ad9d and c70a08c.

Files selected for processing (10)
  • scripts/build/simulations.mk (0 hunks)
  • simapp/sim_test.go (3 hunks)
  • simsx/environment.go (1 hunks)
  • simsx/registry.go (5 hunks)
  • simsx/registry_test.go (2 hunks)
  • simsx/reporter.go (1 hunks)
  • simsx/runner.go (8 hunks)
  • x/gov/simulation/msg_factory.go (1 hunks)
  • x/simulation/mock_cometbft.go (2 hunks)
  • x/simulation/simulate.go (10 hunks)
Files not reviewed due to no reviewable changes (1)
  • scripts/build/simulations.mk
Additional context used
Path-based instructions (9)
x/simulation/mock_cometbft.go (1)

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

simsx/reporter.go (1)

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

simsx/registry_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"

simsx/registry.go (1)

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

simapp/sim_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"

x/gov/simulation/msg_factory.go (1)

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

simsx/environment.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.

x/simulation/simulate.go (1)

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

Additional comments not posted (30)
x/simulation/mock_cometbft.go (2)

95-96: LGTM!

The change from a fatal error to a log message when attempting to delete a non-existent validator enhances the robustness of the function by preventing abrupt test failures due to non-critical issues. This improves the error handling and contributes to a more stable behavior in the simulation.


190-200: LGTM!

The change in the logic for selecting a misbehavior time and corresponding validator improves the reliability of the function by ensuring that it operates within the bounds of available data. By calculating the starting height based on the total number of blocks processed, the selection of past times and vote information is always valid. This change contributes to a more predictable behavior in the simulation.

simsx/reporter.go (1)

243-245: LGTM!

The conditional check and the appending of the "Skip reasons:" header improve the clarity of the output by providing additional context when there are skip reasons present. The code segment is logically correct and follows the Uber Golang style guide.

simsx/registry_test.go (6)

119-122: LGTM!

The change from f1 to exampleFactory using SimMsgFactoryFn is consistent with the rest of the test cases and reflects a more structured approach.


125-130: Test cases look good!

The updated expected output in the test cases reflects the changes in the factory function and covers both unique and duplicate factory scenarios.


158-173: New test function looks good!

The TestWeightedFactories function tests the addition of weighted factory methods and verifies the correct number of entries and their weights.


175-196: New test function looks good!

The TestAppendIterators function checks the functionality of appending iterators from two different registries and verifies that the combined output meets the expected criteria.


198-204: New helper function looks good!

The readAll function streamlines the process of reading from iterators by collecting the weight and factory method pairs into a slice of WeightedFactoryMethod instances.


Line range hint 1-204: Conforms to the Uber Golang style guide!

The file follows the Uber Golang style guide conventions for naming, formatting, and code organization. The package name, imports, function and variable names, structs, interfaces, and comments adhere to the recommended guidelines.

simsx/registry.go (7)

Line range hint 4-12: Imports look good!

The imported packages seem to be valid and necessary for the code in this file.


40-40: The type alias is defined correctly.

The WeightedProposalMsgIter type alias is defined clearly using iter.Seq2[uint32, FactoryMethod]. The name is descriptive and follows the Go naming convention.


Line range hint 112-131: The legacyOperationAdapter function looks good!

The function correctly adapts a SimMsgFactoryX to a simtypes.Operation. It sets up the necessary dependencies, runs the factory method safely, and handles the delivery result appropriately. The error handling and reporting look good. The function is well-structured and readable.


Line range hint 172-186: The Iterator method is implemented correctly.

The method returns a WeightedProposalMsgIter that yields FactoryMethod instances. It correctly sorts the WeightedFactory instances by weight in descending order. The returned iterator function behaves as expected. The method is well-structured and readable.


209-247: The WeightedFactoryMethod and WeightedFactoryMethods types and methods are implemented correctly.

The struct and type definitions are clear and follow Go conventions. The constructor and methods have correct signatures and return types. The Add method correctly appends a new WeightedFactoryMethod and handles nil and zero weight cases. The Iterator method correctly sorts the instances by weight and returns an iterator that yields FactoryMethod instances. The code is well-structured and readable.


249-259: The legacyToMsgFactoryAdapter function looks good!

The function correctly adapts a simtypes.MsgSimulatorFnX to a FactoryMethod. The returned closure calls the simtypes.MsgSimulatorFnX with the provided arguments and returns the generated message. The error handling and reporting look appropriate. The function is well-structured and readable.


261-268: The AppendIterators function is implemented correctly.

The function takes multiple WeightedProposalMsgIter and returns a single iterator that sequentially yields items from each provided iterator. The function is well-structured and readable.

simapp/sim_test.go (4)

119-144: LGTM!

The changes introduce a new way of initializing the application state using the exported genesis state. The accs parameter is being used to ensure consistency in the application state during simulation. The changes improve the clarity of the simulation process by explicitly managing the accounts used during the initialization of the application state.


151-151: LGTM!

Setting the InitialBlockHeight to the exported genesis height ensures that the simulation starts from the correct block height.


Line range hint 198-222: LGTM!

The changes ensure determinism by comparing the app hashes from multiple iterations of the same seed. Printing the execution logs and failing the test when the app hashes are not equal helps in identifying non-determinism.


128-144: LGTM!

Initializing the chain using the exported genesis state ensures that the simulation starts from the correct state. Skipping the test if the validator set is empty after initializing the genesis state prevents the simulation from running with an invalid state. Using the accs parameter to initialize the application state ensures consistency during simulation.

x/gov/simulation/msg_factory.go (1)

118-120: LGTM!

The change simplifies the invocation of the payloadFactory by removing the need for an additional Create() method call. This streamlines the function's logic, enhancing clarity and potentially improving performance by reducing the method call overhead. The overall functionality remains focused on creating a simulation message factory for submitting proposals, but the internal handling of the payloadFactory has been made more straightforward.

simsx/environment.go (1)

272-274: LGTM!

The added validation check enhances the robustness of the code by ensuring that all accounts processed have valid addresses. This proactive error handling prevents potential runtime errors or undefined behavior later in the execution flow.

simsx/runner.go (5)

84-84: LGTM!

The change to include accs []simtypes.Account in the postRunActions variadic function parameter is a good addition. It allows passing the accounts data to the post-run actions for further analysis and assertions.


112-112: Looks good!

The change to include accs []simtypes.Account in the postRunActions variadic function parameter is consistent with the change made in the Run function. It allows passing the accounts data to the post-run actions for further analysis and assertions.


139-139: Looks good to me!

The change to include accs []simtypes.Account in the postRunActions variadic function parameter is consistent with the changes made in the Run and RunWithSeeds functions. It allows passing the accounts data to the post-run actions for further analysis and assertions.


Line range hint 156-166: Looks good!

The change to pass the accs slice returned from SimulateFromSeedX to the postRunActions functions is consistent with the changes made in the function signatures. It allows the post-run actions to access the accounts data for further analysis and assertions.


Line range hint 176-281: The changes look good!

The introduction of the WeightedProposalMsgIter parameter in the HasWeightedOperationsXWithProposals interface and the corresponding updates in the prepareWeightedOps function provide a more flexible way of handling proposals. The changes maintain backward compatibility by handling both the new WeightedProposalMsgIter parameter and the legacy proposal handling code using the legacyPReg variable and the AppendIterators function.

The changes do not introduce any apparent issues and improve the overall proposal handling mechanism.

x/simulation/simulate.go (3)

51-51: LGTM!

The addition of the InitialHeight field to the abci.InitChainRequest based on the config.InitialBlockHeight is a good change. It allows the chain to be initialized at a specific block height, providing more flexibility in the simulation setup.


Line range hint 64-76: LGTM!

The modification to the return signature of SimulateFromSeed to include accs []simtypes.Account is a good change. It allows the accounts generated during the simulation to be propagated to the caller for further analysis or testing.


Line range hint 96-282: LGTM!

The modifications to SimulateFromSeedX are good changes that improve the robustness of the simulation:

  1. The return signature has been updated to include accs []simtypes.Account, which allows the accounts generated during the simulation to be propagated to the caller for further analysis or testing.

  2. The error handling has been refined to return the accounts alongside the parameters in various error scenarios (lines 123, 191, 203, 250). This ensures that the state of the accounts is preserved even when an error occurs, aiding in debugging and understanding the simulation's state at the time of failure.

The changes are straightforward and enhance the functionality and error reporting of the simulation.

@@ -74,7 +74,7 @@ var (
)

func TestAppImportExport(t *testing.T) {
simsx.Run(t, NewSimApp, setupStateFactory, func(t testing.TB, ti simsx.TestInstance[*SimApp]) {
simsx.Run(t, NewSimApp, setupStateFactory, func(t testing.TB, ti simsx.TestInstance[*SimApp], _ []simtypes.Account) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the accs parameter to initialize the application state.

The accs parameter has been added to the function signature but is not being used within the function. Consider using it to initialize the application state to ensure consistency during simulation.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Sep 18, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

heavy to digest, but lgtm!

x := maps.Values(s)
sortedWeightedFactory := slices.SortedFunc(x, func(a, b WeightedFactory) int {
return a.Compare(b)
})

return func(yield func(uint32, SimMsgFactoryX) bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated, but can we add godocs to SimMsgFactoryX

* main:
  refactor(mempool)!: match server/v2/cometbft and sdk mempool interface (#21744)
  feat: make validator key injectable by application developers (#21608)
@alpe alpe enabled auto-merge September 18, 2024 14:37
@alpe alpe disabled auto-merge September 18, 2024 14:47
@alpe alpe enabled auto-merge September 18, 2024 14:59
@alpe alpe added this pull request to the merge queue Sep 18, 2024
Merged via the queue into main with commit cc8366c Sep 18, 2024
75 checks passed
@alpe alpe deleted the alex/sims_after_import branch September 18, 2024 15:08
mergify bot pushed a commit that referenced this pull request Sep 18, 2024
julienrbrt pushed a commit that referenced this pull request Sep 18, 2024
…(backport #21800) (#21805)

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>
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:Simulations C:x/gov
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants