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

bump common & libocr; remove context #45

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
10 changes: 5 additions & 5 deletions llo/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions mercury/onchain_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mercury

import (
"context"
"math/big"

pkgerrors "github.com/pkg/errors"
Expand All @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions mercury/onchain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ 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)
}

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)
}
Expand Down
16 changes: 8 additions & 8 deletions mercury/v1/mercury.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
35 changes: 17 additions & 18 deletions mercury/v1/mercury_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -43,15 +42,15 @@ 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")
}
trc.builtReportFields = &rf
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
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)")
})
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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")
})
Expand All @@ -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)")
})
Expand All @@ -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)")
})
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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)
Expand Down
Loading
Loading