log monero sync state and refresh failures

This commit is contained in:
2026-08-02 15:09:28 +08:00
parent 1c5e5b617f
commit bdfee2a553
2 changed files with 62 additions and 28 deletions
+10
View File
@@ -151,6 +151,7 @@ export function createMoneroHandlers(state: {
console.log('[rpc] moneroGetBalance') console.log('[rpc] moneroGetBalance')
if (!state.manager) if (!state.manager)
throw new Error('Monero wallet RPC not started') throw new Error('Monero wallet RPC not started')
try {
const { balance, unlocked } = await walletGetBalance( const { balance, unlocked } = await walletGetBalance(
state.manager, state.manager,
) )
@@ -171,6 +172,10 @@ export function createMoneroHandlers(state: {
height, height,
daemonHeight, daemonHeight,
} }
} catch (e) {
logError('[rpc] moneroGetBalance failed', e)
throw e
}
}, },
moneroGetTransactions: async ({ moneroGetTransactions: async ({
accountIndex, accountIndex,
@@ -180,12 +185,17 @@ export function createMoneroHandlers(state: {
console.log('[rpc] moneroGetTransactions', { accountIndex }) console.log('[rpc] moneroGetTransactions', { accountIndex })
if (!state.manager) if (!state.manager)
throw new Error('Monero wallet RPC not started') throw new Error('Monero wallet RPC not started')
try {
const txs = await walletGetTransactions( const txs = await walletGetTransactions(
state.manager, state.manager,
accountIndex, accountIndex,
) )
console.log(`[rpc] moneroGetTransactions: ${txs.length} txs`) console.log(`[rpc] moneroGetTransactions: ${txs.length} txs`)
return txs return txs
} catch (e) {
logError('[rpc] moneroGetTransactions failed', e)
throw e
}
}, },
moneroWalletStatus: async () => { moneroWalletStatus: async () => {
if (!state.manager) { if (!state.manager) {
@@ -1,5 +1,7 @@
import { import {
electrobun, electrobun,
frontendLog,
frontendLogError,
type MoneroTxEntry, type MoneroTxEntry,
type MoneroAccountEntry, type MoneroAccountEntry,
type MoneroSendResult, type MoneroSendResult,
@@ -406,6 +408,8 @@ export const MoneroWallet = () => {
refreshInFlight = (async () => { refreshInFlight = (async () => {
loading = true loading = true
let failed = false let failed = false
const wasSyncing = syncing
let lastError: unknown = null
try { try {
const [bal, balErr] = await tryCatch( const [bal, balErr] = await tryCatch(
rpcTimeout( rpcTimeout(
@@ -414,7 +418,10 @@ export const MoneroWallet = () => {
'moneroGetBalance', 'moneroGetBalance',
), ),
) )
if (balErr) failed = true if (balErr) {
failed = true
lastError = balErr
}
if (bal) { if (bal) {
balAtomic = bal.balance balAtomic = bal.balance
unlockedAtomic = bal.unlocked unlockedAtomic = bal.unlocked
@@ -431,21 +438,38 @@ export const MoneroWallet = () => {
'moneroGetTransactions', 'moneroGetTransactions',
), ),
) )
if (txErr) failed = true if (txErr) {
failed = true
lastError = txErr
}
txs = result ?? [] txs = result ?? []
const ok = await fetchAccounts() const ok = await fetchAccounts()
if (!ok) failed = true if (!ok) {
failed = true
lastError = new Error('moneroGetAccounts failed')
}
if (failed) { if (failed) {
// The wallet-rpc is likely busy syncing; keep the stale // The wallet-rpc is likely busy syncing; keep the stale
// balance and retry shortly instead of showing an error. // balance and retry shortly instead of showing an error.
syncing = true syncing = true
scheduleSyncRetry() scheduleSyncRetry()
frontendLogError(
`monero refresh failed (height ${height}/${daemonHeight})`,
lastError,
)
} else { } else {
if (wasSyncing) {
frontendLog(`monero sync complete at height ${height}`)
}
syncing = false syncing = false
} }
} catch (e) { } catch (e) {
syncing = true syncing = true
scheduleSyncRetry() scheduleSyncRetry()
frontendLogError(
`monero refresh failed (height ${height}/${daemonHeight})`,
e,
)
} finally { } finally {
loading = false loading = false
refreshInFlight = null refreshInFlight = null