Repository navigation
feat(incentive): label channel-open failures by reason (insufficient_deposit/contract_revert/rpc_error) (#966) - #984
Conversation
…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]>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
ChannelOpenFailureReasonand revert-data classification helper (with unit tests) indecdn-incentive. - Attaches
ChannelOpenFailureReasonasanyhowcontext in thedecdn-client-pullbuyeropen_channelkernel. - Adds sibling OpenMetrics counters for each failure reason (since
iroh_metricshas 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.
Coverage reportTotal: 83.62% (was 83.61%, ▲ +0.01%) — 40002/47840 lines
History
|
…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]>
Closes #966.
Summary
The buyer-side
openChannelpath (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
reasonfield.Classification approach
The class is decided at the error's source — the
open_channelkernel (decdn-client-pull), where the raw alloy error still carries revert data — and propagated up theanyhowchain as typed context so the metrics layer recovers it viadowncast_ref(it survives the callers'.context(...)wrapping):send()error with ABI revert data is decoded against the insufficient-deposit error selectors (DepositBelowMinimum, OpenZeppelinERC20InsufficientBalance/ERC20InsufficientAllowance) →insufficient_deposit. These deterministic reverts are caught at gas estimation, so they surface onsend()before a receipt.send()error with other revert data →contract_revert.send()/get_receipt()error with no revert data →rpc_error(transport/RPC fault).!receipt.status(), reason not recoverable from the receipt) →contract_revert.Changes
ChannelOpenFailureReasontaxonomy + pureclassify_revert_data(channel_open_error.rs), unit-tested per class.open_channelattaches the reason as typedanyhowcontext on every failure leg.decdn_channel_open_failures_{insufficient_deposit,contract_revert,rpc_error}_total(iroh_metricshas no label support, so the{reason=…}split is realized as siblings, mirroringdht_rate_limit_rejected_*) + achannel_open_failure_by_reasonhelper. The existing unlabelednode_pull_channel_open_failurestotal is unchanged.reasonfield 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..context().🤖 Generated with Claude Code