From bdfee2a553af3cf6aff5af3029125449a538d4ef Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sun, 2 Aug 2026 15:09:28 +0800 Subject: [PATCH] log monero sync state and refresh failures --- apps/desktop/src/bun/rpc/monero/index.ts | 60 +++++++++++-------- .../src/lib/states/monero-wallet.svelte.ts | 30 +++++++++- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/apps/desktop/src/bun/rpc/monero/index.ts b/apps/desktop/src/bun/rpc/monero/index.ts index e6b0910..36ab25b 100644 --- a/apps/desktop/src/bun/rpc/monero/index.ts +++ b/apps/desktop/src/bun/rpc/monero/index.ts @@ -151,25 +151,30 @@ export function createMoneroHandlers(state: { console.log('[rpc] moneroGetBalance') if (!state.manager) throw new Error('Monero wallet RPC not started') - const { balance, unlocked } = await walletGetBalance( - state.manager, - ) - const address = await walletGetAddress(state.manager) - const height = await walletGetHeight(state.manager) - const daemonHeight = await walletGetDaemonHeight(state.manager) - console.log('[rpc] balance:', { - balance: balance.toString(), - unlocked: unlocked.toString(), - address, - height, - daemonHeight, - }) - return { - balance: balance.toString(), - unlocked: unlocked.toString(), - address, - height, - daemonHeight, + try { + const { balance, unlocked } = await walletGetBalance( + state.manager, + ) + const address = await walletGetAddress(state.manager) + const height = await walletGetHeight(state.manager) + const daemonHeight = await walletGetDaemonHeight(state.manager) + console.log('[rpc] balance:', { + balance: balance.toString(), + unlocked: unlocked.toString(), + address, + height, + daemonHeight, + }) + return { + balance: balance.toString(), + unlocked: unlocked.toString(), + address, + height, + daemonHeight, + } + } catch (e) { + logError('[rpc] moneroGetBalance failed', e) + throw e } }, moneroGetTransactions: async ({ @@ -180,12 +185,17 @@ export function createMoneroHandlers(state: { console.log('[rpc] moneroGetTransactions', { accountIndex }) if (!state.manager) throw new Error('Monero wallet RPC not started') - const txs = await walletGetTransactions( - state.manager, - accountIndex, - ) - console.log(`[rpc] moneroGetTransactions: ${txs.length} txs`) - return txs + try { + const txs = await walletGetTransactions( + state.manager, + accountIndex, + ) + console.log(`[rpc] moneroGetTransactions: ${txs.length} txs`) + return txs + } catch (e) { + logError('[rpc] moneroGetTransactions failed', e) + throw e + } }, moneroWalletStatus: async () => { if (!state.manager) { diff --git a/apps/desktop/src/lib/states/monero-wallet.svelte.ts b/apps/desktop/src/lib/states/monero-wallet.svelte.ts index 29ddab3..8a09588 100644 --- a/apps/desktop/src/lib/states/monero-wallet.svelte.ts +++ b/apps/desktop/src/lib/states/monero-wallet.svelte.ts @@ -1,5 +1,7 @@ import { electrobun, + frontendLog, + frontendLogError, type MoneroTxEntry, type MoneroAccountEntry, type MoneroSendResult, @@ -406,6 +408,8 @@ export const MoneroWallet = () => { refreshInFlight = (async () => { loading = true let failed = false + const wasSyncing = syncing + let lastError: unknown = null try { const [bal, balErr] = await tryCatch( rpcTimeout( @@ -414,7 +418,10 @@ export const MoneroWallet = () => { 'moneroGetBalance', ), ) - if (balErr) failed = true + if (balErr) { + failed = true + lastError = balErr + } if (bal) { balAtomic = bal.balance unlockedAtomic = bal.unlocked @@ -431,21 +438,38 @@ export const MoneroWallet = () => { 'moneroGetTransactions', ), ) - if (txErr) failed = true + if (txErr) { + failed = true + lastError = txErr + } txs = result ?? [] const ok = await fetchAccounts() - if (!ok) failed = true + if (!ok) { + failed = true + lastError = new Error('moneroGetAccounts failed') + } if (failed) { // The wallet-rpc is likely busy syncing; keep the stale // balance and retry shortly instead of showing an error. syncing = true scheduleSyncRetry() + frontendLogError( + `monero refresh failed (height ${height}/${daemonHeight})`, + lastError, + ) } else { + if (wasSyncing) { + frontendLog(`monero sync complete at height ${height}`) + } syncing = false } } catch (e) { syncing = true scheduleSyncRetry() + frontendLogError( + `monero refresh failed (height ${height}/${daemonHeight})`, + e, + ) } finally { loading = false refreshInFlight = null