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: add missing rollback command #23618

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

Conversation

wonderfan
Copy link
Contributor

@wonderfan wonderfan commented Feb 6, 2025

update codes to fix #23613

Description

Closes: #XXXX


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

  • Documentation
    • Revised key documentation to improve clarity on Cosmos SDK target user groups.
  • New Features
    • Introduced a rollback command in the server CLI to enhance state management capabilities.
  • Chores
    • Updated the changelog to reflect the addition of the new rollback command.

The sentence "Recently we have identified the following key target user groups:" was accidentally repeated. This commit removes the duplicate to improve readability.
It should be readonly instead of "radonly"
@wonderfan wonderfan requested a review from a team as a code owner February 6, 2025 03:28
Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

📝 Walkthrough

Walkthrough

This pull request rephrases and restructures an RFC document to clarify the identification of key target user groups for the Cosmos SDK. It also introduces a new rollback command (RollbackStateCmd) to the CometBFT server's CLI commands and updates the changelog to reference this addition.

Changes

File(s) Change Summary
docs/rfc/rfc-003-crosslang.md Rephrased and restructured text to clarify and numerically list key target user groups for the Cosmos SDK without altering the technical specifications.
server/v2/cometbft/server.go, server/v2/cometbft/commands.go, server/v2/CHANGELOG.md Added a new RollbackStateCmd to the CLICommands method in the CometBFT server, implemented the rollback functionality in the commands file, and updated the changelog with a new unreleased entry for the rollback command (referencing issue #23618).

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CLI as Command Line Interface
    participant CBS as CometBFT Server
    U->>CLI: Execute "comet rollback" command
    CLI->>CBS: Retrieve CLICommands (includes RollbackStateCmd)
    CBS-->>CLI: Provide rollback command execution
Loading

Assessment against linked issues

Objective [#23613] Addressed Explanation
Wire rollback command in v2 CometBFT server

Suggested labels

C:CLI, C:x/auth

Suggested reviewers

  • julienrbrt
  • tac0turtle
  • akhilkumarpilli
  • sontrinh16
  • kocubinski

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.

@github-actions github-actions bot added C:server/v2 Issues related to server/v2 C:server/v2 cometbft labels Feb 6, 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: 0

🧹 Nitpick comments (1)
docs/rfc/rfc-003-crosslang.md (1)

12-15: Add blank lines around the list for better readability.

According to markdown best practices, lists should be surrounded by blank lines.

Apply this diff to improve formatting:

 have been underway since early 2023. Recently, we have identified the following key target user groups:

 1. projects that want to primarily target a single programming language and virtual machine environment besides Golang but who still want to use Cosmos SDK internals for consensus and storage
 2. projects that want to integrate multiple programming languages and virtual machine environments into an integrated application

 While these two user groups may have substantially different needs,
🧰 Tools
🪛 LanguageTool

[style] ~14-~14: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ... consensus and storage 2. projects that want to integrate multiple programming language...

(REP_WANT_TO_VB)

📜 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 e3a2d6b.

📒 Files selected for processing (2)
  • docs/rfc/rfc-003-crosslang.md (2 hunks)
  • server/v2/cometbft/server.go (1 hunks)
🧰 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.

  • server/v2/cometbft/server.go
`**/*.md`: "Assess the documentation for misspellings, gramm...

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

  • docs/rfc/rfc-003-crosslang.md
🪛 markdownlint-cli2 (0.17.2)
docs/rfc/rfc-003-crosslang.md

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

(MD032, blanks-around-lists)

⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: Analyze
  • GitHub Check: golangci-lint
  • GitHub Check: markdown-link-check
  • GitHub Check: Summary
🔇 Additional comments (1)
server/v2/cometbft/server.go (1)

356-356: LGTM! Addition of rollback command.

The addition of cmtcmd.RollbackStateCmd to the CLI commands is appropriate and aligns with the PR objectives to add the missing rollback command.

Let's verify the command's integration:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Verify the rollback command is properly integrated
# Test: Check if the command is properly imported and accessible
rg -A 2 "RollbackStateCmd" 

Length of output: 175


Validation: Rollback Command Integration Verified
The shell script output confirms that cmtcmd.RollbackStateCmd is present in the codebase in the expected location, indicating that the rollback command has been properly integrated.

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

4-11: Ensure changelog principles are followed consistently

The guiding principles section provides good guidelines for changelog entries. However, some entries in the changelog could be improved to better follow these principles, particularly around being human-readable and having clear version linkages.

Consider adding examples for each principle to make them more concrete and easier to follow.


12-23: Usage instructions are clear but could be enhanced

The usage instructions are clear but could benefit from:

  1. Examples of properly formatted entries
  2. Common pitfalls to avoid
  3. Links to example PRs that follow the format well

2780-2784: Important release notice needs formatting improvements

The Stargate release notice should be formatted more prominently, perhaps using:

  • Headers
  • Bullet points for key changes
  • Links to migration guides
- v0.40.0, known as the Stargate release of the Cosmos SDK, is one of the largest releases
- of the Cosmos SDK since launch. Please read through this changelog and [release notes](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/RELEASE_NOTES.md) to make
- sure you are aware of any relevant breaking changes.

+ # v0.40.0 - Stargate Release
+ 
+ This is one of the largest releases of the Cosmos SDK since launch, introducing several major features and improvements:
+
+ ## Key Changes
+ - Feature A
+ - Feature B 
+
+ ## Migration Guide
+ Please carefully review the [release notes](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/RELEASE_NOTES.md) for breaking changes and migration steps.

3155-3157: Previous releases section needs improvement

The previous releases section should:

  1. Include a brief summary of major changes in each previous version
  2. Maintain consistent formatting with the rest of the changelog
  3. Consider archiving very old changes to a separate file
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3a2d6b and 97437b1.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.md`: "Assess the documentation for misspellings, gramm...

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

  • CHANGELOG.md
⏰ 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-accounts-multisig
  • GitHub Check: test-x-accounts
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: runtime-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: cometbft
  • GitHub Check: test-integration
  • GitHub Check: Check go mod tidy
  • GitHub Check: build (arm64)
  • GitHub Check: Analyze
  • GitHub Check: build (amd64)
  • GitHub Check: golangci-lint
  • GitHub Check: markdown-link-check
  • GitHub Check: Summary
🔇 Additional comments (3)
CHANGELOG.md (3)

1-3: LGTM: Clear and concise introduction

The introduction provides a clear overview of the changelog's purpose and scope.


24-34: Well-defined stanza types

The stanza types are well-defined and cover the major categories of changes. The descriptions are clear and help maintainers properly categorize their changes.


1558-1559: Security advisory notice needs more details

The security advisory notice should include:

  1. Severity level
  2. Affected versions
  3. Mitigation steps
  4. Timeline for fixes

Consider enhancing this section to help users better assess and respond to the security issue.

@julienrbrt
Copy link
Member

julienrbrt commented Feb 6, 2025

Thanks! That looks good to me however I think there's a bug in CometBFT:
failed to rollback state: no blockstore found in data.
They should parse the config like they do in reset:

https://github.com/cometbft/cometbft/blob/v1.0.1/cmd/cometbft/commands/reset.go#L40-L43

Instead of using the global:

https://github.com/cometbft/cometbft/blob/main/cmd/cometbft/commands/rollback.go#L35-L38

EDIT: While I still believe they should parse the config instead of reading the global, their rollback command isn't complete, as it rollsback only on their side. The app needs to be rolled back as well: #23618 (review)

CHANGELOG.md Outdated Show resolved Hide resolved
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.

You actually need to rollback the app as well, check this: https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/server/rollback.go#L42-L44.

My bad about the previous message, we shouldn't just use the cometbft command directly.

@wonderfan wonderfan requested a review from julienrbrt February 6, 2025 08:00
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)
server/v2/CHANGELOG.md (1)

25-26: Changelog Entry Detail

The entry for the rollback command is added in the correct "Unreleased" section and follows the expected issue reference format. Consider providing a tad more detail (if applicable) to clarify that this fix addresses the missing rollback command issue (#23618) and improves rollback functionality. This extra context can help users quickly grasp the purpose of the change.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 97437b1 and cdbd745.

📒 Files selected for processing (1)
  • server/v2/CHANGELOG.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.md`: "Assess the documentation for misspellings, gramm...

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

  • server/v2/CHANGELOG.md
⏰ 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-sim-nondeterminism
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: cometbft
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: Analyze
  • GitHub Check: markdown-link-check
  • GitHub Check: golangci-lint
  • GitHub Check: Summary

@wonderfan
Copy link
Contributor Author

https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/server/rollback.go#L42-L44

Thanks for your information and let me update it

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cdbd745 and de4d1b3.

📒 Files selected for processing (2)
  • server/v2/cometbft/commands.go (2 hunks)
  • server/v2/cometbft/server.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/v2/cometbft/server.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/commands.go
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: tests (00)
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: markdown-link-check
  • GitHub Check: Summary
🔇 Additional comments (1)
server/v2/cometbft/commands.go (1)

10-10: Import usage is valid and clear.
No issues found here. The import alias “cmtcmd” is used in the rollback logic below, so this addition is appropriate.

Comment on lines +437 to +471

func (s *CometBFTServer[T]) RollbackStateCmd() *cobra.Command {
var removeBlock bool

cmd := &cobra.Command{
Use: "rollback",
Short: "rollback Cosmos SDK and CometBFT state by one height",
Long: `
A state rollback is performed to recover from an incorrect application state transition,
when CometBFT has persisted an incorrect app hash and is thus unable to make
progress. Rollback overwrites a state at height n with the state at height n - 1.
The application also rolls back to height n - 1. No blocks are removed, so upon
restarting CometBFT the transactions in block n will be re-executed against the
application.
`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg := client.GetConfigFromCmd(cmd)
// rollback CometBFT state
height, hash, err := cmtcmd.RollbackState(cfg, removeBlock)
if err != nil {
return fmt.Errorf("failed to rollback CometBFT state: %w", err)
}
// rollback the store
// if err := s.store.RollbackToVersion(height); err != nil {
// return fmt.Errorf("failed to rollback to version: %w", err)
// }

fmt.Printf("Rolled back state to height %d and hash %X\n", height, hash)
return nil
},
}

cmd.Flags().BoolVar(&removeBlock, "hard", false, "remove last block as well as state")
return cmd
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Rollback logic is incomplete.
The code’s description (“rollback Cosmos SDK and CometBFT state”) contradicts the fact that the application store rollback is commented out. This can lead to inconsistencies where CometBFT state is rolled back, but the Cosmos SDK application state remains at the newer height. Please either remove the lines referencing application rollback from the description or fully implement the store rollback to avoid leaving the system in a partially rolled-back state.

Below is a possible fix to re-enable the store rollback. Adjust as needed to ensure full coordination between CometBFT and Cosmos SDK state:

- // if err :=  s.store.RollbackToVersion(height); err != nil {
- //   return fmt.Errorf("failed to rollback to version: %w", err)
- // }
+ if err := s.store.RollbackToVersion(height); err != nil {
+   return fmt.Errorf("failed to rollback to version: %w", err)
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *CometBFTServer[T]) RollbackStateCmd() *cobra.Command {
var removeBlock bool
cmd := &cobra.Command{
Use: "rollback",
Short: "rollback Cosmos SDK and CometBFT state by one height",
Long: `
A state rollback is performed to recover from an incorrect application state transition,
when CometBFT has persisted an incorrect app hash and is thus unable to make
progress. Rollback overwrites a state at height n with the state at height n - 1.
The application also rolls back to height n - 1. No blocks are removed, so upon
restarting CometBFT the transactions in block n will be re-executed against the
application.
`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg := client.GetConfigFromCmd(cmd)
// rollback CometBFT state
height, hash, err := cmtcmd.RollbackState(cfg, removeBlock)
if err != nil {
return fmt.Errorf("failed to rollback CometBFT state: %w", err)
}
// rollback the store
// if err := s.store.RollbackToVersion(height); err != nil {
// return fmt.Errorf("failed to rollback to version: %w", err)
// }
fmt.Printf("Rolled back state to height %d and hash %X\n", height, hash)
return nil
},
}
cmd.Flags().BoolVar(&removeBlock, "hard", false, "remove last block as well as state")
return cmd
}
func (s *CometBFTServer[T]) RollbackStateCmd() *cobra.Command {
var removeBlock bool
cmd := &cobra.Command{
Use: "rollback",
Short: "rollback Cosmos SDK and CometBFT state by one height",
Long: `
A state rollback is performed to recover from an incorrect application state transition,
when CometBFT has persisted an incorrect app hash and is thus unable to make
progress. Rollback overwrites a state at height n with the state at height n - 1.
The application also rolls back to height n - 1. No blocks are removed, so upon
restarting CometBFT the transactions in block n will be re-executed against the
application.
`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg := client.GetConfigFromCmd(cmd)
// rollback CometBFT state
height, hash, err := cmtcmd.RollbackState(cfg, removeBlock)
if err != nil {
return fmt.Errorf("failed to rollback CometBFT state: %w", err)
}
// rollback the store
if err := s.store.RollbackToVersion(height); err != nil {
return fmt.Errorf("failed to rollback to version: %w", err)
}
fmt.Printf("Rolled back state to height %d and hash %X\n", height, hash)
return nil
},
}
cmd.Flags().BoolVar(&removeBlock, "hard", false, "remove last block as well as state")
return cmd
}

@wonderfan
Copy link
Contributor Author

wonderfan commented Feb 6, 2025

https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/server/rollback.go#L42-L44

Thanks for your information and let me update it

@julienrbrt The rollback command is added as subcommand of comet since it is more easy to get dependencies from there.

The current store V2 does not implement RollbackToVersion method. Can anyone help implement it at the store layer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wire rollback command in v2 cometbft server
2 participants