Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ica)!: support json tx encoding for interchain accounts #3796

Merged
merged 141 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 134 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
c9d13c7
feat(ica): added EncodingJson to supported encodings
srdtrk May 30, 2023
fc7b2d1
imp(ica): changed the type of cdc to Codec in ica/host
srdtrk May 30, 2023
65bca55
imp(ica): changed the type of cdc to Codec in ica/controller
srdtrk May 30, 2023
3b19ac3
imp(ica.test): added a test cases for EncodingJSON
srdtrk May 30, 2023
ba73e12
imp(ica): created invalid encoding err
srdtrk May 30, 2023
d5f02cf
feat(ica)!: first prototype of json supporting DeserializeCosmosTx
srdtrk May 30, 2023
836dbb7
docs(ica): updated godoc of DeserializeCosmosTx
srdtrk May 30, 2023
57dfd22
docs(ica): added comments to DeserializeCosmosTx
srdtrk May 30, 2023
90907d7
fix(ica.test): fixed tests for DeserializeCosmosTx
srdtrk May 30, 2023
4af1a83
fix(ica): fixed 'OnRecvPacket' in relay.go
srdtrk May 30, 2023
e16a575
fix(ica): fixed unhandled error
srdtrk May 30, 2023
c4b246a
style(ica): made DeserializeCosmosTx more compact
srdtrk May 30, 2023
d08d066
fix(ica/host.cli.test): fixed a cli test
srdtrk May 30, 2023
882fa52
style(ica): ran gofumpt
srdtrk May 30, 2023
2eb410a
style(ica): changed err message
srdtrk May 30, 2023
19c7dc5
feat(ica): first prototype of SerializeCosmosTx is implemented
srdtrk May 31, 2023
66fe43d
fix(ica): fixed codec tests
srdtrk May 31, 2023
345febf
fix(ica/host.test): fix test
srdtrk May 31, 2023
3d5f1c0
fix(ica/host.test): fix test
srdtrk May 31, 2023
e0cde18
fix(ica/host.cli): cli always uses protobuf
srdtrk May 31, 2023
9834a20
nil(ica/host.test): removed unneeded comment
srdtrk May 31, 2023
318f591
fix(ica/controller.test): fix test
srdtrk May 31, 2023
b8208fd
fix(ica/controller.test): fix test
srdtrk May 31, 2023
f7ccaf6
fix(ica/controller.test): fix test
srdtrk May 31, 2023
cc3e293
fix(fee.test): fix test
srdtrk May 31, 2023
ed1edf9
nit: temporary save commit
srdtrk Jun 1, 2023
ae13295
fix(ica): fixed json serde tests not passing
srdtrk Jun 1, 2023
8c34e7d
merge: remote-tracking branch 'origin' into serdar/issue#3246-json-de…
srdtrk Jun 1, 2023
88fe02b
fix(ica): fix panic if message does not implement sdk.Msg
srdtrk Jun 1, 2023
a42145b
imp(ica): improved json serde functions
srdtrk Jun 1, 2023
200b282
style(ica): pleased the linter
srdtrk Jun 1, 2023
9602b47
style(ica): ran gofumpt
srdtrk Jun 1, 2023
97de732
merge: remote-tracking branch 'origin' into serdar/issue#3246-json-de…
srdtrk Jun 1, 2023
f3d9879
fix(e2e): fix compilation errors by adding icatypes.EncodingProtobuf …
srdtrk Jun 1, 2023
a0485f2
feat(ica.test): added important wip test for deserializing directly f…
srdtrk Jun 1, 2023
7bc2f41
imp(ica.test): added a new test case to cw codec unit test
srdtrk Jun 1, 2023
8869b7a
imp(ica): added another test case
srdtrk Jun 1, 2023
7987739
imp(ica.test): added another test case
srdtrk Jun 1, 2023
fb15e55
imp(ica.test): added another test case
srdtrk Jun 1, 2023
cb18323
style(ica.test): improved test style
srdtrk Jun 1, 2023
fef3871
style(ica.test): improved test style
srdtrk Jun 1, 2023
4b8c62f
style(ica.test): ran gofumpt
srdtrk Jun 1, 2023
9ed13d8
imp(ica.test): added json encoding version string for testing
srdtrk Jun 2, 2023
e5d6c68
imp(ica.test): added new 'NewJSONICAPath' function
srdtrk Jun 2, 2023
483937d
imp(ica.test): added encoding field to ica test setup functions
srdtrk Jun 2, 2023
99fb8e8
fix(ica.test): fixed test setups using the new encoding field
srdtrk Jun 2, 2023
1ee1fa7
feat(ica.test): added json test case
srdtrk Jun 2, 2023
550a314
style(ica.test): ran gofumpt
srdtrk Jun 2, 2023
53aeadd
feat(ica.test): got two cases of cosmwasm tests working in relay
srdtrk Jun 2, 2023
3aee5f0
merge: branch 'main' into serdar/issue#3246-json-decoding-for-ica
srdtrk Jun 2, 2023
2dc24bd
style(ica.test): ran gofumpt
srdtrk Jun 2, 2023
f033903
feat(ica): started progress on recursive handling of Anys
srdtrk Jun 2, 2023
509b625
imp(ica.test): added a new test case for ica json encoding, this fails
srdtrk Jun 2, 2023
3daf6e2
feat(ica): achieved total json serialization (excluding any lists)
srdtrk Jun 3, 2023
1e8cbe3
refactor(ica): made function shorter and removed duplicated code
srdtrk Jun 3, 2023
2d50034
style(ica): ran gofumpt
srdtrk Jun 3, 2023
86e5407
imp(ica): added more err handling code
srdtrk Jun 4, 2023
da2801a
refactor(ica): made deserialize code shorter
srdtrk Jun 4, 2023
5785d02
style(ica): made linter a bit more happy
srdtrk Jun 4, 2023
3f389ea
fix(ica.test): fixed one codec test case
srdtrk Jun 4, 2023
e5d982e
feat(ica): added []Any handling code
srdtrk Jun 5, 2023
3bde3dc
fix(ica): added more safety
srdtrk Jun 5, 2023
db4fd5b
nit: deleted testing codec.go
srdtrk Jun 5, 2023
14b3f0d
feat(ica): all works
srdtrk Jun 5, 2023
12b20ec
style(ica): ran gofumpt
srdtrk Jun 5, 2023
e2ad1a1
style(ica): made linter happy
srdtrk Jun 5, 2023
437fd25
refactor(ica): reduced code duplication
srdtrk Jun 5, 2023
f732702
nit(ica): uncommented some test cases
srdtrk Jun 5, 2023
95ccad3
imp(ica.test): added more test cases
srdtrk Jun 5, 2023
ea3792d
feat(ica.test): finished test cases
srdtrk Jun 6, 2023
4f3e7d6
style(ica.test): reorganized test cases
srdtrk Jun 6, 2023
32e91e9
refactor(ica.test): combined the two test cases into one
srdtrk Jun 6, 2023
f9bab4c
style(ica.test): ran gofumpt
srdtrk Jun 6, 2023
6bd1b47
style(ica.test): renamed wallet address
srdtrk Jun 6, 2023
f0ca07d
merge: branch 'main' into serdar/issue#3246-json-decoding-for-ica
srdtrk Jun 6, 2023
e7eabe5
fix(ica.test): fixed test case names
srdtrk Jun 7, 2023
67d02f0
imp(ica.test): added more test cases
srdtrk Jun 7, 2023
ae8aa60
style(ica.test): ran gofumpt
srdtrk Jun 7, 2023
2d01c88
test(ica): added more codec test cases
srdtrk Jun 7, 2023
e331980
merge: branch 'main' into serdar/issue#3246-json-decoding-for-ica
srdtrk Jun 7, 2023
1bd9af7
style(ica.test): ran gofumpt
srdtrk Jun 7, 2023
59d9c2e
feat(ica): removed JSONAny and JSONCosmosTx types
srdtrk Jun 7, 2023
e657656
feat(ica): implemented json encoding using module codec
srdtrk Jun 8, 2023
92648d8
fix(ica.test): tests now match the new codec implementation
srdtrk Jun 8, 2023
d52962d
fix(ica.test): fixed the tests to the new implementation
srdtrk Jun 8, 2023
4749442
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 8, 2023
172879d
style(ica.test): reorgenized the order of tests so that git diff make…
srdtrk Jun 8, 2023
4e18bad
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 8, 2023
3b5b872
imp(ica/controller): controller codec need not be codec.Codec
srdtrk Jun 14, 2023
ade40de
imp(ica): replaced BinaryCodec with Codec
srdtrk Jun 14, 2023
12b556c
test(ica): fixed codec test
srdtrk Jun 14, 2023
5e530b8
docs(ica.test): codec comment updated
srdtrk Jun 14, 2023
575220c
docs(ica.test): updated comments
srdtrk Jun 14, 2023
dbaed63
style(ica.test): removed 'from cosmwasm' from test case name as it is…
srdtrk Jun 14, 2023
b8b41ac
style(ica.test): ran gofumpt
srdtrk Jun 14, 2023
6eff38c
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 14, 2023
2e3914c
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 15, 2023
4597a8b
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 17, 2023
1767dcc
fix: fix merge error
srdtrk Jun 17, 2023
b169aa7
deps(ica): replaced sdk.NewInt with sdkmath.NewInt
srdtrk Jun 17, 2023
5cd75c9
style(ica): ran 'gofumpt'
srdtrk Jun 17, 2023
48aa851
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 20, 2023
936e7a9
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 23, 2023
5123fba
imp(ica): removed redundant cosmwasm tests
srdtrk Jun 24, 2023
e893d21
revert: "imp(ica): removed redundant cosmwasm tests"
srdtrk Jun 26, 2023
2581cc1
imp(ica.test): made codec_test human readable
srdtrk Jun 26, 2023
a06a882
imp(ica.test): made relay_test human readable
srdtrk Jun 26, 2023
1bb2c9f
style(ica.test): ran 'golanci-lint run --fix'
srdtrk Jun 26, 2023
954f12e
Merge branch 'main' into serdar/issue#3246-alternative-approach
crodriguezvega Jun 27, 2023
0dca4ae
merge: branch 'main' into fix-json-merge
srdtrk Jun 27, 2023
5a0cd81
merge: branch 'fix-json-merge' into serdar/issue#3246-alternative-app…
srdtrk Jun 27, 2023
10d79db
imp(ica/host): created 'GetAppMetadata' function
srdtrk Jun 27, 2023
2955eb9
refactor(ica/host): used GetAppMetadata function
srdtrk Jun 27, 2023
3ae45fa
imp(ica.test): removed unneeded encoding argument
srdtrk Jun 27, 2023
0813c59
imp(ica): removed ErrUnsupportedEncoding
srdtrk Jun 27, 2023
6b7ac18
imp(ica.test): used suite chainB height instead of clienttypes.NewHei…
srdtrk Jun 27, 2023
30dfe0f
imp(ica.test): add nil check for unsupported encoding
srdtrk Jun 27, 2023
f4112e7
imp(ica.test): added a empty/nil checks
srdtrk Jun 27, 2023
45bb7a7
style(ica.test): renamed version variable to TestVersionWithJSONEncoding
srdtrk Jun 27, 2023
9a87cee
imp(ica): wrapped some errors
srdtrk Jun 27, 2023
048bedd
style(ica): ran 'golanci-lint run --fix'
srdtrk Jun 27, 2023
704a99f
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 28, 2023
635a878
style(ica)!: renamed EncodingJSON to EncodingProto3JSON
srdtrk Jun 28, 2023
cb5d44d
docs(ica): improved godocs
srdtrk Jun 28, 2023
4408877
imp(ica): passing codec instead of binary codec
srdtrk Jun 28, 2023
7a66beb
style(ica): improved error messages and godocs
srdtrk Jun 28, 2023
85eb946
docs(ica.test): improved godocs for tests
srdtrk Jun 28, 2023
ab72e95
imp(ica.test): improved unsupported encoding test case slightly
srdtrk Jun 28, 2023
3b4e389
style(ica.test): test style improvements
srdtrk Jun 28, 2023
5b7c709
imp(ica.test): added expError to some codec tests
srdtrk Jun 28, 2023
b4cbe28
imp(ica.test): added more error type checks to codec tests
srdtrk Jun 28, 2023
7e2b841
style(ica.test): ran 'golangci-lint run --fix'
srdtrk Jun 28, 2023
985632f
imp(ica/host.test): added 'TestMetadataNotFound'
srdtrk Jun 28, 2023
b771d3f
imp(ica/host.test): reduce test size
srdtrk Jun 28, 2023
68db856
docs(ica/host.test): updated godocs for test
srdtrk Jul 2, 2023
d0b2483
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 2, 2023
f6abbb1
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 3, 2023
6a7c8f9
docs(ica/host): improved godoc
srdtrk Jul 3, 2023
9010228
imp(ica/host): made GetAppMetadata private
srdtrk Jul 3, 2023
9c3ef7e
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 3, 2023
e81ac1f
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// Keeper defines the IBC interchain accounts controller keeper
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
cdc codec.Codec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not strictly necessary since the controller doesn't do JSON marshaling, what prompted this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was your comment that prompted the change: #3796 (comment)

Lmk if you want me to revert the change before I merge today

legacySubspace paramtypes.Subspace
ics4Wrapper porttypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper
Expand All @@ -44,7 +44,7 @@ type Keeper struct {

// NewKeeper creates a new interchain accounts controller Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace,
cdc codec.Codec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string,
) Keeper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (suite *KeeperTestSuite) TestSubmitTx() {
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100))),
}

data, err := icatypes.SerializeCosmosTx(suite.chainA.Codec, []proto.Message{icaMsg}, icatypes.EncodingProtobuf)
data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{icaMsg}, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

packetData := icatypes.InterchainAccountPacketData{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func TestGeneratePacketData(t *testing.T) {
require.Equal(t, tc.memo, packetData.Memo)

data := packetData.Data
// cli tx commands always use protobuf encoding
messages, err := icatypes.DeserializeCosmosTx(cdc, data, icatypes.EncodingProtobuf)

require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
ToAddress: suite.chainB.SenderAccount.GetAddress().String(),
Amount: amount,
}
data, err := icatypes.SerializeCosmosTx(suite.chainA.Codec, []proto.Message{msg}, icatypes.EncodingProtobuf)
data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{msg}, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

icaPacketData := icatypes.InterchainAccountPacketData{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() {
func (suite *KeeperTestSuite) TestExportGenesis() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewICAPath(suite.chainA, suite.chainB)
path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress)
Expand Down Expand Up @@ -356,7 +356,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewICAPath(suite.chainA, suite.chainB)
path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress)
Expand Down Expand Up @@ -399,7 +399,7 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewICAPath(suite.chainA, suite.chainB)
path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
Expand Down
19 changes: 19 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -18,6 +20,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

Expand Down Expand Up @@ -106,6 +109,22 @@ func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string
return k.ics4Wrapper.GetAppVersion(ctx, portID, channelID)
}

