grpc-gateway: Custom Inbound Marshaler not being used for transcoding

🐛 Bug Report

After setting a custom marshaler for encoding/decoding within the grpc-gateway, I’ve noticed the inbound marshaler is not used at all within the compiled gateway files. Not sure if I’m missing something or if this is an oversight.

The inbound marshaler is not used at all for pathParams here: https://github.com/prysmaticlabs/ethereumapis/blob/gen-go-cast/eth/v1/beacon_chain_service.pb.gw.go#L57

Yet it is used as part of runtime.ForwardResponseMessage here: https://github.com/prysmaticlabs/ethereumapis/blob/gen-go-cast/eth/v1/beacon_chain_service.pb.gw.go#L2289

It is also unused for endpoints that take in a protobuf message struct here: https://github.com/prysmaticlabs/ethereumapis/blob/gen-go-cast/eth/v1/beacon_chain_service.pb.gw.go#L861

But also used for the return.

To Reproduce

  1. Set custom marshaler using gwmux.
  2. Query API with a message that depends on marshaler.
  3. Query will fail because the input is not being marshaled, only the output.

Expected behavior

One would expect the marshaler to be used, with the input/output both being transcoded through the assigned marshaler.

Actual Behavior

The marshaler is only used for the outbound messages, not the inbound, see here: The marshaler (which changes base64 to hex) output here:

 kiwi@kiwi   ~/Work/prysm     change-to-gocast    15  curl -H 'Accept: application/json' localhost:3500/eth/v1/beacon/genesis
{
"data": {
"genesis_fork_version": "0x00002009",
"genesis_time": "2020-11-18T12:00:07Z",
"genesis_validators_root": "0x9436e8a630e3162b7ed4f449b12b8a5a368a4b95bc46b941ae65c11613bfa4c1"
}
}%   

Yet, when I try passing a field body or struct to a GET:

curl -H 'Accept: application/json' localhost:3500/eth/v1/beacon/states/0x0780527577054a5323d530d8c4216efdd28e9ffed39bc309214c6d75702515a1/root
> {"code":3,"details":[],"message":"type mismatch, parameter: state_id, error: illegal base64 data at input byte 64"}%  

Your Environment

Ubuntu Linux, using a fork of grpc-gateway from latest master.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17

Most upvoted comments

Agreed, that is clearly a feature the gateway is missing today. It may be complicated to introduce in a backwards compatible manner, but maybe something like what we’re doing for the query parameter parser will work. I think it’d probably take a map[string]string from the existing pathParams. I don’t think it’ll be trivial to work out exactly which parameters need to be parsed, right now that seems to be determined at generation time. I don’t have many spare cycles for designing this sort of thing, but feel free to play around with it and let me know if you need any pointers.