Skip to content

Commit

Permalink
fix: upgradeHeight handling
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherbrumm committed Jan 31, 2025
1 parent 82c17d2 commit 992f9c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions x/bundles/keeper/getters_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ package keeper

import (
"encoding/binary"
"errors"
"github.com/KYVENetwork/chain/x/bundles/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k Keeper) GetBundlesMigrationUpgradeHeight(ctx sdk.Context) uint64 {
func (k Keeper) GetBundlesMigrationUpgradeHeight(ctx sdk.Context) (uint64, error) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))

return binary.BigEndian.Uint64(storeAdapter.Get(types.BundlesMigrationHeightKey))
if storeAdapter.Has(types.BundlesMigrationHeightKey) {
return binary.BigEndian.Uint64(storeAdapter.Get(types.BundlesMigrationHeightKey)), nil
}
return 0, errors.New("upgrade height can't be zero")
}

// SetBundlesMigrationUpgradeHeight stores the upgrade height of the v1.6 bundles migration
// SetBundlesMigrationUpgradeHeight stores the upgrade height of the v2.0 bundles migration
// upgrade in the KV-Store.
func (k Keeper) SetBundlesMigrationUpgradeHeight(ctx sdk.Context, upgradeHeight uint64) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
Expand Down
6 changes: 4 additions & 2 deletions x/bundles/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ func (am AppModule) BeginBlock(ctx context.Context) error {
am.keeper.InitMemStore(sdkCtx)
SplitInflation(sdkCtx, am.keeper, am.bankKeeper, am.mintKeeper, am.poolKeeper, am.teamKeeper, am.upgradeKeeper)

upgradeHeight := am.keeper.GetBundlesMigrationUpgradeHeight(sdkCtx)
migration.MigrateBundlesModule(sdkCtx, am.keeper, int64(upgradeHeight))
upgradeHeight, err := am.keeper.GetBundlesMigrationUpgradeHeight(sdkCtx)
if err == nil {
migration.MigrateBundlesModule(sdkCtx, am.keeper, int64(upgradeHeight))
}

return nil
}
Expand Down

0 comments on commit 992f9c1

Please sign in to comment.