Skip to content

chore: denom traces migration handler #1680

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

Merged
merged 37 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
96f3c49
fix broken link
charleenfei Jun 10, 2022
250e45f
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jun 14, 2022
bf3b96b
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jun 16, 2022
ed4a153
fix: rm AllowUpdateAfter... check (#1118)
charleenfei Jun 14, 2022
8018627
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jun 16, 2022
08e71e7
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jun 20, 2022
05f50c4
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jun 23, 2022
169ead2
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jun 24, 2022
7c46b84
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jul 5, 2022
27998dd
erge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jul 6, 2022
952b114
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jul 8, 2022
7a1d263
first commit
charleenfei Jul 8, 2022
a5b3ff6
register migrator service
charleenfei Jul 8, 2022
b33f4df
testing
charleenfei Jul 12, 2022
f673132
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jul 12, 2022
0b2f4c2
test
charleenfei Jul 14, 2022
78d4616
Merge branch 'main' of github.com:cosmos/ibc-go
charleenfei Jul 14, 2022
3084982
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 14, 2022
b1cd41f
test
charleenfei Jul 14, 2022
3c07902
update docs and tests
charleenfei Jul 14, 2022
6110232
update docs for migration handler
charleenfei Jul 15, 2022
87a97e6
fix for empty baseDenom
charleenfei Jul 18, 2022
ecbd10a
update docs
charleenfei Jul 18, 2022
35ea75e
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 18, 2022
7660328
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 19, 2022
cd8c867
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 19, 2022
0f91661
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 19, 2022
9a44480
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 19, 2022
96aabb5
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 19, 2022
b608e89
update tests, rm empty base denom in trace.go
charleenfei Jul 20, 2022
b86cdd8
Parse ICS20 denomination using channel identifier format (#1730)
colin-axner Jul 20, 2022
45fdc09
Merge branch 'main' into charly/denom_traces_migration_handler
crodriguezvega Jul 21, 2022
60785a6
Update support-denoms-with-slashes.md
crodriguezvega Jul 21, 2022
38c93bc
rm redundant err
charleenfei Jul 21, 2022
515e0e7
Merge branch 'main' into charly/denom_traces_migration_handler
charleenfei Jul 21, 2022
a2fe4ae
fix error
charleenfei Jul 21, 2022
d999103
Merge branch 'charly/denom_traces_migration_handler' of github.com:co…
charleenfei Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions modules/apps/transfer/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the intention that all transfer related migrations will happen here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes -- the cosmos sdk has all migrations in a separate directory but imo that might be overkill for us. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for us it makes sense to have them here, we can worry about additional directories if we end up with a large number of migrations.

return Migrator{keeper: keeper}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
var iterErr error

// list of traces that must replace the old traces in store
var newTraces []types.DenomTrace
m.keeper.IterateDenomTraces(ctx,
func(dt types.DenomTrace) (stop bool) {
// check if the new way of splitting FullDenom
// into Trace and BaseDenom passes validation and
// is the same as the current DenomTrace.
// If it isn't then store the new DenomTrace in the list of new traces.
newTrace := types.ParseDenomTrace(dt.GetFullDenomPath())
err := newTrace.Validate()
if err != nil {
iterErr = err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if there's anything we should do if this (unlikely) scenario happens: if there's a corrupt denom trace and that blocks the migration to complete, is there anything we can do or document to help chains?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should just panic and then have the chain devs export a snapshot and manually address the situation? What do you think?

Copy link
Contributor Author

@charleenfei charleenfei Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is extremely unlikely to happen unless the migration happens from an exported genesis which was manually corrupted -- i think it could make sense rather than panicking the err here to simply pass back to the UpgradeHandler and have the app devs deal with it how they want... does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case, couldn't we return the error immediately? Instead of continuing to do unnecessary work... I'm assuming that the upgrade handler and RunMigrations will likely bubble up the error and revert any changes so I think it seems unnecessary to continue parsing traces if we encounter an error for some unforeseen reason!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do stop the parsing and then return the error in the current code, is there another way to return the error that you think would make more sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I missed the return true underneath here due to the thread of comments!

return true
}
if !equalTraces(newTrace, dt) {
newTraces = append(newTraces, newTrace)
}
iterErr = err
return false
})

// replace the outdated traces with the new trace information
for _, nt := range newTraces {
m.keeper.SetDenomTrace(ctx, nt)
}
return iterErr
}

func equalTraces(dtA, dtB types.DenomTrace) bool {
return dtA.BaseDenom == dtB.BaseDenom && dtA.Path == dtB.Path
}
7 changes: 6 additions & 1 deletion modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier {
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

m := keeper.NewMigrator(am.keeper)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Sprintf("failed to migrate transfer app from version 1 to 2: %v", err))
}
}

// InitGenesis performs genesis initialization for the ibc-transfer module. It returns
Expand All @@ -139,7 +144,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 { return 2 }

// BeginBlock implements the AppModule interface
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
Expand Down