Skip to content

Billing: Emit resource manager values - #2428

Draft
DylanTinianov wants to merge 1 commit into
mainfrom
CRE-6781-emit-usage-value
Draft

DylanTinianov wants to merge 1 commit into
mainfrom
CRE-6781-emit-usage-value

Conversation

@DylanTinianov

@DylanTinianov DylanTinianov commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Groundwork for capability-centric workflow billing (CRE-6778). No behaviour change for existing producers.

What

  • ResourceManager.EmitUsageValue(ctx, identity, eventID, *big.Int, fields): METER_ACTION_USAGE from an arbitrary-precision value, so chain-write capabilities can report gas fees in wei/lamports without int64 truncation. Same event-id contract and fail-open semantics as EmitUsage.

  • resourcemanager/workflow_usage.go: the producer side of the billing contract, shared by the engine (compute) and the chain-write plugins (gas):

    • record type cre:workflow; resource types cre:workflow:compute (ms) and cre:workflow:gas:<chain_selector> (WorkflowGasResourceType)
    • Utilization.ResourceId = "<workflow_id>:<execution_id>" (WorkflowUsageResourceID, rejects : in either part)
    • emitting service names chain-write / workflow-engine, resource pool workflow_usage

    Matches the consumer in billing-platform-service (#963, ConstructCapabilityUsageEventID: cre:workflow:<wf>:<exec>:<EventId>).

  • loop.EnvConfig.CapabilityUsageEnabled (CL_CAPABILITY_USAGE_ENABLED): carries the new node setting [Metering].CapabilityUsageEnabled to LOOP capability plugins. Independent of MeterRecordsEnabled, which gates durable resource metering.

…L_CAPABILITY_USAGE_ENABLED

Groundwork for capability-centric workflow billing (CRE-6778):

- ResourceManager.EmitUsageValue emits a METER_ACTION_USAGE record from a
  *big.Int so chain-write capabilities can report gas fees in wei without
  truncation.
- resourcemanager/workflow_usage.go pins the producer side of the billing
  contract: record type cre:workflow, resource types cre:workflow:compute and
  cre:workflow:gas:<chain_selector>, ResourceId "<workflow_id>:<execution_id>",
  emitting service names and resource pool. Matches the consumer in
  billing-platform-service (ConstructCapabilityUsageEventID).
- loop.EnvConfig.CapabilityUsageEnabled (CL_CAPABILITY_USAGE_ENABLED) carries
  the new [Metering].CapabilityUsageEnabled node setting to LOOP capability
  plugins, independent of MeterRecordsEnabled.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ API Diff Results - github.com/smartcontractkit/chainlink-common

✅ Compatible Changes (10)

pkg/loop.EnvConfig (1)
  • CapabilityUsageEnabled — ➕ Added
pkg/resourcemanager (8)
  • EmittingServiceChainWrite — ➕ Added

  • EmittingServiceWorkflowEngine — ➕ Added

  • ResourceTypeWorkflowCompute — ➕ Added

  • ResourceTypeWorkflowGasPrefix — ➕ Added

  • WorkflowGasResourceType — ➕ Added

  • WorkflowRecordType — ➕ Added

  • WorkflowUsageResourceID — ➕ Added

  • WorkflowUsageResourcePool — ➕ Added

pkg/resourcemanager.(*ResourceManager) (1)
  • EmitUsageValue — ➕ Added

📄 View full apidiff report

@DylanTinianov DylanTinianov changed the title resourcemanager: EmitUsageValue, workflow usage contract, CL_CAPABILITY_USAGE_ENABLED (CRE-6778) Billing: Emit resource manager values Sep 29, 2026
@DylanTinianov
DylanTinianov requested a balanced review from Copilot September 29, 2026 18:40

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Capability usage remains blocked by MeterRecordsEnabled, contradicting the new setting’s documented independence.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Adds workflow capability billing primitives and propagates capability usage configuration to LOOP plugins.

Changes:

  • Adds arbitrary-precision usage emission.
  • Defines workflow compute/gas billing identifiers.
  • Adds CL_CAPABILITY_USAGE_ENABLED configuration transport.
File Description
pkg/​resourcemanager/​workflow_usage.go Defines workflow billing identifiers and helpers.
pkg/​resourcemanager/​workflow_usage_test.go Tests workflow billing helpers.
pkg/​resourcemanager/​resourcemanager.go Adds arbitrary-precision usage emission.
pkg/​resourcemanager/​resourcemanager_test.go Tests large and nil usage values.
pkg/​loop/​config.go Adds capability usage configuration.
pkg/​loop/​config_test.go Tests configuration parsing and propagation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/loop/config.go
Comment on lines +211 to +214
// CapabilityUsageEnabled enables per-capability workflow usage MeterRecords
// (compute, gas) for eventually consistent billing. Independent of
// MeterRecordsEnabled, which gates durable resource metering.
CapabilityUsageEnabled bool

This branch has not been deployed

No deployments
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.

2 participants