debug: add logging to relay initialization to diagnose single relay issue

This commit is contained in:
Gigi
2025-10-20 19:18:03 +02:00
parent fc025b9579
commit 2e5536c331
2 changed files with 17 additions and 0 deletions

View File

@@ -402,6 +402,8 @@ function App() {
// Create a relay group for better event deduplication and management
pool.group(RELAYS)
console.log('[relay-init] Initial pool setup - added RELAYS:', RELAYS.length, 'relays')
console.log('[relay-init] Pool now has:', Array.from(pool.relays.keys()).length, 'relays')
// Load persisted accounts from localStorage
try {
@@ -606,6 +608,8 @@ function App() {
// Handle user relay list and blocked relays when account changes
const userRelaysSub = accounts.active$.subscribe(async (account) => {
console.log('[relay-init] userRelaysSub fired, account:', account ? 'logged in' : 'logged out')
console.log('[relay-init] Pool has', Array.from(pool.relays.keys()).length, 'relays before applying changes')
if (account) {
// User logged in - load their relay list and apply it
try {
@@ -636,6 +640,8 @@ function App() {
// Apply to pool
applyRelaySetToPool(pool, finalRelays)
console.log('[relay-init] After applyRelaySetToPool (logged in), pool has:', Array.from(pool.relays.keys()).length, 'relays')
console.log('[relay-init] Relay URLs:', Array.from(pool.relays.keys()))
// Update keep-alive subscription with new relay set
const poolWithSub = pool as unknown as { _keepAliveSubscription?: { unsubscribe: () => void } }
@@ -661,7 +667,10 @@ function App() {
}
} else {
// User logged out - reset to hardcoded relays
console.log('[relay-init] Applying RELAYS for logged out user, RELAYS.length:', RELAYS.length)
applyRelaySetToPool(pool, RELAYS)
console.log('[relay-init] After applyRelaySetToPool (logged out), pool has:', Array.from(pool.relays.keys()).length, 'relays')
console.log('[relay-init] Relay URLs:', Array.from(pool.relays.keys()))
// Update keep-alive subscription
const poolWithSub = pool as unknown as { _keepAliveSubscription?: { unsubscribe: () => void } }

View File

@@ -27,8 +27,13 @@ export function applyRelaySetToPool(
const currentUrls = new Set(Array.from(relayPool.relays.keys()))
const targetUrls = new Set(finalUrls)
console.log('[relayManager] applyRelaySetToPool called')
console.log('[relayManager] Current pool has:', currentUrls.size, 'relays')
console.log('[relayManager] Target has:', finalUrls.length, 'relays')
// Add new relays
const toAdd = finalUrls.filter(url => !currentUrls.has(url))
console.log('[relayManager] Will add:', toAdd.length, 'relays', toAdd)
if (toAdd.length > 0) {
relayPool.group(toAdd)
}
@@ -40,6 +45,7 @@ export function applyRelaySetToPool(
toRemove.push(url)
}
}
console.log('[relayManager] Will remove:', toRemove.length, 'relays', toRemove)
for (const url of toRemove) {
const relay = relayPool.relays.get(url)
@@ -48,5 +54,7 @@ export function applyRelaySetToPool(
relayPool.relays.delete(url)
}
}
console.log('[relayManager] After apply, pool has:', relayPool.relays.size, 'relays')
}