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(consensus): do not override app version in msg update params #23622

Open
wants to merge 7 commits into
base: main-backup
Choose a base branch
from

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Feb 6, 2025

Description

  • Allow to update the initial version at height 0 in baseapp and v2 (as we do not read it from genesis)
  • As afterwards app version is managed by upgrade, avoid to reset it to 0 after a consensus msg update params
  • Simplify handling of consensus params for v2

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

  • Refactor

    • Enhanced application version management to allow dynamic runtime updates.
    • Streamlined consensus parameter handling using an updated API for clearer initialization and validation.
  • Tests

    • Updated integration test setups to align with the new consensus parameter structure, ensuring consistency and improved reliability during system initialization.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Feb 6, 2025
@julienrbrt julienrbrt requested review from raynaudoe and a team as code owners February 6, 2025 11:25
Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

📝 Walkthrough

Walkthrough

The changes update how the application version and consensus parameters are handled. The InitialAppVersion is now declared as a variable rather than a constant in both the baseapp and server modules, allowing runtime modifications. The updates also transition the consensus parameters from the old type to the new versioned API (cmtproto.ConsensusParams) in simulation, integration tests, and keeper logic. Additionally, the method for retrieving the app version in the dependency injection module has been streamlined to directly delegate to the keeper.

Changes

File(s) Change Summary
baseapp/params.go, server/v2/cometbft/abci.go Changed InitialAppVersion from a constant to a variable; updated its usage in initializing the application version and in context setup for consensus parameters.
simapp/v2/sim_runner.go, tests/integration/v2/app.go Updated import statements and variable types to use cmtproto.ConsensusParams instead of the previous consensus type, reflecting a shift to the new versioned API.
x/consensus/depinject.go, x/consensus/keeper/keeper.go Simplified the AppVersion retrieval by delegating directly to the keeper and updated consensus parameter validation to work with cmtproto.ConsensusParams.
x/consensus/types/msgs.go Revised the comment for the Version field in the conversion method to clarify that the version is updated during migration by x/upgrade.
baseapp/abci.go Modified InitChain method to streamline consensus parameter handling and ensure proper initialization of the application version.

Suggested labels

C:x/upgrade, C:core/testing, C:Cosmovisor

Suggested reviewers

  • kocubinski
  • facundomedica
  • testinginprod
  • tac0turtle

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package sqlite3: could not load export data: no export data for "github.com/bvinc/go-sqlite-lite/sqlite3""
level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package sqlite3: could not load export data: no export data for "github.com/bvinc/go-sqlite-lite/sqlite3""

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

Copy link
Contributor

github-actions bot commented Feb 6, 2025

@julienrbrt your pull request is missing a changelog!

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)
server/v2/cometbft/abci.go (1)

144-160: Improve error handling in Info method.

The error handling logic could be simplified and made more robust:

  1. The error check for GetConsensusParams is duplicated (lines 157-159).
  2. The error handling for collections.ErrNotFound could be combined with the nil check.

Apply this diff to improve the error handling:

 // if height is 0, we dont know the consensus params
 var appVersion = InitialAppVersion
 if version > 0 {
     cp, err := GetConsensusParams(ctx, c.app)
-    // if the consensus params are not found, we set the app version to 0
-    // in the case that the start version is > 0
-    if cp == nil || errors.Is(err, collections.ErrNotFound) {
+    if err != nil {
+        if errors.Is(err, collections.ErrNotFound) {
+            appVersion = 0
+        } else {
+            return nil, err
+        }
+    } else if cp == nil {
         appVersion = 0
-    } else if err != nil {
-        return nil, err
     } else {
         appVersion = cp.Version.GetApp()
     }
-    if err != nil {
-        return nil, err
-    }
 }
🧹 Nitpick comments (2)
server/v2/cometbft/abci.go (2)

37-39: Consider using a constant instead of a mutable global variable.

Using a mutable global variable for InitialAppVersion could lead to race conditions and make the code harder to reason about. Unless there's a specific requirement for runtime modification, consider using a constant.

Apply this diff to make it a constant:

-// InitialAppVersion returned by Info at height 0.
-// Afterwards, the consensus params are queried from the app.
-var InitialAppVersion uint64 = 0
+// InitialAppVersion is returned by Info at height 0.
+// Afterwards, the consensus params are queried from the app.
+const InitialAppVersion uint64 = 0

287-290: Add clarifying comments about app version handling in genesis.

The comments explain the app version handling policy well, but they could be more detailed about the implications and rationale.

Add more detailed comments:

 // note the app version is not read from genesis
 // user can update InitialAppVersion to that value if needed
 // from height 1, we will query the app for the version
+// This design allows for flexible app version management:
+// 1. At height 0: Uses InitialAppVersion
+// 2. At height 1+: Queries app's consensus params
+// 3. For custom genesis: User can modify InitialAppVersion
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7e39195 and fedaa70.

📒 Files selected for processing (7)
  • baseapp/params.go (1 hunks)
  • server/v2/cometbft/abci.go (3 hunks)
  • simapp/v2/sim_runner.go (2 hunks)
  • tests/integration/v2/app.go (2 hunks)
  • x/consensus/depinject.go (1 hunks)
  • x/consensus/keeper/keeper.go (3 hunks)
  • x/consensus/types/msgs.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • x/consensus/types/msgs.go
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Ub...

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

  • baseapp/params.go
  • x/consensus/depinject.go
  • simapp/v2/sim_runner.go
  • server/v2/cometbft/abci.go
  • tests/integration/v2/app.go
  • x/consensus/keeper/keeper.go
`tests/**/*`: "Assess the integration and e2e test code asse...

tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

  • tests/integration/v2/app.go
🪛 GitHub Actions: Lint
simapp/v2/sim_runner.go

[error] 15-15: package "github.com/cometbft/cometbft/api/cometbft/types/v1" is being imported more than once (stylecheck)

🪛 golangci-lint (1.62.2)
x/consensus/keeper/keeper.go

10-10: ST1019(related information): other import of "github.com/cometbft/cometbft/api/cometbft/types/v1"

(stylecheck)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: tests (03)
  • GitHub Check: tests (00)
  • GitHub Check: test-system-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (5)
baseapp/params.go (1)

9-9: LGTM! The change from const to var is appropriate.

This change allows for runtime modification of the initial app version, which aligns with the PR's objective.

x/consensus/depinject.go (1)

102-104: LGTM! Good simplification of the AppVersion method.

The change reduces code duplication by directly delegating to the keeper's implementation, improving maintainability without losing any functionality.

x/consensus/keeper/keeper.go (1)

155-158: LGTM! Good protection of version parameters.

The added comments and logic ensure that version parameters are not accidentally overridden during updates, which aligns with the PR's objective.

tests/integration/v2/app.go (1)

279-286: LGTM! Clean transition to v1.ConsensusParams.

The context initialization correctly uses the new type while preserving all necessary consensus parameters.

server/v2/cometbft/abci.go (1)

296-298: LGTM!

The simplification of consensus params context value setting is a good improvement.

x/consensus/keeper/keeper.go Outdated Show resolved Hide resolved
simapp/v2/sim_runner.go Outdated Show resolved Hide resolved
@aljo242
Copy link
Collaborator

aljo242 commented Feb 6, 2025

Can we get a test for this?

@julienrbrt
Copy link
Member Author

julienrbrt commented Feb 6, 2025

Can we get a test for this?

There's not really a functional change. The test is kind of that the app still start 😅

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)
x/consensus/keeper/keeper.go (1)

66-77: Consider simplifying validation logic.

The validation is performed by converting back to MsgUpdateParams just for validation purposes. This seems redundant since we already have the consensus params in the correct type.

Consider validating the consensus params directly:

-	// validate the consensus params
-	// this avoids to duplicate the validation in here as well
-	if _, err := (&types.MsgUpdateParams{
-		Block:     value.Block,
-		Evidence:  value.Evidence,
-		Validator: value.Validator,
-		Abci:      value.Abci,
-		Synchrony: value.Synchrony,
-		Feature:   value.Feature,
-	}).ToProtoConsensusParams(); err != nil {
+	// validate the consensus params directly
+	if err := validateConsensusParams(value); err != nil {
		return err
	}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fedaa70 and b8709a0.

📒 Files selected for processing (5)
  • baseapp/abci.go (1 hunks)
  • server/v2/cometbft/abci.go (4 hunks)
  • simapp/v2/sim_runner.go (1 hunks)
  • tests/integration/v2/app.go (1 hunks)
  • x/consensus/keeper/keeper.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/integration/v2/app.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Golang code for conformity with the Ub...

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

  • server/v2/cometbft/abci.go
  • x/consensus/keeper/keeper.go
  • simapp/v2/sim_runner.go
  • baseapp/abci.go
📓 Learnings (1)
x/consensus/keeper/keeper.go (1)
Learnt from: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2024-11-10T03:53:32.474Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: tests (00)
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (6)
x/consensus/keeper/keeper.go (2)

60-64: LGTM! Improved type safety in context value handling.

The change from MsgUpdateParams to *cmtproto.ConsensusParams aligns with the direct usage of consensus parameters, reducing unnecessary type conversions.


154-157: LGTM! Clear documentation of version handling.

The comments clearly explain why version parameters should not be overridden, as they are managed by the upgrade module.

simapp/v2/sim_runner.go (1)

374-386: LGTM! Clear initialization of consensus parameters.

The initialization of consensus parameters is well-structured and includes all necessary fields with appropriate values for simulation testing.

server/v2/cometbft/abci.go (2)

38-40: LGTM! Well-documented version initialization.

The InitialAppVersion variable is clearly documented, explaining its usage at height 0 and subsequent behavior.


296-304: LGTM! Proper version parameter initialization.

The code correctly initializes version parameters when they are nil or zero, using InitialAppVersion as the default value.

baseapp/abci.go (1)

76-87: LGTM! Consistent version parameter handling.

The code maintains consistency with other files by initializing version parameters with InitialAppVersion when they are nil or zero.

@julienrbrt julienrbrt changed the base branch from main to main-backup February 10, 2025 20:10
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:server/v2 cometbft C:server/v2 Issues related to server/v2 C:x/consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants