From ba6533ff1aa6a24479d4036e881a9c374c0f7946 Mon Sep 17 00:00:00 2001 From: David Przybilla Date: Wed, 11 Nov 2026 14:06:23 +0900 Subject: [PATCH] llo attribute observation: add epoch field --- llo/dev/v31/statetransition.go | 2 +- llo/dev/v31/telemetry.go | 14 +++++++++++--- llo/dev/v31/telemetry_test.go | 19 ++++++++++++------- llo/protocol/llo_plugin_telemetry.pb.go | 17 ++++++++++++++--- llo/protocol/llo_plugin_telemetry.proto | 4 ++++ 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/llo/dev/v31/statetransition.go b/llo/dev/v31/statetransition.go index 20b0e95..9c85525 100644 --- a/llo/dev/v31/statetransition.go +++ b/llo/dev/v31/statetransition.go @@ -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) diff --git a/llo/dev/v31/telemetry.go b/llo/dev/v31/telemetry.go index 7ed3349..89cfd6d 100644 --- a/llo/dev/v31/telemetry.go +++ b/llo/dev/v31/telemetry.go @@ -1,6 +1,7 @@ package llo import ( + "context" "fmt" "slices" "sync" @@ -14,6 +15,7 @@ import ( 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" ) @@ -157,6 +159,7 @@ type attributedObservation struct { type attributedObservationRound struct { seqNr uint64 + epoch uint64 agreedObservationTimestampNanos uint64 aos []attributedObservation } @@ -196,12 +199,16 @@ func (p *Plugin) emitsTelemetry(stage llotypes.LifeCycleStage) bool { // 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) p.attributedObservationTelemeter.enqueue(attributedObservationRound{ seqNr: seqNr, + epoch: epoch, agreedObservationTimestampNanos: out.ObservationTimestampNanoseconds, aos: aos, }) @@ -271,7 +278,7 @@ func (t *attributedObservationTelemeter) run() { 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: @@ -287,11 +294,12 @@ func (t *attributedObservationTelemeter) run() { // 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), diff --git a/llo/dev/v31/telemetry_test.go b/llo/dev/v31/telemetry_test.go index a9eb611..ed8275c 100644 --- a/llo/dev/v31/telemetry_test.go +++ b/llo/dev/v31/telemetry_test.go @@ -20,6 +20,7 @@ import ( 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" ) @@ -92,7 +93,7 @@ func Test_makeReportTelemetry_EffectiveStreams(t *testing.T) { } func Test_AttributedObservationTelemetry_StateTransition(t *testing.T) { - ctx := tests.Context(t) + ctx := ocr3_1types.ContextWithEpoch(tests.Context(t), 42) p := testPlugin(t) p.DonID = 7 tel := attachAOTelemeter(t, p) @@ -135,16 +136,18 @@ func Test_AttributedObservationTelemetry_StateTransition(t *testing.T) { 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) @@ -172,7 +175,7 @@ func Test_AttributedObservationTelemetry_StateTransition(t *testing.T) { 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) }) @@ -358,7 +361,8 @@ func Test_AttributedObservationTelemetry_Deterministic(t *testing.T) { } 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) require.NoError(t, err) require.Equal(t, want, got, "seqNr %d", seqNr) require.Equal(t, plainKV.m, telKV.m, "seqNr %d", seqNr) @@ -385,6 +389,7 @@ func Test_AttributedObservationTelemetry_Split(t *testing.T) { 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) @@ -407,14 +412,14 @@ func Test_AttributedObservationTelemetry_Split(t *testing.T) { } 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 { @@ -437,7 +442,7 @@ func Test_AttributedObservationTelemetry_Split(t *testing.T) { 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) diff --git a/llo/protocol/llo_plugin_telemetry.pb.go b/llo/protocol/llo_plugin_telemetry.pb.go index 48150c7..13990ee 100644 --- a/llo/protocol/llo_plugin_telemetry.pb.go +++ b/llo/protocol/llo_plugin_telemetry.pb.go @@ -356,7 +356,10 @@ type LLOAttributedObservationTelemetry struct { RemoveChannelIds []uint32 `protobuf:"varint,11,rep,packed,name=remove_channel_ids,json=removeChannelIds,proto3" json:"remove_channel_ids,omitempty"` UpdateChannelDefinitions map[uint32]*LLOChannelDefinitionProto `protobuf:"bytes,12,rep,name=update_channel_definitions,json=updateChannelDefinitions,proto3" json:"update_channel_definitions,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` // observation decode error if any - DecodeError *string `protobuf:"bytes,16,opt,name=decode_error,json=decodeError,proto3,oneof" json:"decode_error,omitempty"` + DecodeError *string `protobuf:"bytes,16,opt,name=decode_error,json=decodeError,proto3,oneof" json:"decode_error,omitempty"` + // OCR epoch in which the emitter ran StateTransition. Local to the emitter: + // oracles may report different epochs for the same seq_nr. + Epoch uint64 `protobuf:"varint,17,opt,name=epoch,proto3" json:"epoch,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -468,6 +471,13 @@ func (x *LLOAttributedObservationTelemetry) GetDecodeError() string { return "" } +func (x *LLOAttributedObservationTelemetry) GetEpoch() uint64 { + if x != nil { + return x.Epoch + } + return 0 +} + var File_llo_plugin_telemetry_proto protoreflect.FileDescriptor const file_llo_plugin_telemetry_proto_rawDesc = "" + @@ -514,7 +524,7 @@ const file_llo_plugin_telemetry_proto_rawDesc = "" + "\x06seq_nr\x18\t \x01(\x04R\x05seqNr\x12#\n" + "\rconfig_digest\x18\n" + " \x01(\fR\fconfigDigest\x12\x15\n" + - "\x06don_id\x18\v \x01(\rR\x05donId\"\xe8\x06\n" + + "\x06don_id\x18\v \x01(\rR\x05donId\"\xfe\x06\n" + "!LLOAttributedObservationTelemetry\x12#\n" + "\rconfig_digest\x18\x01 \x01(\fR\fconfigDigest\x12\x15\n" + "\x06seq_nr\x18\x02 \x01(\x04R\x05seqNr\x12\x15\n" + @@ -526,7 +536,8 @@ const file_llo_plugin_telemetry_proto_rawDesc = "" + "\rstream_values\x18\t \x03(\v27.v1.LLOAttributedObservationTelemetry.StreamValuesEntryR\fstreamValues\x12,\n" + "\x12remove_channel_ids\x18\v \x03(\rR\x10removeChannelIds\x12\x81\x01\n" + "\x1aupdate_channel_definitions\x18\f \x03(\v2C.v1.LLOAttributedObservationTelemetry.UpdateChannelDefinitionsEntryR\x18updateChannelDefinitions\x12&\n" + - "\fdecode_error\x18\x10 \x01(\tH\x00R\vdecodeError\x88\x01\x01\x1aS\n" + + "\fdecode_error\x18\x10 \x01(\tH\x00R\vdecodeError\x88\x01\x01\x12\x14\n" + + "\x05epoch\x18\x11 \x01(\x04R\x05epoch\x1aS\n" + "\x11StreamValuesEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\rR\x03key\x12(\n" + "\x05value\x18\x02 \x01(\v2\x12.v1.LLOStreamValueR\x05value:\x028\x01\x1aj\n" + diff --git a/llo/protocol/llo_plugin_telemetry.proto b/llo/protocol/llo_plugin_telemetry.proto index 7473784..3606ee0 100644 --- a/llo/protocol/llo_plugin_telemetry.proto +++ b/llo/protocol/llo_plugin_telemetry.proto @@ -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; }