2022-03-30 17:10:54 +00:00
|
|
|
package v010
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
2022-07-28 13:43:49 +00:00
|
|
|
sdkmath "cosmossdk.io/math"
|
|
|
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
2022-03-30 17:10:54 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
|
|
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
2022-06-19 09:43:41 +00:00
|
|
|
"github.com/evmos/ethermint/x/feemarket/migrations/v010/types"
|
|
|
|
v09types "github.com/evmos/ethermint/x/feemarket/migrations/v09/types"
|
2022-03-30 17:10:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2022-07-28 13:43:49 +00:00
|
|
|
func MigrateStore(ctx sdk.Context, paramstore *paramtypes.Subspace, storeKey storetypes.StoreKey) error {
|
2022-03-30 17:10:54 +00:00
|
|
|
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)
|
2022-07-28 13:43:49 +00:00
|
|
|
baseFee = sdkmath.NewIntFromBigInt(new(big.Int).SetBytes(bz))
|
2022-03-30 17:10:54 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|