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

feat: implement new gov msg & query servers #10868

Merged
merged 49 commits into from
Jan 21, 2022
Merged

Conversation

cmwaters
Copy link
Contributor

@cmwaters cmwaters commented Jan 4, 2022

Description

Ref: #9438

This PR performs the major work of swapping out the v1beta1 msg server and query server for the new one which can process a proposal as an array of messages. This PR still retains the legacy servers which simply wrap around the new ones, providing the same interface as before.

In order to keep backwards compatibility, a new msg, MsgExecLegacyContent has been created which allows Content to become a Msg type and still be used as part of the new implementation.


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)

@cmwaters cmwaters changed the title gov: implement new msg server feat: implement new gov msg & query servers Jan 4, 2022
x/gov/abci.go Show resolved Hide resolved
proto/cosmos/gov/v1beta2/gov.proto Outdated Show resolved Hide resolved
x/gov/keeper/msg_server.go Outdated Show resolved Hide resolved
x/gov/module.go Outdated
Comment on lines 159 to 160
v1beta2.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
v1beta2.RegisterQueryServer(cfg.QueryServer(), am.keeper)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add v1beta1 too, for backwards-compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sorry, we want both.

Copy link
Contributor

Choose a reason for hiding this comment

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

TO not overload this PR, I created a spearate issue for query: #10951

@codecov
Copy link

codecov bot commented Jan 18, 2022

Codecov Report

Merging #10868 (69b2e66) into master (fd5b97b) will decrease coverage by 0.07%.
The diff coverage is 51.47%.

❗ Current head 69b2e66 differs from pull request most recent head e1d59ef. Consider uploading reports for the commit e1d59ef to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10868      +/-   ##
==========================================
- Coverage   65.86%   65.78%   -0.08%     
==========================================
  Files         638      644       +6     
  Lines       64303    64802     +499     
==========================================
+ Hits        42352    42630     +278     
- Misses      19577    19781     +204     
- Partials     2374     2391      +17     
Impacted Files Coverage Δ
x/gov/client/cli/query.go 0.00% <0.00%> (ø)
x/gov/client/cli/tx.go 18.61% <0.00%> (-0.10%) ⬇️
x/gov/types/v1beta1/params.go 0.00% <ø> (ø)
x/gov/types/v1beta2/content.go 0.00% <0.00%> (ø)
x/gov/types/v1beta2/deposit.go 0.00% <ø> (ø)
x/gov/types/v1beta2/genesis.go 47.50% <0.00%> (ø)
x/gov/types/v1beta2/params.go 22.42% <0.00%> (+0.20%) ⬆️
x/gov/types/v1beta2/proposal.go 15.87% <0.00%> (-0.26%) ⬇️
x/gov/types/v1beta2/tally.go 0.00% <0.00%> (ø)
x/gov/types/v1beta2/vote.go 27.27% <0.00%> (-2.00%) ⬇️
... and 35 more

Copy link
Contributor

@blushi blushi left a comment

Choose a reason for hiding this comment

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

looks good overall, but still a few comments

x/gov/keeper/msg_server.go Outdated Show resolved Hide resolved
x/gov/keeper/msg_server.go Outdated Show resolved Hide resolved
x/gov/keeper/querier_test.go Outdated Show resolved Hide resolved
x/gov/simulation/operations.go Show resolved Hide resolved
x/gov/types/v1beta2/msgs.go Outdated Show resolved Hide resolved
x/gov/types/v1beta2/proposal.go Show resolved Hide resolved
Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
Copy link
Contributor Author

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

Added a few comments.

Do we want to keep the legacy querier tests around so that we are testing both the v1beta1 and the v1beta2 query server?

Also why do we have this codecov/patch thing? It's quite disruptive to the review process and if we're not actually using it then I'd advocate to remove it.

x/gov/keeper/msg_server.go Show resolved Hide resolved
Comment on lines 97 to 100
// Execute the proposal content in a new context branch (with branched store)
// to validate the actual parameter changes before the proposal proceeds
// through the governance process. State is not persisted.
cacheCtx, _ := ctx.CacheContext()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't we eventually want to run writeCache. Currently this looks like it never actually persists state. Is this intentional?

Copy link
Contributor

@amaury1093 amaury1093 Jan 20, 2022

Choose a reason for hiding this comment

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

Ah you're right.

So the way it currently works is:

  • in EndBlocker, we create a CacheContext
  • if all Msgs pass then we write

Which means that in the msg server implementation of ExecLegacyContent, we don't need a CacheContext at all. I removed it.

x/gov/keeper/proposal.go Outdated Show resolved Hide resolved
Comment on lines +45 to +55
// Only if it's a MsgExecLegacyContent do we try to execute the
// proposal in a cached context.
// For other Msgs, we do not verify the proposal messages any further.
// They may fail upon execution.
// ref: https://github.com/cosmos/cosmos-sdk/pull/10868#discussion_r784872842
if msg, ok := msg.(*v1beta2.MsgExecLegacyContent); ok {
cacheCtx, _ := ctx.CacheContext()
if _, err := handler(cacheCtx, msg); err != nil {
return v1beta2.Proposal{}, sdkerrors.Wrap(types.ErrNoProposalHandlerExists, err.Error())
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer need to do this right because we have the new MsgServer method for executing legacy content messages.

Copy link
Contributor

@amaury1093 amaury1093 Jan 20, 2022

Choose a reason for hiding this comment

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

this is related to #10868 (comment).

The current code runs the Msg in SubmitProposal iif it's a MsgExecLegacyContent (to match old behavior). We could also remove this code, in which case the legacy content will be run for the 1st time once the proposal passes

I feel that mock running legacy content in SubmitProposal is safe, those old gov handlers are well-known and don't do any side-effects such as sending IBC messages or writing to disk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok yeah that's fine with me

x/gov/types/errors.go Outdated Show resolved Hide resolved
@amaury1093
Copy link
Contributor

amaury1093 commented Jan 20, 2022

thanks for the review @cmwaters

Also why do we have this codecov/patch thing? It's quite disruptive to the review process and if we're not actually using it then I'd advocate to remove it.

You mean this comment #10868 (comment) ? I feel it's one comment per PR, so it doesn't bother me too much, but happy to hear other opinions

Do we want to keep the legacy querier tests around so that we are testing both the v1beta1 and the v1beta2 query server?

Yeah, in this PR I switched querier_test.go to use v1beta2, but once we have #10951 I think we should add both grpc_query and legacy_querier tests to test both

@cmwaters
Copy link
Contributor Author

You mean this comment #10868 (comment) ? I feel it's one comment per PR, so it doesn't bother me too much, but happy to hear other opinions

No I meant the inline comments for every line which doesn't have a test which hits it

Copy link
Contributor Author

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

🚀 LGTM. I can't actually approve this because I am the author but in any case this seems to ready to merge from my side

Copy link
Contributor

@blushi blushi left a comment

Choose a reason for hiding this comment

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

LGTM, pending merge conflicts

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

🚀 LGTM. I can't actually approve this because I am the author but in any case this seems to ready to merge from my side

I'll give you mine!

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Jan 21, 2022
@mergify mergify bot merged commit eb5b11b into master Jan 21, 2022
@mergify mergify bot deleted the callum/gov-msg-server branch January 21, 2022 11:14
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
## Description

Ref: cosmos#9438

This PR performs the major work of swapping out the v1beta1 msg server and query server for the new one which can process a proposal as an array of messages. This PR still retains the legacy servers which simply wrap around the new ones, providing the same interface as before.

In order to keep backwards compatibility, a new msg, `MsgExecLegacyContent` has been created which allows `Content` to become a `Msg` type and still be used as part of the new implementation. 


---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

6 participants