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

Fix escrow proto E2E #3517

Merged
merged 13 commits into from
May 3, 2023
Merged

Fix escrow proto E2E #3517

merged 13 commits into from
May 3, 2023

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Apr 24, 2023

Description

closes: #XXXX

We were getting this error

panic: invalid Go type math.Int for field ibc.applications.transfer.v1.QueryTotalEscrowForDenomResponse.amount [recovered]
        panic: invalid Go type math.Int for field ibc.applications.transfer.v1.QueryTotalEscrowForDenomResponse.amount

In our E2E tests. This PR is being used to debug this proto issue.

By making the Amount field a string we can serialize it properly.

EDIT: After discussion with @colin-axner , we decided that an sdk.Coin makes more sense and will be less confusing. Serialization works as expected with this type.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@chatton
Copy link
Contributor Author

chatton commented Apr 24, 2023

@mark-rushakoff provided the following insight to help debug the problem. Thank you!

=================================================================

The SDK is using gogo/proto (by way of our fork, https://github.com/cosmos/gogoproto). The TLDR is incompatibilities with gogoproto and official google.golang.org/protobuf.

The one I was running into was just a plain sdk.Coin. It uses a custom type, with the gogoproto.customtype option, to specify sdkmath.Int for the Amount field.

We tell it to serialize on the wire as a string (effectively (*big.Int).String(). But the gogoproto-generated struct still uses a sdkmath.Int field.

I think the correct answer here is:

  • Define your new message with a string field, not a math.Int customtype
  • Use plain google.golang.org/protobuf to generate the Go types
  • Add an “application layer” wrapper struct that contains the protobuf type, that exposes a sdkmath.Int by parsing the underlying protobuf struct’s string field

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix, @chatton; and thank you @mark-rushakoff for the insight that got us here!

I need this is in draft yet, but I just left a couple of suggestions. If the test pass, I am good going with this direction.


return &types.QueryTotalEscrowForDenomResponse{
Amount: denomAmount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to return a string, we can just do denomAmount.String(), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this would be a bit nicer, I will play with this idea

e2e/testsuite/grpc_query.go Show resolved Hide resolved
@chatton chatton changed the title [WIP] Fix escrow proto E2E Fix escrow proto E2E Apr 25, 2023
@chatton chatton marked this pull request as ready for review April 25, 2023 10:08
@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2023

Codecov Report

Merging #3517 (fb063c2) into main (c3b12b1) will decrease coverage by 0.02%.
The diff coverage is 87.50%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3517      +/-   ##
==========================================
- Coverage   78.78%   78.76%   -0.02%     
==========================================
  Files         182      182              
  Lines       12688    12688              
==========================================
- Hits         9996     9994       -2     
- Misses       2261     2262       +1     
- Partials      431      432       +1     
Impacted Files Coverage Δ
modules/apps/transfer/keeper/keeper.go 87.03% <75.00%> (-1.86%) ⬇️
modules/apps/transfer/keeper/genesis.go 92.30% <100.00%> (ø)
modules/apps/transfer/keeper/grpc_query.go 73.91% <100.00%> (ø)
modules/apps/transfer/keeper/migrations.go 95.45% <100.00%> (ø)
modules/apps/transfer/keeper/relay.go 90.90% <100.00%> (ø)

} else {
suite.Require().PanicsWithValue("amount cannot be negative: -1", func() {
suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(ctx, denom, expAmount)
suite.Require().PanicsWithError("negative coin amount: -1", func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the panic now happens in the sdk.NewCoin function instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the original behaviour is desirable, we can create a coin literal instead of using the NewCoin function.

proto/ibc/applications/transfer/v1/query.proto Outdated Show resolved Hide resolved
e2e/testsuite/grpc_query.go Outdated Show resolved Hide resolved
modules/apps/transfer/keeper/relay.go Outdated Show resolved Hide resolved
@colin-axner
Copy link
Contributor

@damiannolan can you take over this pr next week? 🙏

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed the comments left by @colin-axner. PR looks good to me and tests are all passing!

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Thanks @chatton and @damiannolan ❤️

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followup ACK, thanks @damiannolan!

@colin-axner colin-axner merged commit 1006426 into main May 3, 2023
@colin-axner colin-axner deleted the escrow-proto-fix branch May 3, 2023 15:02
mergify bot pushed a commit that referenced this pull request May 3, 2023
* wip: experiement with string value for proto

* apply PR suggestions and fix unit tests

* added extension method to gRPC response

* refactor, change response return type to sdk Coin

* rm commented out proto import

* remove empty sdk.Coin literal in e2e/grpc_query

* reference same type in relay.go in favour of creating new sdk.Coin

* adding code comment regarding zero value coin return

* fix typo, linter

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
(cherry picked from commit 1006426)

# Conflicts:
#	e2e/tests/transfer/base_test.go
#	e2e/testsuite/grpc_query.go
#	modules/apps/transfer/keeper/grpc_query.go
#	modules/apps/transfer/keeper/keeper.go
#	modules/apps/transfer/keeper/relay.go
colin-axner pushed a commit that referenced this pull request May 4, 2023
* modify total escrow to take in sdk.Coin in function APIs/proto (#3517)

* wip: experiement with string value for proto

* apply PR suggestions and fix unit tests

* added extension method to gRPC response

* refactor, change response return type to sdk Coin

* rm commented out proto import

* remove empty sdk.Coin literal in e2e/grpc_query

* reference same type in relay.go in favour of creating new sdk.Coin

* adding code comment regarding zero value coin return

* fix typo, linter

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
(cherry picked from commit 1006426)

# Conflicts:
#	e2e/tests/transfer/base_test.go
#	e2e/testsuite/grpc_query.go
#	modules/apps/transfer/keeper/grpc_query.go
#	modules/apps/transfer/keeper/keeper.go
#	modules/apps/transfer/keeper/relay.go

* rm -rf e2e

---------

Co-authored-by: Cian Hatton <cian@interchain.io>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
@crodriguezvega crodriguezvega mentioned this pull request May 14, 2023
7 tasks
@faddat faddat mentioned this pull request Jun 23, 2023
9 tasks
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 this pull request may close these issues.

5 participants