Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration code standartization #1160

Closed
omritoptix opened this issue Aug 31, 2024 · 2 comments · May be fixed by #1429
Closed

Migration code standartization #1160

omritoptix opened this issue Aug 31, 2024 · 2 comments · May be fixed by #1429
Assignees

Comments

@omritoptix
Copy link
Contributor

Currently we have some migration code, with similiar logic (e.g migrating params) written in upgrade.go and some in ad-hoc migration files.

we need to have a standard place for writing migration code and agree which code, if any, goes directly to the upgrade.go module.

@danwt
Copy link
Contributor

danwt commented Nov 6, 2024

Known example of adhoc

package sequencer
import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
seqkeeper "github.com/dymensionxyz/dymension/v3/x/sequencer/keeper"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)
type (
ParamSet = paramtypes.ParamSet
// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
}
)
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper *seqkeeper.Keeper
legacySubspace Subspace
}
// NewMigrator returns a new Migrator.
func NewMigrator(keeper *seqkeeper.Keeper, ss Subspace) Migrator {
return Migrator{keeper: keeper, legacySubspace: ss}
}
// Migrate2to3 migrates from version 2 to 3.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
var currParams types.Params
m.legacySubspace.GetParamSet(ctx, &currParams)
if err := currParams.ValidateBasic(); err != nil {
return err
}
m.keeper.SetParams(ctx, currParams)
return nil
}

@danwt
Copy link
Contributor

danwt commented Nov 6, 2024

I think it's fine to have everything in app/upgrades/v4

Here are more specific issues

@danwt danwt closed this as completed Nov 6, 2024
@zale144 zale144 mentioned this issue Nov 7, 2024
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants