diff --git a/CHANGELOG.md b/CHANGELOG.md index 760c399b8ef..f1ac73885eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (apps/27-interchain-accounts) [\#5785](https://github.com/cosmos/ibc-go/pull/5785) Introduce a new tx message that ICA host submodule can use to query the chain (only those marked with `module_query_safe`) and write the responses to the acknowledgement. + ### Bug Fixes ## [v8.1.0](https://github.com/cosmos/ibc-go/releases/tag/v8.1.0) - 2024-01-31 diff --git a/e2e/tests/interchain_accounts/query_test.go b/e2e/tests/interchain_accounts/query_test.go new file mode 100644 index 00000000000..b8db5f067a6 --- /dev/null +++ b/e2e/tests/interchain_accounts/query_test.go @@ -0,0 +1,161 @@ +//go:build !test_e2e + +package interchainaccounts + +import ( + "context" + "encoding/hex" + "encoding/json" + "testing" + "time" + + "github.com/cosmos/gogoproto/proto" + "github.com/strangelove-ventures/interchaintest/v8/testutil" + testifysuite "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +func TestInterchainAccountsQueryTestSuite(t *testing.T) { + testifysuite.Run(t, new(InterchainAccountsQueryTestSuite)) +} + +type InterchainAccountsQueryTestSuite struct { + testsuite.E2ETestSuite +} + +func (s *InterchainAccountsQueryTestSuite) TestInterchainAccountsQuery() { + t := s.T() + ctx := context.TODO() + + // setup relayers and connection-0 between two chains + // channel-0 is a transfer channel but it will not be used in this test case + relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) + chainA, chainB := s.GetChains() + + // setup 2 accounts: controller account on chain A, a second chain B account. + // host account will be created when the ICA is registered + controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + controllerAddress := controllerAccount.FormattedAddress() + chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + var hostAccount string + + t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + // explicitly set the version string because we don't want to use incentivized channels. + version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.UNORDERED) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) + s.AssertTxSuccess(txResp) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("verify interchain account", func(t *testing.T) { + var err error + hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) + s.Require().NoError(err) + s.Require().NotZero(len(hostAccount)) + + channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) + s.Require().NoError(err) + s.Require().Len(channels, 2) + }) + + t.Run("query via interchain account", func(t *testing.T) { + // the host account need not be funded + t.Run("broadcast query packet", func(t *testing.T) { + balanceQuery := banktypes.NewQueryBalanceRequest(chainBAccount.Address(), chainB.Config().Denom) + queryBz, err := balanceQuery.Marshal() + s.Require().NoError(err) + + queryMsg := icahosttypes.NewMsgModuleQuerySafe(hostAccount, []*icahosttypes.QueryRequest{ + { + Path: "/cosmos.bank.v1beta1.Query/Balance", + Data: queryBz, + }, + }) + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{queryMsg}, icatypes.EncodingProtobuf) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + icaQueryMsg := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) + + txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, icaQueryMsg) + s.AssertTxSuccess(txResp) + + s.Require().NoError(testutil.WaitForBlocks(ctx, 10, chainA, chainB)) + }) + + t.Run("verify query response", func(t *testing.T) { + var expQueryHeight uint64 + + ack := &channeltypes.Acknowledgement_Result{} + t.Run("retrieve acknowledgement", func(t *testing.T) { + txSearchRes, err := s.QueryTxsByEvents( + ctx, chainB, 1, 1, + "message.action='/ibc.core.channel.v1.MsgRecvPacket'", "", + ) + s.Require().NoError(err) + s.Require().Len(txSearchRes.Txs, 1) + + expQueryHeight = uint64(txSearchRes.Txs[0].Height) + + ackHexValue, isFound := s.ExtractValueFromEvents( + txSearchRes.Txs[0].Events, + channeltypes.EventTypeWriteAck, + channeltypes.AttributeKeyAckHex, + ) + s.Require().True(isFound) + s.Require().NotEmpty(ackHexValue) + + ackBz, err := hex.DecodeString(ackHexValue) + s.Require().NoError(err) + + err = json.Unmarshal(ackBz, ack) + s.Require().NoError(err) + }) + + icaAck := &sdk.TxMsgData{} + t.Run("unmarshal ica response", func(t *testing.T) { + err := proto.Unmarshal(ack.Result, icaAck) + s.Require().NoError(err) + s.Require().Len(icaAck.GetMsgResponses(), 1) + }) + + queryTxResp := &icahosttypes.MsgModuleQuerySafeResponse{} + t.Run("unmarshal MsgModuleQuerySafeResponse", func(t *testing.T) { + err := proto.Unmarshal(icaAck.MsgResponses[0].Value, queryTxResp) + s.Require().NoError(err) + s.Require().Len(queryTxResp.Responses, 1) + s.Require().Equal(expQueryHeight, queryTxResp.Height) + }) + + balanceResp := &banktypes.QueryBalanceResponse{} + t.Run("unmarshal and verify bank query response", func(t *testing.T) { + err := proto.Unmarshal(queryTxResp.Responses[0], balanceResp) + s.Require().NoError(err) + s.Require().Equal(chainB.Config().Denom, balanceResp.Balance.Denom) + s.Require().Equal(testvalues.StartingTokenAmount, balanceResp.Balance.Amount.Int64()) + }) + }) + }) +} diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index b9240aeb326..ca08e41c491 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -14,6 +14,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module/testutil" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -88,6 +89,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) { grouptypes.RegisterInterfaces(cfg.InterfaceRegistry) proposaltypes.RegisterInterfaces(cfg.InterfaceRegistry) authz.RegisterInterfaces(cfg.InterfaceRegistry) + txtypes.RegisterInterfaces(cfg.InterfaceRegistry) cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) return cdc, cfg diff --git a/e2e/testsuite/tx.go b/e2e/testsuite/tx.go index c3f39b8685c..ecbde19b3ad 100644 --- a/e2e/testsuite/tx.go +++ b/e2e/testsuite/tx.go @@ -16,6 +16,7 @@ import ( sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -23,6 +24,8 @@ import ( govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/ibc-go/e2e/testsuite/sanitize" "github.com/cosmos/ibc-go/e2e/testvalues" feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" @@ -297,3 +300,60 @@ func (s *E2ETestSuite) PruneAcknowledgements( msg := channeltypes.NewMsgPruneAcknowledgements(portID, channelID, limit, user.FormattedAddress()) return s.BroadcastMessages(ctx, chain, user, msg) } + +// QueryTxsByEvents runs the QueryTxsByEvents command on the given chain. +// https://github.com/cosmos/cosmos-sdk/blob/65ab2530cc654fd9e252b124ed24cbaa18023b2b/x/auth/client/cli/query.go#L33 +func (*E2ETestSuite) QueryTxsByEvents( + ctx context.Context, chain ibc.Chain, + page, limit int, query, orderBy string, +) (*sdk.SearchTxsResult, error) { + cosmosChain, ok := chain.(*cosmos.CosmosChain) + if !ok { + return nil, fmt.Errorf("QueryTxsByEvents must be passed a cosmos.CosmosChain") + } + + cmd := []string{"txs", "--query", query} + if orderBy != "" { + cmd = append(cmd, "--order_by", orderBy) + } + if page != 0 { + cmd = append(cmd, "--"+flags.FlagPage, strconv.Itoa(page)) + } + if limit != 0 { + cmd = append(cmd, "--"+flags.FlagLimit, strconv.Itoa(limit)) + } + + stdout, _, err := cosmosChain.GetNode().ExecQuery(ctx, cmd...) + if err != nil { + return nil, err + } + + result := &sdk.SearchTxsResult{} + err = Codec().UnmarshalJSON(stdout, result) + if err != nil { + return nil, err + } + + return result, nil +} + +// ExtractValueFromEvents extracts the value of an attribute from a list of events. +// If the attribute is not found, the function returns an empty string and false. +// If the attribute is found, the function returns the value and true. +func (*E2ETestSuite) ExtractValueFromEvents(events []abci.Event, eventType, attrKey string) (string, bool) { + for _, event := range events { + if event.Type != eventType { + continue + } + + for _, attr := range event.Attributes { + if attr.Key != attrKey { + continue + } + + return attr.Value, true + } + } + + return "", false +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/export_test.go b/modules/apps/27-interchain-accounts/host/keeper/export_test.go index bad2c32661a..4f413005499 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/export_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/export_test.go @@ -14,3 +14,8 @@ import ( func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) { return k.getAppMetadata(ctx, portID, channelID) } + +// NewModuleQuerySafeAllowList is a wrapper around newModuleQuerySafeAllowList to allow the function to be directly called in tests. +func NewModuleQuerySafeAllowList() []string { + return newModuleQuerySafeAllowList() +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 1012e0f4a0c..971e953f1ca 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -5,6 +5,12 @@ import ( "fmt" "strings" + gogoproto "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + + msgv1 "cosmossdk.io/api/cosmos/msg/v1" + queryv1 "cosmossdk.io/api/cosmos/query/v1" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -36,7 +42,11 @@ type Keeper struct { scopedKeeper exported.ScopedKeeper - msgRouter icatypes.MessageRouter + msgRouter icatypes.MessageRouter + queryRouter icatypes.QueryRouter + + // mqsAllowList is a list of all module safe query paths + mqsAllowList []string // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. @@ -48,7 +58,7 @@ 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, - authority string, + queryRouter icatypes.QueryRouter, authority string, ) Keeper { // ensure ibc interchain accounts module account is set if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil { @@ -69,6 +79,8 @@ func NewKeeper( accountKeeper: accountKeeper, scopedKeeper: scopedKeeper, msgRouter: msgRouter, + queryRouter: queryRouter, + mqsAllowList: newModuleQuerySafeAllowList(), authority: authority, } } @@ -261,3 +273,40 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { bz := k.cdc.MustMarshal(¶ms) store.Set([]byte(types.ParamsKey), bz) } + +// newModuleQuerySafeAllowList returns a list of all query paths labeled with module_query_safe in the proto files. +func newModuleQuerySafeAllowList() []string { + protoFiles, err := gogoproto.MergedRegistry() + if err != nil { + panic(err) + } + + allowList := []string{} + protoFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool { + for i := 0; i < fd.Services().Len(); i++ { + // Get the service descriptor + sd := fd.Services().Get(i) + + // Skip services that are annotated with the "cosmos.msg.v1.service" option. + if ext := proto.GetExtension(sd.Options(), msgv1.E_Service); ext != nil && ext.(bool) { + continue + } + + for j := 0; j < sd.Methods().Len(); j++ { + // Get the method descriptor + md := sd.Methods().Get(j) + + // Skip methods that are not annotated with the "cosmos.query.v1.module_query_safe" option. + if ext := proto.GetExtension(md.Options(), queryv1.E_ModuleQuerySafe); ext == nil || !ext.(bool) { + continue + } + + // Add the method to the whitelist + allowList = append(allowList, fmt.Sprintf("/%s/%s", sd.FullName(), md.Name())) + } + } + return true + }) + + return allowList +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 6af0abb67ca..3b25bf90a85 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -147,6 +147,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().AccountKeeper, suite.chainA.GetSimApp().ScopedICAHostKeeper, suite.chainA.GetSimApp().MsgServiceRouter(), + suite.chainA.GetSimApp().GRPCQueryRouter(), suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), ) }, true}, @@ -161,6 +162,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { authkeeper.AccountKeeper{}, // empty account keeper suite.chainA.GetSimApp().ScopedICAHostKeeper, suite.chainA.GetSimApp().MsgServiceRouter(), + suite.chainA.GetSimApp().GRPCQueryRouter(), suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), ) }, false}, @@ -175,6 +177,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().AccountKeeper, suite.chainA.GetSimApp().ScopedICAHostKeeper, suite.chainA.GetSimApp().MsgServiceRouter(), + suite.chainA.GetSimApp().GRPCQueryRouter(), "", // authority ) }, false}, @@ -198,6 +201,31 @@ func (suite *KeeperTestSuite) TestNewKeeper() { } } +func (suite *KeeperTestSuite) TestNewModuleQuerySafeAllowList() { + // Currently, all queries in bank, staking, auth, and circuit are marked safe + // Notably, the gov and distribution modules are not marked safe + + var allowList []string + suite.Require().NotPanics(func() { + allowList = keeper.NewModuleQuerySafeAllowList() + }) + + suite.Require().NotEmpty(allowList) + suite.Require().Contains(allowList, "/cosmos.bank.v1beta1.Query/Balance") + suite.Require().Contains(allowList, "/cosmos.bank.v1beta1.Query/AllBalances") + suite.Require().Contains(allowList, "/cosmos.staking.v1beta1.Query/Validator") + suite.Require().Contains(allowList, "/cosmos.staking.v1beta1.Query/Validators") + suite.Require().Contains(allowList, "/cosmos.circuit.v1.Query/Account") + suite.Require().Contains(allowList, "/cosmos.circuit.v1.Query/DisabledList") + suite.Require().Contains(allowList, "/cosmos.auth.v1beta1.Query/Accounts") + suite.Require().Contains(allowList, "/cosmos.auth.v1beta1.Query/ModuleAccountByName") + suite.Require().Contains(allowList, "/ibc.core.client.v1.Query/VerifyMembership") + suite.Require().NotContains(allowList, "/cosmos.gov.v1beta1.Query/Proposals") + suite.Require().NotContains(allowList, "/cosmos.gov.v1.Query/Proposals") + suite.Require().NotContains(allowList, "/cosmos.distribution.v1beta1.Query/Params") + suite.Require().NotContains(allowList, "/cosmos.distribution.v1beta1.Query/DelegationRewards") +} + func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { suite.SetupTest() diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index c71dba65576..1dba2815295 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -2,11 +2,14 @@ package keeper import ( "context" + "slices" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) @@ -23,6 +26,41 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { return &msgServer{Keeper: keeper} } +// ModuleQuerySafe routes the queries to the keeper's query router if they are module_query_safe. +// This handler doesn't use the signer. +func (m msgServer) ModuleQuerySafe(goCtx context.Context, msg *types.MsgModuleQuerySafe) (*types.MsgModuleQuerySafeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + responses := make([][]byte, len(msg.Requests)) + for i, query := range msg.Requests { + isModuleQuerySafe := slices.Contains(m.mqsAllowList, query.Path) + if !isModuleQuerySafe { + return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "not module query safe: %s", query.Path) + } + + route := m.queryRouter.Route(query.Path) + if route == nil { + return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "no route to query: %s", query.Path) + } + + res, err := route(ctx, &abci.RequestQuery{ + Path: query.Path, + Data: query.Data, + }) + if err != nil { + m.Logger(ctx).Debug("query failed", "path", query.Path, "error", err) + return nil, err + } + if res == nil || res.Value == nil { + return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "no response for query: %s", query.Path) + } + + responses[i] = res.Value + } + + return &types.MsgModuleQuerySafeResponse{Responses: responses, Height: uint64(ctx.BlockHeight())}, nil +} + // UpdateParams updates the host submodule's params. func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if m.GetAuthority() != msg.Signer { diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go index 4cc47f781d2..d358303fc12 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go @@ -1,10 +1,157 @@ package keeper_test import ( + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" ) +func (suite *KeeperTestSuite) TestModuleQuerySafe() { + var ( + msg *types.MsgModuleQuerySafe + expResponses [][]byte + ) + testCases := []struct { + name string + malleate func() + expErr error + }{ + { + "success", + func() { + balanceQueryBz, err := banktypes.NewQueryBalanceRequest(suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom).Marshal() + suite.Require().NoError(err) + + queryReq := types.QueryRequest{ + Path: "/cosmos.bank.v1beta1.Query/Balance", + Data: balanceQueryBz, + } + + msg = types.NewMsgModuleQuerySafe(suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), []*types.QueryRequest{&queryReq}) + + balance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom) + + expResp := banktypes.QueryBalanceResponse{Balance: &balance} + expRespBz, err := expResp.Marshal() + suite.Require().NoError(err) + + expResponses = [][]byte{expRespBz} + }, + nil, + }, + { + "success: multiple queries", + func() { + balanceQueryBz, err := banktypes.NewQueryBalanceRequest(suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom).Marshal() + suite.Require().NoError(err) + + queryReq := types.QueryRequest{ + Path: "/cosmos.bank.v1beta1.Query/Balance", + Data: balanceQueryBz, + } + + paramsQuery := stakingtypes.QueryParamsRequest{} + paramsQueryBz, err := paramsQuery.Marshal() + suite.Require().NoError(err) + + paramsQueryReq := types.QueryRequest{ + Path: "/cosmos.staking.v1beta1.Query/Params", + Data: paramsQueryBz, + } + + msg = types.NewMsgModuleQuerySafe(suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), []*types.QueryRequest{&queryReq, ¶msQueryReq}) + + balance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom) + + expResp := banktypes.QueryBalanceResponse{Balance: &balance} + expRespBz, err := expResp.Marshal() + suite.Require().NoError(err) + + params, err := suite.chainA.GetSimApp().StakingKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().NoError(err) + expParamsResp := stakingtypes.QueryParamsResponse{Params: params} + expParamsRespBz, err := expParamsResp.Marshal() + suite.Require().NoError(err) + + expResponses = [][]byte{expRespBz, expParamsRespBz} + }, + nil, + }, + { + "failure: not module query safe", + func() { + balanceQueryBz, err := banktypes.NewQueryBalanceRequest(suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom).Marshal() + suite.Require().NoError(err) + + queryReq := types.QueryRequest{ + Path: "/cosmos.bank.v1beta1.Query/Balance", + Data: balanceQueryBz, + } + + paramsQuery := transfertypes.QueryParamsRequest{} + paramsQueryBz, err := paramsQuery.Marshal() + suite.Require().NoError(err) + + paramsQueryReq := types.QueryRequest{ + Path: "/ibc.applications.transfer.v1.Query/Params", + Data: paramsQueryBz, + } + + msg = types.NewMsgModuleQuerySafe(suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), []*types.QueryRequest{&queryReq, ¶msQueryReq}) + }, + ibcerrors.ErrInvalidRequest, + }, + { + "failure: invalid query path", + func() { + balanceQueryBz, err := banktypes.NewQueryBalanceRequest(suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom).Marshal() + suite.Require().NoError(err) + + queryReq := types.QueryRequest{ + Path: "/cosmos.invalid.Query/Invalid", + Data: balanceQueryBz, + } + + msg = types.NewMsgModuleQuerySafe(suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), []*types.QueryRequest{&queryReq}) + }, + ibcerrors.ErrInvalidRequest, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + // reset + msg = nil + expResponses = nil + + tc.malleate() + + ctx := suite.chainA.GetContext() + msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAHostKeeper) + res, err := msgServer.ModuleQuerySafe(ctx, msg) + + if tc.expErr == nil { + suite.Require().NoError(err) + suite.Require().NotNil(res) + + suite.Require().ElementsMatch(expResponses, res.Responses) + } else { + suite.Require().ErrorIs(err, tc.expErr) + suite.Require().Nil(res) + } + }) + } +} + func (suite *KeeperTestSuite) TestUpdateParams() { testCases := []struct { name string diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go index 9ad0ef02f12..ac5d41378e3 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go @@ -274,6 +274,38 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { }, nil, }, + { + "interchain account successfully executes icahosttypes.MsgModuleQuerySafe", + func(encoding string) { + interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID) + suite.Require().True(found) + + balanceQuery := banktypes.NewQueryBalanceRequest(suite.chainB.SenderAccount.GetAddress(), sdk.DefaultBondDenom) + queryBz, err := balanceQuery.Marshal() + suite.Require().NoError(err) + + msg := types.NewMsgModuleQuerySafe(interchainAccountAddr, []*types.QueryRequest{ + { + Path: "/cosmos.bank.v1beta1.Query/Balance", + Data: queryBz, + }, + }) + + data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{msg}, encoding) + suite.Require().NoError(err) + + icaPacketData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: data, + } + + packetData = icaPacketData.GetBytes() + + params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + }, + nil, + }, { "interchain account successfully executes disttypes.MsgSetWithdrawAddress", func(encoding string) { diff --git a/modules/apps/27-interchain-accounts/host/types/codec.go b/modules/apps/27-interchain-accounts/host/types/codec.go index 8752640e767..710d732573b 100644 --- a/modules/apps/27-interchain-accounts/host/types/codec.go +++ b/modules/apps/27-interchain-accounts/host/types/codec.go @@ -11,6 +11,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgUpdateParams{}, + &MsgModuleQuerySafe{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/modules/apps/27-interchain-accounts/host/types/codec_test.go b/modules/apps/27-interchain-accounts/host/types/codec_test.go index 6fb2591cf47..581a9401e2b 100644 --- a/modules/apps/27-interchain-accounts/host/types/codec_test.go +++ b/modules/apps/27-interchain-accounts/host/types/codec_test.go @@ -23,6 +23,11 @@ func TestCodecTypeRegistration(t *testing.T) { sdk.MsgTypeURL(&types.MsgUpdateParams{}), true, }, + { + "success: MsgModuleQuerySafe", + sdk.MsgTypeURL(&types.MsgModuleQuerySafe{}), + true, + }, { "type not registered on codec", "ibc.invalid.MsgTypeURL", diff --git a/modules/apps/27-interchain-accounts/host/types/host.pb.go b/modules/apps/27-interchain-accounts/host/types/host.pb.go index 77db265b6b5..54df248f119 100644 --- a/modules/apps/27-interchain-accounts/host/types/host.pb.go +++ b/modules/apps/27-interchain-accounts/host/types/host.pb.go @@ -78,8 +78,67 @@ func (m *Params) GetAllowMessages() []string { return nil } +// QueryRequest defines the parameters for a particular query request +// by an interchain account. +type QueryRequest struct { + // path defines the path of the query request as defined by ADR-021. + // https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-021-protobuf-query-encoding.md#custom-query-registration-and-routing + Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` + // data defines the payload of the query request as defined by ADR-021. + // https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-021-protobuf-query-encoding.md#custom-query-registration-and-routing + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *QueryRequest) Reset() { *m = QueryRequest{} } +func (m *QueryRequest) String() string { return proto.CompactTextString(m) } +func (*QueryRequest) ProtoMessage() {} +func (*QueryRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_48e202774f13d08e, []int{1} +} +func (m *QueryRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRequest.Merge(m, src) +} +func (m *QueryRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRequest proto.InternalMessageInfo + +func (m *QueryRequest) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + +func (m *QueryRequest) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + func init() { proto.RegisterType((*Params)(nil), "ibc.applications.interchain_accounts.host.v1.Params") + proto.RegisterType((*QueryRequest)(nil), "ibc.applications.interchain_accounts.host.v1.QueryRequest") } func init() { @@ -87,23 +146,25 @@ func init() { } var fileDescriptor_48e202774f13d08e = []byte{ - // 246 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0xcf, 0xbf, 0x4a, 0xc4, 0x40, - 0x10, 0xc7, 0xf1, 0x44, 0xe1, 0xd0, 0xf8, 0xa7, 0x48, 0x75, 0xd5, 0x72, 0x0a, 0xc2, 0x15, 0x66, - 0x97, 0xd3, 0xe2, 0xac, 0x05, 0x1b, 0x41, 0x90, 0x94, 0x36, 0x61, 0x77, 0xb2, 0x24, 0x0b, 0xbb, - 0x3b, 0x21, 0xb3, 0x89, 0xf8, 0x16, 0x3e, 0x96, 0xe5, 0x95, 0x96, 0x92, 0xbc, 0x88, 0x24, 0x0a, - 0x2a, 0x58, 0x0d, 0x7c, 0xe0, 0x07, 0xf3, 0x4d, 0xb6, 0x46, 0x81, 0x90, 0x4d, 0x63, 0x0d, 0xc8, - 0x60, 0xd0, 0x93, 0x30, 0x3e, 0xe8, 0x16, 0x6a, 0x69, 0x7c, 0x21, 0x01, 0xb0, 0xf3, 0x81, 0x44, - 0x8d, 0x14, 0x44, 0xbf, 0x99, 0x2f, 0x6f, 0x5a, 0x0c, 0x98, 0x5e, 0x1a, 0x05, 0xfc, 0xf7, 0x90, - 0xff, 0x33, 0xe4, 0xf3, 0xa0, 0xdf, 0x9c, 0xe7, 0xc9, 0xe2, 0x51, 0xb6, 0xd2, 0x51, 0x7a, 0x96, - 0x1c, 0x4f, 0x58, 0x68, 0x2f, 0x95, 0xd5, 0xe5, 0x32, 0x5e, 0xc5, 0xeb, 0x83, 0xfc, 0x68, 0xb2, - 0xbb, 0x2f, 0x4a, 0x2f, 0x92, 0x53, 0x69, 0x2d, 0x3e, 0x17, 0x4e, 0x13, 0xc9, 0x4a, 0xd3, 0x72, - 0x6f, 0xb5, 0xbf, 0x3e, 0xcc, 0x4f, 0x66, 0x7d, 0xf8, 0xc6, 0xdb, 0xf2, 0x6d, 0x60, 0xf1, 0x6e, - 0x60, 0xf1, 0xc7, 0xc0, 0xe2, 0xd7, 0x91, 0x45, 0xbb, 0x91, 0x45, 0xef, 0x23, 0x8b, 0x9e, 0xee, - 0x2b, 0x13, 0xea, 0x4e, 0x71, 0x40, 0x27, 0x00, 0xc9, 0x21, 0x09, 0xa3, 0x20, 0xab, 0x50, 0xf4, - 0x37, 0xc2, 0x61, 0xd9, 0x59, 0x4d, 0x53, 0x34, 0x89, 0xab, 0x6d, 0xf6, 0xf3, 0x76, 0xf6, 0xb7, - 0x37, 0xbc, 0x34, 0x9a, 0xd4, 0x62, 0xce, 0xbd, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x51, 0x50, - 0x78, 0xd7, 0x29, 0x01, 0x00, 0x00, + // 284 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0xd0, 0x31, 0x4b, 0xfc, 0x30, + 0x18, 0x06, 0xf0, 0xcb, 0xfd, 0xff, 0x1c, 0x5e, 0x3c, 0x1d, 0x3a, 0xdd, 0x14, 0xce, 0x03, 0xa1, + 0x83, 0x6d, 0x38, 0x05, 0xcf, 0x59, 0x70, 0x11, 0x04, 0xcd, 0xe8, 0x52, 0xde, 0xa4, 0xa1, 0x0d, + 0xb4, 0x4d, 0xed, 0x9b, 0x56, 0xee, 0x5b, 0xf8, 0xb1, 0x1c, 0x6f, 0x74, 0x94, 0xf6, 0x8b, 0x48, + 0xa3, 0xa0, 0x82, 0x53, 0x1e, 0x7e, 0xf0, 0x04, 0xde, 0x87, 0x6e, 0x8d, 0x54, 0x1c, 0xea, 0xba, + 0x30, 0x0a, 0x9c, 0xb1, 0x15, 0x72, 0x53, 0x39, 0xdd, 0xa8, 0x1c, 0x4c, 0x95, 0x80, 0x52, 0xb6, + 0xad, 0x1c, 0xf2, 0xdc, 0xa2, 0xe3, 0xdd, 0xc6, 0xbf, 0x71, 0xdd, 0x58, 0x67, 0x83, 0x33, 0x23, + 0x55, 0xfc, 0xb3, 0x18, 0xff, 0x51, 0x8c, 0x7d, 0xa1, 0xdb, 0xac, 0x05, 0x9d, 0xdd, 0x43, 0x03, + 0x25, 0x06, 0x27, 0x74, 0x31, 0x62, 0xa2, 0x2b, 0x90, 0x85, 0x4e, 0x97, 0x64, 0x45, 0xc2, 0x03, + 0x71, 0x38, 0xda, 0xcd, 0x27, 0x05, 0xa7, 0xf4, 0x18, 0x8a, 0xc2, 0x3e, 0x27, 0xa5, 0x46, 0x84, + 0x4c, 0xe3, 0x72, 0xba, 0xfa, 0x17, 0xce, 0xc5, 0x91, 0xd7, 0xbb, 0x2f, 0x5c, 0x5f, 0xd2, 0xc5, + 0x43, 0xab, 0x9b, 0x9d, 0xd0, 0x4f, 0xad, 0x46, 0x17, 0x04, 0xf4, 0x7f, 0x0d, 0x2e, 0xf7, 0x3f, + 0xce, 0x85, 0xcf, 0xa3, 0xa5, 0xe0, 0x60, 0x39, 0x5d, 0x91, 0x70, 0x21, 0x7c, 0xbe, 0x4e, 0x5f, + 0x7b, 0x46, 0xf6, 0x3d, 0x23, 0xef, 0x3d, 0x23, 0x2f, 0x03, 0x9b, 0xec, 0x07, 0x36, 0x79, 0x1b, + 0xd8, 0xe4, 0xf1, 0x36, 0x33, 0x2e, 0x6f, 0x65, 0xac, 0x6c, 0xc9, 0x95, 0xc5, 0xd2, 0x22, 0x37, + 0x52, 0x45, 0x99, 0xe5, 0xdd, 0x15, 0x2f, 0x6d, 0xda, 0x16, 0x1a, 0xc7, 0xb1, 0x90, 0x9f, 0x6f, + 0xa3, 0xef, 0x73, 0xa3, 0xdf, 0x3b, 0xb9, 0x5d, 0xad, 0x51, 0xce, 0xfc, 0x4c, 0x17, 0x1f, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x56, 0xc6, 0xd2, 0x5a, 0x61, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -148,6 +209,43 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintHost(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x12 + } + if len(m.Path) > 0 { + i -= len(m.Path) + copy(dAtA[i:], m.Path) + i = encodeVarintHost(dAtA, i, uint64(len(m.Path))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintHost(dAtA []byte, offset int, v uint64) int { offset -= sovHost(v) base := offset @@ -177,6 +275,23 @@ func (m *Params) Size() (n int) { return n } +func (m *QueryRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Path) + if l > 0 { + n += 1 + l + sovHost(uint64(l)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovHost(uint64(l)) + } + return n +} + func sovHost(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -285,6 +400,122 @@ func (m *Params) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHost + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Path", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHost + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthHost + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthHost + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Path = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHost + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHost + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHost + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipHost(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthHost + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipHost(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/modules/apps/27-interchain-accounts/host/types/msgs.go b/modules/apps/27-interchain-accounts/host/types/msgs.go index 8b23b5040e1..092ff1df850 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs.go @@ -11,6 +11,9 @@ import ( var ( _ sdk.Msg = (*MsgUpdateParams)(nil) _ sdk.HasValidateBasic = (*MsgUpdateParams)(nil) + + _ sdk.Msg = (*MsgModuleQuerySafe)(nil) + _ sdk.HasValidateBasic = (*MsgModuleQuerySafe)(nil) ) // NewMsgUpdateParams creates a new MsgUpdateParams instance @@ -21,7 +24,7 @@ func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams { } } -// ValidateBasic implements sdk.Msg +// ValidateBasic implements sdk.HasValidateBasic func (msg MsgUpdateParams) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { @@ -30,3 +33,25 @@ func (msg MsgUpdateParams) ValidateBasic() error { return msg.Params.Validate() } + +// NewMsgModuleQuerySafe creates a new MsgModuleQuerySafe instance +func NewMsgModuleQuerySafe(signer string, requests []*QueryRequest) *MsgModuleQuerySafe { + return &MsgModuleQuerySafe{ + Signer: signer, + Requests: requests, + } +} + +// ValidateBasic implements sdk.HasValidateBasic +func (msg MsgModuleQuerySafe) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + if len(msg.Requests) == 0 { + return errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "no queries provided") + } + + return nil +} diff --git a/modules/apps/27-interchain-accounts/host/types/tx.pb.go b/modules/apps/27-interchain-accounts/host/types/tx.pb.go index ebcc8995cb5..8663234557f 100644 --- a/modules/apps/27-interchain-accounts/host/types/tx.pb.go +++ b/modules/apps/27-interchain-accounts/host/types/tx.pb.go @@ -109,9 +109,107 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo +// MsgModuleQuerySafe defines the payload for Msg/ModuleQuerySafe +type MsgModuleQuerySafe struct { + // signer address + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + // requests defines the module safe queries to execute. + Requests []*QueryRequest `protobuf:"bytes,2,rep,name=requests,proto3" json:"requests,omitempty"` +} + +func (m *MsgModuleQuerySafe) Reset() { *m = MsgModuleQuerySafe{} } +func (m *MsgModuleQuerySafe) String() string { return proto.CompactTextString(m) } +func (*MsgModuleQuerySafe) ProtoMessage() {} +func (*MsgModuleQuerySafe) Descriptor() ([]byte, []int) { + return fileDescriptor_fa437afde7f1e7ae, []int{2} +} +func (m *MsgModuleQuerySafe) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgModuleQuerySafe) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgModuleQuerySafe.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgModuleQuerySafe) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgModuleQuerySafe.Merge(m, src) +} +func (m *MsgModuleQuerySafe) XXX_Size() int { + return m.Size() +} +func (m *MsgModuleQuerySafe) XXX_DiscardUnknown() { + xxx_messageInfo_MsgModuleQuerySafe.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgModuleQuerySafe proto.InternalMessageInfo + +// MsgModuleQuerySafeResponse defines the response for Msg/ModuleQuerySafe +type MsgModuleQuerySafeResponse struct { + // height at which the responses were queried + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + // protobuf encoded responses for each query + Responses [][]byte `protobuf:"bytes,2,rep,name=responses,proto3" json:"responses,omitempty"` +} + +func (m *MsgModuleQuerySafeResponse) Reset() { *m = MsgModuleQuerySafeResponse{} } +func (m *MsgModuleQuerySafeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgModuleQuerySafeResponse) ProtoMessage() {} +func (*MsgModuleQuerySafeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_fa437afde7f1e7ae, []int{3} +} +func (m *MsgModuleQuerySafeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgModuleQuerySafeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgModuleQuerySafeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgModuleQuerySafeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgModuleQuerySafeResponse.Merge(m, src) +} +func (m *MsgModuleQuerySafeResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgModuleQuerySafeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgModuleQuerySafeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgModuleQuerySafeResponse proto.InternalMessageInfo + +func (m *MsgModuleQuerySafeResponse) GetHeight() uint64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *MsgModuleQuerySafeResponse) GetResponses() [][]byte { + if m != nil { + return m.Responses + } + return nil +} + func init() { proto.RegisterType((*MsgUpdateParams)(nil), "ibc.applications.interchain_accounts.host.v1.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "ibc.applications.interchain_accounts.host.v1.MsgUpdateParamsResponse") + proto.RegisterType((*MsgModuleQuerySafe)(nil), "ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafe") + proto.RegisterType((*MsgModuleQuerySafeResponse)(nil), "ibc.applications.interchain_accounts.host.v1.MsgModuleQuerySafeResponse") } func init() { @@ -119,29 +217,36 @@ func init() { } var fileDescriptor_fa437afde7f1e7ae = []byte{ - // 352 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0xcd, 0x4c, 0x4a, 0xd6, - 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0xcf, 0xcc, 0x2b, - 0x49, 0x2d, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0x8b, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, - 0xd6, 0xcf, 0xc8, 0x2f, 0x2e, 0xd1, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0xd2, 0xc9, 0x4c, 0x4a, 0xd6, 0x43, 0xd6, 0xa6, 0x87, 0x45, 0x9b, 0x1e, 0x48, 0x9b, - 0x5e, 0x99, 0xa1, 0x94, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x58, 0xa3, 0x3e, 0x88, 0x05, 0x31, 0x43, - 0x4a, 0x3c, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x58, 0x3f, 0xb7, 0x38, 0x1d, 0x64, 0x76, 0x6e, 0x71, - 0x3a, 0x54, 0xc2, 0x9c, 0x24, 0x37, 0x81, 0x2d, 0x01, 0x6b, 0x54, 0xea, 0x63, 0xe4, 0xe2, 0xf7, - 0x2d, 0x4e, 0x0f, 0x2d, 0x48, 0x49, 0x2c, 0x49, 0x0d, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0x16, 0x12, - 0xe3, 0x62, 0x2b, 0xce, 0x4c, 0xcf, 0x4b, 0x2d, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, - 0xf2, 0x84, 0x82, 0xb8, 0xd8, 0x0a, 0xc0, 0x2a, 0x24, 0x98, 0x14, 0x18, 0x35, 0xb8, 0x8d, 0x4c, - 0xf4, 0x48, 0xf1, 0x92, 0x1e, 0xc4, 0x74, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, 0x26, - 0x59, 0xf1, 0x77, 0x2c, 0x90, 0x67, 0x68, 0x7a, 0xbe, 0x41, 0x0b, 0x6a, 0x89, 0x92, 0x24, 0x97, - 0x38, 0x9a, 0x7b, 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x8d, 0x16, 0x33, 0x72, 0x31, - 0xfb, 0x16, 0xa7, 0x0b, 0x4d, 0x61, 0xe4, 0xe2, 0x41, 0x71, 0xb0, 0x2d, 0x69, 0x0e, 0x41, 0x33, - 0x5f, 0xca, 0x95, 0x22, 0xed, 0x30, 0xe7, 0x49, 0xb1, 0x36, 0x3c, 0xdf, 0xa0, 0xc5, 0xe8, 0x94, - 0x72, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, - 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x5e, 0xe9, 0x99, 0x25, 0x19, - 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xd0, 0x88, 0xcc, 0x4c, 0x4a, 0xd6, 0x4d, 0xcf, 0xd7, - 0x2f, 0xb3, 0xd0, 0xcf, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x2d, 0x06, 0x45, 0x62, 0xb1, 0xbe, 0x91, - 0xb9, 0x2e, 0xc2, 0x05, 0xba, 0xa8, 0xf1, 0x57, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x8e, - 0x3e, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x76, 0xa2, 0x96, 0x3e, 0x8d, 0x02, 0x00, 0x00, + // 456 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0x41, 0x6b, 0xd4, 0x40, + 0x14, 0xc7, 0x33, 0x6d, 0x5d, 0xec, 0xb4, 0x50, 0x08, 0x62, 0x6b, 0x90, 0xb4, 0xec, 0x69, 0x29, + 0xee, 0x0c, 0x5d, 0x95, 0x4a, 0x41, 0x90, 0x82, 0x20, 0x42, 0x40, 0x47, 0xf4, 0xe0, 0x45, 0x26, + 0xb3, 0xe3, 0x64, 0xa0, 0xc9, 0xc4, 0xbc, 0xc9, 0x62, 0x6f, 0xe2, 0xc9, 0x93, 0x78, 0xd0, 0xa3, + 0xe0, 0x47, 0xe8, 0x77, 0xf0, 0xd2, 0x63, 0x8f, 0x9e, 0x44, 0x76, 0x0f, 0xfd, 0x1a, 0x92, 0x49, + 0xda, 0xda, 0xd4, 0x1e, 0x42, 0x6f, 0x99, 0x64, 0xfe, 0xbf, 0xf7, 0x7b, 0x99, 0x79, 0xf8, 0xbe, + 0x8e, 0x05, 0xe5, 0x79, 0xbe, 0xa7, 0x05, 0xb7, 0xda, 0x64, 0x40, 0x75, 0x66, 0x65, 0x21, 0x12, + 0xae, 0xb3, 0x37, 0x5c, 0x08, 0x53, 0x66, 0x16, 0x68, 0x62, 0xc0, 0xd2, 0xc9, 0x16, 0xb5, 0xef, + 0x49, 0x5e, 0x18, 0x6b, 0xfc, 0x3b, 0x3a, 0x16, 0xe4, 0xdf, 0x18, 0xf9, 0x4f, 0x8c, 0x54, 0x31, + 0x32, 0xd9, 0x0a, 0x6e, 0x28, 0xa3, 0x8c, 0x0b, 0xd2, 0xea, 0xa9, 0x66, 0x04, 0xab, 0xc2, 0x40, + 0x6a, 0x80, 0xa6, 0xa0, 0x2a, 0x76, 0x0a, 0xaa, 0xf9, 0xb0, 0xdd, 0xc9, 0xc9, 0x15, 0x71, 0xc1, + 0xfe, 0x67, 0x84, 0x57, 0x22, 0x50, 0x2f, 0xf3, 0x31, 0xb7, 0xf2, 0x19, 0x2f, 0x78, 0x0a, 0xfe, + 0x4d, 0xdc, 0x03, 0xad, 0x32, 0x59, 0xac, 0xa1, 0x0d, 0x34, 0x58, 0x64, 0xcd, 0xca, 0x67, 0xb8, + 0x97, 0xbb, 0x1d, 0x6b, 0x73, 0x1b, 0x68, 0xb0, 0x34, 0xba, 0x47, 0xba, 0xb4, 0x44, 0x6a, 0xfa, + 0xee, 0xc2, 0xe1, 0xef, 0x75, 0x8f, 0x35, 0xa4, 0x9d, 0x95, 0x4f, 0x3f, 0xd6, 0xbd, 0x8f, 0xc7, + 0x07, 0x9b, 0x4d, 0x91, 0xfe, 0x2d, 0xbc, 0xda, 0xf2, 0x61, 0x12, 0x72, 0x93, 0x81, 0xec, 0x7f, + 0x43, 0xd8, 0x8f, 0x40, 0x45, 0x66, 0x5c, 0xee, 0xc9, 0xe7, 0xa5, 0x2c, 0xf6, 0x5f, 0xf0, 0xb7, + 0xf2, 0x52, 0xdd, 0x57, 0xf8, 0x7a, 0x21, 0xdf, 0x95, 0x12, 0x6c, 0x25, 0x3c, 0x3f, 0x58, 0x1a, + 0xed, 0x74, 0x13, 0x76, 0x25, 0x58, 0x8d, 0x60, 0xa7, 0xac, 0x8b, 0xca, 0x0c, 0x07, 0x17, 0xb5, + 0x4e, 0xac, 0x2b, 0xbd, 0x44, 0x6a, 0x95, 0x58, 0xa7, 0xb7, 0xc0, 0x9a, 0x95, 0x7f, 0x1b, 0x2f, + 0x16, 0xcd, 0x9e, 0xda, 0x6f, 0x99, 0x9d, 0xbd, 0x18, 0xfd, 0x9c, 0xc3, 0xf3, 0x11, 0x28, 0xff, + 0x2b, 0xc2, 0xcb, 0xe7, 0x0e, 0xe7, 0x61, 0xb7, 0x1e, 0x5a, 0xff, 0x32, 0x78, 0x7c, 0xa5, 0xf8, + 0x69, 0x53, 0xdf, 0xab, 0x6b, 0xd3, 0x3a, 0x87, 0x47, 0x9d, 0xd1, 0x2d, 0x42, 0xf0, 0xe4, 0xaa, + 0x84, 0x13, 0xbf, 0xe0, 0xda, 0x87, 0xe3, 0x83, 0x4d, 0xb4, 0x3b, 0x3e, 0x9c, 0x86, 0xe8, 0x68, + 0x1a, 0xa2, 0x3f, 0xd3, 0x10, 0x7d, 0x99, 0x85, 0xde, 0xd1, 0x2c, 0xf4, 0x7e, 0xcd, 0x42, 0xef, + 0xf5, 0x53, 0xa5, 0x6d, 0x52, 0xc6, 0x44, 0x98, 0x94, 0x36, 0x43, 0xa5, 0x63, 0x31, 0x54, 0x86, + 0x4e, 0x1e, 0xd0, 0xd4, 0x51, 0xa1, 0x1a, 0x28, 0xa0, 0xa3, 0xed, 0xe1, 0x99, 0xc4, 0xf0, 0xfc, + 0x2c, 0xd9, 0xfd, 0x5c, 0x42, 0xdc, 0x73, 0xa3, 0x74, 0xf7, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x49, 0x5c, 0x48, 0xd7, 0x19, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -158,6 +263,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // UpdateParams defines a rpc handler for MsgUpdateParams. UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) + // ModuleQuerySafe defines a rpc handler for MsgModuleQuerySafe. + ModuleQuerySafe(ctx context.Context, in *MsgModuleQuerySafe, opts ...grpc.CallOption) (*MsgModuleQuerySafeResponse, error) } type msgClient struct { @@ -177,10 +284,21 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts return out, nil } +func (c *msgClient) ModuleQuerySafe(ctx context.Context, in *MsgModuleQuerySafe, opts ...grpc.CallOption) (*MsgModuleQuerySafeResponse, error) { + out := new(MsgModuleQuerySafeResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.interchain_accounts.host.v1.Msg/ModuleQuerySafe", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // UpdateParams defines a rpc handler for MsgUpdateParams. UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) + // ModuleQuerySafe defines a rpc handler for MsgModuleQuerySafe. + ModuleQuerySafe(context.Context, *MsgModuleQuerySafe) (*MsgModuleQuerySafeResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -190,6 +308,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } +func (*UnimplementedMsgServer) ModuleQuerySafe(ctx context.Context, req *MsgModuleQuerySafe) (*MsgModuleQuerySafeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ModuleQuerySafe not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -213,6 +334,24 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Msg_ModuleQuerySafe_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgModuleQuerySafe) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ModuleQuerySafe(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.interchain_accounts.host.v1.Msg/ModuleQuerySafe", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ModuleQuerySafe(ctx, req.(*MsgModuleQuerySafe)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "ibc.applications.interchain_accounts.host.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -221,6 +360,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateParams", Handler: _Msg_UpdateParams_Handler, }, + { + MethodName: "ModuleQuerySafe", + Handler: _Msg_ModuleQuerySafe_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "ibc/applications/interchain_accounts/host/v1/tx.proto", @@ -289,6 +432,87 @@ func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgModuleQuerySafe) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgModuleQuerySafe) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgModuleQuerySafe) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Requests) > 0 { + for iNdEx := len(m.Requests) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Requests[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgModuleQuerySafeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgModuleQuerySafeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgModuleQuerySafeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Responses) > 0 { + for iNdEx := len(m.Responses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Responses[iNdEx]) + copy(dAtA[i:], m.Responses[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Responses[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if m.Height != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -324,6 +548,43 @@ func (m *MsgUpdateParamsResponse) Size() (n int) { return n } +func (m *MsgModuleQuerySafe) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Requests) > 0 { + for _, e := range m.Requests { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgModuleQuerySafeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovTx(uint64(m.Height)) + } + if len(m.Responses) > 0 { + for _, b := range m.Responses { + l = len(b) + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -495,6 +756,223 @@ func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgModuleQuerySafe) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgModuleQuerySafe: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgModuleQuerySafe: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Requests", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Requests = append(m.Requests, &QueryRequest{}) + if err := m.Requests[len(m.Requests)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgModuleQuerySafeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgModuleQuerySafeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgModuleQuerySafeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Responses", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Responses = append(m.Responses, make([]byte, postIndex-iNdEx)) + copy(m.Responses[len(m.Responses)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/modules/apps/27-interchain-accounts/types/router.go b/modules/apps/27-interchain-accounts/types/router.go index 007091b9d0d..32a334f5f46 100644 --- a/modules/apps/27-interchain-accounts/types/router.go +++ b/modules/apps/27-interchain-accounts/types/router.go @@ -10,3 +10,11 @@ import ( type MessageRouter interface { Handler(msg sdk.Msg) baseapp.MsgServiceHandler } + +// QueryRouter ADR 021 query type routing +// https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-021-protobuf-query-encoding.md +type QueryRouter interface { + // Route returns the GRPCQueryHandler for a given query route path or nil + // if not found + Route(path string) baseapp.GRPCQueryHandler +} diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index 6c78e8e2e17..d58ca8ef669 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -464,7 +464,7 @@ func NewSimApp( app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + app.GRPCQueryRouter(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) // Create IBC Router diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index 7b53ab827f8..29f9e6cbeaf 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -510,7 +510,7 @@ func NewSimApp( app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + app.GRPCQueryRouter(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) // Create IBC Router diff --git a/proto/ibc/applications/interchain_accounts/host/v1/host.proto b/proto/ibc/applications/interchain_accounts/host/v1/host.proto index f036857113a..9165f36e794 100644 --- a/proto/ibc/applications/interchain_accounts/host/v1/host.proto +++ b/proto/ibc/applications/interchain_accounts/host/v1/host.proto @@ -12,3 +12,14 @@ message Params { // allow_messages defines a list of sdk message typeURLs allowed to be executed on a host chain. repeated string allow_messages = 2; } + +// QueryRequest defines the parameters for a particular query request +// by an interchain account. +message QueryRequest { + // path defines the path of the query request as defined by ADR-021. + // https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-021-protobuf-query-encoding.md#custom-query-registration-and-routing + string path = 1; + // data defines the payload of the query request as defined by ADR-021. + // https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-021-protobuf-query-encoding.md#custom-query-registration-and-routing + bytes data = 2; +} diff --git a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto index 5a8073bc931..22e8c9b3567 100644 --- a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto @@ -14,6 +14,9 @@ service Msg { // UpdateParams defines a rpc handler for MsgUpdateParams. rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); + + // ModuleQuerySafe defines a rpc handler for MsgModuleQuerySafe. + rpc ModuleQuerySafe(MsgModuleQuerySafe) returns (MsgModuleQuerySafeResponse); } // MsgUpdateParams defines the payload for Msg/UpdateParams @@ -33,3 +36,25 @@ message MsgUpdateParams { // MsgUpdateParamsResponse defines the response for Msg/UpdateParams message MsgUpdateParamsResponse {} + +// MsgModuleQuerySafe defines the payload for Msg/ModuleQuerySafe +message MsgModuleQuerySafe { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + // signer address + string signer = 1; + + // requests defines the module safe queries to execute. + repeated QueryRequest requests = 2; +} + +// MsgModuleQuerySafeResponse defines the response for Msg/ModuleQuerySafe +message MsgModuleQuerySafeResponse { + // height at which the responses were queried + uint64 height = 1; + + // protobuf encoded responses for each query + repeated bytes responses = 2; +} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index a451470e401..18b93b9f02b 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -458,8 +458,8 @@ func NewSimApp( app.ICAHostKeeper = icahostkeeper.NewKeeper( appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack - 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(), )