Repository navigation
core/services/ocr3_1/plugins/queue: ReportingPlugin implementation - #24102
Conversation
|
✅ No conflicts with other open PRs targeting |
|
I see you updated files related to
|
|
7ff9593 to
01b7262
Compare
01b7262 to
8e88824
Compare
| const roundDur = 10 * time.Second //TODO dynamic calibration? | ||
| expSeqNr := seqNr + uint64(expirationGraceDur/roundDur) //TODO pad extra time and/or rounds |
There was a problem hiding this comment.
@cedric-cordenier Is there precedent for how to calculate safe expiration sequence numbers?
CORA - Analysis SkippedReason: The number of code owners (4) is less than the minimum required (5) and/or the number of CODEOWNERS entries with changed files (7) is less than the minimum required (2). |
f10fd41 to
2f2592e
Compare
bolekk
left a comment
There was a problem hiding this comment.
First pass, covered queue/queue.go but not kvstate yet.
| wrapped ocr3_1types.ReportingPluginFactory2[RI], | ||
| lggr logger.Logger, | ||
| plugin string, | ||
| meter metric.Meter, |
There was a problem hiding this comment.
nit: Meter updates could've been done in a separate PR, same for common bump.
| return events, nil | ||
| } | ||
|
|
||
| // observationSize returns the encoded size of an observation that grows as events are appended, without sizing every |
There was a problem hiding this comment.
nit: do we need to be super precise here? We could measure the size of each event and then add some fixed overhead to always end up below the limit.
There was a problem hiding this comment.
Can you elaborate? I'm not sure a fixed overhead is viable, but maybe if we use a placeholder for worst case wfCapacity map?
|
|
||
| if _, ok := obs.WorkflowCapacities[event.WorkflowID]; !ok { | ||
| newWF = true | ||
| obs.WorkflowCapacities[event.WorkflowID] = clampUint32(wfCapacities[event.WorkflowID]) |
There was a problem hiding this comment.
nit: This feels a bit wasteful - most of the time there will be no other execution in flight and we the capacity will be max. Maybe there's a way to optimize it?
There was a problem hiding this comment.
It might be possible to get clever about only observing things that will have capacity, based on what is already in the KV state, but that sounds very delicate since we expect reordering and want to maintain throughput.
| } | ||
| obs.BlobHandles = nil // remove placeholders | ||
|
|
||
| fit, err := c.broadcastObservationBlobs(ctx, obs, blobBroadcaster, events, seqNr) |
There was a problem hiding this comment.
This might be my lack of knowledge on OCR3.1 but could this take a very long time and stall the plugin? Claude agrees with this concern and suggest a separate lower timeout here.
There was a problem hiding this comment.
Yes, one optimization is to broadcast in the background so that we can observe things already broadcast without delay, which avoids this problem. That might actually work nicely with the inline events optimization in #24261. Some background process would monitor the set of events eligible for the next round, and if they became too large to inline, then it would broadcast them as a blob.
| }) | ||
| eg.Go(func() error { | ||
| if err := state.loadFrom(kvReaderWriter); err != nil { | ||
| return fmt.Errorf("failed to read state: %w", err) |
There was a problem hiding this comment.
This will likely happen on all nodes at once. Is there a way to recover?
There was a problem hiding this comment.
Why is it likely happen everywhere? And how can we classify that programmatically? @russell-stern gave me the opposite intuition, that we should short-circuit/fail-fast in most situations.
We have the FeatureConsensusQueueKVDrainActivePeriod recovery mechanism, but failing this hard would undermine even that.
There was a problem hiding this comment.
If it's an error with loading from the KV store it will most likely be on a single node so we should fail fast. If it's an issue with malformed data in the KV store it will fail everywhere and I don't think you can recover from that with FeatureConsensusQueueKVDrainActivePeriod. In the vault we have a mechanism that tracks whether a round fails and after a certain number of failures it will purge the KV store automatically: https://github.com/smartcontractkit/chainlink/blob/develop/core/services/ocr2/plugins/vault/plugin.go#L428. Might be worth adding that as a follow up
The consensus-queue defaults from #24260 left every blob limit at zero. The reporting plugin in #24102 broadcasts trigger events as blobs and rejects a config whose blob quotas cannot hold a full observation, so DONs deployed with the defaults would fail to start the plugin once #24102 lands. Take #24102's limits as the defaults: 512 KiB observations, 4 modified keys, 10 MiB of keys plus values, 5 MiB blobs, 100 unexpired blobs and 100 MiB of unexpired blob payload per oracle. Refs: CRE-6011
| func medianTimestamp(s []*timestamppb.Timestamp) *timestamppb.Timestamp { | ||
| switch len(s) { | ||
| case 0: | ||
| panic("median: len must be greater than 0") |
There was a problem hiding this comment.
is this safe? wouldn't returning an error instead be better?
There was a problem hiding this comment.
All else being equal, an error would be better, but it creates a bit of a mess in this case. However, we already must only perform median on slices >= 2F+1, so we can be confident in that invariant and avoid all the boilerplate.
MStreet3
left a comment
There was a problem hiding this comment.
lgtm, the plugin will not be executing any workflows once this is merged as it is feature flagged.
https://smartcontract-it.atlassian.net/browse/CRE-6002
Requires:
Optional Inline Events:
sequenceDiagram participant trigger@{ "type" : "boundary" } as Trigger participant local@{ "type" : "queue" } as Local<br>queue actor Observation as Observation() actor StateTransition as StateTransition() box KV state participant observed@{ "type" : "collections" } as Observed<br>events participant queued@{ "type" : "queue" } as Queued<br>events participant consensus@{ "type" : "collections" } as Consensus<br>events end box Blob store participant blobs@{ "type" : "database" } as Event<br>blobs end actor Committed as Committed() participant coord@{ "type" : "entity" } as Trigger<br>coordinator alt trigger->>local: Cron else trigger->>local: HTTP else trigger->>local: Log end rect Note over Observation: Observation(), on every node par TryStartExecute (idempotent) consensus->>Observation: Read() and queued->>Observation: Read() and blobs->>Observation: FetchBlob() end Observation->>coord: StartExecution() Observation->>local: Remove(consensus + queued) alt KV drain mode (this node's setting) Observation->>local: Sorted() + Remove(): discard, not observed Note over Observation: no events, no blobs, kvDrainActive else local->>Observation: Sorted(): by deadline, skipping events already voted for Observation->>blobs: BroadcastBlob(): up to 10, concurrently end Note over Observation: events, blob handles, capacities,<br>expiration, kvDrainActive end rect Note over StateTransition: StateTransition(), from 2F+1 observations: the same on every node Observation-->>StateTransition: ValidateObservation(), then the observations par Note over StateTransition: aggregate: median expiration,<br>F+1th lowest capacities, F+1 drain votes and observed->>StateTransition: Read() queued->>StateTransition: Read() end Note over StateTransition: drop expired votes alt more than F nodes report KV drain Note over StateTransition: nothing new is added StateTransition->>consensus: Write(): every queued event, whatever the capacity else alt >=2F+1 votes for an event StateTransition->>queued: Write(): by deadline, then hash else >=F+1 votes StateTransition->>observed: Write(): the vote and its blob end StateTransition->>consensus: Write(): capacity limited batch (overall and per workflow) end Note over StateTransition: expired events are dropped,<br>then pruned to fit the KV limits end rect Note over Committed: Committed(), on every node par TryStartExecute (idempotent) consensus->>Committed: Read() and blobs->>Committed: FetchBlob(): the first voter's blob that works end Committed->>coord: StartExecution(), without waiting for the execution Committed->>local: Remove(consensus + queued) end