Paul/fix change server #698
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Server Bug Fixes
This document explains the fixes for three known issues with the change server integration in edge-core-js.
Issue 1: Sending 0 Checkpoint to the Change Server
Problem
The core was sending a
0(orundefined) checkpoint to the change server even if it had received a higher-number checkpoint in a previous notification or subscription response.This happened because when
onSubscribeAddresseswas called by the currency engine with plain string addresses (rather than objects with checkpoints), the code would create new subscription objects withcheckpoint: undefined, discarding any checkpoint that had been previously received and stored in the wallet state.Root Cause
In
currency-wallet-callbacks.ts, theonSubscribeAddressescallback was mapping addresses to subscriptions without checking if an existing subscription (with a valid checkpoint) already existed for that address:Fix
The fix looks up any existing subscription for the address and preserves its checkpoint:
Files Changed
src/core/currency/wallet/currency-wallet-callbacks.tssrc/core/currency/wallet/currency-wallet-pixie.tsIssue 2: Failing to Re-establish Change Server Connections
Problem
The core was not properly re-establishing the connection to the change server after a disconnect. Wallets would remain in a disconnected state and would not receive change notifications.
Root Cause
Two issues contributed to this problem:
Reconnection logic in wrong event handler: The WebSocket reconnection logic was in the
errorevent handler instead of thecloseevent handler. Since theerrorevent doesn't always fire (and thecloseevent always fires when a connection is lost), reconnection was unreliable.'reconnecting'status not handled: After a disconnect, wallets would be set to'reconnecting'status by thehandleDisconnectcallback. However, the subscription filters incurrency-pixie.tsonly checked for'subscribing'and'resubscribing'statuses, so wallets in'reconnecting'status would never be re-subscribed.Fix
errorhandler to theclosehandler, with aclosingflag to prevent reconnection when the connection was intentionally closed:'reconnecting'to subscription filters: The subscription filters now include'reconnecting'status:[0]), ensuring proper status tracking:Files Changed
src/core/currency/change-server-connection.tssrc/core/currency/currency-pixie.tsIssue 3: Not Properly Saving Checkpoints
Problem
The core was not properly saving checkpoints received from the change server. This meant that after an app restart, the wallet would lose track of its synchronization progress and might receive duplicate notifications or miss changes.
Root Cause
Two issues:
Checkpoints not persisted after sync: When a wallet completed a sync cycle and transitioned to
'listening'status, the updated checkpoint was stored in Redux state but not persisted to disk.Case-sensitive address comparison: When preserving existing checkpoints, the address comparison was case-sensitive. Since blockchain addresses can be represented in different cases (especially for EVM chains with checksummed addresses), this could cause checkpoint loss when the engine provided addresses in a different case than what was stored.
Fix
syncNetworkUpdatepixie now saves checkpoints to disk after each successful sync:EdgeSubscribedAddressobjects consistently, preferring any explicit checkpoint from the param but falling back to an existing checkpoint:Files Changed
src/core/currency/wallet/currency-wallet-callbacks.tssrc/core/currency/wallet/currency-wallet-pixie.tsSummary
d80434a0055200fa'reconnecting'statusd80434a0,8a79c7f0These fixes ensure that:
onSubscribeAddresses'reconnecting'status are properly re-subscribedDoes this branch warrant an entry to the CHANGELOG?
Dependencies
noneDescription
noneNote
Strengthens change-server reliability and checkpoint handling.
closewith aclosingguard; stop auto-reconnect on intentionalclose()(change-server-connection.ts)reconnectingin subscription filters and status updates; handle batch subscribe failures by returning a result per item (currency-pixie.ts)onSubscribeAddressesusing case-insensitive address matching; persist subscribed addresses and checkpoints (currency-wallet-callbacks.ts)syncNetwork, set subscriptions tolisteningand persist updated checkpoints to disk (currency-wallet-pixie.ts)Written by Cursor Bugbot for commit 0e0331b. This will update automatically on new commits. Configure here.