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 Aug 5, 2024
1 parent d90bb66 commit 65883f1
Show file tree
Hide file tree
Showing 92 changed files with 645 additions and 1,538 deletions.
4 changes: 2 additions & 2 deletions core/capabilities/integration_tests/mock_libocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (m *mockLibOCR) simulateProtocolRound(ctx context.Context) error {

var outcomes []ocr3types.Outcome
for _, node := range m.nodes {
outcome, err2 := node.Outcome(m.outcomeCtx, query, observations)
outcome, err2 := node.Outcome(ctx, m.outcomeCtx, query, observations)
if err2 != nil {
return fmt.Errorf("failed to get outcome: %w", err)
}
Expand All @@ -140,7 +140,7 @@ func (m *mockLibOCR) simulateProtocolRound(ctx context.Context) error {
}
}

reports, err := leader.Reports(0, outcomes[0])
reports, err := leader.Reports(ctx, 0, outcomes[0])
if err != nil {
return fmt.Errorf("failed to get reports: %w", err)
}
Expand Down
11 changes: 7 additions & 4 deletions core/capabilities/integration_tests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import (
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
ocrTypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/feeds_consumer"

commoncap "github.com/smartcontractkit/chainlink-common/pkg/capabilities"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/datastreams"
"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
coretypes "github.com/smartcontractkit/chainlink-common/pkg/types/core"
v3 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v3"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/feeds_consumer"

"github.com/smartcontractkit/chainlink/v2/core/capabilities"
remotetypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
Expand Down Expand Up @@ -168,7 +170,7 @@ func createDons(ctx context.Context, t *testing.T, lggr logger.Logger, reportsSi
repConfig := ocr3types.ReportingPluginConfig{
F: int(workflowDon.F),
}
plugin, _, err := pluginFactory.NewReportingPlugin(repConfig)
plugin, _, err := pluginFactory.NewReportingPlugin(ctx, repConfig)
require.NoError(t, err)

transmitter := ocr3.NewContractTransmitter(lggr, capabilityRegistry, "")
Expand Down Expand Up @@ -330,8 +332,9 @@ func newFeedID(t *testing.T) string {
}

func newReport(t *testing.T, feedID [32]byte, price *big.Int, timestamp int64) []byte {
ctx := tests.Context(t)
v3Codec := reportcodec.NewReportCodec(feedID, logger.TestLogger(t))
raw, err := v3Codec.BuildReport(v3.ReportFields{
raw, err := v3Codec.BuildReport(ctx, v3.ReportFields{
BenchmarkPrice: price,
Timestamp: uint32(timestamp),
Bid: big.NewInt(0),
Expand Down
4 changes: 3 additions & 1 deletion core/capabilities/streams/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/capabilities/datastreams"
v3 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v3"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink-common/pkg/values"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/streams"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -95,8 +96,9 @@ func newFeedID(t *testing.T) ([32]byte, string) {
}

func newReport(t *testing.T, feedID [32]byte, price *big.Int, timestamp int64) []byte {
ctx := tests.Context(t)
v3Codec := reportcodec.NewReportCodec(feedID, logger.TestLogger(t))
raw, err := v3Codec.BuildReport(v3.ReportFields{
raw, err := v3Codec.BuildReport(ctx, v3.ReportFields{
BenchmarkPrice: price,
Timestamp: uint32(timestamp),
ValidFromTimestamp: uint32(timestamp),
Expand Down
9 changes: 5 additions & 4 deletions core/chains/evm/log/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func newBroadcasterHelperWithEthClient(t *testing.T, ethClient evmclient.Client,
lb := log.NewTestBroadcaster(orm, ethClient, config.EVM(), lggr, highestSeenHead, mailMon)
kst := cltest.NewKeyStore(t, db)

cc := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{
chainsAndConfig := evmtest.NewLegacyChainsAndConfig(t, evmtest.TestChainOpts{
Client: ethClient,
GeneralConfig: globalConfig,
DB: db,
Expand All @@ -107,10 +107,11 @@ func newBroadcasterHelperWithEthClient(t *testing.T, ethClient evmclient.Client,
})

m := make(map[string]legacyevm.Chain)
for _, r := range cc.Slice() {
m[r.Chain().ID().String()] = r.Chain()
for _, r := range chainsAndConfig.Slice() {
m[r.ID().String()] = r
}
legacyChains := legacyevm.NewLegacyChains(m, cc.AppConfig().EVMConfigs())

legacyChains := chainsAndConfig.NewLegacyChains()
pipelineHelper := cltest.NewJobPipelineV2(t, globalConfig.WebServer(), globalConfig.JobPipeline(), legacyChains, db, kst, nil, nil)

return &broadcasterHelper{
Expand Down
21 changes: 3 additions & 18 deletions core/chains/legacyevm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,12 @@ type AppConfig interface {
toml.HasEVMConfigs
}

type ChainRelayExtenderConfig struct {
type ChainRelayOpts struct {
Logger logger.Logger
KeyStore keystore.Eth
ChainOpts
}

func (c ChainRelayExtenderConfig) Validate() error {
err := c.ChainOpts.Validate()
if c.Logger == nil {
err = errors.Join(err, errors.New("nil Logger"))
}
if c.KeyStore == nil {
err = errors.Join(err, errors.New("nil Keystore"))
}

if err != nil {
err = fmt.Errorf("invalid ChainRelayerExtenderConfig: %w", err)
}
return err
}

type ChainOpts struct {
AppConfig AppConfig

Expand Down Expand Up @@ -187,7 +172,7 @@ func (o ChainOpts) Validate() error {
return err
}

func NewTOMLChain(ctx context.Context, chain *toml.EVMConfig, opts ChainRelayExtenderConfig) (Chain, error) {
func NewTOMLChain(ctx context.Context, chain *toml.EVMConfig, opts ChainRelayOpts) (Chain, error) {
err := opts.Validate()
if err != nil {
return nil, err
Expand All @@ -202,7 +187,7 @@ func NewTOMLChain(ctx context.Context, chain *toml.EVMConfig, opts ChainRelayExt
return newChain(ctx, cfg, chain.Nodes, opts)
}

func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Node, opts ChainRelayExtenderConfig) (*chain, error) {
func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Node, opts ChainRelayOpts) (*chain, error) {
chainID := cfg.EVM().ChainID()
l := opts.Logger
var client evmclient.Client
Expand Down
2 changes: 1 addition & 1 deletion core/chains/legacyevm/evm_txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func newEvmTxm(
client evmclient.Client,
lggr logger.Logger,
logPoller logpoller.LogPoller,
opts ChainRelayExtenderConfig,
opts ChainRelayOpts,
) (txm txmgr.TxManager,
estimator gas.EvmFeeEstimator,
err error,
Expand Down
6 changes: 3 additions & 3 deletions core/cmd/shell_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
"github.com/urfave/cli"
)

func genTestEVMRelayers(t *testing.T, opts legacyevm.ChainRelayExtenderConfig, ks evmrelayer.CSAETHKeystore) *chainlink.CoreRelayerChainInteroperators {
func genTestEVMRelayers(t *testing.T, opts legacyevm.ChainRelayOpts, ks evmrelayer.CSAETHKeystore) *chainlink.CoreRelayerChainInteroperators {
f := chainlink.RelayerFactory{
Logger: opts.Logger,
LoopRegistry: plugins.NewLoopRegistry(opts.Logger, opts.AppConfig.Tracing()),
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestShell_RunNodeWithPasswords(t *testing.T) {

lggr := logger.TestLogger(t)

opts := legacyevm.ChainRelayExtenderConfig{
opts := legacyevm.ChainRelayOpts{
Logger: lggr,
KeyStore: keyStore.Eth(),
ChainOpts: legacyevm.ChainOpts{
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestShell_RunNodeWithAPICredentialsFile(t *testing.T) {
ethClient.On("BalanceAt", mock.Anything, mock.Anything, mock.Anything).Return(big.NewInt(10), nil).Maybe()

lggr := logger.TestLogger(t)
opts := legacyevm.ChainRelayExtenderConfig{
opts := legacyevm.ChainRelayOpts{
Logger: lggr,
KeyStore: keyStore.Eth(),
ChainOpts: legacyevm.ChainOpts{
Expand Down
7 changes: 3 additions & 4 deletions core/internal/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocrkey"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/webhook"
"github.com/smartcontractkit/chainlink/v2/core/static"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
Expand Down Expand Up @@ -1270,7 +1269,7 @@ func TestIntegration_BlockHistoryEstimator(t *testing.T) {
kst := cltest.NewKeyStore(t, db)
require.NoError(t, kst.Unlock(ctx, cltest.Password))

cc := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, KeyStore: kst.Eth(), Client: ethClient, GeneralConfig: cfg})
chainsAndConfig := evmtest.NewLegacyChainsAndConfig(t, evmtest.TestChainOpts{DB: db, KeyStore: kst.Eth(), Client: ethClient, GeneralConfig: cfg})

b41 := evmtypes.Block{
Number: 41,
Expand Down Expand Up @@ -1326,8 +1325,7 @@ func TestIntegration_BlockHistoryEstimator(t *testing.T) {
ethClient.On("HeadByHash", mock.Anything, h41.Hash).Return(&h41, nil).Maybe()
ethClient.On("HeadByHash", mock.Anything, h42.Hash).Return(&h42, nil).Maybe()

legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(cc)
for _, re := range cc.Slice() {
for _, re := range chainsAndConfig.Slice() {
servicetest.Run(t, re)
}
var newHeads evmtestutils.RawSub[*evmtypes.Head]
Expand All @@ -1337,6 +1335,7 @@ func TestIntegration_BlockHistoryEstimator(t *testing.T) {
t.Fatal("timed out waiting for app to subscribe")
}

legacyChains := chainsAndConfig.NewLegacyChains()
chain := evmtest.MustGetDefaultChain(t, legacyChains)
estimator := chain.GasEstimator()
gasPrice, gasLimit, err := estimator.GetFee(testutils.Context(t), nil, 500_000, maxGasPrice)
Expand Down
19 changes: 13 additions & 6 deletions core/internal/testutils/evmtest/evmtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,26 @@ type TestChainOpts struct {
GasEstimator gas.EvmFeeEstimator
}

// NewChainRelayExtenders returns a simple chain collection with one chain and
// NewLegacyChainsAndConfig returns a simple chain collection with one chain and
// allows to mock client/config on that chain
func NewChainRelayExtenders(t testing.TB, testopts TestChainOpts) *evmrelay.ChainRelayerExtenders {
opts := NewChainRelayExtOpts(t, testopts)
cc, err := evmrelay.NewChainRelayerExtenders(testutils.Context(t), opts)
func NewLegacyChainsAndConfig(t testing.TB, testopts TestChainOpts) *evmrelay.LegacyChainsAndConfig {
opts := NewChainOpts(t, testopts)
cc, err := evmrelay.NewLegacyChainsAndConfig(testutils.Context(t), opts)
require.NoError(t, err)
return cc
}

func NewChainRelayExtOpts(t testing.TB, testopts TestChainOpts) legacyevm.ChainRelayExtenderConfig {
func NewLegacyChains(t testing.TB, testopts TestChainOpts) *legacyevm.LegacyChains {
opts := NewChainOpts(t, testopts)
cc, err := evmrelay.NewLegacyChainsAndConfig(testutils.Context(t), opts)
require.NoError(t, err)
return cc.NewLegacyChains()
}

func NewChainOpts(t testing.TB, testopts TestChainOpts) legacyevm.ChainRelayOpts {
require.NotNil(t, testopts.KeyStore)
lggr := logger.TestLogger(t)
opts := legacyevm.ChainRelayExtenderConfig{
opts := legacyevm.ChainRelayOpts{
Logger: lggr,
KeyStore: testopts.KeyStore,
ChainOpts: legacyevm.ChainOpts{
Expand Down
24 changes: 12 additions & 12 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/smartcontractkit/chainlink/v2 => ../../

require (
github.com/docker/docker v24.0.7+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-connections v0.5.0
github.com/ethereum/go-ethereum v1.13.8
github.com/gkampitakis/go-snaps v0.5.4
github.com/google/go-cmp v0.6.0
Expand All @@ -21,10 +21,10 @@ require (
github.com/pelletier/go-toml/v2 v2.2.0
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240805160614-501c4f40b98c
github.com/smartcontractkit/chainlink-automation v1.0.5-0.20240801163457-43763630e965
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240805231047-ec2d56020a49
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240717100443-f6226e09bee7
github.com/smartcontractkit/libocr v0.0.0-20240805102757-d84f1198d177
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -270,15 +270,15 @@ require (
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shirou/gopsutil/v3 v3.24.3 // indirect
github.com/smartcontractkit/chain-selectors v1.0.10 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240801131703-fd75761c982f // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240710170203-5b41615da827 // indirect
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240712132946-267a37c5ac6e // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240709043547-03612098f799 // indirect
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240801172621-0780686e8cd7 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240805231213-4fc7a43d063d // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240801163225-8d63d719e411 // indirect
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240801182727-03e9d9e161e0 // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240801215534-34b4aec98b2d // indirect
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20240801223644-b81c0f1b9c79 // indirect
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20240801223644-b81c0f1b9c79 // indirect
github.com/smartcontractkit/wsrpc v0.7.3 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
Loading

0 comments on commit 65883f1

Please sign in to comment.