forked from evmos/ethermint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.go
74 lines (61 loc) · 2.44 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package v010
import (
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
v09types "github.com/tharsis/ethermint/x/feemarket/migrations/v09/types"
"github.com/tharsis/ethermint/x/feemarket/types"
)
// KeyPrefixBaseFeeV1 is the base fee key prefix used in version 1
var KeyPrefixBaseFeeV1 = []byte{2}
// MigrateStore migrates the BaseFee value from the store to the params for
// In-Place Store migration logic.
func MigrateStore(ctx sdk.Context, paramstore *paramtypes.Subspace, storeKey sdk.StoreKey) error {
baseFee := types.DefaultParams().BaseFee
store := ctx.KVStore(storeKey)
if !paramstore.HasKeyTable() {
ps := paramstore.WithKeyTable(types.ParamKeyTable())
paramstore = &ps
}
switch {
case store.Has(KeyPrefixBaseFeeV1):
bz := store.Get(KeyPrefixBaseFeeV1)
baseFee = sdk.NewIntFromBigInt(new(big.Int).SetBytes(bz))
case paramstore.Has(ctx, types.ParamStoreKeyNoBaseFee):
paramstore.GetIfExists(ctx, types.ParamStoreKeyBaseFee, &baseFee)
}
var (
noBaseFee bool
baseFeeChangeDenom, elasticityMultiplier uint32
enableHeight int64
)
paramstore.GetIfExists(ctx, types.ParamStoreKeyNoBaseFee, &noBaseFee)
paramstore.GetIfExists(ctx, types.ParamStoreKeyBaseFeeChangeDenominator, &baseFeeChangeDenom)
paramstore.GetIfExists(ctx, types.ParamStoreKeyElasticityMultiplier, &elasticityMultiplier)
paramstore.GetIfExists(ctx, types.ParamStoreKeyEnableHeight, &enableHeight)
params := types.Params{
NoBaseFee: noBaseFee,
BaseFeeChangeDenominator: baseFeeChangeDenom,
ElasticityMultiplier: elasticityMultiplier,
BaseFee: baseFee,
EnableHeight: enableHeight,
}
paramstore.SetParamSet(ctx, ¶ms)
store.Delete(KeyPrefixBaseFeeV1)
return nil
}
// MigrateJSON accepts exported v0.9 x/feemarket genesis state and migrates it to
// v0.10 x/feemarket genesis state. The migration includes:
// - Migrate BaseFee to Params
func MigrateJSON(oldState v09types.GenesisState) types.GenesisState {
return types.GenesisState{
Params: types.Params{
NoBaseFee: oldState.Params.NoBaseFee,
BaseFeeChangeDenominator: oldState.Params.BaseFeeChangeDenominator,
ElasticityMultiplier: oldState.Params.ElasticityMultiplier,
EnableHeight: oldState.Params.EnableHeight,
BaseFee: oldState.BaseFee,
},
BlockGas: oldState.BlockGas,
}
}