Skip to content

Conversation

@bordalix
Copy link
Contributor

@bordalix bordalix commented Oct 18, 2025

@louisinger please review

Summary by CodeRabbit

  • Bug Fixes
    • Wallet UTXO state now clears previous entries before saving to ensure consistent stored balances.
    • UTXO update notifications now always broadcast (even when no new UTXOs) and await delivery, improving sync reliability.
    • UTXO notifications now include richer coin details so clients receive more complete update data.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2025

Walkthrough

The service worker's UTXO handling and notifications were updated: mapped utxo variable renamed, early-return removed so flow always continues, boarding utxos are cleared before saving, client vtxo notifications are now awaited, and UTXO notification payloads/types changed to use ExtendedCoin[].

Changes

Cohort / File(s) Summary
Service worker UTXO flow
src/wallet/serviceWorker/worker.ts
Renamed newUtxosutxos; removed early return when no utxos; added walletRepository.clearUtxos(boardingAddress) before save; save uses utxos; vtxo update notification is awaited.
Response payload typings
src/wallet/serviceWorker/response.ts
UtxoUpdate.coins type changed from Coin[]ExtendedCoin[]; utxoUpdate function signature updated to accept ExtendedCoin[]; import/typing adjusted accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant Worker as ServiceWorker
  participant Repo as WalletRepository
  participant Clients as Clients (broadcast)

  Worker->>Worker: map funds -> utxos
  Worker->>Repo: clearUtxos(boardingAddress)
  Repo-->>Worker: cleared
  Worker->>Repo: save(boardingAddress, utxos)
  Repo-->>Worker: saved
  Worker->>Clients: await broadcast.vtxoUpdate(vtxo)
  Clients-->>Worker: ack
  Worker->>Clients: broadcast.utxoUpdate(utxos as ExtendedCoin[])
  Clients-->>Worker: ack
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • louisinger

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "reset utxos" directly aligns with the core functionality change in the PR. The primary modification in worker.ts is adding a call to walletRepository.clearUtxos(boardingAddress) before saving utxos, which reflects the "resetting" concept conveyed in the title. The branch name hotfix_clear_utxos further confirms this is the intended focus. While the PR also includes type updates to use ExtendedCoin[] and changes to notification handling, these are supporting modifications to the primary objective of clearing and resetting utxos.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hotfix_clear_utxos

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f28ab9 and 7753686.

📒 Files selected for processing (2)
  • src/wallet/serviceWorker/response.ts (2 hunks)
  • src/wallet/serviceWorker/worker.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/wallet/serviceWorker/worker.ts (1)
src/wallet/utils.ts (1)
  • extendCoin (21-28)
src/wallet/serviceWorker/response.ts (2)
src/wallet/index.ts (1)
  • ExtendedCoin (154-156)
src/wallet/serviceWorker/request.ts (1)
  • Base (22-25)
🔇 Additional comments (4)
src/wallet/serviceWorker/worker.ts (3)

188-190: LGTM - Await ensures notification completes before callback returns.

Adding await to the vtxo notification makes it synchronous with the callback, ensuring clients are notified before proceeding. This improves consistency with the utxo notification at line 208.

Note: If client notifications are slow or fail, this will block the callback. Consider adding error handling or timeout logic if notification reliability becomes an issue.


208-210: LGTM - Addresses past review comments.

Two improvements here:

  1. Adding await ensures the notification completes before proceeding, addressing louisinger's concern about the missing await.
  2. Changing the payload from funds.coins to utxos (which are ExtendedCoin[] enriched at lines 193-195) aligns with the type signature update in response.ts and resolves the type mismatch flagged in previous reviews.

Both changes improve correctness and type safety.


193-195: The code change is correct as originally written.

The removal of the early return was an intentional fix in commit 2f28ab9 titled "don't return earlier if empty utxos". The previous early return prevented proper wallet cleanup when funds.coins was empty. The new behavior ensures that when the provider sends an empty coins array (indicating all UTXOs are spent), the wallet properly clears all stored UTXOs from the repository and notifies clients, rather than silently returning and leaving stale data.

The variable rename from newUtxos to utxos accurately reflects that funds.coins represents a complete snapshot of current UTXOs from the provider, not just newly arrived ones. This semantic change aligns with the fixed behavior.

src/wallet/serviceWorker/response.ts (1)

2-9: LGTM - Import added for ExtendedCoin type.

Adding ExtendedCoin to the imports supports the type signature updates at lines 379 and 386.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85cf9d6 and 28e992d.

📒 Files selected for processing (1)
  • src/wallet/serviceWorker/worker.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/wallet/serviceWorker/worker.ts (1)
src/wallet/utils.ts (1)
  • extendCoin (21-28)
🔇 Additional comments (2)
src/wallet/serviceWorker/worker.ts (2)

193-195: LGTM: Variable naming aligns with new semantics.

The rename from newUtxos to utxos better reflects the "replace all" semantics introduced by the clearUtxos call on line 206.


197-200: LGTM: Empty array handling is correct.

The early return with an empty array notification is appropriate and efficient. It correctly signals to clients when no UTXOs are available.

this.sendMessageToAllClients(
Response.utxoUpdate(funds.coins)
);
this.sendMessageToAllClients(Response.utxoUpdate(utxos));
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't this async? why no await ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@tiero tiero merged commit 5a46496 into master Oct 18, 2025
2 checks passed
@louisinger louisinger deleted the hotfix_clear_utxos branch December 29, 2025 10:13
@coderabbitai coderabbitai bot mentioned this pull request Jan 15, 2026
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.

4 participants