From ef557663071628cf088fb766a72dc516ec8ffd09 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:22:23 +0900 Subject: [PATCH] fix: make panic when GRPCGateway handler is not registered correctly (#722) --- CHANGELOG.md | 1 + x/auth/tx/service.go | 4 +++- x/authz/module/module.go | 4 +++- x/bank/module.go | 4 +++- x/distribution/module.go | 4 +++- x/evidence/module.go | 4 +++- x/gov/module.go | 4 +++- .../27-interchain-accounts/module.go | 13 +++++++++---- x/ibc/applications/transfer/module.go | 9 ++++++--- x/ibc/core/module.go | 17 ++++++++++++----- x/mint/module.go | 4 +++- x/params/module.go | 4 +++- x/slashing/module.go | 4 +++- x/staking/module.go | 4 +++- x/upgrade/module.go | 4 +++- 15 files changed, 61 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef764ec986..95e7746c8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/auth,bank,foundation,wasm) [\#691](https://github.com/line/lbm-sdk/pull/691) change AccAddressFromBech32 to MustAccAddressFromBech32 * (x/wasm) [\#690](https://github.com/line/lbm-sdk/pull/690) fix to prevent accepting file name * (cli) [\#708](https://github.com/line/lbm-sdk/pull/708) In CLI, allow 1 SIGN_MODE_DIRECT signer in transactions with multiple signers. +* (x/modules) [\#722](https://github.com/line/lbm-sdk/pull/722) Check error for `RegisterQueryHandlerClient` in all modules `RegisterGRPCGatewayRoutes` * (x/bank) [\#716](https://github.com/line/lbm-sdk/pull/716) remove useless DenomMetadata key function diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index 9815a7c3f1..2304af1983 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -262,7 +262,9 @@ func RegisterTxService( // RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the // given Mux. func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) { - txtypes.RegisterServiceHandlerClient(context.Background(), mux, txtypes.NewServiceClient(clientConn)) + if err := txtypes.RegisterServiceHandlerClient(context.Background(), mux, txtypes.NewServiceClient(clientConn)); err != nil { + panic(err) + } } func parseOrderBy(orderBy txtypes.OrderBy) string { diff --git a/x/authz/module/module.go b/x/authz/module/module.go index cde1328f6b..2f21a2dae7 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -77,7 +77,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, r *mux.Rou // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module. func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { - authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)) + if err := authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetQueryCmd returns the cli query commands for the authz module diff --git a/x/bank/module.go b/x/bank/module.go index 4f3b5abaa0..3dbc0c0ceb 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -69,7 +69,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bank module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the root tx command for the bank module. diff --git a/x/distribution/module.go b/x/distribution/module.go index a84066d3ff..48e22012f3 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -69,7 +69,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, rtr *mux.R // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the distribution module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the root tx command for the distribution module. diff --git a/x/evidence/module.go b/x/evidence/module.go index 6e3779e1fb..74f0ed36fc 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -87,7 +87,9 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the evidence module. func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the evidence module's root tx command. diff --git a/x/gov/module.go b/x/gov/module.go index 6655468c37..57b549bda7 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -85,7 +85,9 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the gov module. func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the root tx command for the gov module. diff --git a/x/ibc/applications/27-interchain-accounts/module.go b/x/ibc/applications/27-interchain-accounts/module.go index 4f3689a99d..a5a1d78c54 100644 --- a/x/ibc/applications/27-interchain-accounts/module.go +++ b/x/ibc/applications/27-interchain-accounts/module.go @@ -7,13 +7,14 @@ import ( "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" + abci "github.com/line/ostracon/abci/types" + "github.com/spf13/cobra" + "github.com/line/lbm-sdk/client" "github.com/line/lbm-sdk/codec" codectypes "github.com/line/lbm-sdk/codec/types" sdk "github.com/line/lbm-sdk/types" "github.com/line/lbm-sdk/types/module" - abci "github.com/line/ostracon/abci/types" - "github.com/spf13/cobra" "github.com/line/lbm-sdk/x/ibc/applications/27-interchain-accounts/client/cli" "github.com/line/lbm-sdk/x/ibc/applications/27-interchain-accounts/controller" @@ -73,8 +74,12 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) { // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the interchain accounts module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - controllertypes.RegisterQueryHandlerClient(context.Background(), mux, controllertypes.NewQueryClient(clientCtx)) - hosttypes.RegisterQueryHandlerClient(context.Background(), mux, hosttypes.NewQueryClient(clientCtx)) + if err := controllertypes.RegisterQueryHandlerClient(context.Background(), mux, controllertypes.NewQueryClient(clientCtx)); err != nil { + panic(err) + } + if err := hosttypes.RegisterQueryHandlerClient(context.Background(), mux, hosttypes.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd implements AppModuleBasic interface diff --git a/x/ibc/applications/transfer/module.go b/x/ibc/applications/transfer/module.go index 000ceaa11e..e7d1909390 100644 --- a/x/ibc/applications/transfer/module.go +++ b/x/ibc/applications/transfer/module.go @@ -8,14 +8,15 @@ import ( "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" + abci "github.com/line/ostracon/abci/types" + "github.com/spf13/cobra" + "github.com/line/lbm-sdk/client" "github.com/line/lbm-sdk/codec" codectypes "github.com/line/lbm-sdk/codec/types" sdk "github.com/line/lbm-sdk/types" "github.com/line/lbm-sdk/types/module" simtypes "github.com/line/lbm-sdk/types/simulation" - abci "github.com/line/ostracon/abci/types" - "github.com/spf13/cobra" "github.com/line/lbm-sdk/x/ibc/applications/transfer/client/cli" "github.com/line/lbm-sdk/x/ibc/applications/transfer/keeper" @@ -70,7 +71,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-transfer module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd implements AppModuleBasic interface diff --git a/x/ibc/core/module.go b/x/ibc/core/module.go index de42a87986..4b11aea041 100644 --- a/x/ibc/core/module.go +++ b/x/ibc/core/module.go @@ -8,14 +8,15 @@ import ( "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" + abci "github.com/line/ostracon/abci/types" + "github.com/spf13/cobra" + "github.com/line/lbm-sdk/client" "github.com/line/lbm-sdk/codec" codectypes "github.com/line/lbm-sdk/codec/types" sdk "github.com/line/lbm-sdk/types" "github.com/line/lbm-sdk/types/module" simtypes "github.com/line/lbm-sdk/types/simulation" - abci "github.com/line/ostracon/abci/types" - "github.com/spf13/cobra" ibcclient "github.com/line/lbm-sdk/x/ibc/core/02-client" clientkeeper "github.com/line/lbm-sdk/x/ibc/core/02-client/keeper" @@ -69,9 +70,15 @@ func (AppModuleBasic) RegisterRESTRoutes(client.Context, *mux.Router) {} // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - clienttypes.RegisterQueryHandlerClient(context.Background(), mux, clienttypes.NewQueryClient(clientCtx)) - connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, connectiontypes.NewQueryClient(clientCtx)) - channeltypes.RegisterQueryHandlerClient(context.Background(), mux, channeltypes.NewQueryClient(clientCtx)) + if err := clienttypes.RegisterQueryHandlerClient(context.Background(), mux, clienttypes.NewQueryClient(clientCtx)); err != nil { + panic(err) + } + if err := connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, connectiontypes.NewQueryClient(clientCtx)); err != nil { + panic(err) + } + if err := channeltypes.RegisterQueryHandlerClient(context.Background(), mux, channeltypes.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the root tx command for the ibc module. diff --git a/x/mint/module.go b/x/mint/module.go index b8241e0c2a..a41d2f9f00 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -71,7 +71,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } diff --git a/x/params/module.go b/x/params/module.go index e19d06a7d3..d414eb236a 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -57,7 +57,9 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the params module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - proposal.RegisterQueryHandlerClient(context.Background(), mux, proposal.NewQueryClient(clientCtx)) + if err := proposal.RegisterQueryHandlerClient(context.Background(), mux, proposal.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns no root tx command for the params module. diff --git a/x/slashing/module.go b/x/slashing/module.go index e63c8414c9..5202b55f78 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -77,7 +77,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the slashig module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the root tx command for the slashing module. diff --git a/x/staking/module.go b/x/staking/module.go index 1409dbecc4..6aefec8aa3 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -76,7 +76,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the staking module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the root tx command for the staking module. diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 77ef989e30..c2e476bdf5 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -49,7 +49,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the upgrade module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetQueryCmd returns the cli query commands for this module