Skip to content
Draft
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 llo/dev/v31/statetransition.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (p *Plugin) StateTransition(ctx context.Context, seqNr uint64, _ ocrtypes.A
p.captureInsufficientHistory(effective, prev.opts, history)
p.freshnessMetrics.record(freshness)
p.captureOutcomeTelemetry(out, seqNr, freshness)
p.captureAttributedObservationTelemetry(out, seqNr, tally.attributed)
p.captureAttributedObservationTelemetry(ctx, out, seqNr, tally.attributed)

// After telemetry, which reports every aggregate.
out.StreamAggregates = out.reportedAggregates(prev.opts)
Expand Down
14 changes: 11 additions & 3 deletions llo/dev/v31/telemetry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package llo

import (
"context"
"fmt"
"slices"
"sync"
Expand All @@ -14,6 +15,7 @@
protocol "github.com/smartcontractkit/chainlink-data-streams/llo/protocol"

"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

Expand Down Expand Up @@ -157,6 +159,7 @@

type attributedObservationRound struct {
seqNr uint64
epoch uint64
agreedObservationTimestampNanos uint64
aos []attributedObservation
}
Expand Down Expand Up @@ -196,12 +199,16 @@

// captureAttributedObservationTelemetry hands the round decoded observations
// to the telemeter.
func (p *Plugin) captureAttributedObservationTelemetry(out precursor, seqNr uint64, aos []attributedObservation) {
func (p *Plugin) captureAttributedObservationTelemetry(ctx context.Context, out precursor, seqNr uint64, aos []attributedObservation) {
if len(aos) == 0 || !p.emitsTelemetry(out.LifeCycleStage) {
return
}
// Telemetry only: the epoch is local to this oracle, so it must never reach
// the replicated state or the precursor.
epoch, _ := ocr3_1types.EpochFromContext(ctx)

Check failure on line 208 in llo/dev/v31/telemetry.go

View workflow job for this annotation

GitHub Actions / ci-lint

undefined: ocr3_1types.EpochFromContext
p.attributedObservationTelemeter.enqueue(attributedObservationRound{
seqNr: seqNr,
epoch: epoch,
agreedObservationTimestampNanos: out.ObservationTimestampNanoseconds,
aos: aos,
})
Expand Down Expand Up @@ -271,7 +278,7 @@
return
case r := <-t.in:
for _, ao := range r.aos {
for _, msg := range t.makeTelemetry(r.seqNr, r.agreedObservationTimestampNanos, ao) {
for _, msg := range t.makeTelemetry(r.seqNr, r.epoch, r.agreedObservationTimestampNanos, ao) {
select {
case t.out <- msg:
default:
Expand All @@ -287,11 +294,12 @@
// most maxBytes. Stream values are packed in ascending stream id order. The
// header is repeated in every part, the votes and decode error are set in the
// first only. A single value larger than maxBytes gets a part of its own.
func (t *attributedObservationTelemeter) makeTelemetry(seqNr, agreedTs uint64, ao attributedObservation) []*protocol.LLOAttributedObservationTelemetry {
func (t *attributedObservationTelemeter) makeTelemetry(seqNr, epoch, agreedTs uint64, ao attributedObservation) []*protocol.LLOAttributedObservationTelemetry {
header := func() *protocol.LLOAttributedObservationTelemetry {
return &protocol.LLOAttributedObservationTelemetry{
ConfigDigest: t.configDigest[:],
SeqNr: seqNr,
Epoch: epoch,
DonId: t.donID,
Observer: uint32(ao.observer),
Emitter: uint32(t.emitter),
Expand Down
19 changes: 12 additions & 7 deletions llo/dev/v31/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
protocol "github.com/smartcontractkit/chainlink-data-streams/llo/protocol"

"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

Expand Down Expand Up @@ -92,7 +93,7 @@
}

func Test_AttributedObservationTelemetry_StateTransition(t *testing.T) {
ctx := tests.Context(t)
ctx := ocr3_1types.ContextWithEpoch(tests.Context(t), 42)

Check failure on line 96 in llo/dev/v31/telemetry_test.go

View workflow job for this annotation

GitHub Actions / ci-lint

undefined: ocr3_1types.ContextWithEpoch
p := testPlugin(t)
p.DonID = 7
tel := attachAOTelemeter(t, p)
Expand Down Expand Up @@ -135,16 +136,18 @@
out := round(2, 1000)
r := requireAORound(t, tel, true)
require.Equal(t, uint64(2), r.seqNr)
require.Equal(t, uint64(42), r.epoch)
require.Equal(t, out.ObservationTimestampNanoseconds, r.agreedObservationTimestampNanos)
require.Len(t, r.aos, 4)

for i, a := range r.aos {
require.Equal(t, commontypes.OracleID(i), a.observer)
msgs := tel.makeTelemetry(r.seqNr, r.agreedObservationTimestampNanos, a)
msgs := tel.makeTelemetry(r.seqNr, r.epoch, r.agreedObservationTimestampNanos, a)
require.Len(t, msgs, 1)
m := msgs[0]
require.Equal(t, p.ConfigDigest[:], m.ConfigDigest)
require.Equal(t, uint64(2), m.SeqNr)
require.Equal(t, uint64(42), m.Epoch)
require.Equal(t, uint32(7), m.DonId)
require.Equal(t, uint32(i), m.Observer)
require.Equal(t, 1000+uint64(i), m.OracleObservationTimestampNanoseconds)
Expand Down Expand Up @@ -172,7 +175,7 @@
r := requireAORound(t, tel, true)
require.Greater(t, out.ObservationTimestampNanoseconds, uint64(500+3), "median must have been held")
require.Equal(t, out.ObservationTimestampNanoseconds, r.agreedObservationTimestampNanos)
m := tel.makeTelemetry(r.seqNr, r.agreedObservationTimestampNanos, r.aos[0])[0]
m := tel.makeTelemetry(r.seqNr, r.epoch, r.agreedObservationTimestampNanos, r.aos[0])[0]
require.Equal(t, uint64(500), m.OracleObservationTimestampNanoseconds)
require.Equal(t, out.ObservationTimestampNanoseconds, m.AgreedObservationTimestampNanoseconds)
})
Expand Down Expand Up @@ -358,7 +361,8 @@
}
want, err := plain.StateTransition(ctx, seqNr, ocrtypes.AttributedQuery{}, aos, plainKV, testBlobs)
require.NoError(t, err)
got, err := withTel.StateTransition(ctx, seqNr, ocrtypes.AttributedQuery{}, aos, telKV, testBlobs)
// The epoch differs between oracles, it must not change the output.
got, err := withTel.StateTransition(ocr3_1types.ContextWithEpoch(ctx, seqNr), seqNr, ocrtypes.AttributedQuery{}, aos, telKV, testBlobs)

Check failure on line 365 in llo/dev/v31/telemetry_test.go

View workflow job for this annotation

GitHub Actions / ci-lint

undefined: ocr3_1types.ContextWithEpoch (typecheck)
require.NoError(t, err)
require.Equal(t, want, got, "seqNr %d", seqNr)
require.Equal(t, plainKV.m, telKV.m, "seqNr %d", seqNr)
Expand All @@ -385,6 +389,7 @@
for i, m := range msgs {
require.Equal(t, []byte(tel.configDigest[:]), m.ConfigDigest)
require.Equal(t, uint64(9), m.SeqNr)
require.Equal(t, uint64(11), m.Epoch)
require.Equal(t, uint32(7), m.DonId)
require.Equal(t, uint32(4), m.Observer)
require.Equal(t, uint32(3), m.Emitter)
Expand All @@ -407,14 +412,14 @@
}

t.Run("fits in one part", func(t *testing.T) {
msgs := tel.makeTelemetry(9, 5678, attributedObservation{observer: 4, obs: obs})
msgs := tel.makeTelemetry(9, 11, 5678, attributedObservation{observer: 4, obs: obs})
require.Len(t, msgs, 1)
requireParts(t, msgs)
})

t.Run("split under the budget", func(t *testing.T) {
tel.maxBytes = 2048
msgs := tel.makeTelemetry(9, 5678, attributedObservation{observer: 4, obs: obs})
msgs := tel.makeTelemetry(9, 11, 5678, attributedObservation{observer: 4, obs: obs})
require.Greater(t, len(msgs), 2)
requireParts(t, msgs)
for _, m := range msgs {
Expand All @@ -437,7 +442,7 @@

t.Run("oversized values get a part each", func(t *testing.T) {
tel.maxBytes = 1
msgs := tel.makeTelemetry(9, 5678, attributedObservation{observer: 4, obs: obs})
msgs := tel.makeTelemetry(9, 11, 5678, attributedObservation{observer: 4, obs: obs})
require.Len(t, msgs, 501, "votes part plus one part per value")
require.Empty(t, msgs[0].StreamValues)
requireParts(t, msgs)
Expand Down
17 changes: 14 additions & 3 deletions llo/protocol/llo_plugin_telemetry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions llo/protocol/llo_plugin_telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@ message LLOAttributedObservationTelemetry {

// observation decode error if any
optional string decode_error = 16;

// OCR epoch in which the emitter ran StateTransition. Local to the emitter:
// oracles may report different epochs for the same seq_nr.
uint64 epoch = 17;
}
Loading