Skip to content

feat(platform-wallet): expose sync_watermark() on PlatformAddressWallet#3723

Merged
lklimek merged 2 commits into
v3.1-devfrom
feat/platform-wallet-sync-watermark-getter
May 21, 2026
Merged

feat(platform-wallet): expose sync_watermark() on PlatformAddressWallet#3723
lklimek merged 2 commits into
v3.1-devfrom
feat/platform-wallet-sync-watermark-getter

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented May 21, 2026

Issue being fixed or feature implemented

The PA-007 / PA-007b e2e tests need to observe incremental-sync progress without depending on the periodic PlatformAddressSyncManager event — they call sync_balances() directly and need to verify the watermark advanced. No public accessor existed.

This PR is the minimal extracted slice from the closed #3647 (which also bundled a controversial update_sync_state monotonic-merge change — that is being abandoned, see #3647 discussion with @QuantumExplorer and @thepastaclaw).

What was done?

  • Added pub(crate) fn last_known_recent_block(&self) -> u64 on PlatformPaymentAddressProvider — crate-visible mirror of the field so wallet-level helpers can read it without going through the AddressProvider trait.
  • Added pub async fn sync_watermark(&self) -> Option<u64> on PlatformAddressWallet. None for "provider not initialised" or "watermark == 0", matching the existing apply_sync_state convention.

No behavioural change to existing call sites — pure additive surface.

How Has This Been Tested?

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
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

🤖 Co-authored by Claudius the Magnificent AI Agent

Summary by CodeRabbit

  • New Features
    • Wallet now tracks and exposes a synchronization watermark for the latest processed blockchain block.
    • Sync operation can report when no watermark is available, improving clarity during initial or uninitialized syncs.
    • Enables clearer monitoring of wallet synchronization progress and recent block processing.

Review Change Stack

Adds an async accessor for the unified provider's
last_known_recent_block watermark, so callers driving sync_balances()
directly (e.g. PA-007/PA-007b e2e tests) can observe progress without
waiting for the periodic PlatformAddressSyncManager event.

Returns Option<u64> with None for both "provider not initialised" and
"watermark == 0" — the existing apply_sync_state convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f6995773-bc2a-40cd-a532-9f8788dd790d

📥 Commits

Reviewing files that changed from the base of the PR and between e75932b and e3fd746.

📒 Files selected for processing (2)
  • packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs
  • packages/rs-platform-wallet/src/wallet/platform_addresses/wallet.rs

📝 Walkthrough

Walkthrough

Two accessor methods expose the sync watermark: a crate-visible getter in PlatformPaymentAddressProvider returns last_known_recent_block, and PlatformAddressWallet::sync_watermark() reads that value async and returns None for missing or zero, otherwise Some(non-zero).

Changes

Sync Watermark Accessor Chain

Layer / File(s) Summary
Provider-level watermark accessor
packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs
Added pub(crate) fn last_known_recent_block(&self) -> u64 to expose the internal watermark field as a read-only accessor.
Wallet sync watermark method
packages/rs-platform-wallet/src/wallet/platform_addresses/wallet.rs
Added pub async fn sync_watermark(&self) -> Option<u64> that acquires a read lock on the provider, retrieves the watermark, and maps zero or missing to None.

Suggested Labels

ready for final review

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A little rabbit hops to peep,
Watermarks stored, no longer asleep,
Provider whispers the recent height,
Wallet reads and treats zero light,
Syncs stay steady through day and night.

🚥 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 accurately and concisely describes the main addition: exposing sync_watermark() method on PlatformAddressWallet, which is the primary user-facing API change.
Linked Issues check ✅ Passed The PR fully implements all coding objectives from #3647: exposes last_known_recent_block() accessor on PlatformPaymentAddressProvider and adds sync_watermark() method on PlatformAddressWallet with proper None handling for zero values.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the stated objectives: two new accessor methods in platform-wallet package with no unrelated modifications or behavioral changes to existing functionality.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/platform-wallet-sync-watermark-getter

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
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs (1)

428-430: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make watermark updates monotonic in update_sync_state.

last_known_recent_block is overwritten directly, so out-of-order sync results can move the watermark backward. That breaks the no-regression objective and can report stale progress via sync_watermark().

