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!: Fix gov amino codec #13196

Merged
merged 3 commits into from
Sep 8, 2022
Merged

fix!: Fix gov amino codec #13196

merged 3 commits into from
Sep 8, 2022

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented Sep 8, 2022

Description

Fix a bug when using amino-json with MsgSubmitProposal. Same as with authz, we need to register gov's ModuleCdc with every other module's RegisterLegacyAmino. We forgot to do that in v0.46 unfortunately.

This results in a nested level of fields being cut-off:

// expected
{"type":"cosmos-sdk/v1/MsgSubmitProposal","value":{"initial_deposit":[],"messages":[{"type":"cosmos-sdk/MsgSend","value":{"amount":[],"from_address":"cosmos1abc...def","to_address":"cosmos1abc...def"}}]}}

// actual on v0.46
{"type":"cosmos-sdk/v1/MsgSubmitProposal","value":{"initial_deposit":[],"messages":[{"amount":[],"from_address":"cosmos1abc...def","to_address":"cosmos1abc...def"}]}}

Notice in the messages array, there's a nested level of type and level missing. This makes the Ledger<>CosmJS integration impossible.

The proposed solution is the same fix as for authz, i.e. in every module, register their msgs with the gov's ModuleCdc. To read more, you can read Simon's article about the topic.

cc'ing:


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

},
{
"MsgSend", []sdk.Msg{banktypes.NewMsgSend(addrs[0], addrs[0], sdk.NewCoins())},
fmt.Sprintf(`{"type":"cosmos-sdk/v1/MsgSubmitProposal","value":{"initial_deposit":[],"messages":[{"type":"cosmos-sdk/MsgSend","value":{"amount":[],"from_address":"%s","to_address":"%s"}}]}}`, addrs[0], addrs[0]),
Copy link
Contributor Author

@amaury1093 amaury1093 Sep 8, 2022

Choose a reason for hiding this comment

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

This newly added test case fails on main. Main passes with the following string:

{"type":"cosmos-sdk/v1/MsgSubmitProposal","value":{"initial_deposit":[],"messages":[{"amount":[],"from_address":"%s","to_address":"%s"}]}}

which is incorrect

@codecov
Copy link

codecov bot commented Sep 8, 2022

Codecov Report

Merging #13196 (114e48f) into main (279f3f1) will increase coverage by 0.03%.
The diff coverage is 89.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13196      +/-   ##
==========================================
+ Coverage   53.63%   53.66%   +0.03%     
==========================================
  Files         647      647              
  Lines       55194    55199       +5     
==========================================
+ Hits        29601    29624      +23     
+ Misses      23219    23200      -19     
- Partials     2374     2375       +1     
Impacted Files Coverage Δ
x/gov/types/v1/msgs.go 58.49% <40.00%> (ø)
x/gov/types/v1beta1/msgs.go 50.32% <50.00%> (ø)
x/auth/types/codec.go 100.00% <100.00%> (ø)
x/auth/vesting/types/codec.go 100.00% <100.00%> (ø)
x/authz/codec.go 46.15% <100.00%> (+2.15%) ⬆️
x/bank/types/codec.go 57.14% <100.00%> (+1.58%) ⬆️
x/distribution/types/codec.go 61.29% <100.00%> (+1.29%) ⬆️
x/evidence/types/codec.go 59.09% <100.00%> (+1.94%) ⬆️
x/feegrant/codec.go 100.00% <100.00%> (ø)
x/gov/types/v1/codec.go 52.17% <100.00%> (-7.09%) ⬇️
... and 7 more

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

utACK

somewhat of a foot gun for users since its a hidden thing. Any ideas how to make it automatic?

@amaury1093
Copy link
Contributor Author

amaury1093 commented Sep 8, 2022

somewhat of a foot gun for users since its a hidden thing. Any ideas how to make it automatic?

drop amino support.

More seriously though, I think Riccardo also had some thoughts about this, and this was the best solution we came up with.

@amaury1093 amaury1093 enabled auto-merge (squash) September 8, 2022 15:19
@amaury1093 amaury1093 merged commit d9972c4 into main Sep 8, 2022
@amaury1093 amaury1093 deleted the am/gov-amino branch September 8, 2022 15:35
@RiccardoM
Copy link
Contributor

More seriously though, I think Riccardo also had some thoughts about this, and this was the best solution we came up with.

Yup, there are no other solutions to solve this unless we drop entirely the support for Amino

@amaury1093 amaury1093 mentioned this pull request Sep 15, 2022
19 tasks
Wryhder pushed a commit to Wryhder/cosmos-sdk that referenced this pull request Oct 26, 2022
* fix!: Fix gov amino codec

* changelog
@julienrbrt
Copy link
Member

@Mergifyio backport release/v0.46.x

mergify bot pushed a commit that referenced this pull request Nov 30, 2022
* fix!: Fix gov amino codec

* changelog

(cherry picked from commit d9972c4)

# Conflicts:
#	CHANGELOG.md
#	x/distribution/types/codec.go
#	x/gov/simulation/operations_test.go
#	x/gov/types/v1/msgs.go
#	x/gov/types/v1/msgs_test.go
#	x/mint/types/codec.go
#	x/upgrade/types/codec.go
@mergify
Copy link
Contributor

mergify bot commented Nov 30, 2022

backport release/v0.46.x

✅ Backports have been created

ryanchristo pushed a commit to regen-network/cosmos-sdk that referenced this pull request Dec 14, 2022
* fix!: Fix gov amino codec

* changelog
ryanchristo pushed a commit to regen-network/cosmos-sdk that referenced this pull request Dec 14, 2022
* fix!: Fix gov amino codec

* changelog
clevinson pushed a commit to regen-network/cosmos-sdk that referenced this pull request Dec 15, 2022
* fix!: Fix gov amino codec

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

Successfully merging this pull request may close these issues.

4 participants