Repository navigation
feat(node): bootstrap reconciliation for orphaned buyer channel deposits (#763) - #903
Conversation
…its (#763) `BuyerChannelService::open_and_persist` escrows a deposit on-chain via `openChannel`, then decodes the `ChannelOpened` event and persists the row. If the decode or `store.record` fails *after* the escrow — or a binary downgrade leaves a row postcard-undecodable — the channel is tracked only on-chain and the reclaim sweep (which iterates `load_all`) never sees it, stranding the deposit. Add a one-shot, best-effort bootstrap reconciliation scan that enumerates `ChannelOpened(client == self)` over a bounded recent block window and re-hydrates any still-`Open` channel missing or undecodable locally, so the existing reclaim sweep recovers the deposit. Mirrors the seller-side backfill, reusing its window helpers (promoted to `pub(crate)`). - `reconcile_orphans_once` / `reconcile_one_opened` / pure `reconcile_decision`, wired into `bootstrap` as a non-blocking `_reconciler` task (matches the non-fatal buyer-bootstrap posture). - Reconciler claims the same per-provider in-flight-open slot the live path uses, so its re-hydration can never clobber a channel a concurrent open just recorded. - Distinguishes an unreadable row (corrupt / future-schema → repair from chain) from a backend/IO fault (skip, don't overwrite a possibly-healthy row). - A single window's `eth_getLogs` failure skips just that window; a deferred second-orphan-per-provider is logged rather than dropped silently. Tests: `reconcile_decision` unit table; anvil-e2e scenarios for concurrent same-provider opens, expired rotation via `open_or_reuse_channel`, orphan re-hydration, and undecodable-row repair + mixed corrupt/healthy reclaim. The buyer e2e path now runs under its own identity so the scan is deterministic. Adds a test-only `insert_raw_buyer_record` store seam. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements a one-shot bootstrap reconciliation scan for the buyer channel service to re-hydrate orphaned on-chain channels (e.g., due to post-escrow failures or database downgrades). It exposes helper functions from payment_settlement to reuse block windowing logic, adds a test-only database helper to simulate corrupt records, and introduces comprehensive unit and end-to-end integration tests to verify concurrent opens, expired-channel rotation, and orphan recovery. There are no review comments, so no additional 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 a buyer-side, one-shot bootstrap reconciliation scan to recover orphaned buyer payment-channel deposits that exist on-chain but are missing/undecodable in the local store, and extends e2e coverage for concurrency/corruption scenarios.
Changes:
- Introduces buyer-channel reconciliation logic (
reconcile_*) and spawns it duringBuyerChannelService::bootstrap. - Promotes seller-side backfill window helpers (
MAX_BACKFILL_BLOCK_SPAN,backfill_windows,check_backfill_range) topub(crate)for reuse. - Extends Anvil e2e tests and adds a test-only store seam to inject corrupt buyer rows.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/node/src/buyer_channel.rs | Adds bootstrap reconciliation task + decision logic and unit tests for orphan repair behavior. |
| crates/node/src/payment_settlement.rs | Exposes backfill window helpers/constants for buyer reconciliation reuse. |
| crates/node/src/channel_store.rs | Adds test/e2e-only insert_raw_buyer_record seam to simulate undecodable buyer rows. |
| crates/node/tests/anvil_settlement_e2e.rs | Adds deterministic buyer identity + new e2e scenarios for concurrent opens, rotation, orphan re-hydration, and corrupt-row reclaim behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 85.74% (was 85.99%, ▼ 0.24%) — 35985/41968 lines
History
|
- anvil-e2e scenario D: chmod the persistent-store tempdir to 0o700 before `PersistentChannelStateStore::open` (a CI umask of 002 leaves it at 0o755, which the data_dir security check rejects). Mirrors the seller-store setup. This is the anvil-e2e CI failure on the prior commit. - reconcile scan: topic-filter the `ChannelOpened` query on the indexed `client` topic (`topic2(self_address)`) so `eth_getLogs` returns only this node's own opens, bounding result-count/latency on busy deployments instead of fetching every open in the window. The in-code `client == self` check stays as defense-in-depth, and the stale "filter is by signature, not topic" comment is corrected. Addresses Copilot review feedback on #903. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…h + all-windows escalation Follow-ups from a second review round on the #763 reconciliation scan (no behavior change to the happy path): - `reconcile_decision` now returns a `ReconcileOutcome` enum (Rehydrate / DeferredSecondOpen / Skip) instead of a bare `Option`, so the caller no longer re-derives the deferred-orphan predicate and each branch is directly unit-testable. Adds a unit test for the DeferredSecondOpen classification. - `reconcile_one_opened` matches every `StoreError` variant explicitly (no catch-all), so a future variant is a compile error forcing a repair-vs-skip decision rather than silently defaulting to skip (which would strand an orphan whose row became unreadable in a new way). - `reconcile_orphans_once` escalates the completion log to `error!` when every window's query failed (RPC outage → scan accomplished nothing), instead of burying it under an `info!` "complete". Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Closes #763. Adds a one-shot, best-effort bootstrap reconciliation scan that recovers buyer payment-channel deposits the node escrowed on-chain but lost track of locally.
BuyerChannelService::open_and_persistescrows a deposit viaopenChannel, then decodes theChannelOpenedevent and persists the row. If the decode orstore.recordfails after the escrow — or a binary downgrade leaves a row postcard-undecodable — the channel is tracked only on-chain, and the reclaim sweep (which iteratesload_all) never sees it, stranding the deposit. The blocker (#763 was gated on the cache-miss hook callingopen_or_reuse_channel) is now resolved (wired in #831).What it does
reconcile_orphans_once/reconcile_one_opened/ purereconcile_decisionincrates/node/src/buyer_channel.rs, wired intobootstrapas a non-blocking_reconcilertask (matches the non-fatal buyer-bootstrap posture). It enumeratesChannelOpened(client == self)over a bounded recent window (BUYER_RECONCILE_LOOKBACK_BLOCKS, ~1–2 days) and re-hydrates any still-Openchannel that is missing or undecodable locally; the existing reclaim sweep then recovers the deposit on expiry.backfill_windows/check_backfill_range/MAX_BACKFILL_BLOCK_SPAN, promoted topub(crate)).Robustness (from multi-agent review)
eth_getLogsfailure skips just that window (failed_windowsreported); a second still-open channel per provider (the documented one-row-per-provider residual) is logged, not dropped silently.Tests
reconcile_decisiontable (orphan re-hydrate, watermark hydration from on-chain claimed totals, skip-healthy-row, skip-non-Open, skip-not-owned).anvil-e2efeature): concurrent same-provider opens, expired rotation viaopen_or_reuse_channel, orphan re-hydration, undecodable-row repair + mixed corrupt/healthy reclaim. The buyer e2e path now runs under its own identity so the scan is deterministic. Adds a test-onlyinsert_raw_buyer_recordstore seam.Verification
cargo clippy -D warnings(with/withoutanvil-e2e),cargo fmt --check, and 779 node+incentive unit tests all pass locally. The full anvil-e2e could not be re-run to completion in the dev sandbox (anvil-spawn limits) after the review fixes; it is left to the CI anvil e2e job to validate scenarios B/C/D end-to-end.Follow-up
A latent, pre-existing concern surfaced while testing: a reverting
reclaimExpiredleaks the alloy provider's cached nonce, which can wedge subsequent buyer transactions (the code expectsreclaimExpiredto "simply revert and be retried" under clock skew). Filed separately; this PR avoids triggering it.🤖 Generated with Claude Code