From b53d270b1c94fdf5c81edf70df6c79bef7125afd Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Wed, 27 Mar 2024 13:57:50 -0500 Subject: [PATCH] bump common & libocr; remove context --- go.mod | 4 ++-- go.sum | 10 ++++----- llo/plugin.go | 10 ++++----- mercury/onchain_config.go | 5 ++--- mercury/onchain_config_test.go | 8 +++---- mercury/v1/mercury.go | 16 ++++++------- mercury/v1/mercury_test.go | 35 ++++++++++++++--------------- mercury/v2/mercury.go | 16 ++++++------- mercury/v2/mercury_test.go | 41 +++++++++++++++++----------------- mercury/v3/mercury.go | 16 ++++++------- mercury/v3/mercury_test.go | 35 ++++++++++++++--------------- 11 files changed, 94 insertions(+), 102 deletions(-) diff --git a/go.mod b/go.mod index efe6366..c5670c9 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/pkg/errors v0.9.1 github.com/shopspring/decimal v1.3.1 github.com/smartcontractkit/chain-selectors v1.0.5 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240324182820-92b84cfb6373 - github.com/smartcontractkit/libocr v0.0.0-20240322223357-61738d25af14 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240327133125-eed636b9a6df + github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 github.com/stretchr/testify v1.9.0 google.golang.org/protobuf v1.32.0 ) diff --git a/go.sum b/go.sum index 7f2da0e..446b343 100644 --- a/go.sum +++ b/go.sum @@ -209,19 +209,17 @@ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5g github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/smartcontractkit/chain-selectors v1.0.5 h1:NOefQsogPZS4aBbWPFrgAyoke0gppN2ojfa8SQkhu8c= github.com/smartcontractkit/chain-selectors v1.0.5/go.mod h1:WBhLlODF5b95vvx2tdKK55vGACg1+qZpuBhOGu1UXVo= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240324182820-92b84cfb6373 h1:zlPLi+aJRwOp4Y/JlHSqKnBd038rCCUzgDSYszbmySI= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240324182820-92b84cfb6373/go.mod h1:kmBPIyrTt8Q3HuSC3qdK96uwr4edw9SYbxjWmle7la4= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240327133125-eed636b9a6df h1:AKjckaIV8R53dLJwoQ3VlUI56L34Ca+nkkzjR1784zY= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240327133125-eed636b9a6df/go.mod h1:u2XnvJHl7sQ9HMlRnVLsOKgV9ihk0RGIYywB12p9gQQ= github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16 h1:TFe+FvzxClblt6qRfqEhUfa4kFQx5UobuoFGO2W4mMo= github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU= github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= -github.com/smartcontractkit/libocr v0.0.0-20240322223357-61738d25af14 h1:sGlxJ7y3guP20ohhn23XDj5kPXf+sOR7iFJaWjIvao0= -github.com/smartcontractkit/libocr v0.0.0-20240322223357-61738d25af14/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4= +github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 h1:1WFjrrVrWoQ9UpVMh7Mx4jDpzhmo1h8hFUKd9awIhIU= +github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/llo/plugin.go b/llo/plugin.go index 731b978..db58c10 100644 --- a/llo/plugin.go +++ b/llo/plugin.go @@ -179,7 +179,7 @@ type PluginFactory struct { Codecs map[llotypes.ReportFormat]ReportCodec } -func (f *PluginFactory) NewReportingPlugin(ctx context.Context, cfg ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[llotypes.ReportInfo], ocr3types.ReportingPluginInfo, error) { +func (f *PluginFactory) NewReportingPlugin(cfg ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[llotypes.ReportInfo], ocr3types.ReportingPluginInfo, error) { offchainCfg, err := DecodeOffchainConfig(cfg.OffchainConfig) if err != nil { return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("NewReportingPlugin failed to decode offchain config; got: 0x%x (len: %d); %w", cfg.OffchainConfig, len(cfg.OffchainConfig), err) @@ -374,7 +374,7 @@ func (p *LLOPlugin) Observation(ctx context.Context, outctx ocr3types.OutcomeCon // *not* strictly) across the lifetime of a protocol instance and that // outctx.previousOutcome contains the consensus outcome with sequence // number (outctx.SeqNr-1). -func (p *LLOPlugin) ValidateObservation(ctx context.Context, outctx ocr3types.OutcomeContext, query types.Query, ao types.AttributedObservation) error { +func (p *LLOPlugin) ValidateObservation(outctx ocr3types.OutcomeContext, query types.Query, ao types.AttributedObservation) error { if outctx.SeqNr <= 1 { if len(ao.Observation) != 0 { return fmt.Errorf("Observation is not empty") @@ -515,7 +515,7 @@ func (out *Outcome) ReportableChannels() []llotypes.ChannelID { // // libocr guarantees that this will always be called with at least 2f+1 // AttributedObservations -func (p *LLOPlugin) Outcome(ctx context.Context, outctx ocr3types.OutcomeContext, query types.Query, aos []types.AttributedObservation) (ocr3types.Outcome, error) { +func (p *LLOPlugin) Outcome(outctx ocr3types.OutcomeContext, query types.Query, aos []types.AttributedObservation) (ocr3types.Outcome, error) { if len(aos) < 2*p.F+1 { return nil, fmt.Errorf("invariant violation: expected at least 2f+1 attributed observations, got %d (f: %d)", len(aos), p.F) } @@ -797,7 +797,7 @@ func (p *LLOPlugin) encodeReport(r Report, format llotypes.ReportFormat) (types. // *not* strictly) across the lifetime of a protocol instance and that // outctx.previousOutcome contains the consensus outcome with sequence // number (outctx.SeqNr-1). -func (p *LLOPlugin) Reports(ctx context.Context, seqNr uint64, rawOutcome ocr3types.Outcome) ([]ocr3types.ReportWithInfo[llotypes.ReportInfo], error) { +func (p *LLOPlugin) Reports(seqNr uint64, rawOutcome ocr3types.Outcome) ([]ocr3types.ReportWithInfo[llotypes.ReportInfo], error) { if seqNr <= 1 { // no reports for initial round return nil, nil @@ -888,7 +888,7 @@ func (p *LLOPlugin) ShouldTransmitAcceptedReport(context.Context, uint64, ocr3ty // This is an advanced feature. The "default" approach (what OCR1 & OCR2 // did) is to have an empty ValidateObservation function and return // QuorumTwoFPlusOne from this function. -func (p *LLOPlugin) ObservationQuorum(ctx context.Context, outctx ocr3types.OutcomeContext, query types.Query) (ocr3types.Quorum, error) { +func (p *LLOPlugin) ObservationQuorum(outctx ocr3types.OutcomeContext, query types.Query) (ocr3types.Quorum, error) { return ocr3types.QuorumTwoFPlusOne, nil } diff --git a/mercury/onchain_config.go b/mercury/onchain_config.go index c551421..977f0a3 100644 --- a/mercury/onchain_config.go +++ b/mercury/onchain_config.go @@ -1,7 +1,6 @@ package mercury import ( - "context" "math/big" pkgerrors "github.com/pkg/errors" @@ -28,7 +27,7 @@ var _ mercury.OnchainConfigCodec = StandardOnchainConfigCodec{} // returned by EncodeValueInt192. type StandardOnchainConfigCodec struct{} -func (StandardOnchainConfigCodec) Decode(ctx context.Context, b []byte) (mercury.OnchainConfig, error) { +func (StandardOnchainConfigCodec) Decode(b []byte) (mercury.OnchainConfig, error) { if len(b) != onchainConfigEncodedLength { return mercury.OnchainConfig{}, pkgerrors.Errorf("unexpected length of OnchainConfig, expected %v, got %v", onchainConfigEncodedLength, len(b)) } @@ -57,7 +56,7 @@ func (StandardOnchainConfigCodec) Decode(ctx context.Context, b []byte) (mercury return mercury.OnchainConfig{Min: min, Max: max}, nil } -func (StandardOnchainConfigCodec) Encode(ctx context.Context, c mercury.OnchainConfig) ([]byte, error) { +func (StandardOnchainConfigCodec) Encode(c mercury.OnchainConfig) ([]byte, error) { verBytes, err := bigbigendian.SerializeSigned(32, onchainConfigVersionBig) if err != nil { return nil, err diff --git a/mercury/onchain_config_test.go b/mercury/onchain_config_test.go index 6386b03..1d1d09c 100644 --- a/mercury/onchain_config_test.go +++ b/mercury/onchain_config_test.go @@ -6,11 +6,10 @@ import ( "testing" "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" ) func FuzzDecodeOnchainConfig(f *testing.F) { - valid, err := StandardOnchainConfigCodec{}.Encode(tests.Context(f), mercury.OnchainConfig{Min: big.NewInt(1), Max: big.NewInt(1000)}) + valid, err := StandardOnchainConfigCodec{}.Encode(mercury.OnchainConfig{Min: big.NewInt(1), Max: big.NewInt(1000)}) if err != nil { f.Fatalf("failed to construct valid OnchainConfig: %s", err) } @@ -18,13 +17,12 @@ func FuzzDecodeOnchainConfig(f *testing.F) { f.Add([]byte{}) f.Add([]byte(valid)) f.Fuzz(func(t *testing.T, encoded []byte) { - ctx := tests.Context(t) - decoded, err := StandardOnchainConfigCodec{}.Decode(ctx, encoded) + decoded, err := StandardOnchainConfigCodec{}.Decode(encoded) if err != nil { return } - encoded2, err := StandardOnchainConfigCodec{}.Encode(ctx, decoded) + encoded2, err := StandardOnchainConfigCodec{}.Encode(decoded) if err != nil { t.Fatalf("failed to re-encode decoded input: %s", err) } diff --git a/mercury/v1/mercury.go b/mercury/v1/mercury.go index 4b9c387..0fd90ea 100644 --- a/mercury/v1/mercury.go +++ b/mercury/v1/mercury.go @@ -78,18 +78,18 @@ func NewFactory(ds DataSource, lggr logger.Logger, occ mercurytypes.OnchainConfi return Factory{ds, lggr, occ, rc} } -func (fac Factory) NewMercuryPlugin(ctx context.Context, configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { +func (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { offchainConfig, err := mercury.DecodeOffchainConfig(configuration.OffchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - onchainConfig, err := fac.onchainConfigCodec.Decode(ctx, configuration.OnchainConfig) + onchainConfig, err := fac.onchainConfigCodec.Decode(configuration.OnchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - maxReportLength, err := fac.reportCodec.MaxReportLength(ctx, configuration.N) + maxReportLength, err := fac.reportCodec.MaxReportLength(configuration.N) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } @@ -328,7 +328,7 @@ func parseAttributedObservations(lggr logger.Logger, aos []types.AttributedObser return paos } -func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { +func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { paos := parseAttributedObservations(rp.logger, aos) if len(paos) == 0 { @@ -340,7 +340,7 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta return false, nil, pkgerrors.Errorf("only received %v valid attributed observations, but need at least f+1 (%v)", len(paos), rp.f+1) } - rf, err := rp.buildReportFields(ctx, previousReport, paos) + rf, err := rp.buildReportFields(previousReport, paos) if err != nil { rp.logger.Errorw("failed to build report fields", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts, "err", err) return false, nil, err @@ -359,7 +359,7 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta "timestamp", repts, ) - report, err = rp.reportCodec.BuildReport(ctx, rf) + report, err = rp.reportCodec.BuildReport(rf) if err != nil { rp.logger.Debugw("failed to BuildReport", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts) return false, nil, err @@ -373,11 +373,11 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta return true, report, nil } -func (rp *reportingPlugin) buildReportFields(ctx context.Context, previousReport types.Report, paos []PAO) (rf v1.ReportFields, merr error) { +func (rp *reportingPlugin) buildReportFields(previousReport types.Report, paos []PAO) (rf v1.ReportFields, merr error) { var err error if previousReport != nil { var maxFinalizedBlockNumber int64 - maxFinalizedBlockNumber, err = rp.reportCodec.CurrentBlockNumFromReport(ctx, previousReport) + maxFinalizedBlockNumber, err = rp.reportCodec.CurrentBlockNumFromReport(previousReport) if err != nil { merr = errors.Join(merr, err) } else { diff --git a/mercury/v1/mercury_test.go b/mercury/v1/mercury_test.go index 00eaef8..b3786fa 100644 --- a/mercury/v1/mercury_test.go +++ b/mercury/v1/mercury_test.go @@ -23,7 +23,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" mercurytypes "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" v1 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v1" - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-data-streams/mercury" ) @@ -43,7 +42,7 @@ func (trc *testReportCodec) reset() { trc.builtReportFields = nil } -func (trc *testReportCodec) BuildReport(ctx context.Context, rf v1.ReportFields) (types.Report, error) { +func (trc *testReportCodec) BuildReport(rf v1.ReportFields) (types.Report, error) { if trc.buildReportShouldFail { return nil, errors.New("buildReportShouldFail=true") } @@ -51,7 +50,7 @@ func (trc *testReportCodec) BuildReport(ctx context.Context, rf v1.ReportFields) return trc.builtReport, nil } -func (trc *testReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) { +func (trc *testReportCodec) MaxReportLength(n int) (int, error) { return 8*32 + // feed ID 32 + // timestamp 192 + // benchmarkPrice @@ -63,12 +62,12 @@ func (trc *testReportCodec) MaxReportLength(ctx context.Context, n int) (int, er nil } -func (trc *testReportCodec) CurrentBlockNumFromReport(context.Context, types.Report) (int64, error) { +func (trc *testReportCodec) CurrentBlockNumFromReport(types.Report) (int64, error) { return trc.currentBlock, trc.currentBlockErr } func newReportingPlugin(t *testing.T, codec *testReportCodec) *reportingPlugin { - maxReportLength, err := codec.MaxReportLength(tests.Context(t), 4) + maxReportLength, err := codec.MaxReportLength(4) require.NoError(t, err) return &reportingPlugin{ f: 1, @@ -713,7 +712,7 @@ func Test_Plugin_Report(t *testing.T) { rp := newReportingPlugin(t, codec) t.Run("errors if not enough attributed observations", func(t *testing.T) { - _, _, err := rp.Report(tests.Context(t), repts, nil, []types.AttributedObservation{}) + _, _, err := rp.Report(repts, nil, []types.AttributedObservation{}) assert.EqualError(t, err, "got zero valid attributed observations") }) t.Run("succeeds, ignoring unparseable attributed observations", func(t *testing.T) { @@ -723,7 +722,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - should, report, err := rp.Report(tests.Context(t), repts, nil, aos) + should, report, err := rp.Report(repts, nil, aos) assert.NoError(t, err) assert.True(t, should) @@ -738,7 +737,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, report, err := rp.Report(tests.Context(t), repts, nil, aos) + should, report, err := rp.Report(repts, nil, aos) assert.True(t, should) assert.Equal(t, codec.builtReport, report) @@ -763,7 +762,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - _, _, err := rp.Report(tests.Context(t), repts, nil, aos) + _, _, err := rp.Report(repts, nil, aos) assert.EqualError(t, err, "no valid maxFinalizedBlockNumber with at least f+1 votes (got counts: map[0:1 1:1 2:1 3:1], f=1)") }) @@ -784,7 +783,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - _, _, err := rp.Report(tests.Context(t), repts, nil, aos) + _, _, err := rp.Report(repts, nil, aos) require.Error(t, err) assert.Contains(t, err.Error(), "GetConsensusCurrentBlock failed: cannot come to consensus on latest block number") @@ -807,7 +806,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - _, _, err := rp.Report(tests.Context(t), repts, nil, aos) + _, _, err := rp.Report(repts, nil, aos) require.Error(t, err) assert.Contains(t, err.Error(), "GetConsensusCurrentBlock failed: cannot come to consensus on latest block number") @@ -828,7 +827,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - should, report, err := rp.Report(tests.Context(t), repts, nil, aos) + should, report, err := rp.Report(repts, nil, aos) assert.False(t, should) assert.Nil(t, report) @@ -845,7 +844,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - _, _, err := rp.Report(tests.Context(t), repts, nil, aos) + _, _, err := rp.Report(repts, nil, aos) assert.EqualError(t, err, "buildReportShouldFail=true") }) @@ -857,7 +856,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - _, _, err := rp.Report(tests.Context(t), repts, nil, aos) + _, _, err := rp.Report(repts, nil, aos) assert.EqualError(t, err, "report with len 9999 violates MaxReportLength limit set by ReportCodec (1248)") }) @@ -869,7 +868,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - _, _, err := rp.Report(tests.Context(t), repts, nil, aos) + _, _, err := rp.Report(repts, nil, aos) assert.EqualError(t, err, "report may not have zero length (invariant violation)") }) @@ -893,7 +892,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, report, err := rp.Report(tests.Context(t), repts, previousReport, aos) + should, report, err := rp.Report(repts, previousReport, aos) assert.True(t, should) assert.Equal(t, codec.builtReport, report) @@ -912,7 +911,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, _, err := rp.Report(tests.Context(t), repts, previousReport, aos) + should, _, err := rp.Report(repts, previousReport, aos) assert.False(t, should) assert.EqualError(t, err, "test error current block fail") @@ -927,7 +926,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, _, err := rp.Report(tests.Context(t), repts, previousReport, aos) + should, _, err := rp.Report(repts, previousReport, aos) assert.False(t, should) assert.NoError(t, err) diff --git a/mercury/v2/mercury.go b/mercury/v2/mercury.go index ad6660a..ec5f592 100644 --- a/mercury/v2/mercury.go +++ b/mercury/v2/mercury.go @@ -64,18 +64,18 @@ func NewFactory(ds DataSource, lggr logger.Logger, occ mercurytypes.OnchainConfi return Factory{ds, lggr, occ, rc} } -func (fac Factory) NewMercuryPlugin(ctx context.Context, configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { +func (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { offchainConfig, err := mercury.DecodeOffchainConfig(configuration.OffchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - onchainConfig, err := fac.onchainConfigCodec.Decode(ctx, configuration.OnchainConfig) + onchainConfig, err := fac.onchainConfigCodec.Decode(configuration.OnchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - maxReportLength, err := fac.reportCodec.MaxReportLength(ctx, configuration.N) + maxReportLength, err := fac.reportCodec.MaxReportLength(configuration.N) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } @@ -262,7 +262,7 @@ func parseAttributedObservations(lggr logger.Logger, aos []types.AttributedObser return paos } -func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { +func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { paos := parseAttributedObservations(rp.logger, aos) if len(paos) == 0 { @@ -274,7 +274,7 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta return false, nil, pkgerrors.Errorf("only received %v valid attributed observations, but need at least f+1 (%v)", len(paos), rp.f+1) } - rf, err := rp.buildReportFields(ctx, previousReport, paos) + rf, err := rp.buildReportFields(previousReport, paos) if err != nil { rp.logger.Errorw("failed to build report fields", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts, "err", err) return false, nil, err @@ -291,7 +291,7 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta } rp.logger.Debugw("shouldReport: yes", "repts", repts) - report, err = rp.reportCodec.BuildReport(ctx, rf) + report, err = rp.reportCodec.BuildReport(rf) if err != nil { rp.logger.Debugw("failed to BuildReport", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts) return false, nil, err @@ -306,14 +306,14 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta return true, report, nil } -func (rp *reportingPlugin) buildReportFields(ctx context.Context, previousReport types.Report, paos []PAO) (rf v2.ReportFields, merr error) { +func (rp *reportingPlugin) buildReportFields(previousReport types.Report, paos []PAO) (rf v2.ReportFields, merr error) { mPaos := convert(paos) rf.Timestamp = mercury.GetConsensusTimestamp(mPaos) var err error if previousReport != nil { var maxFinalizedTimestamp uint32 - maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(ctx, previousReport) + maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(previousReport) merr = errors.Join(merr, err) rf.ValidFromTimestamp = maxFinalizedTimestamp + 1 } else { diff --git a/mercury/v2/mercury_test.go b/mercury/v2/mercury_test.go index e75a1b8..0bf6984 100644 --- a/mercury/v2/mercury_test.go +++ b/mercury/v2/mercury_test.go @@ -15,13 +15,12 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" + "github.com/smartcontractkit/libocr/commontypes" + "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "github.com/smartcontractkit/chainlink-common/pkg/logger" mercurytypes "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" v2 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v2" - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" - - "github.com/smartcontractkit/libocr/commontypes" - "github.com/smartcontractkit/libocr/offchainreporting2plus/types" "github.com/smartcontractkit/chainlink-data-streams/mercury" ) @@ -42,17 +41,17 @@ type testReportCodec struct { err error } -func (rc *testReportCodec) BuildReport(ctx context.Context, rf v2.ReportFields) (types.Report, error) { +func (rc *testReportCodec) BuildReport(rf v2.ReportFields) (types.Report, error) { rc.builtReportFields = &rf return rc.builtReport, nil } -func (rc testReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) { +func (rc testReportCodec) MaxReportLength(n int) (int, error) { return 123, nil } -func (rc testReportCodec) ObservationTimestampFromReport(context.Context, types.Report) (uint32, error) { +func (rc testReportCodec) ObservationTimestampFromReport(types.Report) (uint32, error) { return rc.observationTimestamp, rc.err } @@ -65,7 +64,7 @@ func newTestReportPlugin(t *testing.T, codec *testReportCodec, ds *testDataSourc Min: big.NewInt(1), Max: big.NewInt(1000), } - maxReportLength, _ := codec.MaxReportLength(tests.Context(t), 4) + maxReportLength, _ := codec.MaxReportLength(4) return &reportingPlugin{ offchainConfig: offchainConfig, onchainConfig: onchainConfig, @@ -167,7 +166,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("when previous report is nil", func(t *testing.T) { t.Run("errors if not enough attributed observations", func(t *testing.T) { - _, _, err := rp.Report(tests.Context(t), repts, nil, newValidAos(t)[0:1]) + _, _, err := rp.Report(repts, nil, newValidAos(t)[0:1]) assert.EqualError(t, err, "only received 1 valid attributed observations, but need at least f+1 (2)") }) t.Run("errors if too many maxFinalizedTimestamp observations are invalid", func(t *testing.T) { @@ -177,7 +176,7 @@ func Test_Plugin_Report(t *testing.T) { ps[2].MaxFinalizedTimestampValid = false aos := newValidAos(t, ps...) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "fewer than f+1 observations have a valid maxFinalizedTimestamp (got: 1/4)") }) @@ -189,7 +188,7 @@ func Test_Plugin_Report(t *testing.T) { ps[3].MaxFinalizedTimestamp = math.MaxUint32 aos := newValidAos(t, ps...) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "maxFinalizedTimestamp is too large, got: 4294967295") }) @@ -197,7 +196,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("succeeds and generates validFromTimestamp from maxFinalizedTimestamp when maxFinalizedTimestamp is positive", func(t *testing.T) { aos := newValidAos(t) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -218,7 +217,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -239,7 +238,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -258,7 +257,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) aos[0] = newUnparseableAttributedObservation() - should, report, err := rp.Report(tests.Context(t), repts, nil, aos) + should, report, err := rp.Report(repts, nil, aos) require.NoError(t, err) assert.True(t, should) @@ -291,7 +290,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), repts, previousReport, aos) + should, report, err := rp.Report(repts, previousReport, aos) require.NoError(t, err) assert.True(t, should) @@ -311,7 +310,7 @@ func Test_Plugin_Report(t *testing.T) { codec.err = errors.New("something exploded trying to extract timestamp") aos := newValidAos(t) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.EqualError(t, err, "something exploded trying to extract timestamp") }) @@ -325,7 +324,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.NoError(t, err) }) @@ -340,7 +339,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) assert.True(t, should) assert.NoError(t, err) @@ -357,7 +356,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) codec.builtReport = make([]byte, 1<<16) - _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report with len 65536 violates MaxReportLength limit set by ReportCodec (123)") }) @@ -365,7 +364,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("Report errors when the report length is 0", func(t *testing.T) { aos := newValidAos(t) codec.builtReport = []byte{} - _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report may not have zero length (invariant violation)") }) diff --git a/mercury/v3/mercury.go b/mercury/v3/mercury.go index 9aa5989..853b7a1 100644 --- a/mercury/v3/mercury.go +++ b/mercury/v3/mercury.go @@ -66,18 +66,18 @@ func NewFactory(ds DataSource, lggr logger.Logger, occ mercurytypes.OnchainConfi return Factory{ds, lggr, occ, rc} } -func (fac Factory) NewMercuryPlugin(ctx context.Context, configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { +func (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { offchainConfig, err := mercury.DecodeOffchainConfig(configuration.OffchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - onchainConfig, err := fac.onchainConfigCodec.Decode(ctx, configuration.OnchainConfig) + onchainConfig, err := fac.onchainConfigCodec.Decode(configuration.OnchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - maxReportLength, err := fac.reportCodec.MaxReportLength(ctx, configuration.N) + maxReportLength, err := fac.reportCodec.MaxReportLength(configuration.N) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } @@ -295,7 +295,7 @@ func parseAttributedObservations(lggr logger.Logger, aos []types.AttributedObser return paos } -func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { +func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { paos := parseAttributedObservations(rp.logger, aos) if len(paos) == 0 { @@ -307,7 +307,7 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta return false, nil, pkgerrors.Errorf("only received %v valid attributed observations, but need at least f+1 (%v)", len(paos), rp.f+1) } - rf, err := rp.buildReportFields(ctx, previousReport, paos) + rf, err := rp.buildReportFields(previousReport, paos) if err != nil { rp.logger.Errorw("failed to build report fields", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts, "err", err) return false, nil, err @@ -324,7 +324,7 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta } rp.logger.Debugw("shouldReport: yes", "repts", repts) - report, err = rp.reportCodec.BuildReport(ctx, rf) + report, err = rp.reportCodec.BuildReport(rf) if err != nil { rp.logger.Debugw("failed to BuildReport", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts) return false, nil, err @@ -339,14 +339,14 @@ func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimesta return true, report, nil } -func (rp *reportingPlugin) buildReportFields(ctx context.Context, previousReport types.Report, paos []PAO) (rf v3.ReportFields, merr error) { +func (rp *reportingPlugin) buildReportFields(previousReport types.Report, paos []PAO) (rf v3.ReportFields, merr error) { mPaos := convert(paos) rf.Timestamp = mercury.GetConsensusTimestamp(mPaos) var err error if previousReport != nil { var maxFinalizedTimestamp uint32 - maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(ctx, previousReport) + maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(previousReport) merr = errors.Join(merr, err) rf.ValidFromTimestamp = maxFinalizedTimestamp + 1 } else { diff --git a/mercury/v3/mercury_test.go b/mercury/v3/mercury_test.go index cf2b204..1d01f61 100644 --- a/mercury/v3/mercury_test.go +++ b/mercury/v3/mercury_test.go @@ -21,7 +21,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" mercurytypes "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" v3 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v3" - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-data-streams/mercury" ) @@ -42,17 +41,17 @@ type testReportCodec struct { err error } -func (rc *testReportCodec) BuildReport(ctx context.Context, rf v3.ReportFields) (types.Report, error) { +func (rc *testReportCodec) BuildReport(rf v3.ReportFields) (types.Report, error) { rc.builtReportFields = &rf return rc.builtReport, nil } -func (rc testReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) { +func (rc testReportCodec) MaxReportLength(n int) (int, error) { return 123, nil } -func (rc testReportCodec) ObservationTimestampFromReport(context.Context, types.Report) (uint32, error) { +func (rc testReportCodec) ObservationTimestampFromReport(types.Report) (uint32, error) { return rc.observationTimestamp, rc.err } @@ -65,7 +64,7 @@ func newTestReportPlugin(t *testing.T, codec *testReportCodec, ds *testDataSourc Min: big.NewInt(1), Max: big.NewInt(1000), } - maxReportLength, _ := codec.MaxReportLength(tests.Context(t), 4) + maxReportLength, _ := codec.MaxReportLength(4) return &reportingPlugin{ offchainConfig: offchainConfig, onchainConfig: onchainConfig, @@ -175,7 +174,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("when previous report is nil", func(t *testing.T) { t.Run("errors if not enough attributed observations", func(t *testing.T) { - _, _, err := rp.Report(tests.Context(t), repts, nil, newValidAos(t)[0:1]) + _, _, err := rp.Report(repts, nil, newValidAos(t)[0:1]) assert.EqualError(t, err, "only received 1 valid attributed observations, but need at least f+1 (2)") }) @@ -186,7 +185,7 @@ func Test_Plugin_Report(t *testing.T) { ps[2].MaxFinalizedTimestampValid = false aos := newValidAos(t, ps...) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "fewer than f+1 observations have a valid maxFinalizedTimestamp (got: 1/4)") }) @@ -198,7 +197,7 @@ func Test_Plugin_Report(t *testing.T) { ps[3].MaxFinalizedTimestamp = math.MaxUint32 aos := newValidAos(t, ps...) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "maxFinalizedTimestamp is too large, got: 4294967295") }) @@ -206,7 +205,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("succeeds and generates validFromTimestamp from maxFinalizedTimestamp when maxFinalizedTimestamp is positive", func(t *testing.T) { aos := newValidAos(t) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -229,7 +228,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -252,7 +251,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -273,7 +272,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) aos[0] = newUnparseableAttributedObservation() - should, report, err := rp.Report(tests.Context(t), repts, nil, aos) + should, report, err := rp.Report(repts, nil, aos) require.NoError(t, err) assert.True(t, should) @@ -308,7 +307,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), repts, previousReport, aos) + should, report, err := rp.Report(repts, previousReport, aos) require.NoError(t, err) assert.True(t, should) @@ -330,7 +329,7 @@ func Test_Plugin_Report(t *testing.T) { codec.err = errors.New("something exploded trying to extract timestamp") aos := newValidAos(t) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.EqualError(t, err, "something exploded trying to extract timestamp") }) @@ -344,7 +343,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.NoError(t, err) }) @@ -359,7 +358,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) + should, report, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) assert.True(t, should) assert.NoError(t, err) @@ -376,7 +375,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) codec.builtReport = make([]byte, 1<<16) - _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report with len 65536 violates MaxReportLength limit set by ReportCodec (123)") }) @@ -384,7 +383,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("Report errors when the report length is 0", func(t *testing.T) { aos := newValidAos(t) codec.builtReport = []byte{} - _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report may not have zero length (invariant violation)") })