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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.20
go 1.21

toolchain go1.21.7

Expand Down
426 changes: 424 additions & 2 deletions go/go.work.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/ocr2/decryptionplugin/decryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

pluginConfig, err := f.ConfigParser.ParseConfig(rpConfig.OffchainConfig)
if err != nil {
return nil, types.ReportingPluginInfo{},
Expand Down
10 changes: 7 additions & 3 deletions go/ocr2/decryptionplugin/decryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ func TestNewReportingPlugin(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
factory := DecryptionReportingPluginFactory{
Logger: dummyLogger{},
PublicKey: pk,
PrivKeyShare: sh[0],
ConfigParser: &config.DefaultConfigParser{},
}
plugin, info, err := factory.NewReportingPlugin(tc.conf)
plugin, info, err := factory.NewReportingPlugin(ctx, tc.conf)
if !cmp.Equal(err, tc.err, cmpopts.EquateErrors()) {
t.Fatalf("err=%v, want=%v", err, tc.err)
} else if err != nil {
Expand Down Expand Up @@ -800,6 +802,8 @@ func TestReport(t *testing.T) {
}

func TestNewReportingPlugin_CustomConfigParser(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
customParser := mocks.NewConfigParser(t)
factory := DecryptionReportingPluginFactory{
ConfigParser: customParser,
Expand All @@ -811,10 +815,10 @@ func TestNewReportingPlugin_CustomConfigParser(t *testing.T) {
K: 1,
},
}, nil).Once()
_, _, err := factory.NewReportingPlugin(types.ReportingPluginConfig{})
_, _, err := factory.NewReportingPlugin(ctx, types.ReportingPluginConfig{})
require.NoError(t, err)

customParser.On("ParseConfig", mock.Anything).Return(nil, errors.New("error")).Once()
_, _, err = factory.NewReportingPlugin(types.ReportingPluginConfig{})
_, _, err = factory.NewReportingPlugin(ctx, types.ReportingPluginConfig{})
require.Error(t, err)
}
18 changes: 11 additions & 7 deletions go/ocr2/decryptionplugin/go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
module github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin

go 1.20
go 1.21

toolchain go1.21.7

replace github.com/smartcontractkit/libocr => github.com/jmank88/libocr v0.0.0-20240425103000-0eed0c09969e

require (
github.com/google/go-cmp v0.5.9
github.com/smartcontractkit/libocr v0.0.0-20230503222226-29f534b2de1a
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230616062456-5c32c95fc166
github.com/stretchr/testify v1.3.0
google.golang.org/protobuf v1.30.0
github.com/stretchr/testify v1.7.0
google.golang.org/protobuf v1.31.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/objx v0.1.0 // indirect
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
33 changes: 17 additions & 16 deletions go/ocr2/decryptionplugin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/jmank88/libocr v0.0.0-20240425103000-0eed0c09969e h1:gswd1U2Jht2eq230MMRq1E9+XMUiiTvm/30KGaOfuvA=
github.com/jmank88/libocr v0.0.0-20240425103000-0eed0c09969e/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartcontractkit/libocr v0.0.0-20230503222226-29f534b2de1a h1:NFTlIAjSwx9vBYZeUerd0DDsvg+zZ5TSESw4dPNdwJk=
github.com/smartcontractkit/libocr v0.0.0-20230503222226-29f534b2de1a/go.mod h1:5JnCHuYgmIP9ZyXzgAfI5Iwu0WxBtBKp+ApeT5o1Cjw=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230616062456-5c32c95fc166 h1:cNH0nQjRfmWj173L8exDkQratcFVQ8AAj8RZ8a+suaI=
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230616062456-5c32c95fc166/go.mod h1:G5Sd/yzHWf26rQ+X0nG9E0buKPqRGPMJAfk2gwCzOOw=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 h1:uCLL3g5wH2xjxVREVuAbP9JM5PPKjRbXKRa6IBjkzmU=
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 2 additions & 1 deletion go/tdh2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ go 1.19

require (
github.com/google/go-cmp v0.5.9
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
8 changes: 6 additions & 2 deletions go/tdh2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading