From 5583a02a617a8bf1782a372419d0a66777c53d1f Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Fri, 12 Jan 2024 17:23:34 -0600 Subject: [PATCH] bump libocr; add context --- go.mod | 10 +++------- go.sum | 13 ++++++------- pkg/v2/factory.go | 3 ++- pkg/v3/plugin/factory.go | 6 ++++-- pkg/v3/plugin/ocr3.go | 8 ++++---- pkg/v3/plugin/ocr3_test.go | 6 +++--- tools/simulator/simulate/loader/ocr3config.go | 9 +++++---- tools/simulator/simulate/loader/ocr3config_test.go | 3 ++- tools/simulator/simulate/ocr/transmit.go | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 8960898e..35b1b30d 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,7 @@ module github.com/smartcontractkit/chainlink-automation go 1.21 -replace ( - github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.3 - golang/github.com/gogo/protobuf => golang/github.com/gogo/protobuf v1.3.3 -) +replace github.com/smartcontractkit/libocr => github.com/jmank88/libocr v0.0.0-20240425103000-0eed0c09969e require ( github.com/Maldris/mathparse v0.0.0-20170508133428-f0d009a7a773 @@ -16,7 +13,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.17.0 github.com/shopspring/decimal v1.3.1 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240401172519-4bfc659b80bf + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724 github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 @@ -29,6 +26,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect + github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.1 // indirect @@ -67,5 +65,3 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) - -exclude golang/github.com/influxdata/influxdb v1.8.3 diff --git a/go.sum b/go.sum index 0fa50f1e..203f2722 100644 --- a/go.sum +++ b/go.sum @@ -10,11 +10,10 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= -github.com/btcsuite/btcd v0.23.3 h1:4KH/JKy9WiCd+iUS9Mu0Zp7Dnj17TGdKrg9xc/FGj24= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3 h1:SDlJ7bAm4ewvrmZtR0DaiYbQGdKPeaaIm7bM+qRhFeU= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU= github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= @@ -94,6 +93,8 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedib0t/go-pretty/v6 v6.4.7 h1:lwiTJr1DEkAgzljsUsORmWsVn5MQjt1BPJdPCtJ6KXE= github.com/jedib0t/go-pretty/v6 v6.4.7/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs= +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/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -140,10 +141,8 @@ github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKl github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240401172519-4bfc659b80bf h1:yW8rTFycozLVnXRyOgZWGktnmzoFLxSWh1xPJXsp7vg= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240401172519-4bfc659b80bf/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA= -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/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724 h1:1qpCBUyjYP7nTYi2mdN27ZmOB9r7kA0GFww4M6VYbBA= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724/go.mod h1:2BbaKM4DOcZCH+x1SNAPq1+X/1BCMOJNx12u/OzLlNk= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= diff --git a/pkg/v2/factory.go b/pkg/v2/factory.go index 79cf8c23..b6221ba7 100644 --- a/pkg/v2/factory.go +++ b/pkg/v2/factory.go @@ -1,6 +1,7 @@ package ocr2keepers import ( + "context" "fmt" "log" @@ -58,7 +59,7 @@ type pluginFactory struct { logger *log.Logger } -func (f *pluginFactory) NewReportingPlugin(c types.ReportingPluginConfig) (types.ReportingPlugin, types.ReportingPluginInfo, error) { +func (f *pluginFactory) NewReportingPlugin(ctx context.Context, c types.ReportingPluginConfig) (types.ReportingPlugin, types.ReportingPluginInfo, error) { f.logger.Printf("creating new reporting plugin instance") offChainCfg, err := config.DecodeOffchainConfig(c.OffchainConfig) diff --git a/pkg/v3/plugin/factory.go b/pkg/v3/plugin/factory.go index 9d23280f..e9727d61 100644 --- a/pkg/v3/plugin/factory.go +++ b/pkg/v3/plugin/factory.go @@ -1,18 +1,20 @@ package plugin import ( + "context" "fmt" "log" "math" "math/cmplx" "strconv" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3" "github.com/smartcontractkit/chainlink-automation/pkg/v3/config" "github.com/smartcontractkit/chainlink-automation/pkg/v3/runner" "github.com/smartcontractkit/chainlink-automation/pkg/v3/types" commontypes "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ) type pluginFactory struct { @@ -63,7 +65,7 @@ func NewReportingPluginFactory( } } -func (factory *pluginFactory) NewReportingPlugin(c ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[AutomationReportInfo], ocr3types.ReportingPluginInfo, error) { +func (factory *pluginFactory) NewReportingPlugin(ctx context.Context, c ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[AutomationReportInfo], ocr3types.ReportingPluginInfo, error) { info := ocr3types.ReportingPluginInfo{ Name: fmt.Sprintf("Oracle: %d: Automation Plugin Instance w/ Digest '%s'", c.OracleID, c.ConfigDigest), Limits: ocr3types.ReportingPluginLimits{ diff --git a/pkg/v3/plugin/ocr3.go b/pkg/v3/plugin/ocr3.go index 564c4edd..6449b41e 100644 --- a/pkg/v3/plugin/ocr3.go +++ b/pkg/v3/plugin/ocr3.go @@ -88,17 +88,17 @@ func (plugin *ocr3Plugin) Observation(ctx context.Context, outctx ocr3types.Outc return observation.Encode() } -func (plugin *ocr3Plugin) ObservationQuorum(outctx ocr3types.OutcomeContext, query ocr2plustypes.Query) (ocr3types.Quorum, error) { +func (plugin *ocr3Plugin) ObservationQuorum(ctx context.Context, outctx ocr3types.OutcomeContext, query ocr2plustypes.Query) (ocr3types.Quorum, error) { return ocr3types.QuorumTwoFPlusOne, nil } -func (plugin *ocr3Plugin) ValidateObservation(outctx ocr3types.OutcomeContext, query ocr2plustypes.Query, ao ocr2plustypes.AttributedObservation) error { +func (plugin *ocr3Plugin) ValidateObservation(ctx context.Context, outctx ocr3types.OutcomeContext, query ocr2plustypes.Query, ao ocr2plustypes.AttributedObservation) error { plugin.Logger.Printf("inside ValidateObservation for seqNr %d", outctx.SeqNr) _, err := ocr2keepersv3.DecodeAutomationObservation(ao.Observation, plugin.UpkeepTypeGetter, plugin.WorkIDGenerator) return err } -func (plugin *ocr3Plugin) Outcome(outctx ocr3types.OutcomeContext, query ocr2plustypes.Query, attributedObservations []ocr2plustypes.AttributedObservation) (ocr3types.Outcome, error) { +func (plugin *ocr3Plugin) Outcome(ctx context.Context, outctx ocr3types.OutcomeContext, query ocr2plustypes.Query, attributedObservations []ocr2plustypes.AttributedObservation) (ocr3types.Outcome, error) { plugin.Logger.Printf("inside Outcome for seqNr %d", outctx.SeqNr) p := newPerformables(plugin.F+1, ocr2keepersv3.OutcomeAgreedPerformablesLimit, getRandomKeySource(plugin.ConfigDigest, outctx.SeqNr), plugin.Logger) c := newCoordinatedBlockProposals(plugin.F+1, ocr2keepersv3.OutcomeSurfacedProposalsRoundHistoryLimit, ocr2keepersv3.OutcomeSurfacedProposalsLimit, getRandomKeySource(plugin.ConfigDigest, outctx.SeqNr), plugin.Logger) @@ -146,7 +146,7 @@ func (plugin *ocr3Plugin) Outcome(outctx ocr3types.OutcomeContext, query ocr2plu return outcome.Encode() } -func (plugin *ocr3Plugin) Reports(seqNr uint64, raw ocr3types.Outcome) ([]ocr3types.ReportWithInfo[AutomationReportInfo], error) { +func (plugin *ocr3Plugin) Reports(ctx context.Context, seqNr uint64, raw ocr3types.Outcome) ([]ocr3types.ReportWithInfo[AutomationReportInfo], error) { plugin.Logger.Printf("inside Reports for seqNr %d", seqNr) var ( reports []ocr3types.ReportWithInfo[AutomationReportInfo] diff --git a/pkg/v3/plugin/ocr3_test.go b/pkg/v3/plugin/ocr3_test.go index 7c27dc45..d90dbdbd 100644 --- a/pkg/v3/plugin/ocr3_test.go +++ b/pkg/v3/plugin/ocr3_test.go @@ -990,7 +990,7 @@ func TestOcr3Plugin_ValidateObservation(t *testing.T) { UpkeepTypeGetter: mockUpkeepTypeGetter, WorkIDGenerator: tc.wg, } - err := plugin.ValidateObservation(ocr3types.OutcomeContext{}, nil, tc.observation) + err := plugin.ValidateObservation(context.Background(), ocr3types.OutcomeContext{}, nil, tc.observation) if tc.expectsErr { assert.Error(t, err) assert.Equal(t, err.Error(), tc.wantErr.Error()) @@ -1093,7 +1093,7 @@ func TestOcr3Plugin_Outcome(t *testing.T) { WorkIDGenerator: tc.wg, Logger: logger, } - outcome, err := plugin.Outcome(ocr3types.OutcomeContext{ + outcome, err := plugin.Outcome(context.Background(), ocr3types.OutcomeContext{ PreviousOutcome: tc.prevOutcome, }, nil, tc.observations) if tc.expectsErr { @@ -1274,7 +1274,7 @@ func TestOcr3Plugin_Reports(t *testing.T) { UpkeepTypeGetter: tc.utg, WorkIDGenerator: tc.wg, } - reportsWithInfo, err := plugin.Reports(tc.sequenceNumber, tc.outcome) + reportsWithInfo, err := plugin.Reports(context.Background(), tc.sequenceNumber, tc.outcome) if tc.expectsErr { assert.Error(t, err) assert.Equal(t, err.Error(), tc.wantErr.Error()) diff --git a/tools/simulator/simulate/loader/ocr3config.go b/tools/simulator/simulate/loader/ocr3config.go index 54dcbae2..6e588098 100644 --- a/tools/simulator/simulate/loader/ocr3config.go +++ b/tools/simulator/simulate/loader/ocr3config.go @@ -1,6 +1,7 @@ package loader import ( + "context" "log" "sync" @@ -27,7 +28,7 @@ type OffchainKeySourcer interface { } type Digester interface { - ConfigDigest(config types.ContractConfig) (types.ConfigDigest, error) + ConfigDigest(ctx context.Context, config types.ContractConfig) (types.ConfigDigest, error) } type ProgressTelemetry interface { @@ -79,7 +80,7 @@ func (l *OCR3ConfigLoader) Load(block *chain.Block) { // check if new block indicates a new config event should be loaded if evt, ok := l.events[block.Number.String()]; ok { - conf, err := buildConfig(evt, l.oracles, l.digest, l.count+1) + conf, err := buildConfig(context.Background(), evt, l.oracles, l.digest, l.count+1) if err != nil { l.logger.Printf("error building config: %s", err) @@ -117,7 +118,7 @@ func (l *OCR3ConfigLoader) AddSigner(id string, onKey KeySourcer, offKey Offchai l.oracles = append(l.oracles, newOracle) } -func buildConfig(conf config.OCR3ConfigEvent, oracles []ocr2config.OracleIdentityExtra, digester Digester, count uint64) (types.ContractConfig, error) { +func buildConfig(ctx context.Context, conf config.OCR3ConfigEvent, oracles []ocr2config.OracleIdentityExtra, digester Digester, count uint64) (types.ContractConfig, error) { // S is a slice of values that indicate the number of oracles involved // in attempting to transmit. For the simulator, all nodes will be involved // in transmit attempts. @@ -159,7 +160,7 @@ func buildConfig(conf config.OCR3ConfigEvent, oracles []ocr2config.OracleIdentit OffchainConfig: offchainConfig, } - digest, _ := digester.ConfigDigest(contractConf) + digest, _ := digester.ConfigDigest(ctx, contractConf) contractConf.ConfigDigest = digest return contractConf, nil diff --git a/tools/simulator/simulate/loader/ocr3config_test.go b/tools/simulator/simulate/loader/ocr3config_test.go index fec4714b..091c5f3b 100644 --- a/tools/simulator/simulate/loader/ocr3config_test.go +++ b/tools/simulator/simulate/loader/ocr3config_test.go @@ -1,6 +1,7 @@ package loader_test import ( + "context" "crypto/rand" "crypto/sha256" "fmt" @@ -59,7 +60,7 @@ type mockDigester struct { mock.Mock } -func (_m *mockDigester) ConfigDigest(config types.ContractConfig) (types.ConfigDigest, error) { +func (_m *mockDigester) ConfigDigest(ctx context.Context, config types.ContractConfig) (types.ConfigDigest, error) { req := _m.Called(config) hash := sha256.Sum256([]byte(fmt.Sprintf("%+v", config))) diff --git a/tools/simulator/simulate/ocr/transmit.go b/tools/simulator/simulate/ocr/transmit.go index c6c78536..a0648c49 100644 --- a/tools/simulator/simulate/ocr/transmit.go +++ b/tools/simulator/simulate/ocr/transmit.go @@ -41,7 +41,7 @@ func (tr *OCR3Transmitter) Transmit( } // Account from which the transmitter invokes the contract -func (tr *OCR3Transmitter) FromAccount() (types.Account, error) { +func (tr *OCR3Transmitter) FromAccount(ctx context.Context) (types.Account, error) { tr.mu.RLock() defer tr.mu.RUnlock()