Skip to content

Remove OnchainWallet trait - #259

Open
muchai254 wants to merge 11 commits into
arkade-os:masterfrom
muchai254:muchai254/remove-OnchainWallet-trait
Open

Remove OnchainWallet trait#259
muchai254 wants to merge 11 commits into
arkade-os:masterfrom
muchai254:muchai254/remove-OnchainWallet-trait

Conversation

@muchai254

@muchai254 muchai254 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Closes #137. Removes the OnchainWallet abstraction and the W generic it required. Removing Boardingwallet was already addressed prior to this PR. No behavioural change.

Summary by CodeRabbit

  • New Features
    • Added wallet-provided spending dependencies for change addresses, coin selection, and transaction signing.
    • On-chain transactions now accept an explicit change address and validate addresses against the configured network.
  • API Improvements
    • Client connections no longer require an embedded wallet, allowing wallet management to remain separate.
    • Wallet operations are available directly through the wallet API.
  • Bug Fixes
    • Improved handling and error reporting for transaction bumping, PSBT finalization, dust amounts, and invalid addresses.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@muchai254, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 782a4fbc-b682-4dc8-b729-6400e745c7ac

📥 Commits

Reviewing files that changed from the base of the PR and between 29e4c30 and 6d8123d.

📒 Files selected for processing (1)
  • SECURITY.md

Walkthrough

Changes

Wallet and client decoupling

