Skip to content

Buyer-channel robustness follow-ups: orphan-deposit reconciliation + concurrent-open / multi-row reclaim e2e coverage #763

Closed

Description

@thiras

Follow-ups deferred from #753 (buyer-side PaymentChannel openChannel, #744). Both are gated on the not-yet-wired cache-miss hook that calls BuyerChannelService::open_or_reuse_channel (provider-discovery — ADR 001/022), so they're tracked here rather than padding #753. Surfaced by the multi-agent review on #753.

1. Bootstrap chain-log reconciliation for orphaned deposits

Gap. Once openChannel mines, the deposit is escrowed on-chain. If the subsequent ChannelOpened-event decode or the local store.record fails (crates/node/src/buyer_channel.rs, open_and_persist), the channel is tracked only on-chain. The reclaim sweep iterates load_all, so it never sees an unpersisted channel, and there is no chain-log recovery — the deposit is stranded until manual intervention.

Mitigation already shipped in #753 (c0073ea): both post-escrow failure paths now error! with the tx hash so an operator can reconcile/reclaim manually, and a skipped-undecodable buyer record (buyer_load_all) logs at error!.

This issue — automate it. Add a bootstrap reconciliation scan that enumerates on-chain channels where client == self_address (the seller side already demonstrates the ChannelOpened_filter pattern in crates/node/src/payment_settlement.rs) and re-hydrates / reclaims orphaned or undecodable-locally channels. This also rescues buyer rows that became postcard-undecodable after a downgrade (whose channel_id is otherwise unknowable — it lives inside the undecodable bytes).

2. Anvil e2e coverage for the concurrency + corruption paths

crates/node/tests/anvil_settlement_e2e.rs (feature anvil-e2e) currently drives only sequential, single-row scenarios. Two paths added in #753 have no end-to-end coverage:

  • Concurrent opens for the same provider. The opens_in_flight guard / InFlightOpenGuard::claim (crates/node/src/buyer_channel.rs) serializes opens so two racing callers don't each escrow a deposit (the second record would orphan the first). Add a case that fires two concurrent open_or_reuse_channel(provider, …) and asserts exactly one ChannelOpened + one bail-for-retry, then a reuse on retry. This also covers the post-claim TOCTOU re-check.
  • Mixed corrupt/healthy multi-row reclaim sweep. buyer_load_all skip-and-warn is unit-tested at the store layer, but reclaim_once iterating a store seeded with one corrupt + one healthy expired row — proving the corrupt sibling doesn't block reclaim of the healthy one (the actual production manifestation of the feat(node): buyer-side PaymentChannel openChannel for cache-miss settlement (#744) #753 item-1 bug) — is untested. Add an e2e (or a reclaim_once test with a mock provider) covering it.
  • Expired-channel rotation via open_or_reuse_channel. The reclaim-before-reopen + "not yet reclaimable" bail path is currently only reached via sweep_expired_once directly, not through open_or_reuse_channel. Add a case that expires a channel and re-calls open_or_reuse_channel.

Refs

Activity

  1. added
    status:blocked
    rust
    kind:test
    on Jun 1, 2026
  2. added a commit that references this issue on Jun 1, 2026
  3. github-actions commented on Jun 1, 2026

    @github-actions

    🎯 Triage report

    Two well-scoped follow-up tasks deferred from #753 (buyer-side openChannel): (1) automated bootstrap reconciliation to recover orphaned on-chain deposits that weren't persisted locally, and (2) Anvil e2e coverage for three paths that only have unit-test or no coverage — concurrent opens, mixed-corrupt reclaim sweep, and expired-channel rotation via open_or_reuse_channel. A manual mitigation (error-logged tx hash) is already in place for the deposit-stranding scenario. Both tasks are currently blocked on provider-discovery wiring (ADR 001/022).

    📊 Assessment

    Dimension Value Reasoning
    Type Task Clearly scoped follow-up work items, not a bug report or feature request
    Labels medium added; existing technical, blocked, rust, testing retained Medium priority: real funds-at-risk gap but a manual mitigation is already shipped; blocked label is correct — gated on cache-miss hook / provider-discovery
    Coding agent Needs more info Both tasks are concrete and well-specified, but they're gated on open_or_reuse_channel being wired to the cache-miss hook (provider-discovery — ADR 001/022). An agent could implement the reconciliation scan and the three e2e test cases independently, but the e2e tests for concurrent opens and expired rotation won't have a realistic call path until the hook is live. The orphan-reconciliation scan in BuyerChannelService::run (using the existing ChannelOpened_filter pattern from payment_settlement.rs) could be implemented immediately.

    🔗 Similar issues

    💡 Notes and suggestions

    Task 1 — Bootstrap chain-log reconciliation

    Approach: mirror payment_settlement.rs's ChannelOpened_filter on startup, filtered to client == self_address. Walk each on-chain channel:

    • If locally present and decodable → skip (already healthy).
    • If locally absent or postcard-undecodable → re-hydrate from chain state and call store.record; if the channel is past its expiry window, go straight to reclaimChannel.

    Key reference: open_and_persist in crates/node/src/buyer_channel.rs (the two error! sites added in c0073ea are the exact gap this fills).

    Unblock dependency: None — this can be implemented now. It only needs the RPC provider and the existing PaymentChannel contract bindings.

    Task 2 — Anvil e2e coverage

    Three test cases to add in crates/node/tests/anvil_settlement_e2e.rs (feature anvil-e2e):

    • Concurrent opens: spawn two open_or_reuse_channel(same_provider, ...) tasks concurrently; assert exactly one ChannelOpened event mined and one task bails for retry; on retry the second task reuses.
    • Mixed corrupt/healthy reclaim: seed the store with one corrupt row + one healthy expired row; call reclaim_once; assert the healthy channel is reclaimed and the corrupt row is skipped without blocking.
    • Expired-channel rotation via open_or_reuse_channel: expire a channel; call open_or_reuse_channel; assert it triggers reclaim-before-reopen (or the "not yet reclaimable" bail if the dispute window hasn't closed).

    Unblock dependency: Cases 1 and 2 can be written against the store/service directly without the cache-miss hook. Case 3 (rotation path) is also reachable by calling open_or_reuse_channel directly in the test — no hook wiring required.

    Suggested work order

    1. Bootstrap reconciliation (unblocked, fund-safety impact)
    2. Mixed corrupt/healthy reclaim e2e (unblocked, directly tests the feat(node): buyer-side PaymentChannel openChannel for cache-miss settlement (#744) #753 production bug)
    3. Concurrent open e2e (unblocked)
    4. Expired-channel rotation e2e (unblocked)

    Generated by Agentic Triage for issue #763 · sonnet46 639.6K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. self-assigned this
    on Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:testprio:mediumruststatus:blocked

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions