Skip to content

feat: fetch rollkitmngr state in migration command #190

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

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

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Jul 10, 2025

Closes: #164
Supersed #175

Summary by CodeRabbit

  • New Features

    • Enhanced migration process to support multiple validators by retrieving sequencer information from the application state when needed.
  • Bug Fixes

    • Improved error handling for cases with no validators in the last validator set.
  • Chores

    • Updated internal dependency declarations to clarify direct dependencies.

@julienrbrt julienrbrt requested a review from a team as a code owner July 10, 2025 13:41
Copy link
Contributor

coderabbitai bot commented Jul 10, 2025

Walkthrough

The migration command logic was updated to support cases where the last CometBFT validator set contains multiple validators. A new helper function retrieves the sequencer from the rollkitmngr module state if needed. Supporting type and function signatures were updated, and the go.mod dependency for cosmos-db was promoted to a direct dependency.

Changes

File(s) Change Summary
go.mod Promoted github.com/cosmos/cosmos-db from indirect to direct dependency.
server/migration_cmd.go Refactored imports; updated function/type signatures; added logic to fetch sequencer from rollkitmngr state; added sequencerInfo type and getSequencerFromRollkitMngrState function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MigrationCmd
    participant AppDB
    participant RollkitMngr

    User->>MigrationCmd: Run rollkit-migrate
    MigrationCmd->>MigrationCmd: Load last CometBFT validator set
    alt Multiple validators
        MigrationCmd->>AppDB: Open app DB
        AppDB->>RollkitMngr: Mount rollkitmngr module store
        RollkitMngr->>MigrationCmd: Return sequencer info
        MigrationCmd->>MigrationCmd: Verify sequencer in validator set
    else One validator
        MigrationCmd->>MigrationCmd: Use validator as sequencer
    end
    MigrationCmd->>User: Complete migration
Loading

Assessment against linked issues

Objective Addressed Explanation
Support fetching rollkitmngr state in rollkit-migrate when multiple validators in last CometBFT set (#164)
Use rollkitmngr module to determine sequencer address when using attester set (#164)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Possibly related PRs

Suggested reviewers

  • randygrok
  • tac0turtle

Poem

A migration hop, a sequencer found,
From many validators, we look around.
Into rollkitmngr's state we peer,
The right address now crystal clear!
With code refactored, the path is bright—
The chain moves forward, all is right.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6ba0c6 and 795bed2.

📒 Files selected for processing (1)
  • server/migration_cmd.go (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/migration_cmd.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Test with Rollkit Chain
  • GitHub Check: lint / golangci-lint
  • GitHub Check: test / Run Unit Tests
  • GitHub Check: Test Migration from Cosmos SDK to Rollkit
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@julienrbrt
Copy link
Member Author

@copilot, please add a unit test

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @julienrbrt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the migration command by enabling it to fetch the active sequencer's information directly from the rollkitmngr module's state. This change is crucial for supporting migration scenarios involving multiple validators, ensuring that the correct sequencer is identified and used when generating the Rollkit migration genesis file.

Highlights

  • Enhanced Sequencer Identification in Migration: The migration command now intelligently determines the sequencer's address and public key by querying the rollkitmngr module's state within the Cosmos SDK application database. This new logic is activated when the CometBFT state's LastValidators contains more than one validator, addressing a previous limitation where only single-validator setups were directly supported.
  • Integration with Cosmos SDK Application State: A new helper function, getSequencerFromRollkitMngrState, has been introduced. This function is responsible for opening the application's database, initializing a Cosmos SDK CommitMultiStore, and using the rollkitmngr module's keeper to fetch the currently configured sequencer. This allows the migration process to leverage the application's specific state for critical configuration.
  • Robustness and Validation: The newly implemented sequencer lookup includes validation steps. After retrieving a sequencer from the rollkitmngr state, the system verifies that this sequencer's address is indeed present within the LastValidators set provided by CometBFT, ensuring consistency and preventing misconfigurations during the migration.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The code changes introduce the ability to load multiple signed images to a registry using a bulk load feature. The overall approach is sound, but I've identified a few issues in the implementation of getSequencerFromRollkitMngrState that would cause the migration command to fail. My review includes a critical fix for a panic, a high-severity fix for state decoding, and a medium-severity suggestion for improving code robustness. Addressing these will ensure the new functionality works as intended.

Comment on lines 433 to 464
k := rollkitmngrkeeper.NewKeeper(
moduletestutil.MakeTestEncodingConfig(rollkitmngr.AppModuleBasic{}).Codec,
runtime.NewKVStoreService(storeKey),
addresscodec.NewBech32Codec("cosmos"),
nil,
nil,
"",
)

ctx := sdk.NewContext(cms, cmtproto.Header{
Height: int64(cometBFTState.LastBlockHeight),
ChainID: cometBFTState.ChainID,
Time: cometBFTState.LastBlockTime,
}, false, log.NewNopLogger())
sequencer, err := k.Sequencer.Get(ctx)
if errors.Is(err, collections.ErrNotFound) {
return nil, fmt.Errorf("sequencer not found in rollkitmngr state, ensure the module is initialized and sequencer is set")
} else if err != nil {
return nil, fmt.Errorf("failed to get sequencer from rollkitmngr state: %w", err)
}

// Extract the public key from the sequencer
pubKeyAny := sequencer.ConsensusPubkey
if pubKeyAny == nil {
return nil, fmt.Errorf("sequencer consensus public key is nil")
}

// Get the cached value which should be a crypto.PubKey
pubKey, ok := pubKeyAny.GetCachedValue().(crypto.PubKey)
if !ok {
return nil, fmt.Errorf("failed to extract public key from sequencer")
}

Choose a reason for hiding this comment

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

critical

This block of code has a few issues that need to be addressed:

  1. critical: The call to rollkitmngrkeeper.NewKeeper on line 433 passes an empty string for the authority parameter. This will cause a panic because the keeper's constructor validates the authority address. Since the authority is not used for reading state, you can provide a valid dummy bech32 address to prevent the crash.

  2. high: The sequencer object fetched from the store has a ConsensusPubkey of type *codectypes.Any. Before you can access the underlying crypto.PubKey, you must call sequencer.UnpackInterfaces(). This is missing, which will cause pubKeyAny.GetCachedValue() on line 461 to return nil, leading to a failed type assertion.

  3. medium: The function uses moduletestutil.MakeTestEncodingConfig to create a codec. This is a test utility and its use in application code, especially a migration script, is not ideal. It would be more robust to create a proper EncodingConfig as done in the application's app.go.

Here is a suggested refactoring to address these points. It introduces encCfg to be used for both codec creation and interface unpacking.

encCfg := moduletestutil.MakeTestEncodingConfig(rollkitmngr.AppModuleBasic{})
	k := rollkitmngrkeeper.NewKeeper(
		encCfg.Codec,
		runtime.NewKVStoreService(storeKey),
		addresscodec.NewBech32Codec("cosmos"),
		nil,
		nil,
		"cosmos1qyqsyqcyq5rqwzryf5c6d2kzl702kfs5p3y2z5", // A valid dummy address for authority
	)

	ctx := sdk.NewContext(cms, cmtproto.Header{
		Height:  int64(cometBFTState.LastBlockHeight),
		ChainID: cometBFTState.ChainID,
		Time:    cometBFTState.LastBlockTime,
	}, false, log.NewNopLogger())
	sequencer, err := k.Sequencer.Get(ctx)
	if errors.Is(err, collections.ErrNotFound) {
		return nil, fmt.Errorf("sequencer not found in rollkitmngr state, ensure the module is initialized and sequencer is set")
	} else if err != nil {
		return nil, fmt.Errorf("failed to get sequencer from rollkitmngr state: %w", err)
	}

	if err := sequencer.UnpackInterfaces(encCfg.InterfaceRegistry); err != nil {
		return nil, fmt.Errorf("failed to unpack sequencer interfaces: %w", err)
	}

	// Extract the public key from the sequencer
	pubKeyAny := sequencer.ConsensusPubkey
	if pubKeyAny == nil {
		return nil, fmt.Errorf("sequencer consensus public key is nil")
	}

	// Get the cached value which should be a crypto.PubKey
	pubKey, ok := pubKeyAny.GetCachedValue().(crypto.PubKey)
	if !ok {
		return nil, fmt.Errorf("failed to extract public key from sequencer")
	}

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)
server/migration_cmd.go (2)

363-373: Well-implemented multi-validator support.

The logic correctly handles all three cases:

  1. Single validator: Uses it as the sequencer (unchanged)
  2. Multiple validators: Fetches from rollkitmngr state (new feature)
  3. No validators: Returns a clear error

As mentioned in your PR comment, unit tests for this new functionality would be valuable.

Would you like me to help generate unit tests for the new getSequencerFromRollkitMngrState function and the multi-validator scenario?


403-441: Solid implementation of sequencer retrieval.

The function properly:

  • Checks for application database existence with clear error messages
  • Uses defer for database cleanup
  • Creates the necessary store infrastructure to access module state

One minor consideration: The address codec uses a hardcoded "cosmos" prefix. This should work for most Cosmos SDK chains, but you might want to make it configurable if different chains use different prefixes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e58749 and b6ba0c6.

📒 Files selected for processing (2)
  • go.mod (1 hunks)
  • server/migration_cmd.go (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#81
File: .github/workflows/integration_test.yml:28-30
Timestamp: 2025-05-07T12:20:24.290Z
Learning: For the rollkit/go-execution-abci repository, the maintainer prefers using the latest version of Ignite CLI rather than pinning to a specific version during the current development phase. Version tags will be added later when Rollkit has a tag.
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#114
File: modules/rollkitmngr/keeper/migration.go:18-46
Timestamp: 2025-05-30T09:43:01.102Z
Learning: In the rollkitmngr module migration functions, input validation for migration data parameters (like checking if Sequencer.ConsensusPubkey is nil) is not needed according to the project maintainer's preference.
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#113
File: server/migration_cmd.go:231-231
Timestamp: 2025-06-20T13:20:04.030Z
Learning: In the rollkit migration command (server/migration_cmd.go), InitialHeight is correctly set to LastBlockHeight because the Rollkit chain is technically a new chain that starts where the CometBFT chain ended, ensuring continuity during migration.
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#114
File: modules/rollkitmngr/keeper/migration.go:13-14
Timestamp: 2025-05-30T09:40:24.076Z
Learning: In modules/rollkitmngr/keeper/migration.go, the IBCSmoothingFactor variable is intentionally mutable (not a constant) to allow different chains to modify the smoothing period for IBC migration based on their specific requirements.
server/migration_cmd.go (4)
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#113
File: server/migration_cmd.go:231-231
Timestamp: 2025-06-20T13:20:04.030Z
Learning: In the rollkit migration command (server/migration_cmd.go), InitialHeight is correctly set to LastBlockHeight because the Rollkit chain is technically a new chain that starts where the CometBFT chain ended, ensuring continuity during migration.
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#114
File: modules/rollkitmngr/keeper/migration.go:18-46
Timestamp: 2025-05-30T09:43:01.102Z
Learning: In the rollkitmngr module migration functions, input validation for migration data parameters (like checking if Sequencer.ConsensusPubkey is nil) is not needed according to the project maintainer's preference.
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#114
File: modules/rollkitmngr/keeper/migration.go:13-14
Timestamp: 2025-05-30T09:40:24.076Z
Learning: In modules/rollkitmngr/keeper/migration.go, the IBCSmoothingFactor variable is intentionally mutable (not a constant) to allow different chains to modify the smoothing period for IBC migration based on their specific requirements.
Learnt from: julienrbrt
PR: rollkit/go-execution-abci#81
File: .github/workflows/integration_test.yml:28-30
Timestamp: 2025-05-07T12:20:24.290Z
Learning: For the rollkit/go-execution-abci repository, the maintainer prefers using the latest version of Ignite CLI rather than pinning to a specific version during the current development phase. Version tags will be added later when Rollkit has a tag.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test / Run Unit Tests
  • GitHub Check: lint / golangci-lint
  • GitHub Check: Test with Rollkit Chain
  • GitHub Check: Test Migration from Cosmos SDK to Rollkit
🔇 Additional comments (3)
go.mod (1)

21-21: LGTM! Correct dependency promotion.

Moving github.com/cosmos/cosmos-db to direct dependencies is appropriate since it's now directly used in server/migration_cmd.go for opening the application database to retrieve rollkitmngr state.

server/migration_cmd.go (2)

12-44: Import changes look good.

The new imports are appropriately added to support:

  • Accessing the application database and mounting module stores
  • Creating the rollkitmngr keeper to retrieve sequencer state
  • Consistent naming with cmt prefix for CometBFT imports

Based on the retrieved learnings, I see you prefer not to have input validation in migration functions, which aligns with the implementation.


469-480: Excellent validation of sequencer presence in validator set.

This validation is crucial for security - it ensures that the sequencer stored in rollkitmngr state is actually one of the current validators. This prevents potential issues where an arbitrary address could be set as the sequencer.

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

Successfully merging this pull request may close these issues.

Allow fetching rollkitmngr state in rollkit-migrate command
1 participant