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(x/simulation): finalize block after operations #23382

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ziscky
Copy link
Contributor

@ziscky ziscky commented Jan 14, 2025

Description

Closes: #22393


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 block finalization process in the simulation module, ensuring queued operations are completed before block closure.
  • API Breaking Changes

    • Removed x/params module.
    • Deprecated testutil/network package; users should utilize the integration framework or system tests framework instead.
    • Modified GetBlockByHeightResponse to return an empty comet block.

These changes enhance the Cosmos SDK's functionality and provide clearer migration paths for developers.

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

📝 Walkthrough

Walkthrough

This pull request introduces changes to the Cosmos SDK's simulation module, specifically ensuring that block finalization occurs after all queued operations are processed. The SimulateFromSeedX function has been modified to reflect this new order. Additionally, the CHANGELOG.md has been updated to include a bug fix for the simulation module and several API breaking changes, including the removal of the x/params module and deprecation of certain response fields.

Changes

File Change Summary
CHANGELOG.md Added bug fix for x/simulation module, noted API breaking changes for x/params, testutil/network, and block response handling
x/simulation/simulate.go Reordered block finalization to occur after operations, ensuring proper transaction processing

Assessment against linked issues

Objective Addressed Explanation
Fix transactions running after FinalizeBlock [#22393]

Possibly related PRs

  • chore: add crisis changelog #22280: This PR adds a changelog specifically for crisis-related updates, which is relevant as the main PR also updates the changelog for various modules, including the x/simulation module.
  • refactor: improve edge case handling for recursion limits #22988: This PR improves edge case handling for recursion limits, which aligns with the main PR's focus on changes in the CHANGELOG.md that include significant modifications and deprecations, indicating a broader restructuring of the SDK.
  • refactor!: remove duplicate block #23437: This PR removes the duplicate block in the GetBlockByHeightResponse, which is directly related to the main PR's deprecation of the Block field in the same response structure, indicating a significant API change.

Suggested labels

backport/v0.52.x

Suggested reviewers

  • julienrbrt
  • tac0turtle
  • testinginprod

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.

@ziscky ziscky marked this pull request as ready for review January 20, 2025 09:26
@ziscky ziscky requested a review from a team as a code owner January 20, 2025 09:26
@ziscky ziscky requested a review from julienrbrt January 20, 2025 09:26
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 (6)
x/simulation/simulate.go (1)

258-262: LGTM! Block finalization timing fixed.

The block finalization is now correctly placed after operations are executed, which aligns with the PR objectives.

Consider enhancing the error message to include the block hash for better debugging:

-			return params, accs, fmt.Errorf("block finalization failed at height %d: %w", blockHeight, err)
+			return params, accs, fmt.Errorf("block finalization failed at height %d (hash: %X): %w", blockHeight, finalizeBlockReq.Hash, err)
🧰 Tools
🪛 GitHub Actions: Tests / Code Coverage

[error] Unable to download artifact '5c63edab8d7b956371a5e3703fffd1380797f992-e2e-coverage'. Artifact not found.

CHANGELOG.md (5)

Line range hint 1-1: Add missing title header

The changelog should start with a # title header for better documentation structure.

+ # Changelog

Line range hint 14-25: Improve changelog guiding principles section formatting

The guiding principles section should be formatted as a proper markdown list for better readability.

- Changelogs are for humans, not machines.
- There should be an entry for every single version.
- The same types of changes should be grouped.
- Versions and sections should be linkable.
- The latest version comes first.
- The release date of each version is displayed.
- Mention whether you follow Semantic Versioning.

+ * Changelogs are for humans, not machines.
+ * There should be an entry for every single version.
+ * The same types of changes should be grouped.
+ * Versions and sections should be linkable.
+ * The latest version comes first.
+ * The release date of each version is displayed.
+ * Mention whether you follow Semantic Versioning.

Line range hint 27-37: Improve usage section formatting

The usage section should be formatted as a proper markdown list for better readability.

- Change log entries are to be added to the Unreleased section under the
- appropriate stanza (see below). Each entry is required to include a tag and
- the Github issue reference in the following format:
-
- * (<tag>) \#<issue-number> message

+ # Usage
+
+ * Change log entries should be added to the Unreleased section under the
+   appropriate stanza (see below)
+ * Each entry must include a tag and GitHub issue reference in the format:
+   * (<tag>) \#<issue-number> message

Line range hint 39-47: Improve types of changes section formatting

The types of changes section should be formatted consistently with proper markdown headers.

- Types of changes (Stanzas):
-
- "Features" for new features.
- "Improvements" for changes in existing functionality.
- "Deprecated" for soon-to-be removed features.
- "Bug Fixes" for any bug fixes.
- "Client Breaking" for breaking Protobuf, gRPC and REST routes used by end-users.
- "CLI Breaking" for breaking CLI commands.
- "API Breaking" for breaking exported APIs used by developers building on SDK.

+ ## Types of Changes
+
+ * **Features**: New features
+ * **Improvements**: Changes in existing functionality
+ * **Deprecated**: Soon-to-be removed features
+ * **Bug Fixes**: Bug fixes
+ * **Client Breaking**: Breaking Protobuf, gRPC and REST routes used by end-users
+ * **CLI Breaking**: Breaking CLI commands
+ * **API Breaking**: Breaking exported APIs used by developers

Line range hint 48-49: Remove redundant reference link

The reference to keepachangelog.com is redundant since the guiding principles are already listed above.

- "State Machine Breaking" for any changes that result in a different AppState given same genesisState and txList.
- Ref: https://keepachangelog.com/en/1.0.0/
+ * **State Machine Breaking**: Changes that result in a different AppState given same genesisState and txList
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f9bb180 and acd6a63.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • x/simulation/simulate.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
x/simulation/simulate.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"

🪛 GitHub Actions: Tests / Code Coverage
x/simulation/simulate.go

[error] Unable to download artifact '5c63edab8d7b956371a5e3703fffd1380797f992-e2e-coverage'. Artifact not found.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (2)
x/simulation/simulate.go (2)

281-281: LGTM! Comprehensive simulation completion logging.

The log message provides valuable metrics including height, block-time, operation count, run-time, and app-hash, which will help in monitoring and debugging simulations.

🧰 Tools
🪛 GitHub Actions: Tests / Code Coverage

[error] Unable to download artifact '5c63edab8d7b956371a5e3703fffd1380797f992-e2e-coverage'. Artifact not found.


258-262: Verify test coverage for block finalization changes.

The pipeline indicates code coverage issues. Please ensure adequate test coverage for the modified block finalization logic.

Run this script to check test coverage for the modified code:

✅ Verification successful

Test coverage for block finalization is adequate

The codebase has comprehensive test coverage for block finalization, including various scenarios like invalid height, transaction handling, gas limits, and error cases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for block finalization logic

# Find all test files that might test block finalization
echo "Searching for relevant test files..."
rg -l "FinalizeBlock|SimulateFromSeedX" --type go --glob "*_test.go"

# Check for specific test coverage of the block finalization logic
echo "Checking test coverage of block finalization..."
rg -A 5 "func.*Test.*FinalizeBlock|func.*Test.*SimulateFromSeedX" --type go

Length of output: 4169

🧰 Tools
🪛 GitHub Actions: Tests / Code Coverage

[error] Unable to download artifact '5c63edab8d7b956371a5e3703fffd1380797f992-e2e-coverage'. Artifact not found.

@aljo242
Copy link
Collaborator

aljo242 commented Jan 20, 2025

Is there a way we can validate this behavior with a test?

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 (2)
CHANGELOG.md (2)

57-58: Inconsistent indentation in changelog entry

The bullet point for simulation module fix is not properly indented compared to other entries in the Bug Fixes section.

-* (x/simulation) [#23382](https://github.com/cosmos/cosmos-sdk/pull/23382) Finalize block after queued operations.
+  * (x/simulation) [#23382](https://github.com/cosmos/cosmos-sdk/pull/23382) Finalize block after queued operations.

Line range hint 785-786: Fix broken link in changelog

The link to previous versions points to a specific commit hash which may become invalid. Consider using a tag or release instead.

-[CHANGELOG of previous versions](https://github.com/cosmos/cosmos-sdk/blob/c17c3caab86a1426a1eef4541e8203f5f54a1a54/CHANGELOG.md#v0391---2020-08-11) (pre Stargate).
+[CHANGELOG of previous versions](https://github.com/cosmos/cosmos-sdk/blob/v0.39.1/CHANGELOG.md#v0391---2020-08-11) (pre Stargate).
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between acd6a63 and be2c190.

📒 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"

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

Line range hint 1-15: LGTM! Well-structured changelog header

The header section follows the Keep a Changelog format and provides clear guiding principles for contributors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug](x/simulation): Transactions run after FinalizeBlock in v0.50.x
4 participants