cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

[Bug]: `math.LegacyDec` type is not deserialized in GRPC queries

Open wojtek-coreum opened this issue 2 years ago • 14 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

What happened?

When querying for inflation using GRPC client:

$ cored query mint inflation --grpc-addr 127.0.0.1:9090 --grpc-insecure

it panics:

panic: invalid Go type math.LegacyDec for field cosmos.mint.v1beta1.QueryInflationResponse.inflation

Call stack:

goroutine 1 [running]:
google.golang.org/protobuf/internal/impl.newSingularConverter({0x33c00d0?, 0x2714860}, {0x33c1508, 0xc000cf0870})
	google.golang.org/[email protected]/internal/impl/convert.go:142 +0xaa8
google.golang.org/protobuf/internal/impl.NewConverter({0x33c00d0, 0x2714860}, {0x33c1508?, 0xc000cf0870?})
	google.golang.org/[email protected]/internal/impl/convert.go:60 +0x9d
google.golang.org/protobuf/internal/impl.fieldInfoForScalar({0x33c1508, 0xc000cf0870}, {{0x242e3c2, 0x9}, {0x0, 0x0}, {0x33c00d0, 0x2714860}, {0x242e3cc, 0x6f}, ...}, ...)
	google.golang.org/[email protected]/internal/impl/message_reflect_field.go:270 +0x17c
google.golang.org/protobuf/internal/impl.(*MessageInfo).makeKnownFieldsFunc(0xc0001c62c0, {0xffffffffffffffff, {0x0, 0x0}, 0xffffffffffffffff, {0x0, 0x0}, 0xffffffffffffffff, {0x0, 0x0}, ...})
	google.golang.org/[email protected]/internal/impl/message_reflect.go:80 +0x78a
google.golang.org/protobuf/internal/impl.(*MessageInfo).makeReflectFuncs(0xc0001c62c0, {0x33c00d0, 0x2400020}, {0xffffffffffffffff, {0x0, 0x0}, 0xffffffffffffffff, {0x0, 0x0}, 0xffffffffffffffff, ...})
	google.golang.org/[email protected]/internal/impl/message_reflect.go:42 +0x58
google.golang.org/protobuf/internal/impl.(*MessageInfo).initOnce(0xc0001c62c0)
	google.golang.org/[email protected]/internal/impl/message.go:90 +0x1b0
google.golang.org/protobuf/internal/impl.(*MessageInfo).init(...)
	google.golang.org/[email protected]/internal/impl/message.go:72
google.golang.org/protobuf/internal/impl.(*messageReflectWrapper).ProtoMethods(0xc0014963d0)
	google.golang.org/[email protected]/internal/impl/message_reflect_gen.go:150 +0x28
google.golang.org/protobuf/proto.protoMethods(...)
	google.golang.org/[email protected]/proto/proto_methods.go:19
google.golang.org/protobuf/proto.UnmarshalOptions.unmarshal({{}, 0x1, 0x1, 0x0, {0x3378ec0, 0xc0000ebd40}, 0x2710}, {0xc000058af8, 0x14, 0x14}, ...)
	google.golang.org/[email protected]/proto/decode.go:93 +0xe8
google.golang.org/protobuf/proto.UnmarshalOptions.UnmarshalState({{}, 0x1, 0x1, 0x0, {0x0, 0x0}, 0x2710}, {{}, {0x33b6e78, 0xc0014963d0}, ...})
	google.golang.org/[email protected]/proto/decode.go:77 +0xa8
github.com/golang/protobuf/proto.UnmarshalMerge({0xc000058af8, 0x14, 0x14}, {0x3385070?, 0xc000206888?})
	github.com/golang/[email protected]/proto/wire.go:67 +0x12b
github.com/golang/protobuf/proto.Unmarshal({0xc000058af8, 0x14, 0x14}, {0x3385070, 0xc000206888?})
	github.com/golang/[email protected]/proto/wire.go:58 +0x53
google.golang.org/grpc/encoding/proto.codec.Unmarshal({}, {0xc000058af8, 0x14, 0x14}, {0x25ff2a0, 0xc000206888})
	google.golang.org/[email protected]/encoding/proto/proto.go:53 +0x5f
google.golang.org/grpc.recv(0xc00148c1b0, {0x7ff1bc6c8168, 0x4a03dc0}, 0xc0000ac048?, {0x0, 0x0}, {0x25ff2a0, 0xc000206888}, 0x25ff520?, 0x0, ...)
	google.golang.org/[email protected]/rpc_util.go:800 +0x10a
google.golang.org/grpc.(*csAttempt).recvMsg(0xc0015908f0, {0x25ff2a0?, 0xc000206888}, 0x4a03dc0?)
	google.golang.org/[email protected]/stream.go:1084 +0x27d
google.golang.org/grpc.(*clientStream).RecvMsg.func1(0x0?)
	google.golang.org/[email protected]/stream.go:927 +0x1f
google.golang.org/grpc.(*clientStream).withRetry(0xc00162b320, 0xc00119e6d8, 0xc00119e6c8)
	google.golang.org/[email protected]/stream.go:776 +0x13a
google.golang.org/grpc.(*clientStream).RecvMsg(0xc00162b320, {0x25ff2a0?, 0xc000206888?})
	google.golang.org/[email protected]/stream.go:926 +0x113
google.golang.org/grpc.invoke({0x33972e0?, 0xc001434090?}, {0x2788fcb?, 0x3396da0?}, {0x25ff520, 0x4a03dc0}, {0x25ff2a0, 0xc000206888}, 0x0?, {0x0, ...})
	google.golang.org/[email protected]/call.go:73 +0xcb
google.golang.org/grpc.(*ClientConn).Invoke(0xc001626c00, {0x33972e0?, 0xc001434090?}, {0x2788fcb?, 0x33acfa0?}, {0x25ff520?, 0x4a03dc0?}, {0x25ff2a0?, 0xc000206888?}, {0x0, ...})
	google.golang.org/[email protected]/call.go:37 +0x23f
github.com/cosmos/cosmos-sdk/client.Context.Invoke({{0x0, 0x0, 0x0}, {0x33acfa0, 0xc0015886c0}, 0xc001626c00, {0x274255b, 0x10}, {0x33b73d0, 0xc001087bd0}, ...}, ...)
	github.com/cosmos/[email protected]/client/grpc_query.go:63 +0x7e5
github.com/cosmos/cosmos-sdk/x/mint/types.(*queryClient).Inflation(0xc00119f610, {0x33972e0, 0xc001434090}, 0x33acfa0?, {0x0, 0x0, 0x0})
	github.com/cosmos/[email protected]/x/mint/types/query.pb.go:356 +0xcb
github.com/cosmos/cosmos-sdk/x/mint/client/cli.GetCmdQueryInflation.func1(0xc000fbcc00, {0xc001436300?, 0x0?, 0x4?})
	github.com/cosmos/[email protected]/x/mint/client/cli/query.go:76 +0x10f
github.com/spf13/cobra.(*Command).execute(0xc000fbcc00, {0xc0014362c0, 0x4, 0x4})
	github.com/spf13/[email protected]/command.go:940 +0x87c
github.com/spf13/cobra.(*Command).ExecuteC(0xc000bc5200)
	github.com/spf13/[email protected]/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:992
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	github.com/spf13/[email protected]/command.go:985
github.com/cosmos/cosmos-sdk/server/cmd.Execute(0x339a880?, {0x272f3da, 0x5}, {0xc001045dd0, 0x14})
	github.com/cosmos/[email protected]/server/cmd/execute.go:32 +0x11b
main.main()
	github.com/CoreumFoundation/coreum/v3/cmd/cored/main.go:30 +0x1d0

I guess all the types using math.LegacyDec are affected everywhere.

Cosmos SDK Version

0.47.5

How to reproduce?

No response

wojtek-coreum avatar Nov 10 '23 09:11 wojtek-coreum

We have bunch of queries that contain sdk.LegacyDec and it works fine both in web-grpc and RPC (CLI).

robert-zaremba avatar Nov 20 '23 14:11 robert-zaremba

@robert-zaremba Did you try the one related to inflation? Same thing is reported here: https://github.com/forbole/bdjuno/issues/655

wojtek-coreum avatar Nov 21 '23 07:11 wojtek-coreum

@robert-zaremba Did you try the one related to inflation? Same thing is reported here: https://github.com/forbole/bdjuno/issues/655

No, I will try.

robert-zaremba avatar Nov 21 '23 20:11 robert-zaremba

The same thing happens for osmosis's ArithmeticTwap query on the latest version - we're using it to measure differences between Ojo's prices & osmosis's. I'll comment here if we find anything

Code example:

	ctx, cancel := context.WithTimeout(ctx, c.grpcTimeout)
	ctx = metadata.AppendToOutgoingContext(ctx, c.headers...)
	defer cancel()

	queryClient := twaptypes.NewQueryClient(c.grpcConnection)

	res, err := queryClient.ArithmeticTwap(ctx, &req)
	if err != nil {
		return nil, err
	}

	return res, nil

Results in:

panic: invalid Go type math.LegacyDec for field osmosis.twap.v1beta1.ArithmeticTwapResponse.arithmetic_twap

adamewozniak avatar Nov 30 '23 23:11 adamewozniak

Update: I found an old SDK issue with the same problem. It was solved by adding this replace:

replace google.golang.org/grpc => google.golang.org/grpc v1.33.2

Relevant issue: https://github.com/cosmos/cosmos-sdk/issues/8426

I tested it for my problem above and the patch works for now @robert-zaremba @wojtek-coreum, but it should really be fixed

adamewozniak avatar Dec 01 '23 00:12 adamewozniak

@adamewozniak by any chance do you know the underlying issue? If a replace of grpc seems to "fix" it, then is it an issue with gRPC or something else?

alexanderbez avatar Dec 01 '23 00:12 alexanderbez

@adamewozniak by any chance do you know the underlying issue? If a replace of grpc seems to "fix" it, then is it an issue with gRPC or something else?

Didn't find any details as to the actual fix, though to me it makes the most sense that this bug is somewhere in the SDK if it reappeared only recently with the dec package moving. I'll post here if I have some time to look into it.

Also, good to see you @alexanderbez !

adamewozniak avatar Dec 01 '23 01:12 adamewozniak

When I run locally our latest v0.47 based version (main branch) it works well. We don't do google.golang.org/grpc replace.

image

Same with RPC:

❯ ./build/umeed query mint inflation --grpc-insecure
0.130001914115398131

❯ ./build/umeed query mint inflation
0.130001944988227148

robert-zaremba avatar Dec 01 '23 14:12 robert-zaremba

@robert-zaremba when you use --grpc-insecure without a grpc address it does nothing. can you try with a grpc address? I think you will encounter the issue

doggystylez avatar Feb 20 '24 16:02 doggystylez

@tac0turtle @julienrbrt can someone pls check this out. the problem occurs for any use of cosmossdk.io/math.LegacyDec and Int in gprc queries as far as i can tell

doggystylez avatar Mar 01 '24 12:03 doggystylez

I met the same issue when using this gRPC query, any updates?

dadamu avatar Apr 08 '24 11:04 dadamu

Just to add another instance of this bug, when trying to call some liquidity queries in Osmosis:

panic: invalid Go type math.LegacyDec for field osmosis.concentratedliquidity.v1beta1.LiquidityNetInDirectionResponse.current_liquidity

maxrobot avatar Jul 01 '24 21:07 maxrobot