Fix settlement hang#230
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR adds timeout enforcement to batch event-processing loops in the Ark client and adjusts an e2e test to advance the blockchain. Both ChangesBatch timeout enforcement
🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Review: Fix settlement hang
Verdict: APPROVE — clean, correct, minimal fix. Requesting human sign-off below because this is settlement-path code.
What the PR does
Two changes:
-
ark-client/src/batch.rs(lines ~646, ~1392): Wraps the barestream.next().awaitcalls in bothsettle_delegateand the main settle/batch event loops withtimeout_op(self.inner.timeout, stream.next()). Previously, if the server stopped sending events (crash, network partition, bug), the client would hang forever onstream.next().await. Now it fails with a clear timeout error. -
e2e-tests/tests/e2e_assets.rs(line 32): Addsnigiri.mine(1).awaitafteralice.settle()so the commitment transaction actually confirms before the test checks the offchain balance. Without this, the test could hang waiting for confirmation that never comes in regtest.
Analysis
Type safety ✅ — timeout_op returns Result<Option<Result<StreamEvent, ...>>>. The .context(...) + ? unwraps the outer Result, leaving Option<Result<...>> for the existing match arms (Some(Ok(...)), Some(Err(...)), None). No match arm changes needed. Correct.
Both paths covered ✅ — The fix is applied symmetrically to both settle_delegate (delegated settlement, ~line 646) and the main settlement path (~line 1392). These are the only two stream.next().await calls in batch.rs.
Per-iteration timeout is correct ✅ — Each loop iteration gets a fresh timeout. The server sends StreamEvent::Heartbeat events, so legitimate long-running rounds (many participants, slow nonce aggregation) won't spuriously timeout as long as heartbeats arrive within the configured timeout window (typically 30s per the doc examples).
No API/type changes ✅ — No public API surface changes. No cross-repo impact. timeout_op is already used extensively throughout batch.rs for other operations (intent registration, nonce submission, etc.).
e2e test fix ✅ — nigiri.mine(1) is standard practice in this test suite for confirming on-chain transactions in regtest. The existing sleep(2s) alone was insufficient without a mined block.
Other stream.next() sites not in this PR
boltz.rshas 4stream.next().awaitcalls for swap status streams — different concern, out of scope.ark-rest/src/client.rshas 2 calls for HTTP byte stream parsing — different layer.e2e-tests/andark-client-sample/— test/sample code, not production.
None of these need this fix.
No issues found
No protocol correctness concerns, no race conditions, no missing error handling. The fix is straightforward and well-scoped.
🤖 Reviewed by Arkana
Summary by CodeRabbit