Skip to content

Commit

Permalink
bump libocr; add context
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Apr 25, 2024
1 parent 13d6bb7 commit 5583a02
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion pkg/v2/factory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ocr2keepers

import (
"context"
"fmt"
"log"

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pkg/v3/plugin/factory.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions pkg/v3/plugin/ocr3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions pkg/v3/plugin/ocr3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
9 changes: 5 additions & 4 deletions tools/simulator/simulate/loader/ocr3config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loader

import (
"context"
"log"
"sync"

Expand All @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tools/simulator/simulate/loader/ocr3config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loader_test

import (
"context"
"crypto/rand"
"crypto/sha256"
"fmt"
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion tools/simulator/simulate/ocr/transmit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 5583a02

Please sign in to comment.