Skip to content

Commit

Permalink
fix(migration): fix setting canonical light clients and gauged denom-…
Browse files Browse the repository at this point in the history
…metadata (#1680)
  • Loading branch information
mtsitrin authored Dec 28, 2024
1 parent 109d4d3 commit 94f7ccd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func CreateUpgradeHandler(
}
migrateSequencers(ctx, keepers.SequencerKeeper)

migrateRollappLightClients(ctx, keepers.RollappKeeper, keepers.LightClientKeeper, keepers.IBCKeeper.ChannelKeeper)
if err := migrateRollappLightClients(ctx, keepers.RollappKeeper, keepers.LightClientKeeper, keepers.IBCKeeper.ChannelKeeper); err != nil {
return nil, err
}
if err := migrateStreamer(ctx, keepers.StreamerKeeper, keepers.EpochsKeeper); err != nil {
return nil, err
}
Expand Down Expand Up @@ -205,23 +207,26 @@ func migrateRollapps(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper, dymns
return nil
}

func migrateRollappLightClients(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper, lightClientKeeper lightclientkeeper.Keeper, ibcChannelKeeper ibcchannelkeeper.Keeper) {
func migrateRollappLightClients(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper, lightClientKeeper lightclientkeeper.Keeper, ibcChannelKeeper ibcchannelkeeper.Keeper) error {
list := rollappkeeper.GetAllRollapps(ctx)
for _, rollapp := range list {
// check if the rollapp has a canonical channel already
if rollapp.ChannelId == "" {
return
continue
}

// get the client ID the channel belongs to
_, connection, err := ibcChannelKeeper.GetChannelConnection(ctx, ibctransfertypes.PortID, rollapp.ChannelId)
if err != nil {
// if could not find a connection, skip the canonical client assignment
return
return errorsmod.Wrapf(err, "could not find a connection for channel %s rollapp %s", rollapp.ChannelId, rollapp.RollappId)
}

clientID := connection.GetClientID()
// store the rollapp to canonical light client ID mapping
lightClientKeeper.SetCanonicalClient(ctx, rollapp.RollappId, clientID)
}

return nil
}

// migrateStreamer creates epoch pointers for all epoch infos and updates module params
Expand Down Expand Up @@ -326,7 +331,7 @@ func migrateGAMMPoolDenomMetadata(ctx sdk.Context, rk bankkeeper.Keeper) error {
denom := fmt.Sprintf("gamm/pool/%d", i)
dm, ok := rk.GetDenomMetaData(ctx, denom)
if !ok {
return errorsmod.Wrapf(banktypes.ErrDenomMetadataNotFound, "denom metadata not found for denom %s", denom)
break
}

if dm.Name == "" {
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {
// Create and store sequencers
s.seedAndStoreSequencers(numRollapps)

// TODO: create and store IBC clients and connections, to test migration of canonical clients

s.seedPendingRollappPackets()

s.seedRollappFinalizationQueue()
Expand Down Expand Up @@ -437,7 +439,6 @@ func (s *UpgradeTestSuite) seedRollapps(numRollapps int) []rollapptypes.Rollapp
RollappId: rollappID,
Owner: sample.AccAddressFromSecret(rollappID),
GenesisState: rollapptypes.RollappGenesisState{},
ChannelId: fmt.Sprintf("channel-%d", i),
}
rollapps[i] = rollapp
}
Expand Down
3 changes: 1 addition & 2 deletions x/rollapp/types/chain_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ func NewChainID(id string) (ChainID, error) {
}

matches := ethermintChainID.FindStringSubmatch(chainID)

if matches == nil || len(matches) != 4 || matches[1] == "" {
return ChainID{}, ErrInvalidRollappID
return ChainID{}, errorsmod.Wrapf(ErrInvalidRollappID, "invalid chain-id format: %s", chainID)
}
// verify that the chain-id entered is a base 10 integer
chainIDInt, ok := new(big.Int).SetString(matches[2], 10)
Expand Down

0 comments on commit 94f7ccd

Please sign in to comment.