Skip to content
Merged
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
6 changes: 3 additions & 3 deletions llo/dev/v31/precursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions llo/dev/v31/statetransition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions llo/dev/v31/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}

Expand Down
46 changes: 45 additions & 1 deletion llo/dev/v31/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
25 changes: 23 additions & 2 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.

6 changes: 6 additions & 0 deletions llo/protocol/llo_plugin_telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32, LLOStreamValue> stream_values = 9;

Expand Down
Loading