fix(nostr-client): reconnect indefinitely instead of giving up after 5 attempts

Previously the relay reconnect logic gave up after 5 attempts (~31s).
If the relay was down longer, the ATM permanently lost connectivity
and couldn't fetch available balance — causing all bills to be
rejected after the recent safety guard change.

Now reconnects indefinitely with exponential backoff capped at 60s.
Attempts reset on successful connection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Patrick Mulligan 2026-04-02 20:23:58 -04:00
commit ea72623cde

View file

@ -54,7 +54,7 @@ export class NostrClient {
this.config = {
connectionTimeout: 10000,
autoReconnect: true,
maxReconnectAttempts: 5,
maxReconnectAttempts: Infinity,
...config,
}
@ -183,11 +183,16 @@ export class NostrClient {
if (!connection) return
if (connection.reconnectAttempts >= this.config.maxReconnectAttempts) {
console.warn(`[Nostr] Relay ${url}: max reconnect attempts reached`)
return
}
connection.reconnectAttempts++
const delay = Math.min(1000 * Math.pow(2, connection.reconnectAttempts), 30000)
// Exponential backoff: 2s, 4s, 8s, 16s, 32s, then cap at 60s
const delay = Math.min(1000 * Math.pow(2, connection.reconnectAttempts), 60000)
console.log(
`[Nostr] Relay ${url}: reconnecting in ${delay / 1000}s (attempt ${connection.reconnectAttempts})`
)
setTimeout(() => {
this.connectToRelay(url)