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

refactor: use go context instead of sdk.Context #14050

Merged
merged 4 commits into from
Nov 29, 2022
Merged

Conversation

tac0turtle
Copy link
Member

Description

Use go context on abcilistener instead of sdk native context.

Im not sure if I need to unwrap the context before?


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)

@tac0turtle tac0turtle requested a review from a team as a code owner November 28, 2022 20:56
Copy link
Collaborator

@yihuang yihuang left a comment

Choose a reason for hiding this comment

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

LGTM

@sonarcloud
Copy link

sonarcloud bot commented Nov 29, 2022

[Cosmos SDK] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member Author

@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.

going to merge this now so I can continue on another pr but would like @AmauryM or someone to confirm there is no need to unwrap the context like we do in other places

@tac0turtle tac0turtle enabled auto-merge (squash) November 29, 2022 10:07
@tac0turtle tac0turtle added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 29, 2022
@yihuang
Copy link
Collaborator

yihuang commented Nov 29, 2022

going to merge this now so I can continue on another pr but would like @AmauryM or someone to confirm there is no need to unwrap the context like we do in other places

maybe do a wrap on the caller side, on the callee side the ctx is not used at all.

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 like this.

Where do you want to unwrap? It seems the ctx arg is not used in the File streaming service (though still good to keep it on the interface for other implementations maybe)

@tac0turtle
Copy link
Member Author

LGTM like this.

Where do you want to unwrap? It seems the ctx arg is not used in the File streaming service (though still good to keep it for other implementations maybe)

would the caller need to unwrap before using it? since we are passing context.Context I was think we may need to unwrap before passing it to avoid unwrapping in the caller.

@amaury1093
Copy link
Contributor

Ah I see. Yeah, as @yihuang suggested, maybe let's do a wrap on the caller side, e.g. here:

if err := streamingListener.ListenBeginBlock(app.deliverState.ctx, req, res); err != nil {

(and all other instances in baseapp).

I think it's a terrible idea that sdk.Context implements context.Context, we don't catch these statically. Maybe it will work as-is, but I would prefer a goCtx := sdk.WrapSDKContext(ctx) on these lines, just to be sure.

@tac0turtle tac0turtle removed the A:automerge Automatically merge PR once all prerequisites pass. label Nov 29, 2022
@tac0turtle tac0turtle enabled auto-merge (squash) November 29, 2022 11:39
@tac0turtle tac0turtle added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 29, 2022
@tac0turtle tac0turtle merged commit b25908b into main Nov 29, 2022
@tac0turtle tac0turtle deleted the marko/listener_context branch November 29, 2022 11:59
@@ -201,7 +201,10 @@

// call the hooks with the BeginBlock messages
for _, streamingListener := range app.abciListeners {
if err := streamingListener.ListenBeginBlock(app.deliverState.ctx, req, res); err != nil {

goCtx := sdk.WrapSDKContext(app.deliverState.ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -226,7 +229,9 @@

// call the streaming service hooks with the EndBlock messages
for _, streamingListener := range app.abciListeners {
if err := streamingListener.ListenEndBlock(app.deliverState.ctx, req, res); err != nil {
goCtx := sdk.WrapSDKContext(app.deliverState.ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Thanks @tac0turtle!

@aaronc
Copy link
Member

aaronc commented Nov 29, 2022

I think it's a terrible idea that sdk.Context implements context.Context, we don't catch these statically.

Why is this a problem @AmauryM? What is the issue it's causing?

@amaury1093
Copy link
Contributor

In this issue, it was confusing whether a2cb92f was needed or not. If sdk.Context didn't implement context.Context, then we would catch this with the compiler. I think I prefer the explicitness of wrapping and unwrapping between sdk.Context and context.Context.

@aaronc
Copy link
Member

aaronc commented Nov 29, 2022

Calling WrapSDKContext is unnecessary @AmauryM. Look at the code it does nothing. It's just a placeholder for when it was actually needed. It should be marked as deprecated actually.

@amaury1093
Copy link
Contributor

Ah okay, so @tac0turtle my bad about asking you to add it, it was confusing to me too.

@tac0turtle
Copy link
Member Author

sweet, it didnt error on me, but was super unclear. Ill undo it and then mark wrapsdkContext as deprecated?

@aaronc
Copy link
Member

aaronc commented Nov 29, 2022

sweet, it didnt error on me, but was super unclear. Ill undo it and then mark wrapsdkContext as deprecated?

That would be great. Sorry I forgot to mark it as deprecated when I did this refactor.

@tac0turtle
Copy link
Member Author

all good #14072 modified here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:Store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants