Skip to content

Commit 16a8e84

Browse files
colin-axnerexpertdicerdependabot[bot]chattoncrodriguezvega
committed
adr 8 callback packet data impl followups (#3325)
* remove query client (#3227) * remove query client * merge main * go mod tidy * Rename ``IsBound`` to ``HasCapability`` (#3253) ## Description closes: #828 ### Commit Message / Changelog Entry ```bash imp(api!): rename `IsBound` to `HasCapability` for IBC application modules ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [ ] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * chore: add support for tendermint debug log level (#3279) * build(deps): bump cosmossdk.io/math from 1.0.0-beta.6.0.20230216172121-959ce49135e4 to 1.0.0-rc.0 (#3285) Bumps [cosmossdk.io/math](https://github.com/cosmos/cosmos-sdk) from 1.0.0-beta.6.0.20230216172121-959ce49135e4 to 1.0.0-rc.0. <details> <summary>Commits</summary> <ul> <li>See full diff in <a href="https://github.com/cosmos/cosmos-sdk/commits/math/v1.0.0-rc.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cosmossdk.io/math&package-manager=go_modules&previous-version=1.0.0-beta.6.0.20230216172121-959ce49135e4&new-version=1.0.0-rc.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> * Write docker inspect output to diagnostics (#3291) * chore: fix dead links (#3293) ## Description closes: #XXXX ### Commit Message / Changelog Entry ```bash type: commit message ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [x] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * build(deps): bump google.golang.org/protobuf from 1.29.0 to 1.29.1 (#3292) * deps: bump SDK v0.47 (#3295) Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * remove unnecessary import from doc * chore: remove support for v3 (#3294) * build(deps): bump actions/setup-go from 3 to 4 (#3307) * imp: remove unnecessary defer func statements (#3304) * Remove gogoproto yaml tags from proto files (#3290) ## Description Refer from original issue, I removed all `yaml` tags in proto files. closes: #3145 ### Commit Message / Changelog Entry ```bash type: commit message ``` see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)). - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package). - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`). - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review. - [ ] Re-reviewed `Files changed` in the Github PR explorer. - [ ] Review `Codecov Report` in the comment section below once CI passes. * add reasoning for migration to enable localhost * Support configuration file for e2e tests (#3260) * E2E fzf Test Selection Autocompletion (#3313) * post v7 release chores (#3310) * chore: fix linter warnings (#3311) * ADR 008: IBC Actor Callbacks (#1976) * context and decision * complete adr * Apply suggestions from code review Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * change from caller to generalized actor * Apply suggestions from code review Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * create folder and scaffolded middleware * add error handling and generify packetdata interface * complete renaming * add user defined gas limit and clarify pseudocode * Clarify CallbackPacketData interface imp: Add ADR 008: IBC Actor Callbacks --------- Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * lint: fix spelling * chore: apply self review concerns * chore: rename CallbackPacketDataI to CallbackPacketData * chore: finish applying remaining review suggestions * test: add remaining unit tests for transfer and ica * test: add unmarshaling test * imp: address ADR 8 review suggestions (#3319) --------- Co-authored-by: Damian Nolan <damiannolan@gmail.com> * Bump interchain test (#3314) * fix: remove codec registration * fix: build + linting * Only run e2e on R4R (#3330) * fix fork workflows (#3328) * Revert "Merge branch 'main' of github.com:cosmos/ibc-go into colin/callback-packet-data-impl" This reverts commit 1c6164b, reversing changes made to 6f25b8e. * chore: add optional interface godoc * Apply suggestions from code review Co-authored-by: Carlos Rodriguez <carlos@interchain.io> * chore: use backticks instead of escape characters in testing --------- Co-authored-by: Lặc <67097720+expertdicer@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cian Hatton <cian@interchain.io> Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: GNaD13 <89174180+GNaD13@users.noreply.github.com> Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Co-authored-by: Aditya <adityasripal@gmail.com>
1 parent d80eb6f commit 16a8e84

File tree

11 files changed

+390
-124
lines changed

11 files changed

+390
-124
lines changed

modules/apps/27-interchain-accounts/types/codec.go

-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
sdk "github.com/cosmos/cosmos-sdk/types"
88
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
99
"github.com/cosmos/gogoproto/proto"
10-
"github.com/cosmos/ibc-go/v7/modules/core/exported"
1110
)
1211

1312
// ModuleCdc references the global interchain accounts module codec. Note, the codec
@@ -22,11 +21,6 @@ var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
2221
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
2322
registry.RegisterImplementations((*authtypes.AccountI)(nil), &InterchainAccount{})
2423
registry.RegisterImplementations((*authtypes.GenesisAccount)(nil), &InterchainAccount{})
25-
26-
registry.RegisterImplementations(
27-
(*exported.CallbackPacketDataI)(nil),
28-
&InterchainAccountPacketData{},
29-
)
3024
}
3125

3226
// SerializeCosmosTx serializes a slice of sdk.Msg's using the CosmosTx type. The sdk.Msg's are

modules/apps/27-interchain-accounts/types/packet.go

+22-15
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
2727
)
2828

29-
var _ exported.CallbackPacketDataI = (*InterchainAccountPacketData)(nil)
29+
var _ exported.CallbackPacketData = (*InterchainAccountPacketData)(nil)
3030

3131
// ValidateBasic performs basic validation of the interchain account packet data.
3232
// The memo may be empty.
@@ -55,7 +55,7 @@ func (iapd InterchainAccountPacketData) GetBytes() []byte {
5555
5656
ADR-8 CallbackPacketData implementation
5757
58-
InterchainAccountPacketData implements CallbackPacketDataI interface. This will allow middlewares targetting specific VMs
58+
InterchainAccountPacketData implements CallbackPacketDataI interface. This will allow middlewares targeting specific VMs
5959
to retrieve the desired callback addresses for the ICA packet on the source and destination chains.
6060
6161
The Memo is used to set the desired callback addresses.
@@ -66,27 +66,32 @@ The Memo format is defined like so:
6666
{
6767
// ... other memo fields we don't care about
6868
"callbacks": {
69-
"src_callback_address": {contractAddrOnSrcChain},
69+
"src_callback_address": {contractAddrOnSourceChain},
7070
"dest_callback_address": {contractAddrOnDestChain},
71-
"src_callback_msg": {jsonObjectForSrcChainCallback}, // optional field
72-
"dest_callback_msg": {jsonObjectForDestChainCallback}, // optional field
73-
}
7471
72+
// optional fields
73+
"src_callback_msg": {jsonObjectForSourceChainCallback},
74+
"dest_callback_msg": {jsonObjectForDestChainCallback},
75+
}
7576
}
7677
```
7778
7879
*/
7980

80-
// GetSrcCallbackAddress returns the callback address on the source chain.
81-
// ADR-8 middleware should callback on the sender address on the source chain
82-
// if the sender address is an IBC Actor (i.e. smart contract that accepts IBC callbacks)
83-
func (iapd InterchainAccountPacketData) GetSrcCallbackAddress() string {
81+
// GetSourceCallbackAddress returns the source callback address provided in the packet data memo.
82+
// If no callback address is specified, an empty string is returned.
83+
//
84+
// The memo is expected to specify the callback address in the following format:
85+
// { "callbacks": { "src_callback_address": {contractAddrOnSourceChain}}
86+
//
87+
// ADR-8 middleware should callback on the returned address if it is a PacketActor
88+
// (i.e. smart contract that accepts IBC callbacks).
89+
func (iapd InterchainAccountPacketData) GetSourceCallbackAddress() string {
8490
if len(iapd.Memo) == 0 {
8591
return ""
8692
}
8793

8894
jsonObject := make(map[string]interface{})
89-
// the jsonObject must be a valid JSON object
9095
err := json.Unmarshal([]byte(iapd.Memo), &jsonObject)
9196
if err != nil {
9297
return ""
@@ -101,17 +106,19 @@ func (iapd InterchainAccountPacketData) GetSrcCallbackAddress() string {
101106
if !ok {
102107
return ""
103108
}
109+
104110
return callbackAddr
105111
}
106112

107-
// GetDestCallbackAddress returns the callback address on the destination chain.
108-
// ADR-8 middleware should callback on the receiver address on the destination chain
109-
// if the receiver address is an IBC Actor (i.e. smart contract that accepts IBC callbacks)
113+
// GetDestCallbackAddress returns an empty string. Destination callback addresses
114+
// are not supported for ICS 27 since this feature is natively supported by
115+
// interchain accounts host submodule transaction execution.
110116
func (iapd InterchainAccountPacketData) GetDestCallbackAddress() string {
111117
return ""
112118
}
113119

114-
// UserDefinedGasLimit no-ops on this method to use relayer passed in gas
120+
// UserDefinedGasLimit returns 0 (no-op). The gas limit of the executing
121+
// transaction will be used.
115122
func (fptd InterchainAccountPacketData) UserDefinedGasLimit() uint64 {
116123
return 0
117124
}

modules/apps/27-interchain-accounts/types/packet_test.go

+72-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package types_test
22

33
import (
4+
"fmt"
5+
46
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
57
)
68

@@ -83,11 +85,13 @@ func (suite *TypesTestSuite) TestValidateBasic() {
8385
}
8486
}
8587

86-
func (suite *TypesTestSuite) TestGetCallbackAddresses() {
88+
func (suite *TypesTestSuite) TestGetSourceCallbackAddress() {
89+
const expSrcCbAddr = "srcCbAddr"
90+
8791
testCases := []struct {
88-
name string
89-
packetData types.InterchainAccountPacketData
90-
expSrcCallbackAddr string
92+
name string
93+
packetData types.InterchainAccountPacketData
94+
expPass bool
9195
}{
9296
{
9397
"memo is empty",
@@ -96,7 +100,7 @@ func (suite *TypesTestSuite) TestGetCallbackAddresses() {
96100
Data: []byte("data"),
97101
Memo: "",
98102
},
99-
"",
103+
false,
100104
},
101105
{
102106
"memo is not json string",
@@ -105,48 +109,98 @@ func (suite *TypesTestSuite) TestGetCallbackAddresses() {
105109
Data: []byte("data"),
106110
Memo: "memo",
107111
},
108-
"",
112+
false,
109113
},
110114
{
111-
"memo is does not have callbacks in json struct",
115+
"memo does not have callbacks in json struct",
112116
types.InterchainAccountPacketData{
113117
Type: types.EXECUTE_TX,
114118
Data: []byte("data"),
115-
Memo: "{\"Key\": 10}",
119+
Memo: `{"Key": 10}`,
116120
},
117-
"",
121+
false,
118122
},
119123
{
120124
"memo has callbacks in json struct but does not have src_callback_address key",
121125
types.InterchainAccountPacketData{
122126
Type: types.EXECUTE_TX,
123127
Data: []byte("data"),
124-
Memo: "{\"callbacks\": {\"Key\": 10}}",
128+
Memo: `{"callbacks": {"Key": 10}}`,
125129
},
126-
"",
130+
false,
127131
},
128132
{
129133
"memo has callbacks in json struct but does not have string value for src_callback_address key",
130134
types.InterchainAccountPacketData{
131135
Type: types.EXECUTE_TX,
132136
Data: []byte("data"),
133-
Memo: "{\"callbacks\": {\"src_callback_address\": 10}}",
137+
Memo: `{"callbacks": {"src_callback_address": 10}}`,
134138
},
135-
"",
139+
false,
136140
},
137141
{
138-
"memo has callbacks in json struct but does not have string value for src_callback_address key",
142+
"memo has callbacks in json struct and properly formatted src_callback_address",
143+
types.InterchainAccountPacketData{
144+
Type: types.EXECUTE_TX,
145+
Data: []byte("data"),
146+
Memo: fmt.Sprintf(`{"callbacks": {"src_callback_address": "%s"}}`, expSrcCbAddr),
147+
},
148+
true,
149+
},
150+
}
151+
152+
for _, tc := range testCases {
153+
tc := tc
154+
suite.Run(tc.name, func() {
155+
srcCbAddr := tc.packetData.GetSourceCallbackAddress()
156+
157+
if tc.expPass {
158+
suite.Require().Equal(expSrcCbAddr, srcCbAddr)
159+
} else {
160+
suite.Require().Equal("", srcCbAddr)
161+
}
162+
})
163+
}
164+
}
165+
166+
func (suite *TypesTestSuite) TestGetDestCallbackAddress() {
167+
testCases := []struct {
168+
name string
169+
packetData types.InterchainAccountPacketData
170+
}{
171+
{
172+
"memo is empty",
139173
types.InterchainAccountPacketData{
140174
Type: types.EXECUTE_TX,
141175
Data: []byte("data"),
142-
Memo: "{\"callbacks\": {\"src_callback_address\": \"testAddress\"}}",
176+
Memo: "",
177+
},
178+
},
179+
{
180+
"memo has dest callback address specified in json struct",
181+
types.InterchainAccountPacketData{
182+
Type: types.EXECUTE_TX,
183+
Data: []byte("data"),
184+
Memo: `{"callbacks": {"dest_callback_address": "testAddress"}}`,
143185
},
144-
"testAddress",
145186
},
146187
}
147188

148189
for _, tc := range testCases {
149-
srcCbAddr := tc.packetData.GetSrcCallbackAddress()
150-
suite.Require().Equal(tc.expSrcCallbackAddr, srcCbAddr, "%s testcase does not have expected src_callback_address", tc.name)
190+
tc := tc
191+
suite.Run(tc.name, func() {
192+
destCbAddr := tc.packetData.GetDestCallbackAddress()
193+
suite.Require().Equal("", destCbAddr)
194+
})
195+
}
196+
}
197+
198+
func (suite *TypesTestSuite) TestUserDefinedGasLimit() {
199+
packetData := types.InterchainAccountPacketData{
200+
Type: types.EXECUTE_TX,
201+
Data: []byte("data"),
202+
Memo: `{"callbacks": {"user_defined_gas_limit": 100}}`,
151203
}
204+
205+
suite.Require().Equal(uint64(0), packetData.UserDefinedGasLimit(), "user defined gas limit does not return 0")
152206
}

modules/apps/transfer/types/codec.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package types
33
import (
44
"bytes"
55

6-
"github.com/cosmos/cosmos-sdk/x/authz"
7-
"github.com/cosmos/gogoproto/jsonpb"
8-
"github.com/cosmos/gogoproto/proto"
9-
"github.com/cosmos/ibc-go/v7/modules/core/exported"
10-
116
"github.com/cosmos/cosmos-sdk/codec"
127
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
138
sdk "github.com/cosmos/cosmos-sdk/types"
149
"github.com/cosmos/cosmos-sdk/types/msgservice"
10+
"github.com/cosmos/cosmos-sdk/x/authz"
11+
"github.com/cosmos/gogoproto/jsonpb"
12+
"github.com/cosmos/gogoproto/proto"
1513
)
1614

1715
// RegisterLegacyAminoCodec registers the necessary x/ibc transfer interfaces and concrete types
@@ -30,11 +28,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
3028
&TransferAuthorization{},
3129
)
3230

33-
registry.RegisterImplementations(
34-
(*exported.CallbackPacketDataI)(nil),
35-
&FungibleTokenPacketData{},
36-
)
37-
3831
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
3932
}
4033

0 commit comments

Comments
 (0)