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

Register MsgServer type URLs in AppModuleBasic.RegisterInterfaces #7647

Closed
aaronc opened this issue Oct 23, 2020 · 0 comments · Fixed by #7671
Closed

Register MsgServer type URLs in AppModuleBasic.RegisterInterfaces #7647

aaronc opened this issue Oct 23, 2020 · 0 comments · Fixed by #7671
Assignees

Comments

@aaronc
Copy link
Member

aaronc commented Oct 23, 2020

Context

In #7519, MsgServer request types are registered with custom type URLs in the InterfaceRegistry in AppModule.RegisterServices. Clients will not have these URLs registered just by calling AppModuleBasic.RegisterInterfaces so the registration needs to happen earlier for clients (CLI and grpc-gateway).

Implementation

First add a function RegisterMsgServiceDesc(InterfaceRegistry, grpc.ServiceDesc) which will be used in RegisterInterfaces:

// x/bank/types/codec.go

func RegisterInterfaces(registry types.InterfaceRegistry) {
  ...
  RegisterMsgServiceDesc(registry, _Msg_serviceDesc) // _Msg_serviceDesc is generated by proto-gen
}

RegisterMsgServiceDesc should do the same thing under the hood that MsgServiceRouter.RegisterServices is now doing under the hood:

		// NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry.
		// This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself.
		// We use a no-op interceptor to avoid actually calling into the handler itself.
		_, _ = methodHandler(nil, context.Background(), func(i interface{}) error {
			msg, ok := i.(proto.Message)
			if !ok {
				// We panic here because there is no other alternative and the app cannot be initialized correctly
				// this should only happen if there is a problem with code generation in which case the app won't
				// work correctly anyway.
				panic(fmt.Errorf("can't register request type %T for service method %s", i, fqMethod))
			}

			msr.interfaceRegistry.RegisterCustomTypeURL((*sdk.MsgRequest)(nil), fqMethod, msg)
			return nil
		}, noopInterceptor)

MsgServiceRouter.RegisterServices should then be updated to return an error if interfaces are not already registered. It can check what is registered using the InterfaceRegistry.Resolve method. That error should be very clear and explain how to use RegisterMsgServiceDesc.

It would be ideal to have an integration test to verify that CLI clients (using QueryTxCmd) and ideally grpc-gateway have these type URLs registered properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants