This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* changelog: v0.12.2 * fix
- Loading branch information
Showing
11 changed files
with
1,019 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package v010_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
|
||
"github.com/tharsis/ethermint/encoding" | ||
|
||
"github.com/tharsis/ethermint/app" | ||
feemarketkeeper "github.com/tharsis/ethermint/x/feemarket/keeper" | ||
v010 "github.com/tharsis/ethermint/x/feemarket/migrations/v010" | ||
"github.com/tharsis/ethermint/x/feemarket/types" | ||
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types" | ||
) | ||
|
||
func TestMigrateStore(t *testing.T) { | ||
encCfg := encoding.MakeConfig(app.ModuleBasics) | ||
feemarketKey := sdk.NewKVStoreKey(feemarkettypes.StoreKey) | ||
tFeeMarketKey := sdk.NewTransientStoreKey(fmt.Sprintf("%s_test", feemarkettypes.StoreKey)) | ||
ctx := testutil.DefaultContext(feemarketKey, tFeeMarketKey) | ||
paramstore := paramtypes.NewSubspace( | ||
encCfg.Marshaler, encCfg.Amino, feemarketKey, tFeeMarketKey, "feemarket", | ||
) | ||
fmKeeper := feemarketkeeper.NewKeeper(encCfg.Marshaler, feemarketKey, paramstore) | ||
fmKeeper.SetParams(ctx, types.DefaultParams()) | ||
require.True(t, paramstore.HasKeyTable()) | ||
|
||
// check that the fee market is not nil | ||
err := v010.MigrateStore(ctx, ¶mstore, feemarketKey) | ||
require.NoError(t, err) | ||
require.False(t, ctx.KVStore(feemarketKey).Has(v010.KeyPrefixBaseFeeV1)) | ||
|
||
params := fmKeeper.GetParams(ctx) | ||
require.False(t, params.BaseFee.IsNil()) | ||
|
||
baseFee := fmKeeper.GetBaseFee(ctx) | ||
require.NotNil(t, baseFee) | ||
|
||
require.Equal(t, baseFee.Int64(), params.BaseFee.Int64()) | ||
} |
Oops, something went wrong.