Skip to content

Commit a25c7ef

Browse files
feat(flatkv): combine the post-evm flatkv migration phases into one MigrateCosmos (#4561)
## Summary Phase 2 and phase 3 of the memiavl -> flatkv migration are merged into a single transition, `MigrateCosmos`. It moves every non-`evm/` module, `bank/` included, from memiavl to flatkv in one pass. The migration chain becomes: `memiavl_only -> migrate_evm -> evm_migrated -> migrate_cosmos -> flatkv_only` Migration version 2 is now the `flatkv_only` terminal state. The `migrate_all_but_bank`, `all_migrated_but_bank` and `migrate_bank` modes are removed, and version 3 is unknown. In v6.7, version 2 meant all-but-bank. Reusing it is safe because no node in sync with a network can hold that layout: v6.7 starts at runtime only `memiavl_only -> migrate_evm`, so an auto node never entered `migrate_all_but_bank`. A node pinned to it would have migrated alone and failed AppHash verification at its first migrating block. Keeping `flatkv_only` at version 3 was tried and reverted. Only a node that finished all-but-bank alone can hold v6.7's version 2, and a diverging node halts at the next block, so the gap would guard a state that cannot exist. The existing `NumKeysToMigratePerBlock` gov param paces the new migration, so phase 1's governance flow is reused as is. A new chain-state param, `MigrateCosmosEnabled`, gates the step past EVM. The v6.8 upgrade handler and `InitChainer` both set it, so upgraded chains and chains started from genesis on this binary can both run the migration. Rollout: governance has already set `NumKeysToMigratePerBlock` back to 0, so v6.8 opens the gate while the migration stays paused. `MigrateCosmos` starts at the first block after a gov proposal raises the rate, the same flow v6.7 used for `MigrateEVM`. With a rate above 0 at the upgrade, it would start at the upgrade height + 1, because `BeginBlock` reads the gate before the upgrade handler runs. - `sei-db/state_db/sc/types/write_mode.go`: `MigrateCosmos` replaces the three old modes. `ValidateTransition` admits exactly four edges: `MemiavlOnly -> MigrateEVM`, `MigrateEVM -> EVMMigrated`, `EVMMigrated -> MigrateCosmos`, `MigrateCosmos -> FlatKVOnly`. - `sei-db/state_db/sc/migration/migration_versions.go`: versions are `0` memiavl only, `1` EVM migrated, `2` flatkv only. - `sei-db/state_db/sc/migration/derive_write_mode.go`: version 1 with an in-flight boundary derives `MigrateCosmos`. Version 2 derives `FlatKVOnly`. A boundary at version 2 is rejected as corrupt metadata, and any other version is rejected as unknown. `IsModeComplete(MigrateCosmos)` is true once version 2 is persisted. - `sei-db/state_db/sc/migration/router_builder.go`: `buildMigrateCosmosRouter` routes `evm/` straight to flatkv and every other module through one `MigrationManager` (start version 1, target version 2) whose iterator covers all non-`evm/` stores. - `sei-db/state_db/sc/composite/store.go`: AppHash and export gating key on `MigrateCosmos` completion. Memiavl's per-store infos leave the commit info at the commit that persists version 2, while the live mode is still `MigrateCosmos`. That keeps a live node and a restarted node (which derives `FlatKVOnly`) byte-identical. The exclusion latch resets on rollback below completion. `IsWriteModeComplete` exposes completion to the root store. - `sei-cosmos/storev2/rootmulti/store.go`: `SetMigrationBatchSize(batchSize, allowMigrateCosmos bool)` runs as named steps. `readyForNextMigration` decides whether a migration is due: `migrate_evm` from `memiavl_only`, and, with the gate open, `migrate_cosmos` from `evm_migrated` or from a `migrate_evm` store whose EVM migration is complete. `mayAdvanceWriteMode` then skips a pinned store and logs the skip once per batch size. Because readiness is checked first, a pinned `migrate_evm` node does not report a divergence while the network is still migrating EVM. `startNextMigration` advances `migrate_evm -> evm_migrated -> migrate_cosmos` in the same call. A store that cannot report migration completion returns an error rather than skipping silently. The transition is level-triggered, so a node that crashes before the next commit starts it again on the next block. - `app/migration/params.go`: adds `MigrateCosmosEnabled` (bool) to the `migration` subspace. An absent value means false, so a pre-v6.8 chain cannot start the migration. Governance can set it back to false, which prevents a new start but does not stop a MigrateCosmos in progress. - `app/abci.go`: `applyMigrationBatchSize` reads `MigrateCosmosEnabled` from chain state each block and passes it with the batch size. Every node reads the same value at the same height, so the transition is consensus-deterministic. - `app/app.go`, `app/upgrades.go`: `InitChainer` and the v6.8 upgrade handler call `enableMigrateCosmos`, which sets the param to true. Both writes happen only at the v6.8 upgrade height and at genesis. Before v6.8 the param is absent, so blocks replay as on main. - `sei-db/config/sc_config.go`, `sei-db/config/toml.go`: valid `sc-write-mode` values are now `memiavl_only`, `migrate_evm`, `evm_migrated`, `migrate_cosmos`, `flatkv_only`, `test_only_dual_write`, `auto`. - `sei-db/state_db/sc/migration/README.md`, `OPERATIONS.md`: the state machine and docs describe the V0 -> V1 -> V2 chain. The diagrams for the removed phases are deleted. `OPERATIONS.md` states that one rate increase runs both migrations back to back, and that clearing `MigrateCosmosEnabled` does not stop a MigrateCosmos in progress. ## Test plan - `app/abci_test.go` - `TestMigrateCosmosEnabledAtGenesis`: a chain started from genesis has `MigrateCosmosEnabled = true`. - `TestMigrateCosmosGate`: drives real blocks at the maximum rate. With the param true, the store reaches `migrate_cosmos`. With the param false, it stays in `migrate_evm`; opening the gate then starts `migrate_cosmos` on the first block that reads it, which shows the EVM migration was complete and only the gate held it. - `app/upgrade_v68_test.go` - `TestV68EnablesMigrateCosmos`: clears the param, applies v6.8, and asserts the param is true. - `TestV68PrunesTokenfactoryParams`: removes `MigrateCosmosEnabled` before the snapshot, and requires v6.8 to delete the tokenfactory subspace, write `MigrateCosmosEnabled = true`, and change nothing else in the params store. - `app/upgrade_v68_offline_target_test.go`: `requireV68OfflineMigrateCosmosEnabled` requires the v6.7 source snapshot to hold no `MigrateCosmosEnabled` and the migrated database to hold it set to true. The harness diff checks only recorded keys, so the added key is checked directly. - `sei-cosmos/storev2/rootmulti/set_write_mode_test.go` - `TestRootMultiMigrateCosmosGateClosedAfterEVMComplete`: with the EVM migration confirmed complete, a closed gate leaves the store in `migrate_evm`. - `TestRootMultiMigrateCosmosGateOpenStartsFromLiveAndRestartedState`: an open gate starts `MigrateCosmos` both from a live `migrate_evm` store and from a store restarted into `evm_migrated`. - `TestRootMultiMigrateCosmosGateOpenRestartBeforeFirstCommitReKicks`: a `MigrateCosmos` start that no commit persisted derives `evm_migrated` after a restart, and the next open-gate call starts it again. - `TestRootMultiMigrateCosmosGateOpenPinnedEVMMigratedSkips`: a store pinned to `evm_migrated` is not advanced by an open gate and logs the skip. - `TestRootMultiMigrateCosmosGateOpenPinnedMigrateEVMInFlightIsQuiet`: a store pinned to `migrate_evm` with its EVM migration in flight logs nothing. It fails against the previous ordering. - `sei-db/state_db/sc/migration/migration_transitions_test.go` - `TestMigrateCosmos`: V1 -> V2 across all real modules, with a restart mid-migration that resumes from the persisted boundary. After completion, every module's keys are in flatkv, memiavl is empty, and version 2 is persisted with no boundary. - `sei-db/state_db/sc/migration/migration_steady_state_test.go`: the `FlatKVOnly` steady-state router routes every module to flatkv. - `sei-db/state_db/sc/migration/derive_write_mode_test.go`: version and boundary combinations derive the right mode. A version-2 boundary and unknown versions, 3 included, are rejected. `IsModeComplete` uses the new target versions. - `sei-db/state_db/sc/types/write_mode_test.go`: the four legal transitions, migration-mode classification, and string round-trips. - `sei-db/state_db/sc/composite/store_migration_test.go` - Memiavl leaves the commit info exactly at the version-2 commit, and the live and restarted commit infos stay byte-identical. - `TestComposite_MigrateCosmos_RollbackAcrossCompletionBoundary`, `TestComposite_Auto_RollbackAcrossMigrateCosmosCompletionAfterRestart`: rollback below completion re-includes memiavl and derives the mode again. - `TestComposite_PinnedFlatKVOnly_RefusesRollbackIntoMigrateCosmos`: a pinned `flatkv_only` store refuses a rollback below completion. - `sei-db/state_db/sc/composite/store_auto_test.go`, `random_test.go`: an auto store walks the full chain to version 2. `TestRandomMigration_MigrateCosmos` runs randomized workloads through the merged transition. - `sei-db/config/toml_test.go`: the rendered template lists the new valid modes. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3f2dd73 commit a25c7ef

34 files changed

Lines changed: 898 additions & 823 deletions

‎app/abci.go‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,18 @@ func (app *App) BeginBlock(
5757
}
5858
}
5959

60-
// applyMigrationBatchSize paces the SC store's background data migration at the network-agreed rate.
61-
// The NumKeysToMigratePerBlock gov param is read from chain state so every node
62-
// applies the same value each block; a per-node rate would diverge the
63-
// AppHash. 0 (the default until a gov proposal raises it) leaves the migration
64-
// paused; it is the sole source of the rate (there is no node-local fallback).
60+
// applyMigrationBatchSize paces the SC store's background data migrations at
61+
// the network-agreed rate. The NumKeysToMigratePerBlock gov param is read from
62+
// chain state so every node applies the same value each block; a per-node rate
63+
// would diverge the AppHash. 0 (the default until a gov proposal raises it)
64+
// leaves the current migration paused; it is the sole source of the rate (there
65+
// is no node-local fallback).
6566
func (app *App) applyMigrationBatchSize(ctx sdk.Context) {
6667
if app.rootStore == nil {
6768
return
6869
}
6970
numKeys := migration.DefaultNumKeysToMigratePerBlock
71+
allowMigrateCosmos := false
7072
if subspace, ok := app.ParamsKeeper.GetSubspace(migration.SubspaceName); ok {
7173
// The migration subspace has no owning module to seed it in InitGenesis,
7274
// so lazily persist the default the first time we see it unset. This is
@@ -77,6 +79,7 @@ func (app *App) applyMigrationBatchSize(ctx sdk.Context) {
7779
subspace.Set(ctx, migration.KeyNumKeysToMigratePerBlock, migration.DefaultNumKeysToMigratePerBlock)
7880
}
7981
subspace.GetIfExists(ctx, migration.KeyNumKeysToMigratePerBlock, &numKeys)
82+
subspace.GetIfExists(ctx, migration.KeyMigrateCosmosEnabled, &allowMigrateCosmos)
8083
}
8184
// Defense-in-depth: gov validation already rejects values above
8285
// MaxNumKeysToMigratePerBlock, but clamp here too so an out-of-range value
@@ -86,7 +89,7 @@ func (app *App) applyMigrationBatchSize(ctx sdk.Context) {
8689
if numKeys > migration.MaxNumKeysToMigratePerBlock {
8790
numKeys = migration.MaxNumKeysToMigratePerBlock
8891
}
89-
if err := app.rootStore.SetMigrationBatchSize(int(numKeys)); err != nil {
92+
if err := app.rootStore.SetMigrationBatchSize(int(numKeys), allowMigrateCosmos); err != nil {
9093
// Never panic on the migration-rate update: log and continue. AppHash
9194
// verification is the safety net. If the rate/mode update fails on only
9295
// some nodes, those nodes' AppHash diverges and the normal AppHash
@@ -99,6 +102,16 @@ func (app *App) applyMigrationBatchSize(ctx sdk.Context) {
99102
}
100103
}
101104

105+
// enableMigrateCosmos records in chain state that the SC store may start the
106+
// MigrateCosmos migration once its EVM migration is complete.
107+
func (app *App) enableMigrateCosmos(ctx sdk.Context) {
108+
subspace, ok := app.ParamsKeeper.GetSubspace(migration.SubspaceName)
109+
if !ok {
110+
panic("migration parameter subspace is not registered")
111+
}
112+
subspace.Set(ctx, migration.KeyMigrateCosmosEnabled, true)
113+
}
114+
102115
func (app *App) MidBlock(ctx sdk.Context, height int64) []abci.Event {
103116
_, span := app.GetBaseApp().TracingInfo.StartWithContext("MidBlock", ctx.TraceSpanContext())
104117
defer span.End()

‎app/abci_test.go‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app
22

33
import (
44
"context"
5+
"fmt"
56
"math"
67
"strings"
78
"testing"
@@ -194,6 +195,81 @@ func TestMigrationBatchSizeAppliedAtBlockStart(t *testing.T) {
194195
require.Equal(t, 640, got, "BeginBlock must apply a param already in state when the block starts")
195196
}
196197

198+
// TestMigrateCosmosEnabledAtGenesis pins that a chain started from genesis on
199+
// this binary may start MigrateCosmos without a v6.8 upgrade record.
200+
func TestMigrateCosmosEnabledAtGenesis(t *testing.T) {
201+
a := Setup(t, false, false, false)
202+
subspace, ok := a.ParamsKeeper.GetSubspace(migration.SubspaceName)
203+
require.True(t, ok)
204+
205+
var enabled bool
206+
subspace.GetIfExists(a.GetContextForDeliverTx([]byte{}), migration.KeyMigrateCosmosEnabled, &enabled)
207+
require.True(t, enabled, "InitChainer must enable MigrateCosmos")
208+
}
209+
210+
// TestMigrateCosmosGate drives real blocks at the maximum rate and checks that
211+
// the store advances past the EVM migration only when MigrateCosmosEnabled is
212+
// set. With the gate open the store walks the whole chain: MigrateCosmos
213+
// completes within a block at this rate, and the next block's BeginBlock then
214+
// lands it in flatkv_only.
215+
func TestMigrateCosmosGate(t *testing.T) {
216+
for _, tc := range []struct {
217+
enabled bool
218+
wantMode sctypes.WriteMode
219+
}{
220+
{enabled: false, wantMode: sctypes.MigrateEVM},
221+
{enabled: true, wantMode: sctypes.FlatKVOnly},
222+
} {
223+
t.Run(fmt.Sprintf("enabled=%v", tc.enabled), func(t *testing.T) {
224+
a := Setup(t, false, false, false)
225+
bg := context.Background()
226+
227+
subspace, ok := a.ParamsKeeper.GetSubspace(migration.SubspaceName)
228+
require.True(t, ok)
229+
ctx := a.GetContextForDeliverTx([]byte{})
230+
subspace.Set(ctx, migration.KeyNumKeysToMigratePerBlock, migration.MaxNumKeysToMigratePerBlock)
231+
subspace.Set(ctx, migration.KeyMigrateCosmosEnabled, tc.enabled)
232+
233+
runBlock := func(height int64) {
234+
_, err := a.FinalizeBlock(bg, &abci.RequestFinalizeBlock{
235+
Header: &tmproto.Header{ChainID: "sei-test", Height: height, Time: time.Now()},
236+
})
237+
require.NoError(t, err)
238+
_, err = a.Commit(bg)
239+
require.NoError(t, err)
240+
}
241+
for height := int64(1); height <= 5; height++ {
242+
runBlock(height)
243+
}
244+
245+
mode, ok := a.rootStore.GetWriteMode()
246+
require.True(t, ok)
247+
require.Equal(t, tc.wantMode, mode)
248+
if tc.enabled {
249+
return
250+
}
251+
252+
// Opening the gate must start MigrateCosmos on the first block that
253+
// reads it, which shows the EVM migration was already complete and
254+
// only the closed gate held the store in migrate_evm. The write
255+
// lands with block 6's commit, so block 7 is that first block.
256+
subspace.Set(a.NewUncachedContext(false, tmproto.Header{}), migration.KeyMigrateCosmosEnabled, true)
257+
runBlock(6)
258+
runBlock(7)
259+
mode, ok = a.rootStore.GetWriteMode()
260+
require.True(t, ok)
261+
require.Equal(t, sctypes.MigrateCosmos, mode)
262+
263+
// Block 7 completes MigrateCosmos; block 8's BeginBlock observes
264+
// the persisted version and leaves the migration router.
265+
runBlock(8)
266+
mode, ok = a.rootStore.GetWriteMode()
267+
require.True(t, ok)
268+
require.Equal(t, sctypes.FlatKVOnly, mode)
269+
})
270+
}
271+
}
272+
197273
func TestIBCStoreQueriesAreUnavailable(t *testing.T) {
198274
testApp := Setup(t, false, false, false)
199275

‎app/app.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
11101110
}
11111111
}
11121112
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
1113+
app.enableMigrateCosmos(ctx)
11131114
return app.mm.InitGenesis(ctx, app.appCodec, genesisState, app.genesisImportConfig)
11141115
}
11151116

‎app/migration/params.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,29 @@ const DefaultNumKeysToMigratePerBlock uint64 = 0
3737
// at a safe size, so we reject anything larger at proposal-validation time.
3838
const MaxNumKeysToMigratePerBlock uint64 = 1_000_000
3939

40+
// KeyMigrateCosmosEnabled is the param key that allows an SC store to start
41+
// the MigrateCosmos migration once its EVM migration is complete. The v6.8
42+
// upgrade and InitChainer set it to true; an absent value means false. Setting
43+
// it to false prevents a new start but does not stop a MigrateCosmos in
44+
// progress; set NumKeysToMigratePerBlock to 0 to pause that.
45+
var KeyMigrateCosmosEnabled = []byte("MigrateCosmosEnabled")
46+
4047
// ParamKeyTable returns the key table for the migration subspace.
4148
func ParamKeyTable() paramtypes.KeyTable {
4249
return paramtypes.NewKeyTable(
4350
paramtypes.NewParamSetPair(KeyNumKeysToMigratePerBlock, new(uint64), validateNumKeysToMigratePerBlock),
51+
paramtypes.NewParamSetPair(KeyMigrateCosmosEnabled, new(bool), validateMigrateCosmosEnabled),
4452
)
4553
}
4654

55+
// validateMigrateCosmosEnabled type-checks the MigrateCosmosEnabled value.
56+
func validateMigrateCosmosEnabled(i interface{}) error {
57+
if _, ok := i.(bool); !ok {
58+
return fmt.Errorf("invalid parameter type: %T", i)
59+
}
60+
return nil
61+
}
62+
4763
// validateNumKeysToMigratePerBlock type-checks the value and bounds it to
4864
// MaxNumKeysToMigratePerBlock. 0 means "paused"; any rate in [0, max] is a
4965
// valid (consensus-deterministic) value. Rejecting oversized values here, at

‎app/upgrade_v68_offline_target_test.go‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"testing"
1515
"time"
1616

17+
"github.com/sei-protocol/sei-chain/app/migration"
1718
"github.com/sei-protocol/sei-chain/sei-cosmos/crypto/keys/secp256k1"
1819
"github.com/sei-protocol/sei-chain/sei-cosmos/store/prefix"
1920
sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types"
@@ -149,9 +150,10 @@ func applyV68OfflineUpgradeCrashReplay(t *testing.T, root string, artifact offli
149150
// is recorded, the retired module versions and stores are gone, the vesting
150151
// accounts are rewritten, the retired IBC proposal reads back as a text
151152
// proposal, the upgraded IBC client record, the denom allowlists and the
152-
// tokenfactory parameters are pruned, the wasm flag parameters are stored, the
153-
// IBC voucher balance and supply are intact and spendable, every delegation is
154-
// indexed by validator, and nothing else in the retained stores changed.
153+
// tokenfactory parameters are pruned, the wasm flag parameters are stored,
154+
// MigrateCosmos is enabled, the IBC voucher balance and supply are intact and
155+
// spendable, every delegation is indexed by validator, and nothing else in the
156+
// retained stores changed.
155157
func requireV68OfflineMigrated(t *testing.T, testApp *App, artifact offlineUpgradeArtifact) {
156158
t.Helper()
157159
requireV68OfflineAppliedName(t, testApp, artifact)
@@ -163,6 +165,7 @@ func requireV68OfflineMigrated(t *testing.T, testApp *App, artifact offlineUpgra
163165
requireV68OfflineDenomAllowListsPruned(t, testApp, artifact.Stores[banktypes.StoreKey])
164166
requireV68OfflineTokenfactoryParamsPruned(t, testApp, artifact.Stores[paramstypes.StoreKey])
165167
requireV68OfflineWasmFlagsStored(t, testApp, artifact.Stores[paramstypes.StoreKey])
168+
requireV68OfflineMigrateCosmosEnabled(t, testApp, artifact.Stores[paramstypes.StoreKey])
166169
requireV68OfflineVoucher(t, testApp, artifact.Retained)
167170
requireV68OfflineDelegationIndex(t, testApp)
168171
requireOfflineUpgradeRetainedStoresExcept(t, testApp, artifact.Stores, v68OfflineTouchedKey(t, artifact))
@@ -480,6 +483,18 @@ func requireV68OfflineWasmFlagsStored(t *testing.T, testApp *App, sourceParams m
480483
}
481484
}
482485

486+
// requireV68OfflineMigrateCosmosEnabled requires the source phase's params
487+
// snapshot to hold no MigrateCosmosEnabled parameter and the committed params
488+
// store to hold it set to true.
489+
func requireV68OfflineMigrateCosmosEnabled(t *testing.T, testApp *App, sourceParams map[string]string) {
490+
t.Helper()
491+
key := []byte(migration.SubspaceName + "/" + string(migration.KeyMigrateCosmosEnabled))
492+
_, recorded := sourceParams[encodeOfflineUpgradeKey(key)]
493+
require.False(t, recorded, "the source phase already held MigrateCosmosEnabled")
494+
store := testApp.CommitMultiStore().GetCommitKVStore(testApp.GetKey(paramstypes.StoreKey))
495+
require.Equal(t, []byte("true"), store.Get(key), "v6.8 did not enable MigrateCosmos")
496+
}
497+
483498
func requireV68OfflineVoucher(t *testing.T, testApp *App, retained offlineUpgradeRetainedState) {
484499
t.Helper()
485500
ctx, _ := offlineUpgradeReadContext(testApp, testApp.LastBlockHeight()).CacheContext()

‎app/upgrade_v68_test.go‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/sei-protocol/sei-chain/app"
14+
"github.com/sei-protocol/sei-chain/app/migration"
1415
"github.com/sei-protocol/sei-chain/app/retiredoracle"
1516
"github.com/sei-protocol/sei-chain/app/retiredtokenfactory"
1617
"github.com/sei-protocol/sei-chain/app/retiredvesting"
@@ -661,10 +662,10 @@ func TestV68DenomAllowListPruneIsBounded(t *testing.T) {
661662
require.Equal(t, sdk.NewInt64Coin(kept, 40), a.BankKeeper.GetBalance(a.Ctx(), recipient, kept))
662663
}
663664

664-
// TestV68PrunesTokenfactoryParams pins that every entry of the tokenfactory
665-
// parameter subspace is deleted from the params store and that nothing else in
666-
// the store changes. The subspace holds the parameter v6.7 keeps and a creation
667-
// fee an older tokenfactory version left behind.
665+
// TestV68PrunesTokenfactoryParams pins that v6.8 deletes every entry of the
666+
// tokenfactory parameter subspace, writes MigrateCosmosEnabled, and changes
667+
// nothing else in the params store. The subspace holds the parameter v6.7 keeps
668+
// and a creation fee an older tokenfactory version left behind.
668669
func TestV68PrunesTokenfactoryParams(t *testing.T) {
669670
a := newV68Chain(t)
670671
store := a.Ctx().KVStore(a.GetKey(paramstypes.StoreKey))
@@ -676,15 +677,33 @@ func TestV68PrunesTokenfactoryParams(t *testing.T) {
676677
store.Set([]byte(key), []byte(value))
677678
}
678679
store.Set([]byte("tokenfactoryless"), []byte("unrelated"))
680+
migrateCosmosEnabled := migration.SubspaceName + "/" + string(migration.KeyMigrateCosmosEnabled)
681+
store.Delete([]byte(migrateCosmosEnabled))
679682
kept := v68PrefixEntries(t, store, nil)
680683
for key := range retired {
681684
delete(kept, key)
682685
}
686+
kept[migrateCosmosEnabled] = []byte("true")
683687

684688
applyV68(t, a)
685689

686690
require.Equal(t, kept, v68PrefixEntries(t, store, nil),
687-
"v6.8 changed the params store beyond deleting the tokenfactory subspace")
691+
"v6.8 changed the params store beyond deleting the tokenfactory subspace and enabling MigrateCosmos")
692+
}
693+
694+
// TestV68EnablesMigrateCosmos pins that the upgrade allows the SC store to
695+
// start MigrateCosmos once its EVM migration is complete.
696+
func TestV68EnablesMigrateCosmos(t *testing.T) {
697+
a := newV68Chain(t)
698+
subspace, ok := a.ParamsKeeper.GetSubspace(migration.SubspaceName)
699+
require.True(t, ok)
700+
subspace.Set(a.Ctx(), migration.KeyMigrateCosmosEnabled, false)
701+
702+
applyV68(t, a)
703+
704+
var enabled bool
705+
subspace.Get(a.Ctx(), migration.KeyMigrateCosmosEnabled, &enabled)
706+
require.True(t, enabled, "v6.8 must enable MigrateCosmos")
688707
}
689708

690709
// TestV68StoresTheWasmFlags pins that v6.8 stores the wasm

‎app/upgrades.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func (app *App) RegisterUpgradeHandlers() {
173173
app.pruneDenomAllowLists(ctx)
174174
app.pruneTokenfactoryParams(ctx)
175175
app.StakingKeeper.StartDelegationByValIndexBackfill(ctx)
176+
app.enableMigrateCosmos(ctx)
176177
return newVM, nil
177178
}
178179

‎sei-cosmos/storev2/rootmulti/flatkv_helpers_test.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ func migrateEVMConfig() seidbconfig.StateCommitConfig {
132132
return withTestMemIAVL(cfg)
133133
}
134134

135+
func migrateCosmosConfig() seidbconfig.StateCommitConfig {
136+
cfg := seidbconfig.DefaultStateCommitConfig()
137+
cfg.WriteMode = sctypes.MigrateCosmos
138+
return withTestMemIAVL(cfg)
139+
}
140+
135141
// restartRootMultiWithConfig closes the given store and reopens a fresh
136142
// rootmulti store rooted at the same dir under newCfg. This is the
137143
// shortest reliable simulation of the production "operator stops the

‎sei-cosmos/storev2/rootmulti/flatkv_migration_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func driveRootMultiMigration(
106106

107107
// --- Restart: MemiavlOnly -> MigrateEVM ---
108108
store, storeKeys = restartRootMultiWithConfig(t, store, dir, migrateEVMConfig())
109-
require.NoError(t, store.SetMigrationBatchSize(migrateBatchSize))
109+
require.NoError(t, store.SetMigrationBatchSize(migrateBatchSize, false))
110110

111111
for i := phase1Blocks + 1; i <= phase1Blocks+phase2Blocks; i++ {
112112
records = append(records, simulateBlock(t, store, storeKeys, i, addrBase))
@@ -153,7 +153,7 @@ func TestRootMultiMigrateEVM_ReopenPreservesPreFlipAppHash(t *testing.T) {
153153
require.NotEmpty(t, preFlipID.Hash)
154154

155155
store, storeKeys = restartRootMultiWithConfig(t, store, dir, migrateEVMConfig())
156-
require.NoError(t, store.SetMigrationBatchSize(2))
156+
require.NoError(t, store.SetMigrationBatchSize(2, false))
157157
defer func() { require.NoError(t, store.Close()) }()
158158

159159
require.Equal(t, preFlipID, store.LastCommitID(),
@@ -173,7 +173,7 @@ func TestRootMultiMigrateEVM_EmptyBlocksAdvanceMigration(t *testing.T) {
173173
simulateBlockManyStorage(t, store, storeKeys, 1, storageKeys, addrBase)
174174

175175
store, _ = restartRootMultiWithConfig(t, store, dir, migrateEVMConfig())
176-
require.NoError(t, store.SetMigrationBatchSize(2))
176+
require.NoError(t, store.SetMigrationBatchSize(2, false))
177177

178178
for i := 0; i < 4; i++ {
179179
rec := finalizeBlock(t, store)
@@ -199,7 +199,7 @@ func TestRootMultiMigrateEVM_EVMIteratorAvailableDuringMigration(t *testing.T) {
199199
require.Equal(t, int64(1), rec.version)
200200

201201
store, storeKeys = restartRootMultiWithConfig(t, store, dir, migrateEVMConfig())
202-
require.NoError(t, store.SetMigrationBatchSize(2))
202+
require.NoError(t, store.SetMigrationBatchSize(2, false))
203203
defer func() { require.NoError(t, store.Close()) }()
204204

205205
cms = store.CacheMultiStore()
@@ -411,7 +411,7 @@ func TestRootMultiMigrateEVM_DoubleFlushAppHashStable(t *testing.T) {
411411
// per-block advances are required to drain. ---
412412
const batch = 4
413413
store, storeKeys = restartRootMultiWithConfig(t, store, dir, migrateEVMConfig())
414-
require.NoError(t, store.SetMigrationBatchSize(batch))
414+
require.NoError(t, store.SetMigrationBatchSize(batch, false))
415415
defer func() { require.NoError(t, store.Close()) }()
416416

417417
// Alternate empty blocks (exercise the "empty changesets in

0 commit comments

Comments
 (0)