Fix SDK acknowledgement before home channel creation#734
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughtransfer and acknowledge now treat states missing ChangesClient transfer & acknowledge flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@sdk/ts/src/client.ts`:
- Around line 667-670: The branch that handles "no open channel" currently
checks if (!state || !state.homeChannelId) before testing whether the state was
already acknowledged, so states with userSig but no homeChannelId fall into
creation/acknowledgement flow and can be double-acknowledged; move the "already
acknowledged" guard (the check for state.userSig / existing acknowledgement) to
run before the branch selection that starts with if (!state ||
!state.homeChannelId) so that any state with a userSig is immediately
rejected/returned as already-acknowledged; apply the same reordering fix to the
other occurrence around the code referenced at lines ~716-718 to ensure both
code paths reject already-acknowledged states instead of attempting channel
creation/ack.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fbf74e98-bee6-4fdb-8f78-988790251510
⛔ Files ignored due to path filters (1)
sdk/ts/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
sdk/ts/package.jsonsdk/ts/src/client.tssdk/ts/test/unit/client.test.ts
There was a problem hiding this comment.
Good fix!
Two things to be aware of beyond the inline comments:
transfer() has the same pre-fix pattern (client.ts:576 still uses if (!state) without a !state.homeChannelId guard). The Go SDK's Transfer() already handles state.HomeChannelID == nil by routing to channel creation. In the TS SDK, a user with received off-chain funds calling transfer() before acknowledge() will reach signAndSubmitState — and the node will reject with "user has no open channel" (submit_state.go:56–58). The existing comment at client.ts:572 saying "homeChannelId is intentionally not checked here" is now misleading given this PR's rationale. Consider either fixing transfer() the same way or updating the comment to document that acknowledge() must be called first.
The fix to the aforementioned issue should probably be done in a separate PR. Let's wait for @philanton to decide together.
|
@ihsraham , after speaking to @philanton , could you please make the same change for |
7526152 to
2052e6a
Compare
|
@nksazonov done in |
- MF-L01: fix(contracts/ChannelHub): cap ERC20 transfer returndata copy to 32 bytes (#726) - MF-H01: fix(nitronode): paginate get_last_key_states endpoints (#724) - MF-I01-I02: fix(contracts): address security audit findings I-01 and I-02 (#728) - MF-C01: rpc: cap inbound WebSocket frame size and rate-limit per connection (#723) - MF-L02: docs(protocol): qualify enforcement guarantee for intent-specific execution paths (#737) - MF-L02-I03-I04_I05: fix(contracts): add more Node trust assumptions and requirements (#738) - MF-M01: backfill state user_sig from on-chain events (#731) - MF-M02: fix(rpc): release Serve wait group on processSink overflow (#732) - Fix SDK acknowledgement before home channel creation (#734) - MF-I06: fix(nitronode): gate escrow transitions on home channel onchain materialization (#730) - MF-M05: fix(nitronode): enforce TLS by default for Postgres (#733) - MF-M07: Unblock receiver states after finalized escrow operations (#735) - MF-M04: feat: provide tooling for and enhance docs on ValidatorRegistered event (#744) - MF-L04: fix(contracts): reject redundant native value (#741) - MF-H02: bind session key registration to a single owner per kind (#739) - MF-I07: fix(contracts): enforce max challenge duration (#752) - MF-M08: fix(rpc): replace Origin label with application_id on connection gauge (#745) - MF-C02: fix(core): add ChannelStatusClosing to gate post-finalize state transitions (#746) - MF-L06: fix(contracts): clear stale challengeExpireAt on cooperative escrow finalization (#754) - MF-I08: docs: document ChannelClosed event orientation ambiguity during abandoned migration (#755) - MF-M09: fix(nitronode): auto-challenge home channel on withheld escrow finalize (#753) - MF-L09: fix(nitronode): validate parsed app session nonce (#751) - MF-L05: docs(contracts): document informational events not guaranteed to emit (#756) - MF-L08: fix(nitronode/api): default get_last_key_states to active-only with include_inactive opt-in (#749) - MF-L10: fix: emit escrowIds array in EscrowDepositsPurged event and handle it in Nitronode (#757)
Summary
Client.acknowledge(asset)so received off-chain funds can be acknowledged before a home channel is open.homeChannelIdthrough the existing channel creation acknowledgement path.@yellow-org/sdkto1.2.2and adds unit coverage for acknowledgement path selection.Context
While adding channel-readiness UX to the Nitrolite Store example, we found that the app can detect received off-chain funds, but the browser SDK needs to acknowledge those funds through channel creation when no home channel exists yet. This aligns the TS SDK behavior with the Go SDK path for
state exists but no HomeChannelID.Validation
npm --prefix sdk/ts run typechecknpm --prefix sdk/ts test -- --runTestsByPath test/unit/client.test.tsnpm --prefix sdk/ts testnpm --prefix sdk/ts run lintnpm --prefix sdk/ts run build:cigit diff --checkSummary by CodeRabbit
Bug Fixes
Tests
Chores