Skip to content

Commit ba590ac

Browse files
seidroid[bot]blindchasercursoragent
authored
Backport release/v6.7: feat: add migration pause handler (#4409)
Backport of #4405 to `release/v6.7`. Co-authored-by: yirenz <blindchaser@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0adcd5b commit ba590ac

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

‎app/abci_test.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"time"
99

1010
"github.com/sei-protocol/sei-chain/app/migration"
11+
"github.com/sei-protocol/sei-chain/app/upgrades/migrationpause"
12+
sctypes "github.com/sei-protocol/sei-chain/sei-db/state_db/sc/types"
1113
abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types"
1214
tmproto "github.com/sei-protocol/sei-chain/sei-tendermint/proto/tendermint/types"
1315
"github.com/stretchr/testify/require"
@@ -71,6 +73,40 @@ func TestApplyMigrationBatchSize(t *testing.T) {
7173
require.Equal(t, int(migration.MaxNumKeysToMigratePerBlock), got)
7274
}
7375

76+
func TestMigrationPauseHardForkPreservesInFlightMode(t *testing.T) {
77+
a := Setup(t, false, false, false)
78+
ctx := a.NewContext(false, tmproto.Header{Height: 1, ChainID: "sei-test", Time: time.Now()})
79+
80+
subspace, ok := a.ParamsKeeper.GetSubspace(migration.SubspaceName)
81+
require.True(t, ok)
82+
subspace.Set(ctx, migration.KeyNumKeysToMigratePerBlock, uint64(500))
83+
a.applyMigrationBatchSize(ctx)
84+
85+
modeBeforePause, ok := a.rootStore.GetWriteMode()
86+
require.True(t, ok)
87+
require.Equal(t, sctypes.MigrateEVM, modeBeforePause)
88+
89+
const recoveryHeight = int64(2)
90+
a.HardForkManager.RegisterHandler(
91+
migrationpause.NewHardForkHandler(recoveryHeight, ctx.ChainID(), a.ParamsKeeper),
92+
)
93+
ctx = ctx.WithBlockHeight(recoveryHeight)
94+
require.NotPanics(t, func() {
95+
a.BeginBlock(ctx, recoveryHeight, nil, nil, false)
96+
})
97+
98+
var storedRate uint64
99+
subspace.Get(ctx, migration.KeyNumKeysToMigratePerBlock, &storedRate)
100+
require.Zero(t, storedRate)
101+
effectiveRate, ok := a.rootStore.GetMigrationBatchSize()
102+
require.True(t, ok)
103+
require.Zero(t, effectiveRate)
104+
105+
modeAfterPause, ok := a.rootStore.GetWriteMode()
106+
require.True(t, ok)
107+
require.Equal(t, modeBeforePause, modeAfterPause)
108+
}
109+
74110
// TestBeginBlockAppliesMigrationBatchSize exercises the full BeginBlock path
75111
// (not the helper in isolation): it mimics a governance ParameterChangeProposal
76112
// having set NumKeysToMigratePerBlock, then runs app.BeginBlock and asserts the
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package migrationpause
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/sei-protocol/sei-chain/app/migration"
7+
"github.com/sei-protocol/sei-chain/app/upgrades"
8+
sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types"
9+
paramskeeper "github.com/sei-protocol/sei-chain/sei-cosmos/x/params/keeper"
10+
)
11+
12+
const upgradeName = "pause-state-migration"
13+
14+
// HardForkHandler sets the state migration rate to zero at a target height.
15+
type HardForkHandler struct {
16+
targetHeight int64
17+
targetChainID string
18+
paramsKeeper paramskeeper.Keeper
19+
}
20+
21+
// NewHardForkHandler returns a handler for pausing state migration on one chain.
22+
func NewHardForkHandler(
23+
height int64,
24+
chainID string,
25+
paramsKeeper paramskeeper.Keeper,
26+
) upgrades.HardForkHandler {
27+
return HardForkHandler{
28+
targetHeight: height,
29+
targetChainID: chainID,
30+
paramsKeeper: paramsKeeper,
31+
}
32+
}
33+
34+
func (h HardForkHandler) GetName() string {
35+
return fmt.Sprintf("%s-%d", upgradeName, h.targetHeight)
36+
}
37+
38+
func (h HardForkHandler) GetTargetChainID() string {
39+
return h.targetChainID
40+
}
41+
42+
func (h HardForkHandler) GetTargetHeight() int64 {
43+
return h.targetHeight
44+
}
45+
46+
func (h HardForkHandler) ExecuteHandler(ctx sdk.Context) error {
47+
subspace, ok := h.paramsKeeper.GetSubspace(migration.SubspaceName)
48+
if !ok {
49+
return fmt.Errorf("migration parameter subspace is not registered")
50+
}
51+
subspace.Set(ctx, migration.KeyNumKeysToMigratePerBlock, uint64(0))
52+
return nil
53+
}
54+
55+
var _ upgrades.HardForkHandler = HardForkHandler{}

0 commit comments

Comments
 (0)