Repository navigation
Description
Summary
In `packages/rs-sdk/src/platform/address_sync/mod.rs`, both apply paths (`apply_address_changes` forward apply and `refresh_and_replay_unknown` replay) synthesize the persisted nonce as:
```rust
let nonce = result.found.get(&result_key).map(|f| f.nonce).unwrap_or(0);
```
The incremental RPCs `GetRecentAddressBalanceChanges` and `GetRecentAddressBalanceChangesCompacted` carry only balance deltas — never nonces. By construction, every address that lands in the replay path has no prior `result.found` entry, so it gets persisted with `nonce = 0` even when the on-chain nonce is non-zero (e.g. the address was already spent before this sync window).
The `AddressFunds` type makes `nonce` look as authoritative as `balance`, but only the balance is proven. Downstream wallet code treating `result.found`/`on_address_found` as canonical can then build an address-signed transition with a stale nonce and fail with `InvalidAddressNonce`.
Current mitigation
Two `TODO` comments document the gap at `mod.rs:807-811` and `mod.rs:902`:
incremental RPCs carry only balance deltas, never nonces — addresses first seen here get nonce=0. Clients recover via `AddressInvalidNonceError.expected_nonce`; a proper fix would fetch authoritative `AddressFunds` or model `nonce` as `Option`.
Clients have a documented recovery path via `AddressInvalidNonceError.expected_nonce`, so this is a degradation of the canonical-result contract, not a complete failure.
Provenance
- Found and flagged by @thepastaclaw on PR fix(sdk): address-sync no longer silently discards balance changes for post-snapshot addresses (Found-025) #3650 (2026-05-21 review and 2026-05-25 re-validation).
- Author chose to defer in fix(sdk): address-sync no longer silently discards balance changes for post-snapshot addresses (Found-025) #3650; the PR was approved with the TODOs as documentation.
- Triaged on 2026-05-25 to file as a follow-up.
Reviewer thread
PR #3650 review by @thepastaclaw: #3650 (review)
Fix options (verbatim from reviewer)
- (a) Fetch authoritative `AddressFunds` for first-seen-via-incremental addresses (extra RPC, but preserves the canonical-result contract).
- (b) Model `nonce` as `Option` so the unknown state is encoded in the type (caller-visible API change).
- (c) Exclude unknown-path recoveries from `result.found` entirely and surface them as a follow-up full-sync trigger.
Option (a) preserves the existing surface and is likely the lowest-blast-radius fix.
Test plan
- Mock provider whose first delta exposes a new address; assert the persisted entry's nonce matches the on-chain nonce, not 0.
- Regression test: an address with nonce=N pre-sync gets persisted with nonce=N (not 0) after a delta sync that first surfaces it.
Severity
MEDIUM — degradation of the canonical-result contract; documented client-recovery path exists.
🤖 Co-authored by Claudius the Magnificent AI Agent
Activity