Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
increase feemarket's consensus version and add migration handler
Browse files Browse the repository at this point in the history
Closes: #1001
  • Loading branch information
yihuang committed Mar 17, 2022
1 parent edf4569 commit d7fab63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions x/feemarket/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package keeper

import (
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
Expand All @@ -11,3 +17,15 @@ func NewMigrator(keeper Keeper) Migrator {
keeper: keeper,
}
}

func (m Migrator) Migrate1to2(ctx sdk.Context) error {
store := ctx.KVStore(m.keeper.storeKey)
baseFeeKeyPrefix := []byte{2}
bz := store.Get(baseFeeKeyPrefix)
if len(bz) > 0 {
baseFee := new(big.Int).SetBytes(bz)
m.keeper.SetBaseFee(ctx, baseFee)
}
store.Delete(baseFeeKeyPrefix)
return nil
}
8 changes: 6 additions & 2 deletions x/feemarket/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {

// ConsensusVersion returns the consensus state-breaking version for the module.
func (AppModuleBasic) ConsensusVersion() uint64 {
return 1
return 2
}

// DefaultGenesis returns default genesis state as raw bytes for the fee market
Expand Down Expand Up @@ -117,7 +117,11 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

_ = keeper.NewMigrator(am.keeper)
m := keeper.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
if err != nil {
panic(err)
}
}

// Route returns the message routing key for the fee market module.
Expand Down

0 comments on commit d7fab63

Please sign in to comment.