Skip to content

Commit

Permalink
[CCIP-3072] Info log on missing finalized block (#14179)
Browse files Browse the repository at this point in the history
* [CCIP-3072] Info log on broken chain

* sort imports

---------

Co-authored-by: Lukasz <120112546+lukaszcl@users.noreply.github.com>
  • Loading branch information
bukata-sa and lukaszcl authored Aug 21, 2024
1 parent c098805 commit 633eb41
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-laws-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal log info on missed finalized head instead of returning an error
2 changes: 1 addition & 1 deletion core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
for i, chain := range legacyEVMChains.Slice() {
chainIDs[i] = chain.ID()
}
telemReporter := headreporter.NewTelemetryReporter(telemetryManager, chainIDs...)
telemReporter := headreporter.NewTelemetryReporter(telemetryManager, globalLogger, chainIDs...)
headReporter := headreporter.NewHeadReporterService(opts.DS, globalLogger, promReporter, telemReporter)
srvcs = append(srvcs, headReporter)
for _, chain := range legacyEVMChains.Slice() {
Expand Down
9 changes: 6 additions & 3 deletions core/services/headreporter/telemetry_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ import (
"google.golang.org/protobuf/proto"

evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/synchronization"
"github.com/smartcontractkit/chainlink/v2/core/services/synchronization/telem"
"github.com/smartcontractkit/chainlink/v2/core/services/telemetry"
)

type telemetryReporter struct {
lggr logger.Logger
endpoints map[uint64]commontypes.MonitoringEndpoint
}

func NewTelemetryReporter(monitoringEndpointGen telemetry.MonitoringEndpointGenerator, chainIDs ...*big.Int) HeadReporter {
func NewTelemetryReporter(monitoringEndpointGen telemetry.MonitoringEndpointGenerator, lggr logger.Logger, chainIDs ...*big.Int) HeadReporter {
endpoints := make(map[uint64]commontypes.MonitoringEndpoint)
for _, chainID := range chainIDs {
endpoints[chainID.Uint64()] = monitoringEndpointGen.GenMonitoringEndpoint("EVM", chainID.String(), "", synchronization.HeadReport)
}
return &telemetryReporter{endpoints: endpoints}
return &telemetryReporter{lggr: lggr.Named("TelemetryReporter"), endpoints: endpoints}
}

func (t *telemetryReporter) ReportNewHead(ctx context.Context, head *evmtypes.Head) error {
Expand Down Expand Up @@ -55,7 +57,8 @@ func (t *telemetryReporter) ReportNewHead(ctx context.Context, head *evmtypes.He
}
monitoringEndpoint.SendLog(bytes)
if finalized == nil {
return errors.Errorf("No finalized block was found for chain_id=%d", head.EVMChainID.Int64())
t.lggr.Infow("No finalized block was found", "chainID", head.EVMChainID.Int64(),
"head.number", head.Number, "chainLength", head.ChainLength())
}
return nil
}
Expand Down
9 changes: 5 additions & 4 deletions core/services/headreporter/telemetry_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/headreporter"
"github.com/smartcontractkit/chainlink/v2/core/services/synchronization"
"github.com/smartcontractkit/chainlink/v2/core/services/synchronization/telem"
Expand Down Expand Up @@ -54,7 +55,7 @@ func Test_TelemetryReporter_NewHead(t *testing.T) {
monitoringEndpointGen.
On("GenMonitoringEndpoint", "EVM", "100", "", synchronization.HeadReport).
Return(monitoringEndpoint)
reporter := headreporter.NewTelemetryReporter(monitoringEndpointGen, big.NewInt(100))
reporter := headreporter.NewTelemetryReporter(monitoringEndpointGen, logger.TestLogger(t), big.NewInt(100))

err = reporter.ReportNewHead(testutils.Context(t), &head)
assert.NoError(t, err)
Expand Down Expand Up @@ -84,10 +85,10 @@ func Test_TelemetryReporter_NewHeadMissingFinalized(t *testing.T) {
monitoringEndpointGen.
On("GenMonitoringEndpoint", "EVM", "100", "", synchronization.HeadReport).
Return(monitoringEndpoint)
reporter := headreporter.NewTelemetryReporter(monitoringEndpointGen, big.NewInt(100))
reporter := headreporter.NewTelemetryReporter(monitoringEndpointGen, logger.TestLogger(t), big.NewInt(100))

err = reporter.ReportNewHead(testutils.Context(t), &head)
assert.Errorf(t, err, "No finalized block was found for chain_id=100")
assert.NoError(t, err)
}

func Test_TelemetryReporter_NewHead_MissingEndpoint(t *testing.T) {
Expand All @@ -96,7 +97,7 @@ func Test_TelemetryReporter_NewHead_MissingEndpoint(t *testing.T) {
On("GenMonitoringEndpoint", "EVM", "100", "", synchronization.HeadReport).
Return(nil)

reporter := headreporter.NewTelemetryReporter(monitoringEndpointGen, big.NewInt(100))
reporter := headreporter.NewTelemetryReporter(monitoringEndpointGen, logger.TestLogger(t), big.NewInt(100))

head := evmtypes.Head{Number: 42, EVMChainID: ubig.NewI(100)}

Expand Down

0 comments on commit 633eb41

Please sign in to comment.