@agoric/cosmos 0.34.2-dev-70d05b1.0.70d05b1 → 0.34.2-dev-4ea2a82.0.4ea2a82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -0
- package/ante/ante.go +2 -2
- package/app/app.go +73 -96
- package/app/sim_test.go +0 -2
- package/app/upgrade.go +6 -6
- package/daemon/cmd/root_test.go +1 -0
- package/git-revision.txt +1 -1
- package/go.mod +83 -116
- package/go.sum +162 -130
- package/go.work +39 -0
- package/go.work.sum +2636 -0
- package/package.json +2 -2
- package/proto/Dockerfile +14 -0
- package/proto/agoric/swingset/msgs.proto +1 -0
- package/proto/agoric/vbank/msgs.proto +5 -1
- package/proto/agoric/vibc/msgs.proto +45 -2
- package/scripts/protocgen.sh +10 -1
- package/tests/integrations/types/aminojson_test.go +18 -2
- package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +2 -3
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +2 -3
- package/third_party/proto/ibc/core/channel/v1/channel.proto +6 -22
- package/third_party/proto/ibc/core/client/v1/client.proto +6 -53
- package/types/address_hooks.go +2 -2
- package/types/address_hooks_test.go +3 -3
- package/types/ibc_packet.go +3 -3
- package/types/ibc_packet_test.go +3 -3
- package/x/swingset/types/msgs.pb.go +90 -89
- package/x/vbank/types/msgs.pb.go +10 -8
- package/x/vibc/alias.go +0 -1
- package/x/vibc/keeper/dynamic_router.go +176 -0
- package/x/vibc/keeper/dynamic_router_test.go +240 -0
- package/x/vibc/keeper/keeper.go +40 -81
- package/x/vibc/keeper/migrations.go +1 -1
- package/x/vibc/keeper/scope.go +114 -0
- package/x/vibc/keeper/triggers.go +8 -4
- package/x/vibc/types/expected_keepers.go +7 -20
- package/x/vibc/types/ibc_module.go +13 -20
- package/x/vibc/types/msgs.go +60 -3
- package/x/vibc/types/msgs.pb.go +683 -31
- package/x/vibc/types/receiver.go +2 -2
- package/x/vlocalchain/vlocalchain_test.go +1 -1
- package/x/vtransfer/ibc_middleware.go +15 -17
- package/x/vtransfer/ibc_middleware_test.go +30 -53
- package/x/vtransfer/keeper/keeper.go +19 -28
- package/x/vtransfer/types/expected_keepers.go +15 -8
- package/x/vtransfer/utils_test.go +4 -9
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
package keeper
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
"testing"
|
|
6
|
+
|
|
7
|
+
"cosmossdk.io/log"
|
|
8
|
+
"cosmossdk.io/store"
|
|
9
|
+
storemetrics "cosmossdk.io/store/metrics"
|
|
10
|
+
storetypes "cosmossdk.io/store/types"
|
|
11
|
+
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
12
|
+
dbm "github.com/cosmos/cosmos-db"
|
|
13
|
+
"github.com/cosmos/cosmos-sdk/runtime"
|
|
14
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
15
|
+
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
|
|
16
|
+
porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
|
|
17
|
+
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
18
|
+
"github.com/stretchr/testify/require"
|
|
19
|
+
|
|
20
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
21
|
+
vibc "github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
var vibcStoreKey = storetypes.NewKVStoreKey(vibc.StoreKey)
|
|
25
|
+
|
|
26
|
+
type noopIBCModule struct {
|
|
27
|
+
name string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func (noopIBCModule) OnChanOpenInit(sdk.Context, channeltypes.Order, []string, string, string, channeltypes.Counterparty, string) (string, error) {
|
|
31
|
+
return "", nil
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func (noopIBCModule) OnChanOpenTry(sdk.Context, channeltypes.Order, []string, string, string, channeltypes.Counterparty, string) (string, error) {
|
|
35
|
+
return "", nil
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func (noopIBCModule) OnChanOpenAck(sdk.Context, string, string, string, string) error {
|
|
39
|
+
return nil
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func (noopIBCModule) OnChanOpenConfirm(sdk.Context, string, string) error {
|
|
43
|
+
return nil
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func (noopIBCModule) OnChanCloseInit(sdk.Context, string, string) error {
|
|
47
|
+
return nil
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func (noopIBCModule) OnChanCloseConfirm(sdk.Context, string, string) error {
|
|
51
|
+
return nil
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func (noopIBCModule) OnRecvPacket(sdk.Context, string, channeltypes.Packet, sdk.AccAddress) ibcexported.Acknowledgement {
|
|
55
|
+
return nil
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func (noopIBCModule) OnAcknowledgementPacket(sdk.Context, string, channeltypes.Packet, []byte, sdk.AccAddress) error {
|
|
59
|
+
return nil
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func (noopIBCModule) OnTimeoutPacket(sdk.Context, string, channeltypes.Packet, sdk.AccAddress) error {
|
|
63
|
+
return nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func makeTestContext(t *testing.T) sdk.Context {
|
|
67
|
+
t.Helper()
|
|
68
|
+
|
|
69
|
+
db := dbm.NewMemDB()
|
|
70
|
+
logger := log.NewNopLogger()
|
|
71
|
+
ms := store.NewCommitMultiStore(db, logger, storemetrics.NewNoOpMetrics())
|
|
72
|
+
ms.MountStoreWithDB(vibcStoreKey, storetypes.StoreTypeIAVL, db)
|
|
73
|
+
require.NoError(t, ms.LoadLatestVersion())
|
|
74
|
+
|
|
75
|
+
return sdk.NewContext(ms, tmproto.Header{}, false, logger)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func resolveWithFallback(router porttypes.PortRouter, portID string) (porttypes.IBCModule, bool) {
|
|
79
|
+
if route, ok := router.Route(portID); ok {
|
|
80
|
+
return route, true
|
|
81
|
+
}
|
|
82
|
+
for _, prefix := range router.Keys() {
|
|
83
|
+
if strings.Contains(portID, prefix) {
|
|
84
|
+
return router.Route(prefix)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return nil, false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
func TestDynamicPortRouterBindsAndRoutesExactPorts(t *testing.T) {
|
|
91
|
+
baseModule := &noopIBCModule{name: "base"}
|
|
92
|
+
dynamicModule := &noopIBCModule{name: "dynamic"}
|
|
93
|
+
router := NewDynamicPortRouter(porttypes.NewRouter().AddRoute("transfer", baseModule))
|
|
94
|
+
|
|
95
|
+
require.NoError(t, router.BindPort("icacontroller-1", dynamicModule))
|
|
96
|
+
|
|
97
|
+
route, ok := router.Route("icacontroller-1")
|
|
98
|
+
require.True(t, ok)
|
|
99
|
+
require.Equal(t, dynamicModule, route)
|
|
100
|
+
|
|
101
|
+
baseRoute, ok := router.Route("transfer")
|
|
102
|
+
require.True(t, ok)
|
|
103
|
+
require.Equal(t, baseModule, baseRoute)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func TestDynamicPortRouterDelegatesFallbackToBaseRoutes(t *testing.T) {
|
|
107
|
+
baseModule := &noopIBCModule{name: "base"}
|
|
108
|
+
router := NewDynamicPortRouter(porttypes.NewRouter().AddRoute("icacontroller", baseModule))
|
|
109
|
+
|
|
110
|
+
route, ok := resolveWithFallback(router, "icacontroller-1")
|
|
111
|
+
require.True(t, ok)
|
|
112
|
+
require.Equal(t, baseModule, route)
|
|
113
|
+
require.Equal(t, []string{"icacontroller"}, router.Keys())
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func TestDynamicPortRouterDelegatesLegacyPrefixRoutes(t *testing.T) {
|
|
117
|
+
baseModule := &noopIBCModule{name: "base"}
|
|
118
|
+
legacyModule := &noopIBCModule{name: "legacy"}
|
|
119
|
+
router := NewDynamicPortRouter(porttypes.NewRouter().AddRoute("transfer", baseModule))
|
|
120
|
+
router.AddLegacyPrefixRoute("icacontroller-", legacyModule)
|
|
121
|
+
router.AddLegacyPrefixRoute("port-", legacyModule)
|
|
122
|
+
router.AddLegacyPrefixRoute("i", legacyModule)
|
|
123
|
+
|
|
124
|
+
route, ok := resolveWithFallback(router, "icacontroller-1")
|
|
125
|
+
require.True(t, ok)
|
|
126
|
+
require.Equal(t, legacyModule, route)
|
|
127
|
+
|
|
128
|
+
route, ok = resolveWithFallback(router, "port-7")
|
|
129
|
+
require.True(t, ok)
|
|
130
|
+
require.Equal(t, legacyModule, route)
|
|
131
|
+
|
|
132
|
+
require.Equal(t, []string{"i", "icacontroller-", "port-", "transfer"}, router.Keys())
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
func TestPortRouterAllowsHostValidatedLegacyPrefixes(t *testing.T) {
|
|
136
|
+
module := &noopIBCModule{name: "legacy"}
|
|
137
|
+
|
|
138
|
+
require.NotPanics(t, func() {
|
|
139
|
+
porttypes.NewRouter().
|
|
140
|
+
AddRoute("i", module).
|
|
141
|
+
AddRoute("icacontroller-", module).
|
|
142
|
+
AddRoute("icqcontroller-", module).
|
|
143
|
+
AddRoute("port-", module).
|
|
144
|
+
AddRoute("custom-", module)
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
func TestPortRouterRejectsInvalidRouteIdentifiers(t *testing.T) {
|
|
149
|
+
module := &noopIBCModule{name: "legacy"}
|
|
150
|
+
|
|
151
|
+
for _, route := range []string{"foo/bar", "with space", "ümlaut"} {
|
|
152
|
+
t.Run(route, func(t *testing.T) {
|
|
153
|
+
require.Panics(t, func() {
|
|
154
|
+
porttypes.NewRouter().AddRoute(route, module)
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
func TestDynamicPortRouterAllowsLegacyPrefixRoutesWithTrailingDash(t *testing.T) {
|
|
161
|
+
legacyModule := &noopIBCModule{name: "legacy"}
|
|
162
|
+
router := NewDynamicPortRouter(porttypes.NewRouter())
|
|
163
|
+
|
|
164
|
+
require.NotPanics(t, func() {
|
|
165
|
+
router.AddLegacyPrefixRoute("icacontroller-", legacyModule)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
route, ok := resolveWithFallback(router, "icacontroller-1")
|
|
169
|
+
require.True(t, ok)
|
|
170
|
+
require.Equal(t, legacyModule, route)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
func TestDynamicPortRouterRejectsInvalidAndCollidingPorts(t *testing.T) {
|
|
174
|
+
baseModule := &noopIBCModule{name: "base"}
|
|
175
|
+
dynamicModule := &noopIBCModule{name: "dynamic"}
|
|
176
|
+
router := NewDynamicPortRouter(porttypes.NewRouter().
|
|
177
|
+
AddRoute("transfer", baseModule).
|
|
178
|
+
AddRoute("icacontroller", baseModule))
|
|
179
|
+
|
|
180
|
+
require.Error(t, router.BindPort("bad port", dynamicModule))
|
|
181
|
+
require.NoError(t, router.BindPort("port-1", dynamicModule))
|
|
182
|
+
require.ErrorContains(t, router.BindPort("port-1", dynamicModule), "already dynamically bound")
|
|
183
|
+
require.ErrorContains(t, router.BindPort("transfer", dynamicModule), "collides with an existing static route")
|
|
184
|
+
require.ErrorContains(t, router.BindPort("icacontroller-1", dynamicModule), "collides with an existing static route")
|
|
185
|
+
|
|
186
|
+
legacyRouter := NewDynamicPortRouter(porttypes.NewRouter())
|
|
187
|
+
legacyRouter.AddLegacyPrefixRoute("custom-", baseModule)
|
|
188
|
+
require.ErrorContains(t, legacyRouter.BindPort("custom-1", dynamicModule), "collides with an existing static route")
|
|
189
|
+
require.NoError(t, legacyRouter.BindPort("custom-1", baseModule))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
func TestDynamicPortRouterRevokeRestoresFallback(t *testing.T) {
|
|
193
|
+
baseModule := &noopIBCModule{}
|
|
194
|
+
dynamicModule := &noopIBCModule{}
|
|
195
|
+
router := NewDynamicPortRouter(porttypes.NewRouter().AddRoute("transfer", baseModule))
|
|
196
|
+
|
|
197
|
+
require.NoError(t, router.BindPort("custom-1", dynamicModule))
|
|
198
|
+
require.NoError(t, router.RevokePort("custom-1"))
|
|
199
|
+
require.ErrorContains(t, router.RevokePort("custom-1"), "is not dynamically bound")
|
|
200
|
+
|
|
201
|
+
_, ok := router.Route("custom-1")
|
|
202
|
+
require.False(t, ok)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func TestDynamicPortScopePersistsAndReloadsBindings(t *testing.T) {
|
|
206
|
+
ctx := makeTestContext(t)
|
|
207
|
+
module := &noopIBCModule{name: "dynamic"}
|
|
208
|
+
storeService := runtime.NewKVStoreService(vibcStoreKey)
|
|
209
|
+
|
|
210
|
+
router := NewDynamicPortRouter(porttypes.NewRouter())
|
|
211
|
+
scope := NewDynamicPortScope(storeService, router, func(sdk.Context, vm.Action) error { return nil })
|
|
212
|
+
scope.SetDynamicModule(module)
|
|
213
|
+
|
|
214
|
+
require.NoError(t, scope.BindPort(ctx, "icacontroller-1"))
|
|
215
|
+
require.True(t, router.HasRoute("icacontroller-1"))
|
|
216
|
+
|
|
217
|
+
reloadedRouter := NewDynamicPortRouter(porttypes.NewRouter())
|
|
218
|
+
reloadedScope := NewDynamicPortScope(storeService, reloadedRouter, func(sdk.Context, vm.Action) error { return nil })
|
|
219
|
+
reloadedScope.SetDynamicModule(module)
|
|
220
|
+
|
|
221
|
+
require.NoError(t, reloadedScope.LoadBindings(ctx))
|
|
222
|
+
require.True(t, reloadedRouter.HasRoute("icacontroller-1"))
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
func TestKeeperReceiveBindPortUsesDynamicScope(t *testing.T) {
|
|
226
|
+
ctx := makeTestContext(t)
|
|
227
|
+
module := &noopIBCModule{name: "dynamic"}
|
|
228
|
+
storeService := runtime.NewKVStoreService(vibcStoreKey)
|
|
229
|
+
router := NewDynamicPortRouter(porttypes.NewRouter())
|
|
230
|
+
scope := NewDynamicPortScope(storeService, router, func(sdk.Context, vm.Action) error { return nil })
|
|
231
|
+
scope.SetDynamicModule(module)
|
|
232
|
+
|
|
233
|
+
keeper := NewKeeper(nil, nil, nil).WithScope(scope)
|
|
234
|
+
require.NoError(t, keeper.ReceiveBindPort(ctx, "port-1"))
|
|
235
|
+
require.True(t, router.HasRoute("port-1"))
|
|
236
|
+
|
|
237
|
+
require.ErrorContains(t, keeper.ReceiveBindPort(ctx, "port-1"), "already dynamically bound")
|
|
238
|
+
require.NoError(t, keeper.RevokePort(ctx, "port-1"))
|
|
239
|
+
require.False(t, router.HasRoute("port-1"))
|
|
240
|
+
}
|
package/x/vibc/keeper/keeper.go
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
package keeper
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
|
|
6
|
-
corestore "cosmossdk.io/core/store"
|
|
7
4
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
8
5
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
|
|
15
|
-
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
|
|
16
|
-
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
|
|
7
|
+
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
|
|
8
|
+
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
|
|
9
|
+
porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
|
|
10
|
+
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
17
11
|
|
|
12
|
+
agtypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
18
13
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
19
14
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
20
15
|
)
|
|
@@ -30,43 +25,36 @@ type Keeper struct {
|
|
|
30
25
|
cdc codec.Codec
|
|
31
26
|
|
|
32
27
|
channelKeeper types.ChannelKeeper
|
|
33
|
-
portKeeper types.PortKeeper
|
|
34
28
|
clientKeeper types.ClientKeeper
|
|
35
29
|
|
|
36
30
|
// Filled out by `WithScope`
|
|
37
|
-
|
|
38
|
-
storeService corestore.KVStoreService
|
|
39
|
-
pushAction vm.ActionPusher
|
|
31
|
+
scope *DynamicPortScope
|
|
40
32
|
}
|
|
41
33
|
|
|
42
34
|
// NewKeeper creates a new vibc Keeper instance
|
|
43
35
|
func NewKeeper(
|
|
44
36
|
cdc codec.Codec,
|
|
45
37
|
channelKeeper types.ChannelKeeper,
|
|
46
|
-
portKeeper types.PortKeeper,
|
|
47
38
|
clientKeeper types.ClientKeeper,
|
|
48
39
|
) Keeper {
|
|
49
40
|
|
|
50
41
|
return Keeper{
|
|
51
42
|
cdc: cdc,
|
|
52
43
|
channelKeeper: channelKeeper,
|
|
53
|
-
portKeeper: portKeeper,
|
|
54
44
|
clientKeeper: clientKeeper,
|
|
55
45
|
}
|
|
56
46
|
}
|
|
57
47
|
|
|
58
48
|
// WithScope returns a new Keeper copied from the receiver, but with the given
|
|
59
|
-
//
|
|
60
|
-
func (k Keeper) WithScope(
|
|
61
|
-
k.
|
|
62
|
-
k.scopedKeeper = scopedKeeper
|
|
63
|
-
k.pushAction = pushAction
|
|
49
|
+
// dynamic port scope.
|
|
50
|
+
func (k Keeper) WithScope(scope *DynamicPortScope) Keeper {
|
|
51
|
+
k.scope = scope
|
|
64
52
|
return k
|
|
65
53
|
}
|
|
66
54
|
|
|
67
55
|
// PushAction sends a vm.Action to the VM controller.
|
|
68
56
|
func (k Keeper) PushAction(ctx sdk.Context, action vm.Action) error {
|
|
69
|
-
return k.
|
|
57
|
+
return k.scope.PushAction(ctx, action)
|
|
70
58
|
}
|
|
71
59
|
|
|
72
60
|
// GetICS4Wrapper returns the ICS4Wrapper interface for the keeper.
|
|
@@ -90,20 +78,10 @@ func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (channelty
|
|
|
90
78
|
func (k Keeper) ReceiveChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string,
|
|
91
79
|
portID, rPortID, version string,
|
|
92
80
|
) error {
|
|
93
|
-
capName := host.PortPath(portID)
|
|
94
|
-
portCap, ok := k.GetCapability(ctx, capName)
|
|
95
|
-
if !ok {
|
|
96
|
-
return sdkioerrors.Wrapf(porttypes.ErrInvalidPort, "could not retrieve port capability at: %s", capName)
|
|
97
|
-
}
|
|
98
81
|
counterparty := channeltypes.Counterparty{
|
|
99
82
|
PortId: rPortID,
|
|
100
83
|
}
|
|
101
|
-
channelID,
|
|
102
|
-
if err != nil {
|
|
103
|
-
return err
|
|
104
|
-
}
|
|
105
|
-
chanCapName := host.ChannelCapabilityPath(portID, channelID)
|
|
106
|
-
err = k.ClaimCapability(ctx, chanCap, chanCapName)
|
|
84
|
+
channelID, err := k.channelKeeper.ChanOpenInit(ctx, order, connectionHops, portID, counterparty, version)
|
|
107
85
|
if err != nil {
|
|
108
86
|
return err
|
|
109
87
|
}
|
|
@@ -120,44 +98,32 @@ func (k Keeper) ReceiveSendPacket(ctx sdk.Context, packet ibcexported.PacketI) (
|
|
|
120
98
|
timeoutTimestamp := packet.GetTimeoutTimestamp()
|
|
121
99
|
data := packet.GetData()
|
|
122
100
|
|
|
123
|
-
|
|
124
|
-
chanCap, ok := k.GetCapability(ctx, capName)
|
|
125
|
-
if !ok {
|
|
126
|
-
return 0, sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
127
|
-
}
|
|
128
|
-
return k.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
|
|
101
|
+
return k.SendPacket(ctx, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
|
|
129
102
|
}
|
|
130
103
|
|
|
131
104
|
// SendPacket defines a wrapper function for the channel Keeper's function
|
|
132
105
|
// in order to expose it to the vibc IBC handler.
|
|
133
106
|
func (k Keeper) SendPacket(
|
|
134
107
|
ctx sdk.Context,
|
|
135
|
-
chanCap *capability.Capability,
|
|
136
108
|
sourcePort string,
|
|
137
109
|
sourceChannel string,
|
|
138
110
|
timeoutHeight clienttypes.Height,
|
|
139
111
|
timeoutTimestamp uint64,
|
|
140
112
|
data []byte,
|
|
141
113
|
) (uint64, error) {
|
|
142
|
-
return k.channelKeeper.SendPacket(ctx,
|
|
114
|
+
return k.channelKeeper.SendPacket(ctx, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
|
|
143
115
|
}
|
|
144
116
|
|
|
145
117
|
// ReceiveWriteAcknowledgement wraps the keeper's WriteAcknowledgment function.
|
|
146
118
|
func (k Keeper) ReceiveWriteAcknowledgement(ctx sdk.Context, packet ibcexported.PacketI, ack ibcexported.Acknowledgement) error {
|
|
147
|
-
|
|
148
|
-
channelID := packet.GetDestChannel()
|
|
149
|
-
capName := host.ChannelCapabilityPath(portID, channelID)
|
|
150
|
-
chanCap, ok := k.GetCapability(ctx, capName)
|
|
151
|
-
if !ok {
|
|
152
|
-
return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
153
|
-
}
|
|
154
|
-
return k.WriteAcknowledgement(ctx, chanCap, packet, ack)
|
|
119
|
+
return k.WriteAcknowledgement(ctx, packet, ack)
|
|
155
120
|
}
|
|
156
121
|
|
|
157
122
|
// WriteAcknowledgement defines a wrapper function for the channel Keeper's function
|
|
158
123
|
// in order to expose it to the vibc IBC handler.
|
|
159
|
-
func (k Keeper) WriteAcknowledgement(ctx sdk.Context,
|
|
160
|
-
|
|
124
|
+
func (k Keeper) WriteAcknowledgement(ctx sdk.Context, packet ibcexported.PacketI, ack ibcexported.Acknowledgement) error {
|
|
125
|
+
channelPacket := agtypes.CopyToChannelPacket(packet)
|
|
126
|
+
return k.channelKeeper.WriteAcknowledgement(ctx, channelPacket, ack)
|
|
161
127
|
}
|
|
162
128
|
|
|
163
129
|
// ReceiveWriteOpenTryChannel wraps the keeper's WriteOpenTryChannel function.
|
|
@@ -178,12 +144,7 @@ func (k Keeper) WriteOpenTryChannel(ctx sdk.Context, portID, channelID string, o
|
|
|
178
144
|
// ReceiveChanCloseInit is a wrapper function for the channel Keeper's function
|
|
179
145
|
// in order to expose it to the vibc IBC handler.
|
|
180
146
|
func (k Keeper) ReceiveChanCloseInit(ctx sdk.Context, portID, channelID string) error {
|
|
181
|
-
|
|
182
|
-
chanCap, ok := k.GetCapability(ctx, capName)
|
|
183
|
-
if !ok {
|
|
184
|
-
return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
185
|
-
}
|
|
186
|
-
err := k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap)
|
|
147
|
+
err := k.channelKeeper.ChanCloseInit(ctx, portID, channelID)
|
|
187
148
|
if err != nil {
|
|
188
149
|
return err
|
|
189
150
|
}
|
|
@@ -193,35 +154,33 @@ func (k Keeper) ReceiveChanCloseInit(ctx sdk.Context, portID, channelID string)
|
|
|
193
154
|
// ReceiveBindPort is a wrapper function for the port Keeper's function in order
|
|
194
155
|
// to expose it to the vibc IBC handler.
|
|
195
156
|
func (k Keeper) ReceiveBindPort(ctx sdk.Context, portID string) error {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
157
|
+
return k.BindPort(ctx, portID)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// BindPort dynamically binds an exact port ID to the vibc IBC module.
|
|
161
|
+
func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
|
|
162
|
+
return k.scope.BindPort(ctx, portID)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// RevokePort removes a previously dynamic exact port binding.
|
|
166
|
+
func (k Keeper) RevokePort(ctx sdk.Context, portID string) error {
|
|
167
|
+
return k.scope.RevokePort(ctx, portID)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// LoadDynamicPortBindings rehydrates persisted dynamic bindings into the live router.
|
|
171
|
+
func (k Keeper) LoadDynamicPortBindings(ctx sdk.Context) error {
|
|
172
|
+
return k.scope.LoadBindings(ctx)
|
|
203
173
|
}
|
|
204
174
|
|
|
205
175
|
// ReceiveTimeoutExecuted is a wrapper function for the channel Keeper's
|
|
206
176
|
// function in order to expose it to the vibc IBC handler.
|
|
207
177
|
func (k Keeper) ReceiveTimeoutExecuted(ctx sdk.Context, packet ibcexported.PacketI) error {
|
|
208
|
-
|
|
209
|
-
channelID := packet.GetSourceChannel()
|
|
210
|
-
capName := host.ChannelCapabilityPath(portID, channelID)
|
|
211
|
-
chanCap, ok := k.GetCapability(ctx, capName)
|
|
212
|
-
if !ok {
|
|
213
|
-
return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
214
|
-
}
|
|
215
|
-
return k.channelKeeper.TimeoutExecuted(ctx, chanCap, packet)
|
|
178
|
+
return k.TimeoutExecuted(ctx, packet)
|
|
216
179
|
}
|
|
217
180
|
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
func (k Keeper)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
// GetCapability allows the vibc module to retrieve a capability.
|
|
225
|
-
func (k Keeper) GetCapability(ctx sdk.Context, name string) (*capability.Capability, bool) {
|
|
226
|
-
return k.scopedKeeper.GetCapability(ctx, name)
|
|
181
|
+
// TimeoutExecuted defines a wrapper function for the channel Keeper's function
|
|
182
|
+
// in order to expose it to the vibc IBC handler.
|
|
183
|
+
func (k Keeper) TimeoutExecuted(ctx sdk.Context, packet ibcexported.PacketI) error {
|
|
184
|
+
channelPacket := agtypes.CopyToChannelPacket(packet)
|
|
185
|
+
return k.channelKeeper.TimeoutExecuted(ctx, channelPacket)
|
|
227
186
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
package keeper
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
|
|
6
|
+
corestore "cosmossdk.io/core/store"
|
|
7
|
+
"cosmossdk.io/store/prefix"
|
|
8
|
+
"github.com/cosmos/cosmos-sdk/runtime"
|
|
9
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
|
+
porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
|
|
11
|
+
|
|
12
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const boundPortStoreKeyPrefix = "boundPort-"
|
|
16
|
+
|
|
17
|
+
type DynamicPortScope struct {
|
|
18
|
+
storeService corestore.KVStoreService
|
|
19
|
+
router *DynamicPortRouter
|
|
20
|
+
pushAction vm.ActionPusher
|
|
21
|
+
module porttypes.IBCModule
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func NewDynamicPortScope(
|
|
25
|
+
storeService corestore.KVStoreService,
|
|
26
|
+
router *DynamicPortRouter,
|
|
27
|
+
pushAction vm.ActionPusher,
|
|
28
|
+
) *DynamicPortScope {
|
|
29
|
+
return &DynamicPortScope{
|
|
30
|
+
storeService: storeService,
|
|
31
|
+
router: router,
|
|
32
|
+
pushAction: pushAction,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func (s *DynamicPortScope) SetDynamicModule(module porttypes.IBCModule) {
|
|
37
|
+
s.module = module
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func (s *DynamicPortScope) PushAction(ctx sdk.Context, action vm.Action) error {
|
|
41
|
+
return s.pushAction(ctx, action)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func (s *DynamicPortScope) BindPort(ctx sdk.Context, portID string) error {
|
|
45
|
+
if s.router == nil {
|
|
46
|
+
return fmt.Errorf("dynamic port router is not configured")
|
|
47
|
+
}
|
|
48
|
+
if s.storeService == nil {
|
|
49
|
+
return fmt.Errorf("dynamic port store is not configured")
|
|
50
|
+
}
|
|
51
|
+
if s.module == nil {
|
|
52
|
+
return fmt.Errorf("dynamic port module is not configured")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if err := s.router.BindPort(portID, s.module); err != nil {
|
|
56
|
+
return err
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
store := s.boundPortStore(ctx)
|
|
60
|
+
store.Set([]byte(portID), []byte{1})
|
|
61
|
+
return nil
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
func (s *DynamicPortScope) RevokePort(ctx sdk.Context, portID string) error {
|
|
65
|
+
if s.router == nil {
|
|
66
|
+
return fmt.Errorf("dynamic port router is not configured")
|
|
67
|
+
}
|
|
68
|
+
if s.storeService == nil {
|
|
69
|
+
return fmt.Errorf("dynamic port store is not configured")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
store := s.boundPortStore(ctx)
|
|
73
|
+
if !store.Has([]byte(portID)) {
|
|
74
|
+
return fmt.Errorf("port %s is not dynamically bound", portID)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
store.Delete([]byte(portID))
|
|
78
|
+
if err := s.router.RevokePort(portID); err != nil {
|
|
79
|
+
store.Set([]byte(portID), []byte{1})
|
|
80
|
+
return err
|
|
81
|
+
}
|
|
82
|
+
return nil
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func (s *DynamicPortScope) LoadBindings(ctx sdk.Context) error {
|
|
86
|
+
if s.router == nil {
|
|
87
|
+
return fmt.Errorf("dynamic port router is not configured")
|
|
88
|
+
}
|
|
89
|
+
if s.storeService == nil {
|
|
90
|
+
return fmt.Errorf("dynamic port store is not configured")
|
|
91
|
+
}
|
|
92
|
+
if s.module == nil {
|
|
93
|
+
return fmt.Errorf("dynamic port module is not configured")
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
store := s.boundPortStore(ctx)
|
|
97
|
+
iter := store.Iterator(nil, nil)
|
|
98
|
+
defer iter.Close()
|
|
99
|
+
|
|
100
|
+
for ; iter.Valid(); iter.Next() {
|
|
101
|
+
portID := string(iter.Key())
|
|
102
|
+
if err := s.router.BindPort(portID, s.module); err != nil {
|
|
103
|
+
return fmt.Errorf("failed to restore bound port %s: %s", portID, err)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return nil
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
func (s *DynamicPortScope) boundPortStore(ctx sdk.Context) prefix.Store {
|
|
111
|
+
kvstore := s.storeService.OpenKVStore(ctx)
|
|
112
|
+
store := runtime.KVStoreAdapter(kvstore)
|
|
113
|
+
return prefix.NewStore(store, []byte(boundPortStoreKeyPrefix))
|
|
114
|
+
}
|
|
@@ -3,7 +3,7 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
5
|
|
|
6
|
-
ibcexported "github.com/cosmos/ibc-go/
|
|
6
|
+
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
7
7
|
|
|
8
8
|
agtypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
9
9
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
@@ -32,12 +32,14 @@ func (k Keeper) TriggerWriteAcknowledgement(
|
|
|
32
32
|
func (k Keeper) TriggerOnAcknowledgementPacket(
|
|
33
33
|
ctx sdk.Context,
|
|
34
34
|
target string,
|
|
35
|
+
channelVersion string,
|
|
35
36
|
packet ibcexported.PacketI,
|
|
36
37
|
acknowledgement []byte,
|
|
37
38
|
relayer sdk.AccAddress,
|
|
38
39
|
) error {
|
|
39
40
|
event := types.AcknowledgementPacketEvent{
|
|
40
41
|
Target: target,
|
|
42
|
+
ChannelVersion: channelVersion,
|
|
41
43
|
Packet: agtypes.CopyToIBCPacket(packet),
|
|
42
44
|
Acknowledgement: acknowledgement,
|
|
43
45
|
Relayer: relayer,
|
|
@@ -54,13 +56,15 @@ func (k Keeper) TriggerOnAcknowledgementPacket(
|
|
|
54
56
|
func (k Keeper) TriggerOnTimeoutPacket(
|
|
55
57
|
ctx sdk.Context,
|
|
56
58
|
target string,
|
|
59
|
+
channelVersion string,
|
|
57
60
|
packet ibcexported.PacketI,
|
|
58
61
|
relayer sdk.AccAddress,
|
|
59
62
|
) error {
|
|
60
63
|
event := types.TimeoutPacketEvent{
|
|
61
|
-
Target:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
Target: target,
|
|
65
|
+
ChannelVersion: channelVersion,
|
|
66
|
+
Packet: agtypes.CopyToIBCPacket(packet),
|
|
67
|
+
Relayer: relayer,
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
err := k.PushAction(ctx, event)
|
|
@@ -4,10 +4,9 @@ import (
|
|
|
4
4
|
context "context"
|
|
5
5
|
|
|
6
6
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
|
|
7
|
+
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
|
|
8
|
+
channel "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
|
|
9
|
+
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
11
10
|
)
|
|
12
11
|
|
|
13
12
|
type BankKeeper interface {
|
|
@@ -20,23 +19,22 @@ type ChannelKeeper interface {
|
|
|
20
19
|
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channel.Channel, found bool)
|
|
21
20
|
SendPacket(
|
|
22
21
|
ctx sdk.Context,
|
|
23
|
-
channelCap *capability.Capability,
|
|
24
22
|
sourcePort string,
|
|
25
23
|
sourceChannel string,
|
|
26
24
|
timeoutHeight clienttypes.Height,
|
|
27
25
|
timeoutTimestamp uint64,
|
|
28
26
|
data []byte,
|
|
29
27
|
) (uint64, error)
|
|
30
|
-
WriteAcknowledgement(ctx sdk.Context,
|
|
28
|
+
WriteAcknowledgement(ctx sdk.Context, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error
|
|
31
29
|
ChanOpenInit(ctx sdk.Context, order channel.Order, connectionHops []string, portID string,
|
|
32
|
-
|
|
30
|
+
counterparty channel.Counterparty, version string) (string, error)
|
|
33
31
|
WriteOpenInitChannel(ctx sdk.Context, portID, channelID string, order channel.Order,
|
|
34
32
|
connectionHops []string, counterparty channel.Counterparty, version string)
|
|
35
33
|
WriteOpenTryChannel(ctx sdk.Context, portID, channelID string, order channel.Order,
|
|
36
34
|
connectionHops []string, counterparty channel.Counterparty, version string)
|
|
37
35
|
WriteOpenAckChannel(ctx sdk.Context, portID, channelID, counterpartyVersion, counterpartyChannelID string)
|
|
38
|
-
ChanCloseInit(ctx sdk.Context, portID, channelID string
|
|
39
|
-
TimeoutExecuted(ctx sdk.Context,
|
|
36
|
+
ChanCloseInit(ctx sdk.Context, portID, channelID string) error
|
|
37
|
+
TimeoutExecuted(ctx sdk.Context, packet channel.Packet) error
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
// ClientKeeper defines the expected IBC client keeper
|
|
@@ -44,14 +42,3 @@ type ClientKeeper interface {
|
|
|
44
42
|
GetParams(ctx sdk.Context) clienttypes.Params
|
|
45
43
|
SetParams(ctx sdk.Context, params clienttypes.Params)
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
// PortKeeper defines the expected IBC port keeper
|
|
49
|
-
type PortKeeper interface {
|
|
50
|
-
BindPort(ctx sdk.Context, portID string) *capability.Capability
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ScopedKeeper defines the expected scoped capability keeper
|
|
54
|
-
type ScopedKeeper interface {
|
|
55
|
-
ClaimCapability(ctx sdk.Context, cap *capability.Capability, name string) error
|
|
56
|
-
GetCapability(ctx sdk.Context, name string) (*capability.Capability, bool)
|
|
57
|
-
}
|