// GetAppMetadata retrieves the interchain accounts metadata from the store associated with the provided portID and channelID
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) {
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
appVersion, found := k.GetAppVersion(ctx, portID, channelID)
if !found {
return icatypes.Metadata{}, errorsmod.Wrapf(ibcerrors.ErrNotFound, "app version not found for port %s and channel %s", portID, channelID)
}

var metadata icatypes.Metadata
if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(appVersion), &metadata); err != nil {
// UnmarshalJSON errors are indeterminate and therefore are not wrapped and included in failed acks
return icatypes.Metadata{}, errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata")
}
Comment on lines +121 to +123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess one slight consideration here is that the error code changes depending on whether you wrap the error or not (the error code is included in the acknowledgement). I don't have a preference one way or another, but given that we do have a strong guarantee that we will wipe non-deterministic info from an error before creating a error acknowledgement, I could be okay with wrapping the error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't wrapped them since this is what we agreed in one of the calls. If you don't have a preference, I'm happy to keep it as is.


return metadata, nil
}

// GetActiveChannelID retrieves the active channelID from the store keyed by the provided connectionID and portID
func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
Expand Down
49 changes: 41 additions & 8 deletions modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/suite"
Expand All @@ -9,6 +10,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
)

Expand All @@ -27,6 +29,15 @@ var (
Encoding: icatypes.EncodingProtobuf,
TxType: icatypes.TxTypeSDKMultiMsg,
}))

// TestJSONVersion defines a reusable interchainaccounts version string that uses JSON encoding for testing purposes
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
TestVersionWithJSONEncoding = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{
Version: icatypes.Version,
ControllerConnectionId: ibctesting.FirstConnectionID,
HostConnectionId: ibctesting.FirstConnectionID,
Encoding: icatypes.EncodingProto3JSON,
TxType: icatypes.TxTypeSDKMultiMsg,
}))
)

type KeeperTestSuite struct {
Expand All @@ -47,14 +58,25 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3))
}

func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
func NewICAPath(chainA, chainB *ibctesting.TestChain, encoding string) *ibctesting.Path {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] is it worth using an enum or type alias for an encoding type instead of a string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't because the original proto didn't include an enum. I'll implement it if others agree

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to make this change, previously I don't think the encoding type as a string was exposed to any public interfaces, but these changes will make that the case. Also happy with a follow up PR making only these changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the enum type!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into using enums and will probably make this change soon but here is something I've noticed:

  • You cannot customise the stringer by using gogoproto extensions. But we need a custom stringer for backwards compatibility (this is because we need the ENCODING_PROTO3 enum variant to become "proto3"). Which means we must disable the default stringer (which is something the extensions can do), and write our own stringer in metadata.go.

This feels over-complicated for this functionality. Nevertheless, I'll make the change and see what happens.