Layer / File(s) Summary
Wallet inherent methods
ark-bdk-wallet/src/lib.rs
Wallet operations are public inherent methods. anchor_spend_deps connects wallet address generation, coin selection, and signing to AnchorSpendDeps.
Client structure and anchor-spend dependencies
ark-client/src/lib.rs
Client and OfflineClient no longer include an on-chain wallet. Constructors and connection methods use wallet-free types. bump_tx receives external spend dependencies.
Client module generic bounds
ark-client/src/{asset,batch,coin_select,fee_estimation,migration,send_vtxo,boltz,vtxo_watcher}.rs
Client implementations and watcher helpers remove the OnchainWallet generic parameter and trait bounds.
Unilateral exit and on-chain spending
ark-client/src/unilateral_exit.rs
Unilateral exits receive AnchorSpendDeps. On-chain transaction construction receives an explicit change address and validates destination and change networks. Tests cover address, dust, selection, signing, and PSBT errors.
Samples and integration setup
ark-client-sample/src/main.rs, e2e-tests/tests/*
Samples and end-to-end tests use wallet-free client types and pass wallet-derived addresses and spend dependencies explicitly.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Wallet
  participant AnchorSpendDeps
  participant Client
  participant UnilateralExit
  UnilateralExit->>Client: broadcast_next_unilateral_exit_node(branch, deps)
  Client->>AnchorSpendDeps: request change address
  AnchorSpendDeps->>Wallet: get_onchain_address
  Client->>AnchorSpendDeps: select coins
  AnchorSpendDeps->>Wallet: select_coins
  Client->>AnchorSpendDeps: sign PSBT
  AnchorSpendDeps->>Wallet: sign PSBT
Loading

Possibly related PRs

Suggested reviewers: bonomat

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: removing the OnchainWallet trait.
Linked Issues check ✅ Passed The changes remove OnchainWallet and its generic throughout the client while preserving signing through caller-provided wallet dependencies, matching issue #137.
Out of Scope Changes check ✅ Passed The changes support removal of OnchainWallet by updating APIs, tests, and wallet callback handling; no unrelated code changes are evident.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
ark-client/src/lib.rs (1)

2069-2099: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update outdated comment.

The closure maps the error type from ark_client::Error to ark_core::Error; it doesn't convert a CoinSelectionResult to UtxoCoinSelection. The deps.select_coins dependency already correctly returns UtxoCoinSelection.

♻️ Proposed fix
-        // Create a closure that converts CoinSelectionResult to UtxoCoinSelection
+        // Create a closure that maps the coin selection error
         let select_coins_fn =
🤖 Prompt for 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.

In `@ark-client/src/lib.rs` around lines 2069 - 2099, Update the comment above
select_coins_fn in bump_tx to describe that the closure maps the
deps.select_coins error from ark_client::Error to ark_core::Error while
preserving its UtxoCoinSelection result; do not describe it as converting
CoinSelectionResult.
🤖 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.

Nitpick comments:
In `@ark-client/src/lib.rs`:
- Around line 2069-2099: Update the comment above select_coins_fn in bump_tx to
describe that the closure maps the deps.select_coins error from
ark_client::Error to ark_core::Error while preserving its UtxoCoinSelection
result; do not describe it as converting CoinSelectionResult.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f10949a-373e-4806-96f7-5e55412ccb88

📥 Commits

Reviewing files that changed from the base of the PR and between d8feefa and 8732795.

📒 Files selected for processing (18)
  • ark-bdk-wallet/src/lib.rs
  • ark-client-sample/src/main.rs
  • ark-client/src/asset.rs
  • ark-client/src/batch.rs
  • ark-client/src/boltz.rs
  • ark-client/src/coin_select.rs
  • ark-client/src/fee_estimation.rs
  • ark-client/src/lib.rs
  • ark-client/src/migration.rs
  • ark-client/src/send_vtxo.rs
  • ark-client/src/unilateral_exit.rs
  • ark-client/src/vtxo_watcher.rs
  • ark-client/src/wallet.rs
  • e2e-tests/tests/boltz_reverse_vhtlc_unilateral_exit.rs
  • e2e-tests/tests/common.rs
  • e2e-tests/tests/e2e_send_onchain_boarding_output.rs
  • e2e-tests/tests/e2e_send_onchain_vtxo_and_boarding_output.rs
  • e2e-tests/tests/e2e_signer_rotation.rs
💤 Files with no reviewable changes (1)
  • ark-client/src/wallet.rs

@muchai254

Copy link
Copy Markdown
Contributor Author

@bonomat @luckysori, would really appreciate a review here when you get the chance.

@arkana-ai-bot arkana-ai-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PROTOCOL-CRITICAL: human review required.

This touches unilateral-exit and anchor fee-bump paths. Refactor looks mechanically correct — but two seams move safety guarantees from the client to the caller without documenting them. Please have a protocol reviewer sign off even after the notes below are addressed.

Findings

1. send_on_chain / create_send_on_chain_transaction: new change_address param is undocumented (money-loss footgun)

ark-client/src/unilateral_exit.rs:207-212, 234-242, 244-249

The new change_address: Address argument has no doc comment. Previously the client fetched this from the internal wallet, so change from a unilateral exit was guaranteed to be self-spendable. Now every caller has to know that (a) the address must be spendable by them, and (b) it must match the correct network — nothing in the client validates either. ark-core::unilateral_exit::create_unilateral_exit_transaction (ark-core/src/unilateral_exit.rs:188-193) just drops it into a TxOut with the leftover value. On a unilateral-exit tx the change can be effectively the entire balance minus to_amount + 1000 sat — silently sending that to a wrong-network or third-party address loses funds unrecoverably.

Please:

  • Add a doc paragraph on send_on_chain, create_send_on_chain_transaction, and create_send_on_chain_transaction_inner stating the address MUST be spendable by the caller.
  • Consider a network sanity check against self.server_info().await?.network in create_send_on_chain_transaction_inner before building the tx.

2. AnchorSpendDeps has no documented consistency invariant

ark-client/src/lib.rs:522-533

The three closures (change_address, select_coins, sign) must all be backed by the same on-chain wallet, otherwise select_coins yields UTXOs sign cannot spend, or fee-bump change lands somewhere unspendable. The doc comment describes each field in isolation. Please add a top-level note on the struct: "All three closures MUST be backed by the same underlying on-chain wallet — mixing sources will produce unsignable or unspendable transactions."

3. No AnchorSpendDeps usage example / helper

ark-client/src/lib.rs (doc example around line 300-404), e2e-tests/tests/e2e_send_onchain_vtxo_and_boarding_output.rs:95-108, e2e-tests/tests/boltz_reverse_vhtlc_unilateral_exit.rs:96-109

The lib.rs doc example was trimmed to remove the old MyWallet, but nothing shows how to build AnchorSpendDeps — which is now the only way to fee-bump a unilateral exit. External consumers coming from the old trait have no example. The two e2e tests repeat the same 14-line closure boilerplate verbatim, which is a clear signal a AnchorSpendDeps::from_bdk_wallet(&Arc<Wallet>) -> AnchorSpendDeps<'_> (or equivalent) helper in ark-bdk-wallet would help both correctness and ergonomics.

4. bdk_wallet::Balance now leaks into the ark-bdk-wallet public API

ark-bdk-wallet/src/lib.rs:119

Fine for an adapter crate, but this hard-pins any downstream consumer typing against Balance to your bdk_wallet major. Previously they saw ark_client::wallet::Balance, which was version-decoupled. Worth calling out in the changelog / release notes as a break.

5. Test coverage gap

  • No unit test exercises AnchorSpendDeps closures (error propagation, mismatched wallet, wrong-network change). Two e2e tests cover the happy path.
  • No test covers a send_on_chain call with a wrong-network change_address.
    Not blocking, but the "no behavioural change" claim in the PR body only holds if callers follow the (currently undocumented) contract — a couple of guard tests would make the contract enforceable.

Cross-repo impact

Scanned ark-flutter-example, ark-rs-flutter-example, demos, wallet, arkade-*. All consumers of ark-client pin a git rev, so nothing breaks at merge time. Downstream migrations will hit exactly the issues above (undocumented change_address semantics, missing AnchorSpendDeps example) — please fix here so migrators don't rediscover them.

Nit

ark-client/src/boltz.rs:2828 — unrelated &self.inner.boltz_urlself.inner.boltz_url cleanup is fine but out of scope.

@arkana-ai-bot arkana-ai-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PROTOCOL-CRITICAL: human review required.

Since cbd50bf: 2 commits directly addressing prior findings; 4/5 issues resolved; 1 still open.


Prior findings close-out

Finding #1change_address undocumented (money-loss footgun)

Fixed. Commit "docs(client): document change-address ownership requirement" added a doc paragraph to send_on_chain, create_send_on_chain_transaction, and create_send_on_chain_transaction_inner (unilateral_exit.rs:204-214, 242-244, 256-257). Commit "feat(client): add AnchorSpendDeps helper and guard tests" adds a network guard in create_send_on_chain_transaction_inner (unilateral_exit.rs:261-269) that rejects both to_address and change_address when they don't match server_info.network.

Finding #2AnchorSpendDeps missing consistency invariant

Fixed. The struct doc now reads: "All three closures MUST be backed by the same underlying on-chain wallet. Mixing sources produces unsignable or unspendable transactions" (lib.rs:525-527). The same commit adds a runtime guard: if sign returns false (PSBT unfinalized), bump_tx now returns a descriptive error naming the invariant violation (lib.rs:2108-2113).

Finding #3 — No AnchorSpendDeps helper / 14-line boilerplate repeated in e2e tests

Fixed. ark-bdk-wallet/src/lib.rs:209-217 adds Wallet::anchor_spend_deps(&self) -> AnchorSpendDeps<'_> that wires all three closures to self. Both e2e tests updated to a one-liner (e2e_boltz_reverse_vhtlc_unilateral_exit.rs:95, e2e_send_onchain_vtxo_and_boarding_output.rs:94).

Finding #4bdk_wallet::Balance leaking into ark-bdk-wallet public API

Still open. The full PR diff shows ark-bdk-wallet/src/lib.rs:120:

pub fn balance(&self) -> Result<bdk_wallet::Balance, Error> {Ok(balance)   // returns bdk_wallet::Balance directly
}

The previous conversion wrapper (ark_client::wallet::Balance { immature, … }) was removed. bdk_wallet::Balance is now a public API type of the crate. Any downstream consumer that types against it is pinned to your bdk_wallet major version. Not made worse by the incremental commits, but not fixed either. Still worth a re-export or newtype before stabilization; a changelog entry at minimum.

Finding #5 — Test coverage gap

Fixed. unilateral_exit.rs:331-639 adds seven unit tests exercising: wrong-network change address, wrong-network destination address, correct-network addresses reaching the dust check, and all four bump_tx error paths (change-address failure, coin-selection failure, sign failure, unfinalized PSBT). Coverage is good.


New finding (incremental diff only)

N1 — Misleading test name

unilateral_exit.rs:427: send_on_chain_accepts_addresses_on_the_server_network expects a dust error, not success. The test is logically correct (valid-network addresses pass the network check and reach the dust guard) but the name implies the call succeeds. A reader skimming by name will assume both addresses and the amount are valid. Rename to e.g. send_on_chain_correct_network_then_rejects_dust_amount.


Incidental changes note

The boltz.rs delta in this range (+3248/-674) is almost entirely from the PR #260 contract manager merge. The vtxo_watcher.rs change passes None for the new subscription filter and handles the new SubscriptionStarted variant — both correct and minimal. No OnchainWallet-removal issues introduced.


Blocking item: Finding #4 (bdk_wallet::Balance in public API). Needs either a newtype/re-export or a changelog entry documenting the break before this lands. Everything else is resolved. N1 is a nit.

@muchai254

Copy link
Copy Markdown
Contributor Author

Will really appreciate a manual review here @luckysori @bonomat when you get a chance

@arkana-ai-bot arkana-ai-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PROTOCOL-CRITICAL: human review required.

Incremental diff (29e4c30…6d8123d): 2 commits, SECURITY.md whitespace-only — zero code change. 0 prior issues fixed this pass, 2 remain open.


Prior findings close-out

Finding #1change_address undocumented (money-loss footgun)

Fixed (previous pass, unchanged).

Finding #2AnchorSpendDeps missing consistency invariant

Fixed (previous pass, unchanged).

Finding #3 — No AnchorSpendDeps helper / boilerplate

Fixed (previous pass, unchanged).

Finding #4bdk_wallet::Balance leaks into ark-bdk-wallet public API

Still open. ark-bdk-wallet/src/lib.rs:120 still returns bdk_wallet::Balance directly. The two commits in this range touch only SECURITY.md; this finding is not made worse but has not been addressed. A newtype, re-export, or explicit changelog entry is needed before this stabilises.

Finding #5 — Test coverage gap

Fixed (previous pass, unchanged).

N1 — Misleading test name

Still open. ark-client/src/unilateral_exit.rs:506 still reads send_on_chain_accepts_addresses_on_the_server_network; the test asserts a dust error, not acceptance. Please rename to e.g. send_on_chain_correct_network_then_rejects_dust_amount.


New findings

None — this diff is purely SECURITY.md whitespace formatting. No code paths changed.


Blocking: Finding #4. N1 is a nit. No new issues to report.

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.

Get rid of the OnchainWallet and BoardingWallet traits

2 participants