Skip to content

Fix syncing races between periodic and change-server syncing #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- added: Added `usesChangeServer` flag to `EdgeCurrencyInfo` to optimize syncing for engines which subscribe to the change-server.
- fixed: Race condition between engine change-server subscription and periodic sync.

## 2.32.0 (2025-06-27)

- changed: Fake PIN disable while in duress mode.
Expand Down
20 changes: 8 additions & 12 deletions src/core/currency/currency-pixie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export const currency: TamePixie<RootProps> = combinePixies({
if (changeService?.connected === true && changeServiceConnected) {
const filteredWallets = supportedWallets.filter(([, wallet]) =>
wallet.changeServiceSubscriptions.some(
subscription => subscription.status === 'subscribing'
subscription =>
subscription.status === 'subscribing' ||
subscription.status === 'resubscribing'
)
)
const indexToWalletId: Array<{
Expand Down Expand Up @@ -282,7 +284,7 @@ export const currency: TamePixie<RootProps> = combinePixies({
// subscribe to the address:
case 0:
// Try subscribing again later:
status = 'subscribing'
status = 'resubscribing'
break
// Change server does support this wallet plugin, and there are no
// changes for the address:
Expand All @@ -298,19 +300,13 @@ export const currency: TamePixie<RootProps> = combinePixies({
break
}

// The status for the subscription is already set to subscribing, so
// we don't need to update it:
if (status === 'subscribing') {
continue
}

// Update the status for the subscription:
const subscriptions = wallet.changeServiceSubscriptions
.filter(subscription => subscription.status === 'subscribing')
.map(subscription => ({
const subscriptions = wallet.changeServiceSubscriptions.map(
subscription => ({
...subscription,
status
}))
})
)
subscriptionUpdates.set(walletId, subscriptions)
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/currency/wallet/currency-wallet-pixie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ export const walletPixie: TamePixie<CurrencyWalletProps> = combinePixies({
!props.state.paused &&
!props.walletState.paused &&
props.walletState.engineStarted &&
(props.walletState.changeServiceSubscriptions.length === 0 ||
(props.walletState.currencyInfo.usesChangeServer !== true ||
props.walletState.changeServiceSubscriptions.some(
subscription =>
subscription.status === 'avoiding' ||
subscription.status === 'subscribing' ||
subscription.status === 'reconnecting'
subscription.status === 'reconnecting' ||
subscription.status === 'resubscribing'
))
? props
: undefined
Expand Down
1 change: 1 addition & 0 deletions src/core/currency/wallet/currency-wallet-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type ChangeServiceSubscriptionStatus =
| 'listening' // The wallet is connected and listening for changes
| 'reconnecting' // The wallet is reconnecting to the change service while its not available
| 'subscribing' // The wallet is in the process of subscribing (supported)
| 'resubscribing' // The wallet is in the process of resubscribing due to a change-server issue (supported)
| 'syncing' // The wallet is syncing historical data

export interface CurrencyWalletNext {
Expand Down
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export interface EdgeCurrencyInfo {
unsafeBroadcastTx?: boolean
unsafeMakeSpend?: boolean
unsafeSyncNetwork?: boolean
usesChangeServer?: boolean

/** @deprecated The default user settings are always `{}` */
defaultSettings?: JsonObject
Expand Down
Loading