-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: allow module safe queries in ICA (#5785) * imp: initial modification of tx.proto * imp: ran 'make proto-all' * fix: compiler errors * imp: added query router interface * imp: added queryRouter to icahost keeper * imp: improved proto definitions * imp: ran 'make proto-all' * imp: added sdk.Msg helpers * feat: basic implementation * style: improved field names * imp: ran 'make proto-all' * fix: compiler errors * imp: ran gofumpt * feat: tests passing * feat: tests improved * test: removed unneeded code * imp: improved 'IsModuleSafe' function * imp: added IsModuleQuerySafe to msg_server * imp: added more test cases * fix: callbacks compiler * fix: non determinancy issues * fix: added query msg to codec * imp: whitelist logic added * e2e: new test added * fix: new test * fix: test * fix: e2e * fix: e2e * imp(e2e): added the QueryTxsByEvents function * fix: e2e * e2e: lint fix * fix: e2e * e2e: debug * fix: e2e * test: debug helpers * debug * test: added codec_test case * imp: additional test case * imp: added important unit test * r4r * e2e: debug * imp: added logs * fix: e2e * fix: e2e * fix: e2e * imp: added height to proto response * imp: ran 'make proto-all' * imp: added height * e2e: updated e2e to test height * imp: review suggestions * e2e: remove unneeded log * refactor: refactored 'ExtractValueFromEvents' * e2e: review item * imp: review item * nit: review item * docs: added godocs * test: unit test for mqsWhitelist added * imp: added logging * style: rename to allow list * add changelog --------- Co-authored-by: Carlos Rodriguez <carlos@interchain.io> (cherry picked from commit eecfa5c) # Conflicts: # e2e/testsuite/codec.go # e2e/testsuite/tx.go # modules/apps/27-interchain-accounts/host/keeper/keeper.go # modules/apps/27-interchain-accounts/host/keeper/keeper_test.go # modules/apps/27-interchain-accounts/host/keeper/msg_server.go # modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go # modules/apps/27-interchain-accounts/host/types/codec.go # modules/apps/27-interchain-accounts/host/types/codec_test.go # modules/apps/27-interchain-accounts/host/types/host.pb.go # modules/apps/27-interchain-accounts/host/types/msgs.go # modules/apps/27-interchain-accounts/host/types/tx.pb.go # modules/apps/callbacks/testing/simapp/app.go # modules/light-clients/08-wasm/testing/simapp/app.go # proto/ibc/applications/interchain_accounts/host/v1/tx.proto # testing/simapp/app.go * fix conflicts * fix tests * gofumpt * do not set ica query router for callbacks * pls * fix comment * panic if query router is nil * break loop earlier * workaround for using module safe queries of x/staking * add comment --------- Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com> Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
- Loading branch information
1 parent
47cf563
commit b78afb0
Showing
17 changed files
with
1,538 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
modules/apps/27-interchain-accounts/host/keeper/msg_server.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
|
||
_ "cosmossdk.io/api/cosmos/staking/v1beta1" // workaround to successfully retrieve staking module safe queries | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
|
||
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" | ||
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" | ||
) | ||
|
||
var _ types.MsgServer = (*msgServer)(nil) | ||
|
||
type msgServer struct { | ||
*Keeper | ||
} | ||
|
||
// NewMsgServerImpl returns an implementation of the ICS27 host MsgServer interface | ||
// for the provided Keeper. | ||
func NewMsgServerImpl(keeper *Keeper) types.MsgServer { | ||
if keeper.queryRouter == nil { | ||
panic("query router must not be nil") | ||
} | ||
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 { | ||
var isModuleQuerySafe bool | ||
for _, allowedQueryPath := range m.mqsAllowList { | ||
if allowedQueryPath == query.Path { | ||
isModuleQuerySafe = true | ||
break | ||
} | ||
} | ||
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.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 | ||
} |
Oops, something went wrong.