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

docs: ICA queries #6068

Merged
merged 8 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions docs/docs/02-apps/02-interchain-accounts/04-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ scopedICAAuthKeeper := app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleNam
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper, app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper,
scopedICAHostKeeper, app.MsgServiceRouter(), app.GRPCQueryRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Create Interchain Accounts AppModule
Expand Down
25 changes: 25 additions & 0 deletions docs/docs/02-apps/02-interchain-accounts/05-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ type MsgSendTxResponse struct {

The packet `Sequence` is returned in the message response.

### Queries

It is possible to use [`MsgModuleQuerySafe`](https://github.com/cosmos/ibc-go/blob/eecfa5c09a4c38a5c9f2cc2a322d2286f45911da/proto/ibc/applications/interchain_accounts/host/v1/tx.proto#L41-L51) to execute a list of queries on the host chain. This message can be included in the list of encoded `sdk.Msg`s of `InterchainPacketData`. The host chain will return on the acknowledgment the responses for all the queries. Please note that only module safe queries can be executed. The following code block shows an example of how this message can be used to query the account balance of an account on the host chain. The resulting packet data variable is used to set the `PacketData` of `MsgSendTx`.
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved

```go
balanceQuery := banktypes.NewQueryBalanceRequest("cosmos1...", "uatom")
queryBz, err := balanceQuery.Marshal()

// signer of message must be the interchain account on the host
queryMsg := icahosttypes.NewMsgModuleQuerySafe("cosmos2...", []*icahosttypes.QueryRequest{
{
Path: "/cosmos.bank.v1beta1.Query/Balance",
Data: queryBz,
},
})

bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{queryMsg}, icatypes.EncodingProtobuf)

packetData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: bz,
Memo: "",
}
```

## Atomicity

As the Interchain Accounts module supports the execution of multiple transactions using the Cosmos SDK `Msg` interface, it provides the same atomicity guarantees as Cosmos SDK-based applications, leveraging the [`CacheMultiStore`](https://docs.cosmos.network/main/learn/advanced/store#cachemultistore) architecture provided by the [`Context`](https://docs.cosmos.network/main/learn/advanced/context.html) type.
Expand Down
15 changes: 15 additions & 0 deletions docs/docs/05-migrations/13-v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ Please use the new functions `path.Setup`, `path.SetupClients`, `path.SetupConne
- Functions `ConstructUpdateTMClientHeader` and `ConstructUpdateTMClientHeaderWithTrustedHeight` of `TestChain` type have been replaced with `IBCClientHeader`. This function will construct a `07-tendermint` header to update the light client on the counterparty chain. The trusted height must be passed in as a non-zero height.
- `GetValsAtHeight` has been renamed to `GetTrustedValidators`

### ICS27 - Interchain Accounts

In [#5785](https://github.com/cosmos/ibc-go/pull/5785) the list of arguments of the `NewKeeper` constructor function of the host submodule was extended with an extra argument for the gRPC query router that the submodule uses when executing a [`MsgModuleQuerySafe`](https://github.com/cosmos/ibc-go/blob/eecfa5c09a4c38a5c9f2cc2a322d2286f45911da/proto/ibc/applications/interchain_accounts/host/v1/tx.proto#L41-L51) to perform queries that are module safe:

```diff
func NewKeeper(
cdc codec.Codec, key storetypes.StoreKey, legacySubspace icatypes.ParamSubspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper,
portKeeper icatypes.PortKeeper, accountKeeper icatypes.AccountKeeper,
scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter,
+ queryRouter icatypes.QueryRouter,
authority string,
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
) Keeper
```

## Relayers

- Renaming of event attribute keys in [#5603](https://github.com/cosmos/ibc-go/pull/5603).
Comment on lines 47 to 67
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [19-19]

The note about golang semantic versioning could be clarified for better understanding. Consider specifying that this applies to the import paths in Go modules.

- **Note:** ibc-go supports golang semantic versioning and therefore all imports must be updated on major version releases.
+ **Note:** IBC-Go adheres to Go's semantic versioning, requiring updates to import paths in Go modules upon major version releases.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [46-46]

The term "favour" is used, which is British English. While not incorrect, the document should maintain consistent use of American English if that's the standard being followed.

- The `mock.PV` type has been removed in favour of [`cmttypes.MockPV`](https://github.com/cometbft/cometbft/blob/v0.38.5/types/priv_validator.go#L50)
+ The `mock.PV` type has been removed in favor of [`cmttypes.MockPV`](https://github.com/cometbft/cometbft/blob/v0.38.5/types/priv_validator.go#L50)

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [77-77]

There's a repeated whitespace before CheckSubstituteAndUpdateState in the table mapping ClientState interface functions to LightClientModule interface functions. This could be a typo or formatting issue.

- |`UpdateStateOnMisbehaviour`    |`UpdateStateOnMisbehaviour`  | |`CheckSubstituteAndUpdateState`|`RecoverClient`              |
+ |`UpdateStateOnMisbehaviour`    |`UpdateStateOnMisbehaviour`  | |`CheckSubstituteAndUpdateState`|`RecoverClient`              |

Expand Down
73 changes: 73 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

Expand Down Expand Up @@ -74,3 +75,75 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {
}
}
}

func TestMsgModuleQuerySafeValidateBasic(t *testing.T) {
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
queryRequest := &types.QueryRequest{
Path: "/cosmos.bank.v1beta1.Query/Balance",
Data: []byte{},
}

testCases := []struct {
name string
msg *types.MsgModuleQuerySafe
expErr error
}{
{
"success: valid signer address",
types.NewMsgModuleQuerySafe(sdk.AccAddress(ibctesting.TestAccAddress).String(), []*types.QueryRequest{queryRequest}),
nil,
},
{
"failure: invalid signer address",
types.NewMsgModuleQuerySafe("signer", []*types.QueryRequest{queryRequest}),
ibcerrors.ErrInvalidAddress,
},
{
"failure: empty query requests",
types.NewMsgModuleQuerySafe(sdk.AccAddress(ibctesting.TestAccAddress).String(), []*types.QueryRequest{}),
ibcerrors.ErrInvalidRequest,
},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
err := tc.msg.ValidateBasic()

expPass := tc.expErr == nil
if expPass {
require.NoError(t, err)
} else {
require.Error(t, err)
require.ErrorIs(t, err, tc.expErr)
}
})
}
}

func TestMsgModuleQuerySafeGetSigners(t *testing.T) {
testCases := []struct {
name string
address sdk.AccAddress
expPass bool
}{
{"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), true},
{"failure: nil address", nil, false},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
msg := types.NewMsgModuleQuerySafe(tc.address.String(), []*types.QueryRequest{})
encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
if tc.expPass {
require.NoError(t, err)
require.Equal(t, tc.address.Bytes(), signers[0])
} else {
require.Error(t, err)
}
})
}
}
Loading