-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe 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
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
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes detected. Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@copilot, please add a unit test |
There was a problem hiding this 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'sLastValidators
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 SDKCommitMultiStore
, and using therollkitmngr
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 theLastValidators
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
-
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. ↩
There was a problem hiding this 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.
server/migration_cmd.go
Outdated
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") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code has a few issues that need to be addressed:
-
critical
: The call torollkitmngrkeeper.NewKeeper
on line 433 passes an empty string for theauthority
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. -
high
: Thesequencer
object fetched from the store has aConsensusPubkey
of type*codectypes.Any
. Before you can access the underlyingcrypto.PubKey
, you must callsequencer.UnpackInterfaces()
. This is missing, which will causepubKeyAny.GetCachedValue()
on line 461 to returnnil
, leading to a failed type assertion. -
medium
: The function usesmoduletestutil.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 properEncodingConfig
as done in the application'sapp.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")
}
There was a problem hiding this 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:
- Single validator: Uses it as the sequencer (unchanged)
- Multiple validators: Fetches from rollkitmngr state (new feature)
- 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
📒 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 inserver/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 importsBased 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.
Closes: #164
Supersed #175
Summary by CodeRabbit
New Features
Bug Fixes
Chores