diff --git a/llo/dev/v31/precursor.go b/llo/dev/v31/precursor.go index dba7144..f41c781 100644 --- a/llo/dev/v31/precursor.go +++ b/llo/dev/v31/precursor.go @@ -25,9 +25,9 @@ type precursor struct { ChannelDefinitions llotypes.ChannelDefinitions // ChannelState is the encoded c/defs record ChannelDefinitions were decoded // from. Nil encodes ChannelDefinitions instead, which yields the same bytes. - ChannelState []byte - ValidAfterNanoseconds map[llotypes.ChannelID]uint64 - StreamAggregates protocol.StreamAggregates + ChannelState []byte + ValidAfterNanoseconds map[llotypes.ChannelID]uint64 + StreamAggregates protocol.StreamAggregates // ChannelStateSeqNr is the c/seqnr of the channel-definitions record that // ChannelDefinitions came from. It lets Reports tell whether the decoded-opts // cache already matches these definitions without walking every channel. diff --git a/llo/dev/v31/statetransition.go b/llo/dev/v31/statetransition.go index 20b0e95..fcc4874 100644 --- a/llo/dev/v31/statetransition.go +++ b/llo/dev/v31/statetransition.go @@ -116,6 +116,12 @@ func (p *Plugin) StateTransition(ctx context.Context, seqNr uint64, _ ocrtypes.A // The window ends with this round, so a contribution gathered this round // resolves to this round's agreed timestamp. agreedTimestamps := appendAgreedTimestamp(prev.recentAgreedTimestamps, out.ObservationTimestampNanoseconds) + for i := range tally.attributed { + ao := &tally.attributed[i] + if ao.obs.CycleStartSeqNr != 0 { + ao.agreedCycleStartTimestampNanos, _ = agreedTimestampAt(agreedTimestamps, seqNr, ao.obs.CycleStartSeqNr) + } + } // Lifecycle stage & promotion. promotedValidAfter := map[llotypes.ChannelID]uint64(nil) diff --git a/llo/dev/v31/telemetry.go b/llo/dev/v31/telemetry.go index 7ed3349..e542d5a 100644 --- a/llo/dev/v31/telemetry.go +++ b/llo/dev/v31/telemetry.go @@ -153,6 +153,9 @@ const attributedObservationTelemetryQueueSize = 8 type attributedObservation struct { observer commontypes.OracleID obs Observation + // agreedCycleStartTimestampNanos is the agreed timestamp of the round + // obs.CycleStartSeqNr, zero when unknown. Set by StateTransition. + agreedCycleStartTimestampNanos uint64 } type attributedObservationRound struct { @@ -297,6 +300,8 @@ func (t *attributedObservationTelemeter) makeTelemetry(seqNr, agreedTs uint64, a Emitter: uint32(t.emitter), OracleObservationTimestampNanoseconds: ao.obs.ObservationTimestampNanoseconds, AgreedObservationTimestampNanoseconds: agreedTs, + CycleStartSeqNr: ao.obs.CycleStartSeqNr, + AgreedCycleStartTimestampNanoseconds: ao.agreedCycleStartTimestampNanos, } } diff --git a/llo/dev/v31/telemetry_test.go b/llo/dev/v31/telemetry_test.go index a9eb611..1a1e724 100644 --- a/llo/dev/v31/telemetry_test.go +++ b/llo/dev/v31/telemetry_test.go @@ -370,6 +370,7 @@ func Test_AttributedObservationTelemetry_Split(t *testing.T) { obs := Observation{ ObservationTimestampNanoseconds: 1234, + CycleStartSeqNr: 8, RemoveChannelIDs: map[llotypes.ChannelID]struct{}{5: {}, 2: {}}, UpdateChannelDefinitions: llotypes.ChannelDefinitions{1: {ReportFormat: llotypes.ReportFormatJSON, Streams: []llotypes.Stream{{StreamID: 1, Aggregator: llotypes.AggregatorMedian}}}}, StreamValues: protocol.StreamValues{}, @@ -407,9 +408,11 @@ 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, 5678, attributedObservation{observer: 4, obs: obs, agreedCycleStartTimestampNanos: 4321}) require.Len(t, msgs, 1) requireParts(t, msgs) + require.EqualValues(t, 8, msgs[0].CycleStartSeqNr) + require.EqualValues(t, 4321, msgs[0].AgreedCycleStartTimestampNanoseconds) }) t.Run("split under the budget", func(t *testing.T) { @@ -678,3 +681,44 @@ func (c *countingReportCodec) Encode(protocol.Report, llotypes.ChannelDefinition } func (c *countingReportCodec) Verify(llotypes.ChannelDefinition) error { return nil } + +func Test_AttributedObservationTelemetry_CycleStart(t *testing.T) { + ctx := tests.Context(t) + p := testPlugin(t) + tel := attachAOTelemeter(t, p) + kv := newMemKV() + + const sec = uint64(time.Second) + obs := func(i int, ts, cycleStart uint64) ocrtypes.AttributedObservation { + return ao(i, mustEncodeObs(t, Observation{ + ObservationTimestampNanoseconds: ts, + StreamValues: protocol.StreamValues{100: protocol.ToDecimal(decimal.NewFromInt(1))}, + CycleStartSeqNr: cycleStart, + })) + } + + _, err := p.StateTransition(ctx, 1, ocrtypes.AttributedQuery{}, emptyRound(), kv, testBlobs) + require.NoError(t, err) + _, err = p.StateTransition(ctx, 2, ocrtypes.AttributedQuery{}, addChannelRound(t, 2*sec, 1, jsonChannel()), kv, testBlobs) + require.NoError(t, err) + + // Emit as the oracle that emits for seqNr 3. + p.OracleID = commontypes.OracleID(3 % p.N) + _, err = p.StateTransition(ctx, 3, ocrtypes.AttributedQuery{}, []ocrtypes.AttributedObservation{ + obs(0, 3*sec, 2), obs(1, 3*sec, 3), obs(2, 3*sec, 3), obs(3, 3*sec, 3), + }, kv, testBlobs) + require.NoError(t, err) + + r := requireAORound(t, tel, true) + require.Len(t, r.aos, 4) + got := func(i int) (uint64, uint64) { + m := tel.makeTelemetry(r.seqNr, r.agreedObservationTimestampNanos, r.aos[i])[0] + return m.CycleStartSeqNr, m.AgreedCycleStartTimestampNanoseconds + } + seq, ts := got(0) + require.EqualValues(t, 2, seq) + require.EqualValues(t, 2*sec, ts, "agreed timestamp of round 2") + seq, ts = got(1) + require.EqualValues(t, 3, seq) + require.Equal(t, r.agreedObservationTimestampNanos, ts, "the current round resolves to its own timestamp") +} diff --git a/llo/protocol/llo_plugin_telemetry.pb.go b/llo/protocol/llo_plugin_telemetry.pb.go index 48150c7..ef24655 100644 --- a/llo/protocol/llo_plugin_telemetry.pb.go +++ b/llo/protocol/llo_plugin_telemetry.pb.go @@ -350,6 +350,11 @@ type LLOAttributedObservationTelemetry struct { // the oracle and don observation_timestamps OracleObservationTimestampNanoseconds uint64 `protobuf:"varint,7,opt,name=oracle_observation_timestamp_nanoseconds,json=oracleObservationTimestampNanoseconds,proto3" json:"oracle_observation_timestamp_nanoseconds,omitempty"` AgreedObservationTimestampNanoseconds uint64 `protobuf:"varint,8,opt,name=agreed_observation_timestamp_nanoseconds,json=agreedObservationTimestampNanoseconds,proto3" json:"agreed_observation_timestamp_nanoseconds,omitempty"` + // the round the observer's contribution cycle started in and that round's + // agreed timestamp. Zero when the observation carries no blobs, and the + // timestamp is also zero when that round is outside the agreed timestamp window. + CycleStartSeqNr uint64 `protobuf:"varint,13,opt,name=cycle_start_seq_nr,json=cycleStartSeqNr,proto3" json:"cycle_start_seq_nr,omitempty"` + AgreedCycleStartTimestampNanoseconds uint64 `protobuf:"varint,14,opt,name=agreed_cycle_start_timestamp_nanoseconds,json=agreedCycleStartTimestampNanoseconds,proto3" json:"agreed_cycle_start_timestamp_nanoseconds,omitempty"` // stream id => value as observed by this oracle StreamValues map[uint32]*LLOStreamValue `protobuf:"bytes,9,rep,name=stream_values,json=streamValues,proto3" json:"stream_values,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` // observation votes to update channels @@ -440,6 +445,20 @@ func (x *LLOAttributedObservationTelemetry) GetAgreedObservationTimestampNanosec return 0 } +func (x *LLOAttributedObservationTelemetry) GetCycleStartSeqNr() uint64 { + if x != nil { + return x.CycleStartSeqNr + } + return 0 +} + +func (x *LLOAttributedObservationTelemetry) GetAgreedCycleStartTimestampNanoseconds() uint64 { + if x != nil { + return x.AgreedCycleStartTimestampNanoseconds + } + return 0 +} + func (x *LLOAttributedObservationTelemetry) GetStreamValues() map[uint32]*LLOStreamValue { if x != nil { return x.StreamValues @@ -514,7 +533,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\"\xed\a\n" + "!LLOAttributedObservationTelemetry\x12#\n" + "\rconfig_digest\x18\x01 \x01(\fR\fconfigDigest\x12\x15\n" + "\x06seq_nr\x18\x02 \x01(\x04R\x05seqNr\x12\x15\n" + @@ -522,7 +541,9 @@ const file_llo_plugin_telemetry_proto_rawDesc = "" + "\bobserver\x18\x04 \x01(\rR\bobserver\x12\x18\n" + "\aemitter\x18\x05 \x01(\rR\aemitter\x12W\n" + "(oracle_observation_timestamp_nanoseconds\x18\a \x01(\x04R%oracleObservationTimestampNanoseconds\x12W\n" + - "(agreed_observation_timestamp_nanoseconds\x18\b \x01(\x04R%agreedObservationTimestampNanoseconds\x12\\\n" + + "(agreed_observation_timestamp_nanoseconds\x18\b \x01(\x04R%agreedObservationTimestampNanoseconds\x12+\n" + + "\x12cycle_start_seq_nr\x18\r \x01(\x04R\x0fcycleStartSeqNr\x12V\n" + + "(agreed_cycle_start_timestamp_nanoseconds\x18\x0e \x01(\x04R$agreedCycleStartTimestampNanoseconds\x12\\\n" + "\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" + diff --git a/llo/protocol/llo_plugin_telemetry.proto b/llo/protocol/llo_plugin_telemetry.proto index 7473784..ab53f26 100644 --- a/llo/protocol/llo_plugin_telemetry.proto +++ b/llo/protocol/llo_plugin_telemetry.proto @@ -70,6 +70,12 @@ message LLOAttributedObservationTelemetry { uint64 oracle_observation_timestamp_nanoseconds = 7; uint64 agreed_observation_timestamp_nanoseconds = 8; + // the round the observer's contribution cycle started in and that round's + // agreed timestamp. Zero when the observation carries no blobs, and the + // timestamp is also zero when that round is outside the agreed timestamp window. + uint64 cycle_start_seq_nr = 13; + uint64 agreed_cycle_start_timestamp_nanoseconds = 14; + // stream id => value as observed by this oracle map stream_values = 9;