Copy link
Member Author

@srdtrk srdtrk Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually sorry, this works: (but it looks weird due to using non-capitalized enum variants):

// Encoding defines the supported codec formats for interchain account transactions
enum Encoding {
  option (gogoproto.goproto_enum_prefix) = false;

  // Default zero value enumeration
  ENCODING_UNKNOWN_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNKNOWN"];
  // proto3 defines the proto3 protobuf encoding
  proto3 = 1 [(gogoproto.enumvalue_customname) = "PROTO3"];
  // proto3json defines the proto3 json encoding
  proto3json = 2 [(gogoproto.enumvalue_customname) = "PROTO3JSON"];
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, after attempting to implement this, I realized this would require reopening of the merged PR to the main, see #3967. Which leads me to think that it is best done in another PR to main, either after this is merged, or before. So I will not push the changes here. I will discuss this briefly in the engineering call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree it should be discussed in a separate pr. As a side note, enums are encoded differently between standard json and proto3 json. Currently ICA uses proto3 json for encoding the metadata, if it used standard json this change wouldn't be backwards compatible

The enum string value for proto3 must be the same as the existing string otherwise we will break cross compatibility for opening channels

I would also not backport this change

path := ibctesting.NewPath(chainA, chainB)

var version string
switch encoding {
case icatypes.EncodingProtobuf:
version = TestVersion
case icatypes.EncodingProto3JSON:
version = TestVersionWithJSONEncoding
default:
panic(fmt.Sprintf("unsupported encoding type: %s", encoding))
}

path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID
path.EndpointB.ChannelConfig.PortID = icatypes.HostPortID
path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointA.ChannelConfig.Version = TestVersion
path.EndpointB.ChannelConfig.Version = TestVersion
path.EndpointA.ChannelConfig.Version = version
path.EndpointB.ChannelConfig.Version = version

return path
}
Expand Down Expand Up @@ -85,7 +107,7 @@ func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) erro

channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(endpoint.Chain.GetContext())

if err := endpoint.Chain.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, TestVersion); err != nil {
if err := endpoint.Chain.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, endpoint.ChannelConfig.Version); err != nil {
return err
}

Expand All @@ -106,7 +128,7 @@ func TestKeeperTestSuite(t *testing.T) {
func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
Expand All @@ -131,7 +153,7 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
Expand Down Expand Up @@ -165,7 +187,7 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {

suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
Expand Down Expand Up @@ -197,7 +219,7 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {
func (suite *KeeperTestSuite) TestIsActiveChannel() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
Expand All @@ -220,6 +242,17 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
suite.Require().Equal(expectedAccAddr, retrievedAddr)
}

func (suite *KeeperTestSuite) TestMetadataNotFound() {
var (
invalidPortID = "invalid-port"
invalidChannelID = "invalid-channel"
)

_, err := suite.chainB.GetSimApp().ICAHostKeeper.GetAppMetadata(suite.chainB.GetContext(), invalidPortID, invalidChannelID)
suite.Require().ErrorIs(err, ibcerrors.ErrNotFound)
suite.Require().Contains(err.Error(), fmt.Sprintf("app version not found for port %s and channel %s", invalidPortID, invalidChannelID))
}

func (suite *KeeperTestSuite) TestParams() {
expParams := types.DefaultParams()

Expand Down
7 changes: 6 additions & 1 deletion modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byt
return nil, errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data")
}

metadata, err := k.GetAppMetadata(ctx, packet.DestinationPort, packet.DestinationChannel)
if err != nil {
return nil, err
}

switch data.Type {
case icatypes.EXECUTE_TX:
msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data, icatypes.EncodingProtobuf)
msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data, metadata.Encoding)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed to deserialize interchain account transaction")
}
Expand Down
Loading
Loading