Skip to content

docs(adr): add ChannelOpened event so wallets can enumerate channels - #427

Merged
alpergundogdu merged 2 commits into
mainfrom
fix/channel-opened-event
May 6, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
fix/channel-opened-event

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #426.

Adds ChannelOpened to ADR 003's events table so off-chain components can enumerate channels by log scan instead of by parsing full tx history.

The gap (from #426)

Today, a channel that has been opened but never had any subsequent on-chain action (no topUp, closeChannel, or disputeChannel) is invisible to log scans. The spec has events for every other state transition — close, dispute, settle, topUp, expire, force-close — but not open.

This breaks:

The only enumeration path today: walk every `openChannel` transaction sent from the client's address via archive RPC, decode calldata, compute channelIds. Heavy, requires full archive RPC, breaks under smart-account abstraction where `tx.origin` is the bundler, not the channel client.

What changes

event ChannelOpened(
    bytes32 indexed channelId,
    address indexed client,
    address indexed provider,
    address token,        // USDC address for PoC; arbitrary ERC-20 in production per ADR 010
    uint256 deposit,
    uint64  expiresAt
);

Three indexed fields — the EVM maximum — covers the natural query patterns:

  • eth_getLogs(topics=[ChannelOpened, *, paddedClient]) → all channels for a client
  • eth_getLogs(topics=[ChannelOpened, *, *, paddedProvider]) → all channels for a provider
  • eth_getLogs(topics=[ChannelOpened, paddedChannelId]) → the specific channel (redundant with getChannel but useful in receipts and migration)

Non-indexed payload (token, deposit, expiresAt) — the token field is USDC for the PoC and an arbitrary governance-approved ERC-20 in production, so the same event signature survives the ADR 010 multi-token migration without a wire-format break.

Three edit sites in ADR 003:

  1. §Function table — openChannel description now mentions "emits ChannelOpened"
  2. §Events table — ChannelOpened added as the chronologically-first row, plus a sentence noting why it has three indexed fields
  3. New paragraph below the events table — explains the off-chain enumeration use case and the failure mode ("channels invisible to log scans") the event closes

Cost

One LOG3 opcode in openChannel. EVM gas: 375 + 8 × 96 (non-indexed bytes) ≈ 1,150 gas. Negligible relative to the SSTORE and safeTransferFrom already in the function (~80k gas).

Refs

  • #426 — the gap analysis
  • #424 — symmetric zero-voucher close (depends on clients being able to find their channels first)
  • ADR 003 §Events — the table this PR extends
  • ADR 010 — multi-token migration; the token field in ChannelOpened carries through

Test plan

  • cargo build clean
  • pre-commit run --files adr/003-payments.md — markdownlint + cargo deny pass
  • Event signature is forward-compatible with ADR 010 multi-token (token field is generic ERC-20 address)
  • Spec review

Note: independent of #422 (watchtower → fraud-detection) and #424 (symmetric zero-voucher close). All three touch ADR 003 in different sections; #422 and #424 will need a small textual rebase against this one but no structural conflict.

🤖 Generated with Claude Code

…426)

A channel that has been opened but never had any subsequent on-chain
action (no closeChannel, no topUp, no dispute) is invisible to log
scans today — there's no ChannelOpened event in the spec. Wallets,
CLI tools, and indexers cannot list a client's or provider's open
channels without parsing the full transaction history of every
candidate address.

Add ChannelOpened with three indexed fields (channelId, client,
provider — the EVM maximum) so:

- Clients enumerate via eth_getLogs(topics=[ChannelOpened, *, paddedClient])
- Providers enumerate via the third topic
- Indexers key on channelId for full history reconstruction

Non-indexed payload carries `token, deposit, expiresAt`. The token
field is USDC for the PoC and an arbitrary governance-approved ERC-20
in production (per ADR 010), so the same event signature carries
through the multi-token migration without a wire-format break.

Cost: one LOG3 per openChannel (~1,150 gas) — negligible relative
to the SSTORE and safeTransferFrom already in the function (~80k gas).

Three sites updated:
- §Function table: openChannel description now mentions the emit
- §Events table: ChannelOpened added as the chronologically-first row
- New paragraph below the events table explaining the off-chain
  enumeration use case the event enables

This unblocks operationally useful CLI tooling on top of the symmetric
zero-voucher close (#424): `decdn channel list` enumerates open
channels via log scan, `decdn channel close <id>` triggers recovery
when a node has failed before any voucher boundary.

Closes #426

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@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 updates the adr/003-payments.md documentation to include the ChannelOpened event, which is emitted by the openChannel function. The event utilizes three indexed fields—channelId, client, and provider—to facilitate efficient off-chain channel enumeration via log filtering. Feedback was provided to refactor the description of this event to remove historical justification and focus strictly on the current design's capabilities, ensuring the ADR remains a concise record of the system's architecture.

Comment thread adr/003-payments.md Outdated
| `ChannelForceClosedByTokenRemoval(channelId, token, caller, …)` | `forceCloseChannel` (production `PaymentChannel` only — see [ADR 010](010-multi-token.md)) | `disputeDeadline` |
| `RateBoundsUpdated` | `setRateBounds` | `newDeliveryFloor, newDeliveryCeiling` |

`ChannelOpened` is the entry point for off-chain channel enumeration: a client lists their channels via `eth_getLogs(topics=[ChannelOpened, *, paddedClientAddress])`; a provider does the same with their address in the third topic; an indexer keys on `channelId`. Without this event, channels that have been opened but not yet acted on (no `topUp`, `closeChannel`, or `disputeChannel`) are invisible to log scans, forcing wallets to walk the client's entire transaction history to enumerate them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This paragraph contains historical narrative and justification for the change ("Without this event..."). According to the general rules, such context should reside in issue discussions or merge commit messages to maintain a clean record of the current design in the canonical documentation. The ADR should focus on the current design and its capabilities.

Suggested change
`ChannelOpened` is the entry point for off-chain channel enumeration: a client lists their channels via `eth_getLogs(topics=[ChannelOpened, *, paddedClientAddress])`; a provider does the same with their address in the third topic; an indexer keys on `channelId`. Without this event, channels that have been opened but not yet acted on (no `topUp`, `closeChannel`, or `disputeChannel`) are invisible to log scans, forcing wallets to walk the client's entire transaction history to enumerate them.
ChannelOpened is the entry point for off-chain channel enumeration: a client lists their channels via eth_getLogs(topics=[ChannelOpened, *, paddedClientAddress]); a provider does the same with their address in the third topic; an indexer keys on channelId. This ensures channels are discoverable via log scans even if they have not yet had any subsequent on-chain activity (no topUp, closeChannel, or disputeChannel).
References
  1. Avoid including historical narratives, iteration details, or information about dropped features in canonical documentation (e.g., ADRs). Such context should reside in issue discussions or merge commit messages to maintain a clean record of the current design.

Replace "Without this event, ... forcing wallets to walk the client's
entire transaction history" with positive framing of current behavior,
per gemini-code-assist review on #427.
@alpergundogdu
alpergundogdu merged commit 0ebfc0c into main May 6, 2026
8 checks passed
@alpergundogdu
alpergundogdu deleted the fix/channel-opened-event branch May 6, 2026 12:45
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.

ADR 003 gap: no ChannelOpened event — clients cannot enumerate their own channels

1 participant