Skip to content

core/services/ocr3_1/plugins/queue: ReportingPlugin implementation - #24102

Merged
jmank88 merged 42 commits into
developfrom
CRE-6002-reporting-plugin-impl
Nov 24, 2026
Merged

jmank88 merged 42 commits into
developfrom
CRE-6002-reporting-plugin-impl

Conversation

@jmank88

@jmank88 jmank88 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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
Loading

@github-actions

Copy link
Copy Markdown
Contributor

✅ No conflicts with other open PRs targeting develop

@github-actions

Copy link
Copy Markdown
Contributor

I see you updated files related to core. Please run make gocs in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

@trunk-io

trunk-io Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

Failed Test Failure Summary Logs
TestHttpTriggerHandler_CheckRateLimit_PerOrgOverride The per-organization rate-limit override test failed because the workflow was still rate-limited, preventing execution from starting. Logs ↗︎

View Full Report ↗︎ ⋅ Docs

@jmank88
jmank88 force-pushed the CRE-6002-reporting-plugin-impl branch from 7ff9593 to 01b7262 Compare October 30, 2026 16:54
@jmank88
jmank88 force-pushed the CRE-6002-reporting-plugin-impl branch from 01b7262 to 8e88824 Compare October 30, 2026 18:55
Comment on lines +128 to +129
const roundDur = 10 * time.Second //TODO dynamic calibration?
expSeqNr := seqNr + uint64(expirationGraceDur/roundDur) //TODO pad extra time and/or rounds

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cedric-cordenier Is there precedent for how to calculate safe expiration sequence numbers?

Base automatically changed from CRE-6002-consensus-queue-wiring to develop November 17, 2026 16:02
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

CORA - Analysis Skipped

Reason: 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).

@jmank88
jmank88 force-pushed the CRE-6002-reporting-plugin-impl branch from f10fd41 to 2f2592e Compare November 23, 2026 21:44
russell-stern
russell-stern previously approved these changes Nov 24, 2026

@bolekk bolekk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass, covered queue/queue.go but not kvstate yet.

wrapped ocr3_1types.ReportingPluginFactory2[RI],
lggr logger.Logger,
plugin string,
meter metric.Meter,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timeout fix here: 8234ced

})
eg.Go(func() error {
if err := state.loadFrom(kvReaderWriter); err != nil {
return fmt.Errorf("failed to read state: %w", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely happen on all nodes at once. Is there a way to recover?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

MStreet3 added a commit that referenced this pull request Nov 24, 2026
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
@jmank88
jmank88 marked this pull request as ready for review November 24, 2026 16:58
@jmank88
jmank88 requested review from a team as code owners November 24, 2026 16:58
func medianTimestamp(s []*timestamppb.Timestamp) *timestamppb.Timestamp {
switch len(s) {
case 0:
panic("median: len must be greater than 0")

@agparadiso agparadiso Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this safe? wouldn't returning an error instead be better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MStreet3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, the plugin will not be executing any workflows once this is merged as it is feature flagged.

@jmank88
jmank88 added this pull request to the merge queue Nov 24, 2026
Merged via the queue into develop with commit a953ad8 Nov 24, 2026
254 of 255 checks passed
@jmank88
jmank88 deleted the CRE-6002-reporting-plugin-impl branch November 24, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants