Skip to content

Commit

Permalink
removing core logger import from exec factory
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Jul 10, 2024
1 parent 230a359 commit 8f006d3
Show file tree
Hide file tree
Showing 22 changed files with 53 additions and 56 deletions.
5 changes: 3 additions & 2 deletions core/services/ocr2/plugins/ccip/ccipcommit/initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"math/big"
"strings"

commonlogger "github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/v2/core/logger"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/pricegetter"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/rpclib"

Expand All @@ -18,7 +21,6 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"

commonlogger "github.com/smartcontractkit/chainlink-common/pkg/logger"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
Expand All @@ -31,7 +33,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
Expand Down
15 changes: 4 additions & 11 deletions core/services/ocr2/plugins/ccip/ccipexec/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/services"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/observability"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/tokendata"

Expand Down Expand Up @@ -75,13 +75,7 @@ func (rf *ExecutionReportingPluginFactory) HealthReport() map[string]error {
}

func NewExecutionReportingPluginFactoryV2(ctx context.Context, lggr logger.Logger, sourceTokenAddress string, srcChainID int64, dstChainID int64, srcProvider commontypes.CCIPExecProvider, dstProvider commontypes.CCIPExecProvider) (*ExecutionReportingPluginFactory, error) {
// TODO: common logger is a subset of core logger.
// what's the golden path for passing a logger through from the plugin to the LOOP reporting plugin factory?
if lggr == nil {
lggr, _ = logger.NewLogger()
}

// TODO: NewOffRampReader doesn't need addr param when provided in job spec
// NewOffRampReader doesn't need addr param when provided in job spec
offRampReader, err := dstProvider.NewOffRampReader(ctx, "")
if err != nil {
return nil, fmt.Errorf("create offRampReader: %w", err)
Expand Down Expand Up @@ -145,8 +139,7 @@ func NewExecutionReportingPluginFactoryV2(ctx context.Context, lggr logger.Logge
cache.NewChainHealthcheck(
// Adding more details to Logger to make healthcheck logs more informative
// It's safe because healthcheck logs only in case of unhealthy state
lggr.With(
"onramp", offRampConfig.OnRamp,
logger.With(lggr, "onramp", offRampConfig.OnRamp,
"commitStore", offRampConfig.CommitStore,
),
onRampReader,
Expand All @@ -167,7 +160,7 @@ func NewExecutionReportingPluginFactoryV2(ctx context.Context, lggr logger.Logge

return &ExecutionReportingPluginFactory{
config: ExecutionPluginStaticConfig{
lggr: lggr,
lggr: logger.Sugared(lggr),
onRampReader: onRampReader,
commitStoreReader: commitStoreReader,
offRampReader: offRampReader,
Expand Down
4 changes: 2 additions & 2 deletions core/services/ocr2/plugins/ccip/ccipexec/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
ccipdataprovidermocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/ccipdataprovider/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestNewReportingPluginRetriesUntilSuccess(t *testing.T) {
priceRegistryProvider.On("NewPriceRegistryReader", mock.Anything, mock.Anything).Return(nil, nil).Once()
execConfig.priceRegistryProvider = priceRegistryProvider

execConfig.lggr, _ = logger.NewLogger()
execConfig.lggr = logger.TestSugared(t)

factory := NewExecutionReportingPluginFactory(execConfig)
reportingConfig := types.ReportingPluginConfig{}
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/ccip/ccipexec/inflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

// InflightInternalExecutionReport serves the same purpose as InflightCommitReport
Expand Down
18 changes: 9 additions & 9 deletions core/services/ocr2/plugins/ccip/ccipexec/ocr2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink-common/pkg/hashutil"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcommon"
Expand Down Expand Up @@ -50,7 +50,7 @@ var (
)

type ExecutionPluginStaticConfig struct {
lggr logger.Logger
lggr logger.SugaredLogger
onRampReader ccipdata.OnRampReader
offRampReader ccipdata.OffRampReader
commitStoreReader ccipdata.CommitStoreReader
Expand All @@ -68,7 +68,7 @@ type ExecutionPluginStaticConfig struct {
type ExecutionReportingPlugin struct {
// Misc
F int
lggr logger.Logger
lggr logger.SugaredLogger
offchainConfig cciptypes.ExecOffchainConfig
tokenDataWorker tokendata.Worker
metricsCollector ccip.PluginMetricsCollector
Expand Down Expand Up @@ -98,7 +98,7 @@ func (r *ExecutionReportingPlugin) Query(context.Context, types.ReportTimestamp)
return types.Query{}, nil
}

func (r *ExecutionReportingPlugin) Observation(ctx context.Context, timestamp types.ReportTimestamp, query types.Query) (types.Observation, error) {
func (r *ExecutionReportingPlugin) Observation(ctx context.Context, _ types.ReportTimestamp, _ types.Query) (types.Observation, error) {
lggr := r.lggr.Named("ExecutionObservation")
if healthy, err := r.chainHealthcheck.IsHealthy(ctx); err != nil {
return nil, err
Expand Down Expand Up @@ -139,7 +139,7 @@ func (r *ExecutionReportingPlugin) Observation(ctx context.Context, timestamp ty
return ccip.NewExecutionObservation(executableObservations).Marshal()
}

func (r *ExecutionReportingPlugin) getExecutableObservations(ctx context.Context, lggr logger.Logger, inflight []InflightInternalExecutionReport) ([]ccip.ObservedMessage, error) {
func (r *ExecutionReportingPlugin) getExecutableObservations(ctx context.Context, lggr logger.SugaredLogger, inflight []InflightInternalExecutionReport) ([]ccip.ObservedMessage, error) {
unexpiredReports, err := r.getUnexpiredCommitReports(ctx, r.commitStoreReader, lggr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -257,7 +257,7 @@ func (r *ExecutionReportingPlugin) getExecutedSeqNrsInRange(ctx context.Context,
// profitability of execution.
func (r *ExecutionReportingPlugin) buildBatch(
ctx context.Context,
lggr logger.Logger,
lggr logger.SugaredLogger,
report commitReportWithSendRequests,
inflightAggregateValue *big.Int,
aggregateTokenLimit *big.Int,
Expand Down Expand Up @@ -624,7 +624,7 @@ func (r *ExecutionReportingPlugin) buildReport(ctx context.Context, lggr logger.
return encodedReport, nil
}

func (r *ExecutionReportingPlugin) Report(ctx context.Context, timestamp types.ReportTimestamp, query types.Query, observations []types.AttributedObservation) (bool, types.Report, error) {
func (r *ExecutionReportingPlugin) Report(ctx context.Context, _ types.ReportTimestamp, _ types.Query, observations []types.AttributedObservation) (bool, types.Report, error) {
lggr := r.lggr.Named("ExecutionReport")
if healthy, err := r.chainHealthcheck.IsHealthy(ctx); err != nil {
return false, nil, err
Expand Down Expand Up @@ -714,7 +714,7 @@ func calculateObservedMessagesConsensus(observations []ccip.ExecutionObservation
return finalSequenceNumbers, nil
}

func (r *ExecutionReportingPlugin) ShouldAcceptFinalizedReport(ctx context.Context, timestamp types.ReportTimestamp, report types.Report) (bool, error) {
func (r *ExecutionReportingPlugin) ShouldAcceptFinalizedReport(ctx context.Context, _ types.ReportTimestamp, report types.Report) (bool, error) {
lggr := r.lggr.Named("ShouldAcceptFinalizedReport")
execReport, err := r.offRampReader.DecodeExecutionReport(ctx, report)
if err != nil {
Expand Down Expand Up @@ -748,7 +748,7 @@ func (r *ExecutionReportingPlugin) ShouldAcceptFinalizedReport(ctx context.Conte
return true, nil
}

func (r *ExecutionReportingPlugin) ShouldTransmitAcceptedReport(ctx context.Context, timestamp types.ReportTimestamp, report types.Report) (bool, error) {
func (r *ExecutionReportingPlugin) ShouldTransmitAcceptedReport(ctx context.Context, _ types.ReportTimestamp, report types.Report) (bool, error) {
lggr := r.lggr.Named("ShouldTransmitAcceptedReport")
execReport, err := r.offRampReader.DecodeExecutionReport(ctx, report)
if err != nil {
Expand Down
19 changes: 10 additions & 9 deletions core/services/ocr2/plugins/ccip/ccipexec/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

commonlogger "github.com/smartcontractkit/chainlink-common/pkg/logger"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"

lpMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks"
Expand Down Expand Up @@ -137,7 +138,7 @@ func TestExecutionReportingPlugin_Observation(t *testing.T) {
p := &ExecutionReportingPlugin{}
p.inflightReports = newInflightExecReportsContainer(time.Minute)
p.inflightReports.reports = tc.inflightReports
p.lggr = logger.TestLogger(t)
p.lggr = commonlogger.TestSugared(t)
p.tokenDataWorker = tokendata.NewBackgroundWorker(
make(map[cciptypes.Address]tokendata.Reader), 10, 5*time.Second, time.Hour)
p.metricsCollector = ccip.NoopMetricsCollector
Expand Down Expand Up @@ -264,7 +265,7 @@ func TestExecutionReportingPlugin_Report(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
p := ExecutionReportingPlugin{}
p.lggr = logger.TestLogger(t)
p.lggr = commonlogger.TestSugared(t)
p.F = tc.f

p.commitStoreReader = ccipdatamocks.NewCommitStoreReader(t)
Expand Down Expand Up @@ -319,7 +320,7 @@ func TestExecutionReportingPlugin_ShouldAcceptFinalizedReport(t *testing.T) {

plugin := ExecutionReportingPlugin{
offRampReader: mockOffRampReader,
lggr: logger.TestLogger(t),
lggr: commonlogger.TestSugared(t),
inflightReports: newInflightExecReportsContainer(1 * time.Hour),
chainHealthcheck: chainHealthcheck,
metricsCollector: ccip.NoopMetricsCollector,
Expand Down Expand Up @@ -371,7 +372,7 @@ func TestExecutionReportingPlugin_ShouldTransmitAcceptedReport(t *testing.T) {
plugin := ExecutionReportingPlugin{
commitStoreReader: mockCommitStoreReader,
offRampReader: mockOffRampReader,
lggr: logger.TestLogger(t),
lggr: commonlogger.TestSugared(t),
inflightReports: newInflightExecReportsContainer(1 * time.Hour),
chainHealthcheck: chainHealthcheck,
}
Expand Down Expand Up @@ -405,7 +406,7 @@ func TestExecutionReportingPlugin_buildReport(t *testing.T) {

// ensure that buildReport should cap the built report to fit in MaxExecutionReportLength
p := &ExecutionReportingPlugin{}
p.lggr = logger.TestLogger(t)
p.lggr = commonlogger.TestSugared(t)

commitStore := ccipdatamocks.NewCommitStoreReader(t)
commitStore.On("VerifyExecutionReport", mock.Anything, mock.Anything, mock.Anything).Return(true, nil)
Expand Down Expand Up @@ -460,7 +461,7 @@ func TestExecutionReportingPlugin_buildReport(t *testing.T) {

func TestExecutionReportingPlugin_buildBatch(t *testing.T) {
offRamp, _ := testhelpers.NewFakeOffRamp(t)
lggr := logger.TestLogger(t)
lggr := commonlogger.TestSugared(t)

sender1 := ccipcalc.HexToAddress("0xa")
destNative := ccipcalc.HexToAddress("0xb")
Expand Down Expand Up @@ -823,7 +824,7 @@ func TestExecutionReportingPlugin_buildBatch(t *testing.T) {
BatchGasLimit: 500_000,
RelativeBoostPerWaitHour: 1,
},
lggr: logger.TestLogger(t),
lggr: commonlogger.TestSugared(t),
gasPriceEstimator: gasPriceEstimator,
}

Expand Down Expand Up @@ -929,7 +930,7 @@ func TestExecutionReportingPlugin_getReportsWithSendRequests(t *testing.T) {
}

ctx := testutils.Context(t)
lggr := logger.TestLogger(t)
lggr := commonlogger.TestSugared(t)
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
p := &ExecutionReportingPlugin{}
Expand Down Expand Up @@ -1826,7 +1827,7 @@ func encodeExecutionReport(t *testing.T, report cciptypes.ExecReport) []byte {
// Verify the price registry update mechanism in case of configuration change on the source onRamp.
func TestExecutionReportingPlugin_ensurePriceRegistrySynchronization(t *testing.T) {
p := &ExecutionReportingPlugin{}
p.lggr = logger.TestLogger(t)
p.lggr = commonlogger.TestSugared(t)
p.sourcePriceRegistryLock = sync.RWMutex{}

sourcePriceRegistryAddress1 := cciptypes.Address(utils.RandomAddress().String())
Expand Down
10 changes: 5 additions & 5 deletions core/services/ocr2/plugins/ccip/internal/cache/chain_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
)

Expand Down Expand Up @@ -53,7 +53,7 @@ type chainHealthcheck struct {
globalStatusExpiration time.Duration
rmnStatusRefreshInterval time.Duration

lggr logger.Logger
lggr logger.SugaredLogger
onRamp ccipdata.OnRampReader
commitStore ccipdata.CommitStoreReader

Expand Down Expand Up @@ -84,7 +84,7 @@ func NewChainHealthcheck(lggr logger.Logger, onRamp ccipdata.OnRampReader, commi
globalStatusExpiration: defaultGlobalStatusExpirationDuration,
rmnStatusRefreshInterval: defaultRMNStateRefreshInterval,

lggr: lggr,
lggr: logger.Sugared(lggr),
onRamp: onRamp,
commitStore: commitStore,

Expand All @@ -106,7 +106,7 @@ func newChainHealthcheckWithCustomEviction(lggr logger.Logger, onRamp ccipdata.O
globalStatusExpiration: globalStatusDuration,
rmnStatusRefreshInterval: rmnStatusRefreshInterval,

lggr: lggr,
lggr: logger.Sugared(lggr),
onRamp: onRamp,
commitStore: commitStore,

Expand All @@ -129,7 +129,7 @@ func (c *chainHealthcheck) IsHealthy(ctx context.Context) (bool, error) {
// If cached value is properly casted to bool and not healthy it means the sticky flag is raised
// and should be returned immediately
if !ok {
c.lggr.Criticalw("Failed to cast cached value to sticky healthcheck", "value", cachedValue)
logger.Sugared(c.lggr).Criticalw("Failed to cast cached value to sticky healthcheck", "value", cachedValue)
} else if ok && !healthy {
return false, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/patrickmn/go-cache"
orderedmap "github.com/wk8/go-ordered-map/v2"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/ccip/internal/ccipcalc/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"
"sort"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
)

// ContiguousReqs checks if seqNrs contains all numbers from min to max.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"

type_and_version "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/type_and_version_interface_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/logger"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package ccipdataprovider
import (
"context"

"github.com/smartcontractkit/chainlink/v2/core/logger"

cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/logger"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/factory"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/observability"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/pkg/errors"

cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ClosePriceRegistryReader(ctx context.Context, lggr logger.Logger, versionFi
return err
}

func initOrClosePriceRegistryReader(ctx context.Context, lggr logger.Logger, versionFinder VersionFinder, priceRegistryAddress cciptypes.Address, lp logpoller.LogPoller, cl client.Client, closeReader bool) (ccipdata.PriceRegistryReader, error) {
func initOrClosePriceRegistryReader(_ context.Context, lggr logger.Logger, versionFinder VersionFinder, priceRegistryAddress cciptypes.Address, lp logpoller.LogPoller, cl client.Client, closeReader bool) (ccipdata.PriceRegistryReader, error) {
registerFilters := !closeReader

priceRegistryEvmAddr, err := ccipcalc.GenericAddrToEvm(priceRegistryAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

"github.com/ethereum/go-ethereum/core/types"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

const (
Expand Down
Loading

0 comments on commit 8f006d3

Please sign in to comment.