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 libocr; add context #14011

Merged
merged 1 commit into from
Oct 12, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jobs:
echo "COUNT=50" >> $GITHUB_ENV
- name: Install gotestloghelper
if: ${{ needs.filter.outputs.changes == 'true' }}
run: go install github.com/smartcontractkit/chainlink-testing-framework/tools/gotestloghelper@v1.1.1
run: go install github.com/smartcontractkit/chainlink-testing-framework/tools/gotestloghelper@v1.50.0
- name: Run tests
if: ${{ needs.filter.outputs.changes == 'true' }}
id: run-tests
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
golang 1.22.7
golang 1.22.8
mockery 2.43.2
nodejs 20.13.1
pnpm 9.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func testSetup(
contractReaders[chain] = cr
}
contractWriters := make(map[cciptypes.ChainSelector]types.ChainWriter)
reader := ccipreaderpkg.NewCCIPReaderWithExtendedContractReaders(lggr, contractReaders, contractWriters, destChain, nil)
reader := ccipreaderpkg.NewCCIPReaderWithExtendedContractReaders(ctx, lggr, contractReaders, contractWriters, destChain, nil)

t.Cleanup(func() {
require.NoError(t, cr.Close())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Test_USDCReader_MessageHashes(t *testing.T) {
ts := testSetup(ctx, t, ethereumChain, evmconfig.USDCReaderConfig, finalityDepth)

usdcReader, err := reader.NewUSDCMessageReader(
ctx,
logger.TestLogger(t),
map[cciptypes.ChainSelector]pluginconfig.USDCCCTPTokenConfig{
ethereumChain: {
Expand Down
10 changes: 7 additions & 3 deletions core/capabilities/ccip/ocrimpls/config_digester.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package ocrimpls

import "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
import (
"context"

"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

type configDigester struct {
d types.ConfigDigest
Expand All @@ -11,12 +15,12 @@ func NewConfigDigester(d types.ConfigDigest) *configDigester {
}

// ConfigDigest implements types.OffchainConfigDigester.
func (c *configDigester) ConfigDigest(types.ContractConfig) (types.ConfigDigest, error) {
func (c *configDigester) ConfigDigest(context.Context, types.ContractConfig) (types.ConfigDigest, error) {
return c.d, nil
}

// ConfigDigestPrefix implements types.OffchainConfigDigester.
func (c *configDigester) ConfigDigestPrefix() (types.ConfigDigestPrefix, error) {
func (c *configDigester) ConfigDigestPrefix(ctx context.Context) (types.ConfigDigestPrefix, error) {
return types.ConfigDigestPrefixCCIPMultiRole, nil
}

Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/ccip/ocrimpls/contract_transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func NewExecContractTransmitter[RI any](
}

// FromAccount implements ocr3types.ContractTransmitter.
func (c *commitTransmitter[RI]) FromAccount() (ocrtypes.Account, error) {
func (c *commitTransmitter[RI]) FromAccount(context.Context) (ocrtypes.Account, error) {
return c.fromAccount, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ocrimpls"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"

Expand Down Expand Up @@ -101,6 +102,7 @@ func testTransmitter(
expectedSigsEnabled bool,
report []byte,
) {
ctx := tests.Context(t)
uni := newTestUniverse[[]byte](t, nil)

c, err := uni.wrapper.LatestConfigDetails(nil, pluginType)
Expand All @@ -123,7 +125,7 @@ func testTransmitter(
seqNr := uint64(1)
attributedSigs := uni.SignReport(t, configDigest, rwi, seqNr)

account, err := uni.transmitterWithSigs.FromAccount()
account, err := uni.transmitterWithSigs.FromAccount(ctx)
require.NoError(t, err, "failed to get from account")
require.Equal(t, ocrtypes.Account(uni.transmitters[0].Hex()), account, "from account mismatch")
if withSigs {
Expand Down
4 changes: 3 additions & 1 deletion core/capabilities/ccip/oraclecreator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ func (ofc offChainConfig) isValid() bool {

func defaultLocalConfig() ocrtypes.LocalConfig {
return ocrtypes.LocalConfig{
BlockchainTimeout: 10 * time.Second,
DefaultMaxDurationInitialization: 30 * time.Second,
BlockchainTimeout: 10 * time.Second,
ContractConfigLoadTimeout: 10 * time.Second,
jmank88 marked this conversation as resolved.
Show resolved Hide resolved
// Config tracking is handled by the launcher, since we're doing blue-green
// deployments we're not going to be using OCR's built-in config switching,
// which always shuts down the previous instance.
Expand Down
8 changes: 7 additions & 1 deletion core/capabilities/compute/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm/host"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/wasmtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -54,6 +55,7 @@ func TestCache(t *testing.T) {
}

func TestCache_EvictAfterSize(t *testing.T) {
ctx := tests.Context(t)
clock := clockwork.NewFakeClock()
tick := 1 * time.Second
timeout := 1 * time.Second
Expand Down Expand Up @@ -82,7 +84,11 @@ func TestCache_EvictAfterSize(t *testing.T) {
assert.Equal(t, got, mod)

clock.Advance(15 * time.Second)
<-cache.onReaper
select {
case <-ctx.Done():
return
case <-cache.onReaper:
}
_, ok = cache.get(id)
assert.True(t, ok)
}
12 changes: 6 additions & 6 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,15 +140,15 @@ 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)
}
for _, report := range reports {
// create signatures
var signatures []types.AttributedOnchainSignature
for i, node := range m.nodes {
sig, err := node.key.Sign(types.ReportContext{}, report.Report)
sig, err := node.key.Sign(types.ReportContext{}, report.ReportWithInfo.Report)
if err != nil {
return fmt.Errorf("failed to sign report: %w", err)
}
Expand All @@ -160,15 +160,15 @@ func (m *mockLibOCR) simulateProtocolRound(ctx context.Context) error {
}

for _, node := range m.nodes {
accept, err := node.ShouldAcceptAttestedReport(ctx, m.seqNr, report)
accept, err := node.ShouldAcceptAttestedReport(ctx, m.seqNr, report.ReportWithInfo)
if err != nil {
return fmt.Errorf("failed to check if report should be accepted: %w", err)
}
if !accept {
continue
}

transmit, err := node.ShouldTransmitAcceptedReport(ctx, m.seqNr, report)
transmit, err := node.ShouldTransmitAcceptedReport(ctx, m.seqNr, report.ReportWithInfo)
if err != nil {
return fmt.Errorf("failed to check if report should be transmitted: %w", err)
}
Expand All @@ -186,7 +186,7 @@ func (m *mockLibOCR) simulateProtocolRound(ctx context.Context) error {
selectedSignatures[i] = signatures[indices[i]]
}

err = node.Transmit(ctx, types.ConfigDigest{}, 0, report, selectedSignatures)
err = node.Transmit(ctx, types.ConfigDigest{}, 0, report.ReportWithInfo, selectedSignatures)
if err != nil {
return fmt.Errorf("failed to transmit report: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions core/capabilities/integration_tests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ 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/capabilities"
remotetypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/feeds_consumer"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -168,7 +168,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 +330,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 @@ -109,8 +110,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 @@ -131,27 +131,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 @@ -188,7 +173,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 @@ -203,7 +188,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 @@ -22,7 +22,7 @@ func newEvmTxm(
client evmclient.Client,
lggr logger.Logger,
logPoller logpoller.LogPoller,
opts ChainRelayExtenderConfig,
opts ChainRelayOpts,
headTracker httypes.HeadTracker,
) (txm txmgr.TxManager,
estimator gas.EvmFeeEstimator,
Expand Down
3 changes: 2 additions & 1 deletion core/cmd/cosmos_transaction_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/cosmoskey"
)

var nativeToken = "cosm"
const nativeToken = "cosm"

func TestMain(m *testing.M) {

Expand All @@ -40,6 +40,7 @@ func TestMain(m *testing.M) {
}

func TestShell_SendCosmosCoins(t *testing.T) {
t.Parallel()
ctx := testutils.Context(t)
// TODO(BCI-978): cleanup once SetupLocalCosmosNode is updated
chainID := cosmostest.RandomChainID()
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(), opts.AppConfig.Telemetry()),
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
Loading
Loading