Skip to content

feat(incentive): label channel-open failures by reason (insufficient_deposit/contract_revert/rpc_error) (#966) - #984

Merged
thiras merged 2 commits into
mainfrom
feat/966-channel-open-failure-metrics
Jun 25, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/966-channel-open-failure-metrics

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #966.

Summary

The buyer-side openChannel path (PR #753) could fail from (a) insufficient deposited USDC, (b) an on-chain revert, or (c) a transient RPC error, but all surfaced as one error log line and one unlabeled counter — operators could not tell a misconfiguration from an infrastructure problem.

This splits them into distinct metric counter labels and a structured-log reason field.

Classification approach

The class is decided at the error's source — the open_channel kernel (decdn-client-pull), where the raw alloy error still carries revert data — and propagated up the anyhow chain as typed context so the metrics layer recovers it via downcast_ref (it survives the callers' .context(...) wrapping):

  • A send() error with ABI revert data is decoded against the insufficient-deposit error selectors (DepositBelowMinimum, OpenZeppelin ERC20InsufficientBalance / ERC20InsufficientAllowance) → insufficient_deposit. These deterministic reverts are caught at gas estimation, so they surface on send() before a receipt.
  • A send() error with other revert data → contract_revert.
  • A send()/get_receipt() error with no revert data → rpc_error (transport/RPC fault).
  • A mined revert (!receipt.status(), reason not recoverable from the receipt) → contract_revert.

Changes

  • incentive: new ChannelOpenFailureReason taxonomy + pure classify_revert_data (channel_open_error.rs), unit-tested per class.
  • client-pull: open_channel attaches the reason as typed anyhow context on every failure leg.
  • node/metrics: three sibling counters decdn_channel_open_failures_{insufficient_deposit,contract_revert,rpc_error}_total (iroh_metrics has no label support, so the {reason=…} split is realized as siblings, mirroring dht_rate_limit_rejected_*) + a channel_open_failure_by_reason helper. The existing unlabeled node_pull_channel_open_failures total is unchanged.
  • node/node_origin: extracts the reason, bumps the matching counter, and emits a structured reason field on the failure log.

Verification

  • cargo build + cargo clippy -p decdn-incentive -p decdn-client-pull -p decdn-node --all-targets -- -D warnings: clean.
  • cargo fmt -- --check: clean.
  • cargo nextest run -p decdn-incentive -p decdn-client-pull: 197 + pass.
  • cargo nextest run -p decdn-node: 654 passed.
  • New tests: per-class classification (incl. truncated/unknown selectors), label distinctness on the three counters, and reason-survives-.context().

🤖 Generated with Claude Code

…deposit/contract_revert/rpc_error) (#966)

The buyer-side `openChannel` path could fail from insufficient deposited
USDC, an on-chain revert, or a transient RPC error, but all surfaced as a
single error log line and one unlabeled counter — operators could not tell
a misconfiguration from an infrastructure problem.

Classify the failure at its source (the `open_channel` kernel, where the
raw alloy error still carries revert data) and propagate the class through
the `anyhow` chain:

- New `ChannelOpenFailureReason` taxonomy + a pure `classify_revert_data`
  in `decdn-incentive`. A `send()` error with ABI revert data is decoded
  against the insufficient-deposit selectors (`DepositBelowMinimum`,
  OZ `ERC20InsufficientBalance`/`ERC20InsufficientAllowance`) → labeled
  `insufficient_deposit`; any other revert → `contract_revert`; a send/
  receipt error with no revert data → `rpc_error`. A mined revert
  (`!status()`, reason not recoverable from the receipt) → `contract_revert`.
- `open_channel` attaches the reason as typed `anyhow` context on every
  failure leg, recoverable via `downcast_ref`.
- Three sibling counters `decdn_channel_open_failures_{reason}_total`
  (iroh_metrics has no label support, mirroring `dht_rate_limit_rejected_*`)
  plus a `channel_open_failure_by_reason` helper.
- `node_origin` extracts the reason, bumps the matching counter, and emits a
  structured `reason` field on the failure log (the unlabeled
  `node_pull_channel_open_failures` total is unchanged).

Unit tests cover each classification, label distinctness, and reason
survival through `.context()` wrapping.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings June 24, 2026 13:47

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a failure-class taxonomy for buyer-side openChannel failures to help operators distinguish between misconfigurations, contract reverts, and transient RPC errors. It defines the ChannelOpenFailureReason enum, implements revert data classification, and exposes three new Prometheus counters to track these failures individually. The error handling in open_channel and node_origin has been updated to attach and record these structured failure reasons. There are no review comments, so no feedback is provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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.

Pull request overview

Adds reason-aware observability for buyer-side openChannel failures so operators can distinguish configuration issues (insufficient deposit) from deterministic contract reverts and transient RPC/transport errors.

Changes:

  • Introduces ChannelOpenFailureReason and revert-data classification helper (with unit tests) in decdn-incentive.
  • Attaches ChannelOpenFailureReason as anyhow context in the decdn-client-pull buyer open_channel kernel.
  • Adds sibling OpenMetrics counters for each failure reason (since iroh_metrics has no labels) and plumbs reason extraction into node-origin logging/metrics.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/node/src/node_origin.rs Adds helper to record channel-open failures with structured reason and bumps per-reason counters; adds a test ensuring reason survives .context() wrapping.
crates/node/src/metrics.rs Adds three per-reason counters + helper method; adds test asserting counters are distinct and exported at zero.
crates/incentive/src/lib.rs Exposes the new channel-open failure taxonomy from the incentive crate’s public API.
crates/incentive/src/channel_open_error.rs New module defining ChannelOpenFailureReason and revert-data classifier + unit tests.
crates/client-pull/src/buyer_channel.rs Attaches ChannelOpenFailureReason to openChannel submit/receipt/mined-revert failure paths via anyhow context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/client-pull/src/buyer_channel.rs Resolved
Comment thread crates/node/src/node_origin.rs Resolved
Comment thread crates/client-pull/src/buyer_channel.rs Resolved
@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.62% (was 83.61%, ▲ +0.01%) — 40002/47840 lines

File Coverage Lines Δ
crates/client-pull/src/buyer_channel.rs 0.00% 0/87 ● 0.00%
crates/incentive/src/channel_open_error.rs 96.05% 73/76 new
crates/node/src/metrics.rs 84.10% 846/1006 ▲ +0.69%
crates/node/src/node_origin.rs 89.12% 475/533 ▼ 0.82%
History
Commit Total Δ vs base
39a9ec6 83.62% ▲ +0.01%
856da47 (HEAD) 83.62% ▲ +0.01%

…reality (#966)

iroh_metrics has no label support, so the channel-open failure metric is
emitted as sibling counters (decdn_channel_open_failures_{reason}_total)
rather than a single labeled series. Update module/function docstrings,
the buyer kernel doc, and a test comment to describe the sibling-counter /
structured-log reason token, soften over-promised classification claims
(mined reverts can still be insufficient-deposit; missing-ChannelOpened
leg carries no reason), and fix the test's context-ordering note.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@thiras
thiras merged commit d0168d6 into main Jun 25, 2026
20 checks passed
@thiras
thiras deleted the feat/966-channel-open-failure-metrics branch June 25, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants