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 Sep 17, 2024
1 parent a7348f0 commit 7ed7c33
Show file tree
Hide file tree
Showing 151 changed files with 1,059 additions and 1,907 deletions.
17 changes: 9 additions & 8 deletions core/capabilities/ccip/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ import (
"testing"
"time"

"github.com/smartcontractkit/chainlink-ccip/chainconfig"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccip_integration_tests/integrationhelpers"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -24,8 +16,16 @@ import (
confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"

"github.com/smartcontractkit/chainlink-ccip/chainconfig"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"

"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccip_integration_tests/integrationhelpers"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/maybe_revert_message_receiver"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_rmn_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager"
Expand Down Expand Up @@ -503,6 +503,7 @@ func (h *homeChain) AddDON(
schedule,
oracles,
encodedOffchainConfig,
nil,
MaxDurationQuery,
MaxDurationObservation,
MaxDurationShouldAcceptAttestedReport,
Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/ccip/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (d *Delegate) getHomeChainContractReader(
}

reader, err := evm.NewChainReaderService(
context.Background(),
ctx,
d.lggr,
homeChain.LogPoller(),
homeChain.HeadTracker(),
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
4 changes: 3 additions & 1 deletion core/capabilities/ccip/ocrimpls/contract_transmitter_test.go
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 @@ -103,6 +104,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 @@ -125,7 +127,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 @@ -469,7 +469,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,
// 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
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 @@ -169,7 +169,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 @@ -331,8 +331,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
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
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 @@ -1271,7 +1270,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 @@ -1327,8 +1326,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 @@ -1338,6 +1336,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, nil, nil)
Expand Down
Loading

0 comments on commit 7ed7c33

Please sign in to comment.