Skip to content

fix(platform-wallet): enforce FFI lifetime invariants#4160

Merged
QuantumExplorer merged 5 commits into
v4.1-devfrom
codex/fix-ffi-lifetime-safety
Jul 21, 2026
Merged

fix(platform-wallet): enforce FFI lifetime invariants#4160
QuantumExplorer merged 5 commits into
v4.1-devfrom
codex/fix-ffi-lifetime-safety

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Native FFI conversion and manager teardown could violate their pointer/count and callback-lifetime contracts under edge-case data or shutdown timing.

This is a client/SDK boundary hardening change. It does not change Platform consensus or require a protocol-version activation.

What was done?

  • derive exported document-field counts from the allocation actually returned across the C ABI
  • add regression coverage for mixed, empty, and multi-filter document-field conversions
  • stop and join the SPV event source during manager shutdown
  • close payment-task admission and drain all admitted callback-bearing work before callback owners can be released
  • await runner termination after forced cancellation
  • explicitly stop SPV in the Swift wrapper teardown as defense in depth

How Has This Been Tested?

  • cargo test -p rs-sdk-ffi --lib — 304 passed
  • cargo test -p platform-wallet --lib — 470 passed
  • cargo test -p platform-wallet-ffi --lib — 182 passed
  • cargo clippy -p rs-sdk-ffi -p platform-wallet -p platform-wallet-ffi --lib -- -D warnings
  • cargo fmt -p rs-sdk-ffi -p platform-wallet -- --check
  • iOS Simulator build of the SwiftDashSDK scheme with Xcode 26.6

The repository-wide all-target strict Clippy run also reached the changed targets; it is currently blocked by pre-existing warnings in unrelated wallet test files.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • This change contains no breaking API or protocol changes
  • No additional documentation changes are required

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

@github-actions github-actions Bot added this to the v4.1.0 milestone Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f8ffa75d-dc77-4b18-97a5-aa0e9b495801

📥 Commits

Reviewing files that changed from the base of the PR and between 2b3e3fc and 53a091e.

📒 Files selected for processing (7)
  • packages/rs-platform-wallet/src/manager/mod.rs
  • packages/rs-platform-wallet/src/spv/runtime.rs
  • packages/rs-platform-wallet/src/wallet/identity/network/payment_handler.rs
  • packages/rs-sdk-ffi/src/document/queries/info.rs
  • packages/rs-unified-sdk-jni/src/tx_decode.rs
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManager.swift
  • packages/swift-sdk/build_ios.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-ffi-lifetime-safety

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.

@QuantumExplorer QuantumExplorer changed the title fix(ffi): enforce boundary lifetime invariants fix(platform-wallet): enforce FFI lifetime invariants Jul 20, 2026
@QuantumExplorer
QuantumExplorer marked this pull request as ready for review July 21, 2026 02:04
@thepastaclaw

thepastaclaw commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

🕓 Ready for review — 27 ahead in queue (commit 53a091e)
Queue position: 28/72 · 2 reviews active
ETA: start ~02:11 UTC · complete ~02:40 UTC (median 28m across 30 recent reviews; 2 slots)
Queued 23h 43m ago · Last checked: 2026-07-22 19:40 UTC

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.42%. Comparing base (ce8aecb) to head (53a091e).
⚠️ Report is 8 commits behind head on v4.1-dev.

Additional details and impacted files
@@              Coverage Diff              @@
##           v4.1-dev    #4160       +/-   ##
=============================================
- Coverage     87.63%   65.42%   -22.21%     
=============================================
  Files          2624       26     -2598     
  Lines        331678     2707   -328971     
=============================================
- Hits         290659     1771   -288888     
+ Misses        41019      936    -40083     
Components Coverage Δ
dpp ∅ <ø> (∅)
drive ∅ <ø> (∅)
drive-abci ∅ <ø> (∅)
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value ∅ <ø> (∅)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed

@QuantumExplorer
QuantumExplorer merged commit daa8ba3 into v4.1-dev Jul 21, 2026
17 of 20 checks passed
@QuantumExplorer
QuantumExplorer deleted the codex/fix-ffi-lifetime-safety branch July 21, 2026 20:03
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.

2 participants