-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Simplify context #4706
Simplify context #4706
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4706 +/- ##
==========================================
- Coverage 54.15% 54.03% -0.13%
==========================================
Files 272 271 -1
Lines 17349 17307 -42
==========================================
- Hits 9395 9351 -44
- Misses 7271 7274 +3
+ Partials 683 682 -1 |
|
||
Migration guide: | ||
`ctx = ctx.WithValue(contextKeyBadProposal, false)` -> | ||
`ctx = ctx.WithContext(context.WithValue(ctx.Context(), contextKeyBadProposal, false))` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any instances of these calls in the code? Seems like based on the diff this is a minimal change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in x/gov/test_common.go
and x/gov/end_blocker_test.go
to control failure mode or a test handler.
types/context.go
Outdated
|
||
// clone the header before returning | ||
func (c Context) BlockHeader() abci.Header { | ||
// TODO: figure out clone better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guessing this todo will get worked out if you decide to go ahead with this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it paniced about trying to clone the type, not sure why...
I will ensure there are properly cloned if approved
This gets a 👍 on direction from me. Seems to make the code much cleaner! Thanks for the contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally I agree that, because most of the context fields are being used there isn't much point in storing them with decorators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this PR's approach. The rationale is sound and all makes sense.
So far so good, I'm ready to ACK this once all comments are addressed
I addressed all of the code comments here, except for the protobuf Clone. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nihil obstat from me - @ethanfrey it would be appreciated if you could scan through the SDK docs and ensure all references are up to date.
Thanks @alessio I will do a deeper read through docs and polish of the last edges here. Glad to see you like the rename as well. I just added an optional type alias here: But if there is support, I would make a separate PR for a larger rename, updating all references to Context in sdk, but keep backwards compatibility with external libs with: |
gogo/protobuf#519 Seems like the old code never properly cloned this, which was not easily detectable through so many layers of indirection
I fixed the protobuf clone issue, seems to be a time.Time problem. |
Otherwise, I think this is done |
Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
48c7a9c
to
93d98c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 💯
Any progress on the review process? I think I addressed all concerns raised. I also believe it is no longer API breaking, as I did add |
@ethanfrey, someone with merge rights will have to merge it cc: @alessio @jackzampolin @alexanderbez @rigelrozanski. I believe Bez will want to review this once he comes back from vacations tomorrow |
Thanks @alessio |
Took a look at the PR and the changes look reasonable to me, although I'm not sure I'm necessarily in favor of having to require the Also, what is the harm of using |
Hi @alexanderbez my point was that we only use this With Value in some governance test code, and in general, we should not encourage this usage of arbitrary data, when we really use it for structured data. I left the ability to use it as such and no breaking api changes, but push towards a clear and simple struct which is easy to understand. In general, the simplest solution that satisfies the requirements is easier to understand, easier to change later and brings less technical debt. This seemed like low hanging fruit to clean up, as I was not sure all the ways it was used in the Sdk without searching a lot |
## Description This: * addresses an issue with the way `WrapSDKContext` was done in that it doesn't use the `context.Context` that is already inside `sdk.Context` * it allows `sdk.Context` to be used as a `context.Context` directly * it also walks back the deprecation of `Value` and `WithValue` from #4706 as I actually think these are useful, and trying to put everything directly into `Context` as a bag of variables rather than attaching it using something like `WithValue` makes the SDK less extensible --- ### 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)
I will polish this PR a bit more if it is deemed acceptable, but looking for first responses from devs.
I am getting back into sdk development after some time and find a number of places that seem needless complex - adding unneeded confusion. Going from the go maxim that simpler is better, I would like to offer a number of cleanup PRs. Not sure the best place.
Context is some odd object which is kind of like context.Context but then really like a simple immutible struct with getters and a setter than returns a modified copy of the object. Since the only place to make use of
Value()
andGetValue()
outside ofcontext.go
was some governance test code, I figured to just streamline it. I left in an embedded context that can be used like in stdlib for that one case (which maybe is not needed?).Besides that small change, all cleanup was limited to the
types/context*.go
files. I would like to rename Context to Request, which better represents the meaning of this object, and is in alignment with standard idioms used in go (web) frameworks. I just provide a type alias now to hint at future directions.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.
Wrote tests
Updated relevant documentation (
docs/
)Added a relevant changelog entry:
clog add [section] [stanza] [message]
rereviewed
Files changed
in the github PR explorerFor Admin Use: