|
| 1 | +# Migrating an Existing Chain to ev-abci |
| 2 | + |
| 3 | +This guide is for developers of existing Cosmos SDK chains who want to replace their node's default CometBFT consensus engine and `start` command with the `ev-abci` implementation. By following these steps, you will reconfigure your chain to run as an `ev-abci` node. |
| 4 | + |
| 5 | +## Overview of Changes |
| 6 | + |
| 7 | +The migration process involves two key modifications: |
| 8 | + |
| 9 | +1. **Node Entrypoint (`main.go`):** Replacing the default `start` and `init` commands with the `ev-abci` versions. |
| 10 | +2. **Application Logic (`app.go`):** For certain modules like `migrationmngr`, you must add logic to your `app.go` file to correctly manage the chain's state during state-machine transitions. |
| 11 | + |
| 12 | +This document will guide you through both parts. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Part 1: Modifying the Node Entrypoint (`main.go`) |
| 17 | + |
| 18 | +The first step is to change your application's main entrypoint to use the `ev-abci` server commands. |
| 19 | + |
| 20 | +### 1. Locate Your Application's Entrypoint |
| 21 | + |
| 22 | +Open the main entrypoint file for your chain's binary. This is usually found at `cmd/<your-app-name>/main.go`. |
| 23 | + |
| 24 | +### 2. Modify `main.go` |
| 25 | + |
| 26 | +You will need to add a new import and then overwrite the default `start` and `init` commands with the ones provided by `ev-abci`. |
| 27 | + |
| 28 | +Below is a comprehensive example of what your `main.go` might look like before and after the changes. |
| 29 | + |
| 30 | +#### Before Changes |
| 31 | + |
| 32 | +A typical `main.go` file uses the default `server.AddCommands` to add all the standard node commands. |
| 33 | + |
| 34 | +```go |
| 35 | +// cmd/<appd>/main.go |
| 36 | +package main |
| 37 | + |
| 38 | +import ( |
| 39 | + "os" |
| 40 | + |
| 41 | + "github.com/cosmos/cosmos-sdk/server" |
| 42 | + "github.com/spf13/cobra" |
| 43 | + |
| 44 | + "<your-app-path>/app" |
| 45 | +) |
| 46 | + |
| 47 | +func main() { |
| 48 | + rootCmd := &cobra.Command{ |
| 49 | + Use: "<appd>", |
| 50 | + Short: "Your App Daemon", |
| 51 | + } |
| 52 | + |
| 53 | + server.AddCommands(rootCmd, app.DefaultNodeHome, app.New, app.MakeEncodingConfig(), tx.DefaultSignModes) |
| 54 | + |
| 55 | + if err := rootCmd.Execute(); err != nil { |
| 56 | + server.HandleError(err) |
| 57 | + os.Exit(1) |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +#### After Changes |
| 63 | + |
| 64 | +To migrate, you will continue to use `server.AddCommands` to get useful commands like `keys` and `export`, but you will then overwrite the `start` and `init` commands with the `ev-abci` versions. |
| 65 | + |
| 66 | +```go |
| 67 | +// cmd/<appd>/main.go |
| 68 | +package main |
| 69 | + |
| 70 | +import ( |
| 71 | + "os" |
| 72 | + |
| 73 | + "github.com/cosmos/cosmos-sdk/server" |
| 74 | + "github.com/spf13/cobra" |
| 75 | + |
| 76 | + // Import the ev-abci server package |
| 77 | + evabci_server "github.com/evstack/ev-abci/server" |
| 78 | + |
| 79 | + "<your-app-path>/app" |
| 80 | +) |
| 81 | + |
| 82 | +func main() { |
| 83 | + rootCmd := &cobra.Command{ |
| 84 | + Use: "<appd>", |
| 85 | + Short: "Your App Daemon (ev-abci enabled)", |
| 86 | + } |
| 87 | + |
| 88 | + server.AddCommands(rootCmd, app.DefaultNodeHome, app.New, app.MakeEncodingConfig(), tx.DefaultSignModes) |
| 89 | + |
| 90 | + // --- Overwrite with ev-abci commands --- |
| 91 | + rootCmd.AddCommand(evabci_server.InitCmd()) |
| 92 | + |
| 93 | + startCmd := &cobra.Command{ |
| 94 | + Use: "start", |
| 95 | + Short: "Run the full node with ev-abci", |
| 96 | + RunE: func(cmd *cobra.Command, _ []string) error { |
| 97 | + return server.Start(cmd, evabci_server.StartHandler()) |
| 98 | + }, |
| 99 | + } |
| 100 | + |
| 101 | + evabci_server.AddFlags(startCmd) |
| 102 | + rootCmd.AddCommand(startCmd) |
| 103 | + // --- End of ev-abci changes --- |
| 104 | + |
| 105 | + if err := rootCmd.Execute(); err != nil { |
| 106 | + server.HandleError(err) |
| 107 | + os.Exit(1) |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## Part 2: Modifying the Application Logic (`app.go`) |
| 115 | + |
| 116 | +If your chain utilizes the `migrationmngr` module to transition from a PoS validator set to a sequencer-based model, you must ensure that the standard `staking` module does not send conflicting validator updates during the migration. |
| 117 | + |
| 118 | +### For Chains Using the `migrationmngr` Module |
| 119 | + |
| 120 | +**Goal:** To ensure the `migrationmngr` module is the *sole* source of validator set updates during a migration. |
| 121 | + |
| 122 | +Instead of manually adding conditional logic to your `app.go`, you simply need to replace the standard Cosmos SDK `x/staking` module with the **staking wrapper module** provided in `ev-abci`. The wrapper's `EndBlock` method is hardcoded to prevent it from sending validator updates, cleanly delegating that responsibility to the `migrationmngr` module when a migration is active. |
| 123 | + |
| 124 | +#### Action: Swap Staking Module Imports |
| 125 | + |
| 126 | +In your `app.go` file (and any other files that import the staking module), replace the import for the Cosmos SDK's `x/staking` module with the one from `ev-abci`. |
| 127 | + |
| 128 | +**Replace this:** |
| 129 | +```go |
| 130 | +import ( |
| 131 | + // ... |
| 132 | + "github.com/cosmos/cosmos-sdk/x/staking" |
| 133 | + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" |
| 134 | + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" |
| 135 | + // ... |
| 136 | +) |
| 137 | +``` |
| 138 | + |
| 139 | +**With this:** |
| 140 | +```go |
| 141 | +import ( |
| 142 | + // ... |
| 143 | + "github.com/evstack/ev-abci/modules/staking" // The wrapper module |
| 144 | + stakingkeeper "github.com/evstack/ev-abci/modules/staking/keeper" |
| 145 | + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" // Staking types remain the same |
| 146 | + // ... |
| 147 | +) |
| 148 | +``` |
| 149 | + |
| 150 | +By changing the import path, your application's dependency injection system will automatically use the wrapper module. No other changes to your `EndBlocker` method are needed. This is the only required modification to `app.go` for the migration to work correctly. |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +## Part 3: Build and Verification |
| 155 | + |
| 156 | +### 1. Re-build Your Application |
| 157 | + |
| 158 | +After making these changes, re-build your application's binary: |
| 159 | + |
| 160 | +```sh |
| 161 | +go build -o <appd> ./cmd/<appd> |
| 162 | +``` |
| 163 | + |
| 164 | +### 2. Verify the Changes |
| 165 | + |
| 166 | +To verify that the `main.go` changes were successful, check the help text for the new `start` command. It should now include the `ev-abci` specific flags. |
| 167 | + |
| 168 | +```sh |
| 169 | +./<appd> start --help |
| 170 | +``` |
| 171 | + |
| 172 | +You should see flags like `--ev-node.attester-mode`, `--ev-node.aggregator`, and others from the `ev-node` and `network` modules. |
| 173 | + |
| 174 | +Your node is now fully configured to run using `ev-abci`. When you run the `start` command, it will no longer start a CometBFT instance but will instead start the `ev-abci` service that connects to a Rollkit sequencer, and it will correctly handle any on-chain migrations. |
0 commit comments