Repository navigation
Description
Expected Behavior
When a state transition fails to broadcast, the SDK should reset its cached nonce to match the platform's actual nonce value on the next attempt. The SDK should always use the platform as the source of truth for nonces when it queries the platform.
Current Behavior
After a failed state transition, the SDK's cached nonce continues to increment locally while the platform nonce remains unchanged. Even when the SDK queries the platform and receives a lower nonce value, it incorrectly keeps the higher cached value, causing all subsequent state transitions to fail with "nonce too far in future" errors.
Example:
- Platform nonce: 1
- Failed transition attempts increment cached nonce: 42, 43, 44...
- SDK queries platform, gets nonce = 1
- SDK ignores this and keeps using 42+
- Error: "Identity xyz... is trying to set an invalid identity nonce. The current identity nonce is 1, we are setting 42, error is nonce too far in future"
Possible Solution
Per Claude, the bug is in platform/packages/rs-sdk/src/sdk.rs in the get_identity_nonce function (lines 420-435) and similar logic in get_identity_contract_nonce (around line 512).
The problematic logic:
// Entry::Occupied branch when querying platform
let insert_nonce = if platform_nonce > *current_nonce {
// Use platform nonce if higher
if bump_first {
platform_nonce + 1
} else {
platform_nonce
}
} else if bump_first {
// BUG: Keeps cached nonce even when platform says it's lower!
*current_nonce + 1
} else {
*current_nonce
};The fix - always trust the platform as source of truth:
// Always use platform nonce when we query it
let insert_nonce = if bump_first {
platform_nonce + 1
} else {
platform_nonce
};Steps to Reproduce (for bugs)
- Attempt a data contract update state transition on https://evo-sdk.dash.org/ that fails (e.g., network issue, validation error)
- Retry the same state transition without refreshing the page/SDK instance
- Observe that the nonce increments on each retry (42, 43, 44...)
- Check platform's actual nonce for the identity - it remains at expected value (e.g., 1)
- All subsequent state transitions fail with "nonce too far in future" error
Context
This issue prevents retrying failed state transitions without completely reinitializing the SDK. It particularly affects:
- Data contract updates
Document and token operations use per-contract nonces (get_identity_contract_nonce) which has the same bug but may be less frequently triggered.
The issue makes development and testing difficult as any failed transaction requires restarting the application/SDK to clear the cache.
Your Environment
- Version used: Current
v2.1-devbranch - Environment name and version: WASM SDK in browser (Chrome 131), Dash Platform Testnet
- Operating System and version: Linux/macOS/Windows (all affected)
- Link to your project:
/packages/wasm-sdk/test/ui-automation/tests/state-transitions.spec.js
Additional Notes
The cache staleness timeout (DEFAULT_IDENTITY_NONCE_STALE_TIME_S = 1200 seconds / 20 minutes) means the bad cache persists for a long time. The assumption that "nonces only go up" is invalid when transactions fail, as the platform doesn't increment its nonce for failed transactions.
This affects all state transitions using:
get_identity_nonce(..., true, ...)withbump_first: trueget_identity_contract_nonce(..., ..., true, ...)withbump_first: true
Activity
lklimek commentedon Nov 3, 2025
@codex check if this issue is still there in platform packages/rs-sdk crate; if so, prepare a fix.
chatgpt-codex-connector commentedon Nov 3, 2025
Summary
Testing
cargo test -p dash-sdk get_identity_nonce_resets_to_platform_value_after_refresh(fails: tenderdash-proto build cannot download Tenderdash archive because of an invalid TLS certificate)View task →