Skip to content

Billing: Emit gas MeterRecords for EVM + Solana chain writes - #804

Open
DylanTinianov wants to merge 7 commits into
mainfrom
CRE-6781-gas-meter-records
Open

DylanTinianov wants to merge 7 commits into
mainfrom
CRE-6781-gas-meter-records

Conversation

@DylanTinianov

@DylanTinianov DylanTinianov commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Emits cre:workflow:gas usage MeterRecords for EVM and Solana chain writes (CRE-6781, CRE-6782). Uses the shared chain_capabilities/common/gasmeter package from #813 (merge first; the plugins pin that branch until it lands, then re-bump) on top of chainlink-common #2428 (merged).

What

When the host sets [Metering].MeterRecordsEnabled (CL_METER_RECORDS_ENABLED in the LOOP env; the same gate as durable resource metering, no separate flag), the EVM and Solana plugins build a gasmeter.Meter (ResourceManager on the LOOP's durable emitter) and call Emit once per chain write, at the point where the fee is already resolved for the legacy metering metadata.

Field Value
resource type cre:workflow:gas:<chain_selector>
value fee in wei (EVM) / lamports (Solana), EmitUsageValue, no int64 truncation
ResourceId <workflow_id>:<execution_id>
EventId tx hash (EVM) / tx signature (Solana), identical on every node that observes the write
Identity.Service chain-write
Identity.ResourcePool / ResourcePoolId cre:workflow:gas / the resource type
Don.DonId capability DON id when known
OrgId from request metadata

Behaviour:

  • fail-open: emission never affects the write
  • every emission logs Emitted capability usage meter record (executionID, eventID, resourceType, value, orgID, txHash), a contract for the billing reconciler
  • warns at start-up if the LOOP has no durable emitter configured, since records would then be dropped

…ana (CRE-6781, CRE-6782)

When the host sets [Metering].CapabilityUsageEnabled (CL_CAPABILITY_USAGE_ENABLED
in the LOOP env), the EVM and Solana plugins build a ResourceManager on the
LOOP's durable emitter and emit one METER_ACTION_USAGE record per chain write
at the point where the fee is already resolved for the legacy metering
metadata:

- resource type cre:workflow:gas:<chain_selector>, value in wei / lamports
  (EmitUsageValue, no int64 truncation)
- Utilization.ResourceId "<workflow_id>:<execution_id>", EventId = tx hash
  (EVM) or tx signature (Solana): identical on every node that observes the
  write
- Identity.Service chain-write, DON id = capability DON id when known

Independent of MeterRecordsEnabled. Each emission logs "Emitted capability
usage meter record" (executionID, eventID, resourceType, value, orgID, txHash),
a contract for the billing reconciler, covered by unit tests in both plugins.
Logs a warning at start-up if the LOOP has no durable emitter configured, since
records would then be dropped fail-open.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@DylanTinianov
DylanTinianov requested review from a team as code owners September 29, 2026 17:59
@DylanTinianov DylanTinianov changed the title Billing: Emit gas MeterRecords for EVM + Solana chain writew Billing: Emit gas MeterRecords for EVM + Solana chain writes Sep 29, 2026
@DylanTinianov
DylanTinianov marked this pull request as draft September 29, 2026 18:27
@DylanTinianov
DylanTinianov requested a balanced review from Copilot September 29, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The metering lifecycle, deterministic billing fields, fail-open behavior, and large-value handling are implemented consistently and covered by focused tests.

Review effort: Balanced
Findings: None

What changed in this PR

Adds capability-usage gas metering for EVM and Solana writes while preserving legacy response metadata.

Changes:

  • Wires resource managers from LOOP metering configuration.
  • Emits deterministic gas usage records and reconciliation logs.
  • Adds unit coverage and updates dependencies.
File Description
chain_capabilities/​solana/​main.go Configures and manages Solana usage metering.
chain_capabilities/​solana/​go.sum Updates dependency checksums.
chain_capabilities/​solana/​go.mod Adds direct metering dependencies.
chain_capabilities/​solana/​actions/​write_report.go Emits gas records after fee resolution.
chain_capabilities/​solana/​actions/​gas_usage_test.go Tests Solana record content and logging.
chain_capabilities/​solana/​actions/​actions.go Adds usage-meter configuration to Solana actions.
chain_capabilities/​evm/​main.go Configures and manages EVM usage metering.
chain_capabilities/​evm/​go.sum Updates dependency checksums.
chain_capabilities/​evm/​go.mod Adds direct metering dependencies.
chain_capabilities/​evm/​actions/​write_report.go Emits gas records from resolved transaction fees.
chain_capabilities/​evm/​actions/​gas_usage_test.go Tests EVM record content and logging.
chain_capabilities/​evm/​actions/​actions.go Adds usage-meter configuration to EVM actions.

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

Identity.ResourcePool "cre:workflow:gas" and ResourcePoolID
"cre:workflow:gas:<chain_selector>", derived via
resourcemanager.WithWorkflowUsagePool from the plugin's chain selector,
matching the Billing <-> Decentralized stack contract. Bumps chainlink-common.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@DylanTinianov DylanTinianov self-assigned this Oct 7, 2026
DylanTinianov and others added 2 commits October 7, 2026 11:46
…bilityUsageEnabled

chainlink-common #2428 dropped the separate CapabilityUsageEnabled flag per
review: usage records share the host's [Metering].MeterRecordsEnabled gate
with durable resource metering. The EVM and Solana plugins now build the gas
usage ResourceManager from MeteringConfig when MeterRecordsEnabled is set,
snapshots off.

Bumps chainlink-common to main (29594528, includes #2428) in both modules.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@DylanTinianov
DylanTinianov marked this pull request as ready for review October 7, 2026 15:47
DylanTinianov and others added 2 commits October 7, 2026 12:05
Replaces the duplicated ResourceManager wiring, emit function and tests in the
EVM and Solana plugins with chain_capabilities/common/gasmeter (#813). Each
plugin now builds one gasmeter.Meter from the LOOP metering config and calls
Emit at its fee-resolved point. Pins the common module to the #813 branch
until it merges.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cl-sonarqube-production

Copy link
Copy Markdown

@DylanTinianov
DylanTinianov marked this pull request as draft October 7, 2026 16:42
@DylanTinianov
DylanTinianov marked this pull request as ready for review October 7, 2026 16:44
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