@agoric/cosmos 0.35.0-upgrade-14-dev-c8f9e7b.0 → 0.35.0-upgrade-16a-dev-fb592e4.0
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/CHANGELOG.md +121 -77
- package/MAINTAINERS.md +3 -0
- package/Makefile +36 -26
- package/ante/ante.go +7 -9
- package/ante/inbound_test.go +3 -2
- package/ante/vm_admission.go +2 -1
- package/app/app.go +212 -140
- package/app/upgrade.go +76 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/main.go +130 -11
- package/cmd/libdaemon/main.go +64 -53
- package/cmd/libdaemon/main_test.go +2 -1
- package/daemon/cmd/root.go +171 -74
- package/daemon/cmd/root_test.go +189 -1
- package/daemon/main.go +4 -2
- package/e2e_test/Makefile +29 -0
- package/e2e_test/README.md +100 -0
- package/e2e_test/go.mod +217 -0
- package/e2e_test/go.sum +1323 -0
- package/e2e_test/ibc_conformance_test.go +56 -0
- package/e2e_test/pfm_test.go +613 -0
- package/e2e_test/util.go +271 -0
- package/git-revision.txt +1 -1
- package/go.mod +22 -11
- package/go.sum +17 -13
- package/package.json +9 -5
- package/proto/agoric/swingset/genesis.proto +4 -0
- package/proto/agoric/swingset/swingset.proto +1 -1
- package/proto/agoric/vlocalchain/.clang-format +7 -0
- package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +7 -8
- package/types/kv_entry_helpers.go +42 -0
- package/upgradegaia.sh +8 -8
- package/vm/action.go +5 -4
- package/vm/action_test.go +31 -11
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +17 -40
- package/vm/core_proposals.go +22 -2
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/proto_json.go +38 -0
- package/vm/proto_json_test.go +103 -0
- package/vm/server.go +124 -0
- package/x/swingset/abci.go +10 -10
- package/x/swingset/alias.go +2 -0
- package/x/swingset/client/cli/tx.go +4 -0
- package/x/swingset/genesis.go +84 -24
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +2 -2
- package/x/swingset/keeper/keeper.go +13 -25
- package/x/swingset/keeper/msg_server.go +18 -18
- package/x/swingset/keeper/proposal.go +3 -3
- package/x/swingset/keeper/querier.go +12 -11
- package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +7 -7
- package/x/swingset/proposal_handler.go +2 -1
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/expected_keepers.go +3 -2
- package/x/swingset/types/genesis.pb.go +78 -25
- package/x/swingset/types/msgs.go +44 -24
- package/x/swingset/types/params.go +2 -1
- package/x/swingset/types/proposal.go +5 -4
- package/x/swingset/types/swingset.pb.go +1 -1
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/querier.go +4 -3
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +9 -9
- package/x/vbank/vbank_test.go +2 -2
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +16 -9
- package/x/vibc/keeper/keeper.go +102 -65
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +13 -0
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/receiver.go +170 -0
- package/x/vlocalchain/alias.go +19 -0
- package/x/vlocalchain/handler.go +21 -0
- package/x/vlocalchain/keeper/keeper.go +279 -0
- package/x/vlocalchain/keeper/keeper_test.go +97 -0
- package/x/vlocalchain/types/codec.go +34 -0
- package/x/vlocalchain/types/key.go +27 -0
- package/x/vlocalchain/types/msgs.go +16 -0
- package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
- package/x/vlocalchain/vlocalchain.go +114 -0
- package/x/vlocalchain/vlocalchain_test.go +434 -0
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +0 -1
- package/x/vstorage/keeper/keeper.go +13 -20
- package/x/vstorage/keeper/querier.go +6 -5
- package/x/vstorage/keeper/querier_test.go +4 -3
- package/x/vstorage/module.go +0 -5
- package/x/vstorage/testing/queue.go +27 -0
- package/x/vtransfer/alias.go +13 -0
- package/x/vtransfer/genesis.go +39 -0
- package/x/vtransfer/genesis_test.go +12 -0
- package/x/vtransfer/handler.go +20 -0
- package/x/vtransfer/ibc_middleware.go +186 -0
- package/x/vtransfer/ibc_middleware_test.go +448 -0
- package/x/vtransfer/keeper/keeper.go +281 -0
- package/x/vtransfer/module.go +124 -0
- package/x/vtransfer/types/expected_keepers.go +38 -0
- package/x/vtransfer/types/genesis.pb.go +327 -0
- package/x/vtransfer/types/key.go +9 -0
- package/x/vtransfer/types/msgs.go +9 -0
- package/ante/fee.go +0 -96
- package/proto/agoric/lien/genesis.proto +0 -25
- package/proto/agoric/lien/lien.proto +0 -25
- package/x/lien/alias.go +0 -17
- package/x/lien/genesis.go +0 -58
- package/x/lien/genesis_test.go +0 -101
- package/x/lien/keeper/account.go +0 -290
- package/x/lien/keeper/keeper.go +0 -255
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -205
- package/x/lien/lien_test.go +0 -533
- package/x/lien/module.go +0 -115
- package/x/lien/spec/01_concepts.md +0 -146
- package/x/lien/spec/02_messages.md +0 -96
- package/x/lien/types/accountkeeper.go +0 -81
- package/x/lien/types/accountstate.go +0 -27
- package/x/lien/types/expected_keepers.go +0 -18
- package/x/lien/types/genesis.pb.go +0 -567
- package/x/lien/types/key.go +0 -25
- package/x/lien/types/lien.pb.go +0 -403
- package/x/vibc/ibc.go +0 -394
- /package/{src/index.cjs → index.cjs} +0 -0
package/x/vibc/handler.go
CHANGED
|
@@ -3,42 +3,49 @@ package vibc
|
|
|
3
3
|
import (
|
|
4
4
|
"fmt"
|
|
5
5
|
|
|
6
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
6
7
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
8
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
7
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
10
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
9
11
|
)
|
|
10
12
|
|
|
11
13
|
// NewHandler returns a handler for "vibc" type messages.
|
|
12
|
-
func NewHandler(keeper Keeper) sdk.Handler {
|
|
14
|
+
func NewHandler(keeper Keeper, bankKeeper types.BankKeeper) sdk.Handler {
|
|
13
15
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
|
14
16
|
switch msg := msg.(type) {
|
|
15
17
|
case *MsgSendPacket:
|
|
16
|
-
return handleMsgSendPacket(ctx, keeper, msg)
|
|
18
|
+
return handleMsgSendPacket(ctx, keeper, bankKeeper, msg)
|
|
17
19
|
|
|
18
20
|
default:
|
|
19
21
|
errMsg := fmt.Sprintf("Unrecognized vibc Msg type: %T", msg)
|
|
20
|
-
return nil,
|
|
22
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
type sendPacketAction struct {
|
|
28
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
29
|
+
Event string `json:"event" default:"sendPacket"`
|
|
26
30
|
*MsgSendPacket
|
|
27
|
-
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
28
|
-
Event string `json:"event" default:"sendPacket"`
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
func handleMsgSendPacket(
|
|
33
|
+
func handleMsgSendPacket(
|
|
34
|
+
ctx sdk.Context,
|
|
35
|
+
keeper Keeper,
|
|
36
|
+
bankKeeper types.BankKeeper,
|
|
37
|
+
msg *MsgSendPacket,
|
|
38
|
+
) (*sdk.Result, error) {
|
|
32
39
|
onePass := sdk.NewInt64Coin("sendpacketpass", 1)
|
|
33
|
-
balance :=
|
|
40
|
+
balance := bankKeeper.GetBalance(ctx, msg.Sender, onePass.Denom)
|
|
34
41
|
if balance.IsLT(onePass) {
|
|
35
|
-
return nil,
|
|
42
|
+
return nil, sdkioerrors.Wrap(
|
|
36
43
|
sdkerrors.ErrInsufficientFee,
|
|
37
44
|
fmt.Sprintf("sender %s needs at least %s", msg.Sender, onePass.String()),
|
|
38
45
|
)
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
action :=
|
|
48
|
+
action := sendPacketAction{
|
|
42
49
|
MsgSendPacket: msg,
|
|
43
50
|
}
|
|
44
51
|
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
|
package/x/vibc/keeper/keeper.go
CHANGED
|
@@ -7,8 +7,7 @@ import (
|
|
|
7
7
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
8
8
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
|
|
10
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
12
11
|
capability "github.com/cosmos/cosmos-sdk/x/capability/types"
|
|
13
12
|
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
|
|
14
13
|
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
|
|
@@ -16,47 +15,66 @@ import (
|
|
|
16
15
|
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
|
|
17
16
|
ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
vm "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
18
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
22
19
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
23
20
|
)
|
|
24
21
|
|
|
22
|
+
var (
|
|
23
|
+
_ porttypes.ICS4Wrapper = Keeper{}
|
|
24
|
+
_ types.IBCModuleImpl = Keeper{}
|
|
25
|
+
_ types.ReceiverImpl = Keeper{}
|
|
26
|
+
)
|
|
27
|
+
|
|
25
28
|
// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
|
|
26
29
|
type Keeper struct {
|
|
27
|
-
|
|
28
|
-
cdc codec.Codec
|
|
30
|
+
cdc codec.Codec
|
|
29
31
|
|
|
30
32
|
channelKeeper types.ChannelKeeper
|
|
31
33
|
portKeeper types.PortKeeper
|
|
32
|
-
scopedKeeper capabilitykeeper.ScopedKeeper
|
|
33
|
-
bankKeeper bankkeeper.Keeper
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
// Filled out by `WithScope`
|
|
36
|
+
scopedKeeper types.ScopedKeeper
|
|
37
|
+
storeKey storetypes.StoreKey
|
|
38
|
+
pushAction vm.ActionPusher
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
// NewKeeper creates a new
|
|
41
|
+
// NewKeeper creates a new vibc Keeper instance
|
|
39
42
|
func NewKeeper(
|
|
40
|
-
cdc codec.Codec,
|
|
41
|
-
channelKeeper types.ChannelKeeper,
|
|
42
|
-
|
|
43
|
-
scopedKeeper capabilitykeeper.ScopedKeeper,
|
|
44
|
-
pushAction vm.ActionPusher,
|
|
43
|
+
cdc codec.Codec,
|
|
44
|
+
channelKeeper types.ChannelKeeper,
|
|
45
|
+
portKeeper types.PortKeeper,
|
|
45
46
|
) Keeper {
|
|
46
47
|
|
|
47
48
|
return Keeper{
|
|
48
|
-
storeKey: key,
|
|
49
49
|
cdc: cdc,
|
|
50
|
-
bankKeeper: bankKeeper,
|
|
51
50
|
channelKeeper: channelKeeper,
|
|
52
51
|
portKeeper: portKeeper,
|
|
53
|
-
scopedKeeper: scopedKeeper,
|
|
54
|
-
PushAction: pushAction,
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
// WithScope returns a new Keeper copied from the receiver, but with the given
|
|
56
|
+
// store key, scoped keeper, and push action.
|
|
57
|
+
func (k Keeper) WithScope(storeKey storetypes.StoreKey, scopedKeeper types.ScopedKeeper, pushAction vm.ActionPusher) Keeper {
|
|
58
|
+
k.storeKey = storeKey
|
|
59
|
+
k.scopedKeeper = scopedKeeper
|
|
60
|
+
k.pushAction = pushAction
|
|
61
|
+
return k
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// PushAction sends a vm.Action to the VM controller.
|
|
65
|
+
func (k Keeper) PushAction(ctx sdk.Context, action vm.Action) error {
|
|
66
|
+
return k.pushAction(ctx, action)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// GetICS4Wrapper returns the ICS4Wrapper interface for the keeper.
|
|
70
|
+
func (k Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
|
|
71
|
+
return k
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// GetAppVersion defines a wrapper function for the channel Keeper's function
|
|
75
|
+
// in order to expose it to the vibc IBC handler.
|
|
76
|
+
func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
|
|
77
|
+
return k.channelKeeper.GetAppVersion(ctx, portID, channelID)
|
|
60
78
|
}
|
|
61
79
|
|
|
62
80
|
// GetChannel defines a wrapper function for the channel Keeper's function
|
|
@@ -65,15 +83,14 @@ func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (channelty
|
|
|
65
83
|
return k.channelKeeper.GetChannel(ctx, portID, channelID)
|
|
66
84
|
}
|
|
67
85
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
func (k Keeper) ChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string,
|
|
86
|
+
// ReceiveChanOpenInit wraps the keeper's ChanOpenInit function.
|
|
87
|
+
func (k Keeper) ReceiveChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string,
|
|
71
88
|
portID, rPortID, version string,
|
|
72
89
|
) error {
|
|
73
90
|
capName := host.PortPath(portID)
|
|
74
91
|
portCap, ok := k.GetCapability(ctx, capName)
|
|
75
92
|
if !ok {
|
|
76
|
-
return
|
|
93
|
+
return sdkioerrors.Wrapf(porttypes.ErrInvalidPort, "could not retrieve port capability at: %s", capName)
|
|
77
94
|
}
|
|
78
95
|
counterparty := channeltypes.Counterparty{
|
|
79
96
|
PortId: rPortID,
|
|
@@ -92,61 +109,79 @@ func (k Keeper) ChanOpenInit(ctx sdk.Context, order channeltypes.Order, connecti
|
|
|
92
109
|
return nil
|
|
93
110
|
}
|
|
94
111
|
|
|
112
|
+
// ReceiveSendPacket wraps the keeper's SendPacket function.
|
|
113
|
+
func (k Keeper) ReceiveSendPacket(ctx sdk.Context, packet ibcexported.PacketI) (uint64, error) {
|
|
114
|
+
sourcePort := packet.GetSourcePort()
|
|
115
|
+
sourceChannel := packet.GetSourceChannel()
|
|
116
|
+
timeoutHeight := packet.GetTimeoutHeight()
|
|
117
|
+
timeoutRevisionNumber := timeoutHeight.GetRevisionNumber()
|
|
118
|
+
timeoutRevisionHeight := timeoutHeight.GetRevisionHeight()
|
|
119
|
+
clientTimeoutHeight := clienttypes.NewHeight(timeoutRevisionNumber, timeoutRevisionHeight)
|
|
120
|
+
timeoutTimestamp := packet.GetTimeoutTimestamp()
|
|
121
|
+
data := packet.GetData()
|
|
122
|
+
|
|
123
|
+
capName := host.ChannelCapabilityPath(sourcePort, sourceChannel)
|
|
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, clientTimeoutHeight, timeoutTimestamp, data)
|
|
129
|
+
}
|
|
130
|
+
|
|
95
131
|
// SendPacket defines a wrapper function for the channel Keeper's function
|
|
96
132
|
// in order to expose it to the vibc IBC handler.
|
|
97
133
|
func (k Keeper) SendPacket(
|
|
98
134
|
ctx sdk.Context,
|
|
135
|
+
chanCap *capability.Capability,
|
|
99
136
|
sourcePort string,
|
|
100
137
|
sourceChannel string,
|
|
101
138
|
timeoutHeight clienttypes.Height,
|
|
102
139
|
timeoutTimestamp uint64,
|
|
103
140
|
data []byte,
|
|
104
141
|
) (uint64, error) {
|
|
105
|
-
capName := host.ChannelCapabilityPath(sourcePort, sourceChannel)
|
|
106
|
-
chanCap, ok := k.GetCapability(ctx, capName)
|
|
107
|
-
if !ok {
|
|
108
|
-
return 0, sdkerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
109
|
-
}
|
|
110
142
|
return k.channelKeeper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
|
|
111
143
|
}
|
|
112
144
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
type rawAcknowledgement struct {
|
|
116
|
-
data []byte
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
func (r rawAcknowledgement) Acknowledgement() []byte {
|
|
120
|
-
return r.data
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
func (r rawAcknowledgement) Success() bool {
|
|
124
|
-
return true
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// WriteAcknowledgement defines a wrapper function for the channel Keeper's function
|
|
128
|
-
// in order to expose it to the vibc IBC handler.
|
|
129
|
-
func (k Keeper) WriteAcknowledgement(ctx sdk.Context, packet ibcexported.PacketI, acknowledgement []byte) error {
|
|
145
|
+
// ReceiveWriteAcknowledgement wraps the keeper's WriteAcknowledgment function.
|
|
146
|
+
func (k Keeper) ReceiveWriteAcknowledgement(ctx sdk.Context, packet ibcexported.PacketI, ack ibcexported.Acknowledgement) error {
|
|
130
147
|
portID := packet.GetDestPort()
|
|
131
148
|
channelID := packet.GetDestChannel()
|
|
132
149
|
capName := host.ChannelCapabilityPath(portID, channelID)
|
|
133
150
|
chanCap, ok := k.GetCapability(ctx, capName)
|
|
134
151
|
if !ok {
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
ack := rawAcknowledgement{
|
|
138
|
-
data: acknowledgement,
|
|
152
|
+
return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
139
153
|
}
|
|
154
|
+
return k.WriteAcknowledgement(ctx, chanCap, packet, ack)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// WriteAcknowledgement defines a wrapper function for the channel Keeper's function
|
|
158
|
+
// in order to expose it to the vibc IBC handler.
|
|
159
|
+
func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capability.Capability, packet ibcexported.PacketI, ack ibcexported.Acknowledgement) error {
|
|
140
160
|
return k.channelKeeper.WriteAcknowledgement(ctx, chanCap, packet, ack)
|
|
141
161
|
}
|
|
142
162
|
|
|
143
|
-
//
|
|
163
|
+
// ReceiveWriteOpenTryChannel wraps the keeper's WriteOpenTryChannel function.
|
|
164
|
+
func (k Keeper) ReceiveWriteOpenTryChannel(ctx sdk.Context, packet ibcexported.PacketI, order channeltypes.Order, connectionHops []string, version string) error {
|
|
165
|
+
portID := packet.GetDestPort()
|
|
166
|
+
channelID := packet.GetDestChannel()
|
|
167
|
+
counterparty := channeltypes.NewCounterparty(packet.GetSourcePort(), packet.GetSourceChannel())
|
|
168
|
+
k.WriteOpenTryChannel(ctx, portID, channelID, order, connectionHops, counterparty, version)
|
|
169
|
+
return nil
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// WriteOpenTryChannel is a wrapper function for the channel Keeper's function
|
|
173
|
+
func (k Keeper) WriteOpenTryChannel(ctx sdk.Context, portID, channelID string, order channeltypes.Order,
|
|
174
|
+
connectionHops []string, counterparty channeltypes.Counterparty, version string) {
|
|
175
|
+
k.channelKeeper.WriteOpenTryChannel(ctx, portID, channelID, order, connectionHops, counterparty, version)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ReceiveChanCloseInit is a wrapper function for the channel Keeper's function
|
|
144
179
|
// in order to expose it to the vibc IBC handler.
|
|
145
|
-
func (k Keeper)
|
|
180
|
+
func (k Keeper) ReceiveChanCloseInit(ctx sdk.Context, portID, channelID string) error {
|
|
146
181
|
capName := host.ChannelCapabilityPath(portID, channelID)
|
|
147
182
|
chanCap, ok := k.GetCapability(ctx, capName)
|
|
148
183
|
if !ok {
|
|
149
|
-
return
|
|
184
|
+
return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
150
185
|
}
|
|
151
186
|
err := k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap)
|
|
152
187
|
if err != nil {
|
|
@@ -155,36 +190,38 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
|
|
|
155
190
|
return nil
|
|
156
191
|
}
|
|
157
192
|
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
func (k Keeper)
|
|
161
|
-
|
|
193
|
+
// ReceiveBindPort is a wrapper function for the port Keeper's function in order
|
|
194
|
+
// to expose it to the vibc IBC handler.
|
|
195
|
+
func (k Keeper) ReceiveBindPort(ctx sdk.Context, portID string) error {
|
|
196
|
+
portPath := host.PortPath(portID)
|
|
197
|
+
_, ok := k.GetCapability(ctx, portPath)
|
|
162
198
|
if ok {
|
|
163
199
|
return fmt.Errorf("port %s is already bound", portID)
|
|
164
200
|
}
|
|
165
201
|
cap := k.portKeeper.BindPort(ctx, portID)
|
|
166
|
-
return k.ClaimCapability(ctx, cap,
|
|
202
|
+
return k.ClaimCapability(ctx, cap, portPath)
|
|
167
203
|
}
|
|
168
204
|
|
|
169
|
-
//
|
|
170
|
-
// in order to expose it to the vibc IBC handler.
|
|
171
|
-
func (k Keeper)
|
|
205
|
+
// ReceiveTimeoutExecuted is a wrapper function for the channel Keeper's
|
|
206
|
+
// function in order to expose it to the vibc IBC handler.
|
|
207
|
+
func (k Keeper) ReceiveTimeoutExecuted(ctx sdk.Context, packet ibcexported.PacketI) error {
|
|
172
208
|
portID := packet.GetSourcePort()
|
|
173
209
|
channelID := packet.GetSourceChannel()
|
|
174
210
|
capName := host.ChannelCapabilityPath(portID, channelID)
|
|
175
211
|
chanCap, ok := k.GetCapability(ctx, capName)
|
|
176
212
|
if !ok {
|
|
177
|
-
return
|
|
213
|
+
return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
|
|
178
214
|
}
|
|
179
215
|
return k.channelKeeper.TimeoutExecuted(ctx, chanCap, packet)
|
|
180
216
|
}
|
|
181
217
|
|
|
182
218
|
// ClaimCapability allows the vibc module to claim a capability that IBC module
|
|
183
|
-
// passes to it
|
|
219
|
+
// passes to it.
|
|
184
220
|
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capability.Capability, name string) error {
|
|
185
221
|
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
|
|
186
222
|
}
|
|
187
223
|
|
|
224
|
+
// GetCapability allows the vibc module to retrieve a capability.
|
|
188
225
|
func (k Keeper) GetCapability(ctx sdk.Context, name string) (*capability.Capability, bool) {
|
|
189
226
|
return k.scopedKeeper.GetCapability(ctx, name)
|
|
190
227
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
package keeper
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
|
+
|
|
6
|
+
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
|
|
7
|
+
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
|
|
8
|
+
ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"
|
|
9
|
+
|
|
10
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
11
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
func reifyPacket(packet ibcexported.PacketI) channeltypes.Packet {
|
|
15
|
+
height := packet.GetTimeoutHeight()
|
|
16
|
+
ctHeight := clienttypes.Height{
|
|
17
|
+
RevisionHeight: height.GetRevisionHeight(),
|
|
18
|
+
RevisionNumber: height.GetRevisionNumber(),
|
|
19
|
+
}
|
|
20
|
+
return channeltypes.Packet{
|
|
21
|
+
Sequence: packet.GetSequence(),
|
|
22
|
+
SourcePort: packet.GetSourcePort(),
|
|
23
|
+
SourceChannel: packet.GetSourceChannel(),
|
|
24
|
+
DestinationPort: packet.GetDestPort(),
|
|
25
|
+
DestinationChannel: packet.GetDestChannel(),
|
|
26
|
+
Data: packet.GetData(),
|
|
27
|
+
TimeoutHeight: ctHeight,
|
|
28
|
+
TimeoutTimestamp: packet.GetTimeoutTimestamp(),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type WriteAcknowledgementEvent struct {
|
|
33
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
34
|
+
Event string `json:"event" default:"writeAcknowledgement"`
|
|
35
|
+
Target string `json:"target"`
|
|
36
|
+
Packet channeltypes.Packet `json:"packet"`
|
|
37
|
+
Acknowledgement []byte `json:"acknowledgement"`
|
|
38
|
+
Relayer sdk.AccAddress `json:"relayer"`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func (k Keeper) TriggerWriteAcknowledgement(
|
|
42
|
+
ctx sdk.Context,
|
|
43
|
+
target string,
|
|
44
|
+
packet ibcexported.PacketI,
|
|
45
|
+
acknowledgement ibcexported.Acknowledgement,
|
|
46
|
+
) error {
|
|
47
|
+
event := WriteAcknowledgementEvent{
|
|
48
|
+
Target: target,
|
|
49
|
+
Packet: reifyPacket(packet),
|
|
50
|
+
Acknowledgement: acknowledgement.Acknowledgement(),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
err := k.PushAction(ctx, event)
|
|
54
|
+
if err != nil {
|
|
55
|
+
return err
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return nil
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func (k Keeper) TriggerOnAcknowledgementPacket(
|
|
62
|
+
ctx sdk.Context,
|
|
63
|
+
target string,
|
|
64
|
+
packet ibcexported.PacketI,
|
|
65
|
+
acknowledgement []byte,
|
|
66
|
+
relayer sdk.AccAddress,
|
|
67
|
+
) error {
|
|
68
|
+
event := types.AcknowledgementPacketEvent{
|
|
69
|
+
Target: target,
|
|
70
|
+
Packet: reifyPacket(packet),
|
|
71
|
+
Acknowledgement: acknowledgement,
|
|
72
|
+
Relayer: relayer,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
err := k.PushAction(ctx, event)
|
|
76
|
+
if err != nil {
|
|
77
|
+
return err
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return nil
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func (k Keeper) TriggerOnTimeoutPacket(
|
|
84
|
+
ctx sdk.Context,
|
|
85
|
+
target string,
|
|
86
|
+
packet ibcexported.PacketI,
|
|
87
|
+
relayer sdk.AccAddress,
|
|
88
|
+
) error {
|
|
89
|
+
event := types.TimeoutPacketEvent{
|
|
90
|
+
Target: target,
|
|
91
|
+
Packet: reifyPacket(packet),
|
|
92
|
+
Relayer: relayer,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
err := k.PushAction(ctx, event)
|
|
96
|
+
if err != nil {
|
|
97
|
+
return err
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return nil
|
|
101
|
+
}
|
package/x/vibc/module.go
CHANGED
|
@@ -3,7 +3,6 @@ package vibc
|
|
|
3
3
|
import (
|
|
4
4
|
"encoding/json"
|
|
5
5
|
|
|
6
|
-
"github.com/gorilla/mux"
|
|
7
6
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
8
7
|
"github.com/spf13/cobra"
|
|
9
8
|
|
|
@@ -51,10 +50,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
|
|
51
50
|
return nil
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
// Register rest routes
|
|
55
|
-
func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {
|
|
56
|
-
}
|
|
57
|
-
|
|
58
53
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {
|
|
59
54
|
}
|
|
60
55
|
|
|
@@ -70,14 +65,16 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
|
|
70
65
|
|
|
71
66
|
type AppModule struct {
|
|
72
67
|
AppModuleBasic
|
|
73
|
-
keeper
|
|
68
|
+
keeper Keeper
|
|
69
|
+
bankKeeper types.BankKeeper
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
// NewAppModule creates a new AppModule Object
|
|
77
|
-
func NewAppModule(k Keeper) AppModule {
|
|
73
|
+
func NewAppModule(k Keeper, bankKeeper types.BankKeeper) AppModule {
|
|
78
74
|
am := AppModule{
|
|
79
75
|
AppModuleBasic: AppModuleBasic{},
|
|
80
76
|
keeper: k,
|
|
77
|
+
bankKeeper: bankKeeper,
|
|
81
78
|
}
|
|
82
79
|
return am
|
|
83
80
|
}
|
|
@@ -104,7 +101,7 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
|
|
104
101
|
|
|
105
102
|
// Route implements the AppModule interface
|
|
106
103
|
func (am AppModule) Route() sdk.Route {
|
|
107
|
-
return sdk.NewRoute(RouterKey, NewHandler(am.keeper))
|
|
104
|
+
return sdk.NewRoute(RouterKey, NewHandler(am.keeper, am.bankKeeper))
|
|
108
105
|
}
|
|
109
106
|
|
|
110
107
|
// QuerierRoute implements the AppModule interface
|
|
@@ -9,8 +9,13 @@ import (
|
|
|
9
9
|
ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"
|
|
10
10
|
)
|
|
11
11
|
|
|
12
|
+
type BankKeeper interface {
|
|
13
|
+
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
// ChannelKeeper defines the expected IBC channel keeper
|
|
13
17
|
type ChannelKeeper interface {
|
|
18
|
+
GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool)
|
|
14
19
|
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channel.Channel, found bool)
|
|
15
20
|
SendPacket(
|
|
16
21
|
ctx sdk.Context,
|
|
@@ -26,6 +31,8 @@ type ChannelKeeper interface {
|
|
|
26
31
|
portCap *capability.Capability, counterparty channel.Counterparty, version string) (string, *capability.Capability, error)
|
|
27
32
|
WriteOpenInitChannel(ctx sdk.Context, portID, channelID string, order channel.Order,
|
|
28
33
|
connectionHops []string, counterparty channel.Counterparty, version string)
|
|
34
|
+
WriteOpenTryChannel(ctx sdk.Context, portID, channelID string, order channel.Order,
|
|
35
|
+
connectionHops []string, counterparty channel.Counterparty, version string)
|
|
29
36
|
ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capability.Capability) error
|
|
30
37
|
TimeoutExecuted(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI) error
|
|
31
38
|
}
|
|
@@ -44,3 +51,9 @@ type ConnectionKeeper interface {
|
|
|
44
51
|
type PortKeeper interface {
|
|
45
52
|
BindPort(ctx sdk.Context, portID string) *capability.Capability
|
|
46
53
|
}
|
|
54
|
+
|
|
55
|
+
// ScopedKeeper defines the expected scoped capability keeper
|
|
56
|
+
type ScopedKeeper interface {
|
|
57
|
+
ClaimCapability(ctx sdk.Context, cap *capability.Capability, name string) error
|
|
58
|
+
GetCapability(ctx sdk.Context, name string) (*capability.Capability, bool)
|
|
59
|
+
}
|