-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathupgrade.go
74 lines (63 loc) · 2.42 KB
/
upgrade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2024 NASD Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package upgrade
import (
"context"
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
)
func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
capabilityKeeper *capabilitykeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
vm, err := mm.RunMigrations(ctx, cfg, vm)
if err != nil {
return vm, err
}
sdkCtx := sdk.UnwrapSDKContext(ctx)
FixICS27ChannelCapabilities(sdkCtx, capabilityKeeper)
return vm, nil
}
}
// FixICS27ChannelCapabilities finds all capabilities wrongfully owned by the
// ICA Controller module and replaces them with the ICA Host module. This was
// introduced in the v8 Helium upgrade after we executed the recommended ICS27
// migration logic for chains that utilize the ICA Controller module.
func FixICS27ChannelCapabilities(ctx sdk.Context, capabilityKeeper *capabilitykeeper.Keeper) {
index := capabilityKeeper.GetLatestIndex(ctx)
for i := uint64(1); i < index; i++ {
wrapper, ok := capabilityKeeper.GetOwners(ctx, i)
if !ok {
continue
}
for _, owner := range wrapper.GetOwners() {
if owner.Module == icacontrollertypes.SubModuleName {
wrapper.Remove(owner)
wrapper.Set(capabilitytypes.Owner{
Module: icahosttypes.SubModuleName,
Name: owner.Name,
})
}
}
capabilityKeeper.SetOwners(ctx, i, wrapper)
}
capabilityKeeper.InitMemStore(ctx)
}