-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathmigrate.go
41 lines (34 loc) · 1.41 KB
/
migrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package v10
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/node/x/observer/types"
)
type observerKeeper interface {
GetChainParamsList(ctx sdk.Context) (val types.ChainParamsList, found bool)
SetChainParamsList(ctx sdk.Context, chainParams types.ChainParamsList)
}
// MigrateStore migrates the x/observer module state from the consensus version 9 to version 10.
// The migration sets existing 'confirmation_count' as default value for newly added fields:
// - 'safe_inbound_count'
// - 'fast_inbound_count'
// - 'safe_outbound_count'
// - 'fast_outbound_count'
func MigrateStore(ctx sdk.Context, observerKeeper observerKeeper) error {
allChainParams, found := observerKeeper.GetChainParamsList(ctx)
if !found {
return errorsmod.Wrap(types.ErrChainParamsNotFound, "failed to get chain params")
}
// set new fields to the same value as 'confirmation_count'
for _, chainParams := range allChainParams.ChainParams {
if chainParams != nil {
chainParams.Confirmation.SafeInboundCount = chainParams.ConfirmationCount
chainParams.Confirmation.FastInboundCount = chainParams.ConfirmationCount
chainParams.Confirmation.SafeOutboundCount = chainParams.ConfirmationCount
chainParams.Confirmation.FastOutboundCount = chainParams.ConfirmationCount
}
}
// set the updated chain params list
observerKeeper.SetChainParamsList(ctx, allChainParams)
return nil
}