Suggested fix
 pub(crate) fn update_sync_state(
     &mut self,
     result: &AddressSyncResult<PlatformAddressTag, PlatformP2PKHAddress>,
 ) {
-    self.sync_height = result.new_sync_height;
-    self.sync_timestamp = result.new_sync_timestamp;
-    self.last_known_recent_block = result.last_known_recent_block;
+    self.sync_height = self.sync_height.max(result.new_sync_height);
+    self.sync_timestamp = self.sync_timestamp.max(result.new_sync_timestamp);
+    self.last_known_recent_block = self
+        .last_known_recent_block
+        .max(result.last_known_recent_block);
 }
🤖 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 `@packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs` around
lines 428 - 430, update_sync_state currently assigns
self.last_known_recent_block (and potentially sync_height/sync_timestamp)
directly from result, allowing out-of-order results to move the watermark
backward; change the updates to be monotonic: set self.last_known_recent_block =
max(self.last_known_recent_block, result.last_known_recent_block) and similarly
only advance self.sync_height and self.sync_timestamp if result values are
greater than the current ones (use std::cmp::max or conditional checks). Update
the logic inside update_sync_state so no field is ever decreased by a newer
result and keep existing field names (self.sync_height, self.sync_timestamp,
self.last_known_recent_block) to locate the change.
🤖 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.

Outside diff comments:
In `@packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs`:
- Around line 428-430: update_sync_state currently assigns
self.last_known_recent_block (and potentially sync_height/sync_timestamp)
directly from result, allowing out-of-order results to move the watermark
backward; change the updates to be monotonic: set self.last_known_recent_block =
max(self.last_known_recent_block, result.last_known_recent_block) and similarly
only advance self.sync_height and self.sync_timestamp if result values are
greater than the current ones (use std::cmp::max or conditional checks). Update
the logic inside update_sync_state so no field is ever decreased by a newer
result and keep existing field names (self.sync_height, self.sync_timestamp,
self.last_known_recent_block) to locate the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44e6647e-e6df-4ce4-96f2-a50c7c1242ce

📥 Commits

Reviewing files that changed from the base of the PR and between 2e6fc32 and e75932b.

📒 Files selected for processing (2)
  • packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs
  • packages/rs-platform-wallet/src/wallet/platform_addresses/wallet.rs

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "5d3c59eda54be2be8210a268abb2c3f5c76c7c03725c5fcb56240623baeea68b"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

Copy link
Copy Markdown
Collaborator

@thepastaclaw thepastaclaw left a comment

Choose a reason for hiding this comment

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

Code Review

The PR is a small, read-only API addition that exposes existing sync state without changing wallet mutation or persistence behavior. I did not find a correctness, security, or consensus issue in the implementation. The only review-worthy gap is that the new public Option contract is not pinned down by a focused test.

🟡 1 suggestion(s)

Comment thread packages/rs-platform-wallet/src/wallet/platform_addresses/wallet.rs
@thepastaclaw
Copy link
Copy Markdown
Collaborator

Checked CodeRabbit's monotonic-update suggestion. I don't think we should take it in this PR: that behavior was the scope of the superseded #3647 and was intentionally dropped when #3723 narrowed to only expose existing watermark state.

In the active sync_balances() path, the provider write lock is held through update_sync_state(), so the out-of-order same-provider regression described by the bot does not appear reachable from this API addition. No code changes needed here.

@lklimek lklimek merged commit 81fa751 into v3.1-dev May 21, 2026
15 of 16 checks passed
@lklimek lklimek deleted the feat/platform-wallet-sync-watermark-getter branch May 21, 2026 16:02
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.17%. Comparing base (8d2b1cb) to head (e3fd746).
⚠️ Report is 1 commits behind head on v3.1-dev.

Additional details and impacted files
@@            Coverage Diff             @@
##           v3.1-dev    #3723    +/-   ##
==========================================
  Coverage     87.17%   87.17%            
==========================================
  Files          2600     2601     +1     
  Lines        318021   318220   +199     
==========================================
+ Hits         277224   277420   +196     
- Misses        40797    40800     +3     
Components Coverage Δ
dpp 87.68% <ø> (-0.01%) ⬇️
drive 85.95% <ø> (ø)
drive-abci 89.68% <ø> (ø)
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.17% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 49.16% <ø> (ø)
🚀 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.

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.

3 participants