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

add context #33

Closed

Conversation

jmank88
Copy link
Collaborator

@jmank88 jmank88 commented Jan 12, 2024

https://smartcontract-it.atlassian.net/browse/BCF-2887

Bump libocr and react to context.Context signature changes.

Requires:

Supports:

go/tdh2/go.mod Outdated Show resolved Hide resolved
@jmank88 jmank88 force-pushed the BCF-2887-context-propagation branch 4 times, most recently from c55f1c7 to cf396d1 Compare March 22, 2024 23:39
@jmank88 jmank88 marked this pull request as ready for review March 22, 2024 23:41
go/tdh2/go.mod Outdated Show resolved Hide resolved
@jmank88 jmank88 force-pushed the BCF-2887-context-propagation branch 3 times, most recently from 4645944 to 0704599 Compare March 23, 2024 11:20
@@ -33,7 +33,7 @@ type decryptionPlugin struct {
}

// NewReportingPlugin complies with ReportingPluginFactory.
func (f DecryptionReportingPluginFactory) NewReportingPlugin(rpConfig types.ReportingPluginConfig) (types.ReportingPlugin, types.ReportingPluginInfo, error) {
func (f DecryptionReportingPluginFactory) NewReportingPlugin(ctx context.Context, rpConfig types.ReportingPluginConfig) (types.ReportingPlugin, types.ReportingPluginInfo, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be looppcontext types.LOOPPContext? Otherwise I worry about a future maintainer of this code doing long-running work with one of these contexts.

The same concern would apply across all other repos and functions that take a types.LOOPPContext.

Copy link
Collaborator Author

@jmank88 jmank88 Mar 23, 2024

Choose a reason for hiding this comment

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

I only settled for this pattern under the impression that it would not leak out of libocr. I would like to re-emphasize that I think LOOPPContext is the wrong name. I think we need to take two steps back and re-evaluate the purpose of this type.

  1. There is nothing about a regular context that implies doing something "long-running" is allowed or not.
  2. An implementer assuming that the presence of a context argument means that they can make a web request and block for 30 seconds is making a mistake.
  3. A method that has timing expectations needs to be clear about those expectations, regardless of whether or not a context is included in the argument set.

Context type, which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes.

Copy link
Collaborator

@kaleofduty kaleofduty Mar 25, 2024

Choose a reason for hiding this comment

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

would like to re-emphasize that I think LOOPPContext is the wrong name

Thanks for re-iterating that you don't like the name, I'm happy to consider alternatives.
For now, I would suggest that we leave the naming aside and focus on the conceptual aspects.

I agree with your three points.
My concern is about misuse resistance. The intention behind types.LOOPPContext is to make people read the docs.
Expanding on that (apologies if I am being repetitive): Contexts are frequently used for "long-running" interactions e.g. with remote servers. I worry that someone will (incorrectly as you point out, and without having read the docs on the interface) take the context and stuff it into whatever HTTP/Ethereum RPC call they want to perform, because they just assume that the presence of the context means that they're in "long-running" land. However, the context that's passed here effectively never expires (only when the underlying OCR configuration changes or the offchainreporting2plus.Oracle is shutdown). This is particularly concerning for the ReportingPlugin functions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Lmk if you'd prefer to take this discussion back to the original PR or elsewhere. Not sure whether this is the best place for it, since it goes beyond tdh2.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no "long-running land" and "short-running land". There are methods and collections of methods with specific timing expectations, and those expectations fall on a sliding scale.

Copy link

@patrickhuie19 patrickhuie19 Mar 25, 2024

Choose a reason for hiding this comment

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

Rephrasing the tradeoff as I understand it for my understanding:
What amount of standard tooling breakage and type conversion boiler plate are we willing to introduce to signal to LibOCR consumers that they need to be careful with their usage of context?

So, it seems like the best case scenario is one where we

  • Don't break standard tooling
  • Don't introduce unnecessary type conversion boiler plate
  • Do signal to consumers that they need to be careful with their usage of context

Can we accomplish that best case scenario with standard Godoc comments?

Copy link
Collaborator

@kaleofduty kaleofduty Mar 25, 2024

Choose a reason for hiding this comment

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

@jmank88 you wrote above

and then after reading the docs possibly confused more when they realize it is just a context with ambiguously short runtime expectations of some kind.

Am I reading this correctly that you are unhappy with the docs? But then why ask to merge the original PR?

The correct thing to do is still just to meet the deadline

But many of these will not have a deadline!? They only expire once offchainreporting2plus.Oracle.Close() is called or there is a setConfig on the contract.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Am I reading this correctly that you are unhappy with the docs? But then why ask to merge the original PR?

The whole approach has diverged from my proposal and feedback. I have tried to be maximally receptive to this alternative in the interest of time and with the understanding that it would not have cascading effects across other repos.

But many of these will not have a deadline!? They only expire once offchainreporting2plus.Oracle.Close() is called or there is a setConfig on the contract.

Should they have a deadline? It seems in conflict to claim they should not have a deadline, but also that the implementations "need to be fast". Why can't/shouldn't "fast" be quantified as specific deadlines?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should they have a deadline? It seems in conflict to claim they should not have a deadline, but also that the implementations "need to be fast". Why can't/shouldn't "fast" be quantified as specific deadlines?

Adding a good deadline for these is tricky for a few reasons, here are some of them:

  • it would force reporting plugin implementers to think about more timing parameters. setting the params wrong risks breaking things.
  • timing parameters for the other reportingplugin functions are set via setConfig, adding more parameters there is a far reaching change!

Copy link
Collaborator Author

@jmank88 jmank88 Mar 26, 2024

Choose a reason for hiding this comment

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

I think we need to be precise about the problem being solved.

If the author of the interface and caller of the method are not equipped to handle this, then how is an
implementer supposed to be any better equipped to solve the problem?

I am not proposing adding a bunch of new fine tuned configuration. I would propose that we start by doing the obvious naive thing, which is to not block forever. e.g. If the upstream caller knows a round has ended, then it should cancel all associated contexts, not block on an unbounded one forever. Only after we have exhausted the standard patterns for context usage should we start trying to invent new complexities. It has not been stated clearly where the idiomatic approaches fall short.

@jmank88 jmank88 marked this pull request as draft March 27, 2024 19:40
@jmank88 jmank88 force-pushed the BCF-2887-context-propagation branch from 0704599 to 9b8b97a Compare April 25, 2024 10:40
@jmank88 jmank88 closed this Apr 25, 2024
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.

6 participants