diff --git a/signet-dashboard/src/bitcoin-rpc.js b/signet-dashboard/src/bitcoin-rpc.js index 180cdbc..f6bfc12 100644 --- a/signet-dashboard/src/bitcoin-rpc.js +++ b/signet-dashboard/src/bitcoin-rpc.js @@ -415,18 +415,35 @@ class BitcoinRPC { try { const cacheContent = readFileSync(cachePath, 'utf8').trim(); const parts = cacheContent.split(';'); - if (parts.length >= 1) { - const cachedHeight = parseInt(parts[1], 10) || 0; - if (cachedHeight < currentHeight) { - needsUpdate = true; - logger.info('New blocks detected, updating UTXO list', { - cachedHeight, - currentHeight, - newBlocks: currentHeight - cachedHeight, - }); + // Format attendu : ; (2 parties) + // Format ancien : (1 partie) - nécessite une mise à jour + if (parts.length === 2) { + // Nouveau format avec hauteur + const cachedHeight = parseInt(parts[1], 10); + if (!isNaN(cachedHeight) && cachedHeight >= 0) { + if (cachedHeight < currentHeight) { + needsUpdate = true; + logger.info('New blocks detected, updating UTXO list', { + cachedHeight, + currentHeight, + newBlocks: currentHeight - cachedHeight, + }); + } else { + logger.debug('UTXO list up to date, no RPC call needed', { currentHeight }); + } } else { - logger.debug('UTXO list up to date, no RPC call needed', { currentHeight }); + // Hauteur invalide, forcer la mise à jour + logger.warn('Invalid height in UTXO cache, forcing update'); + needsUpdate = true; } + } else if (parts.length === 1) { + // Ancien format sans hauteur, forcer la mise à jour pour réécrire avec le bon format + logger.info('Old UTXO cache format detected (without height), forcing update to rewrite cache'); + needsUpdate = true; + } else { + // Format inattendu, forcer la mise à jour + logger.warn('Unexpected UTXO cache format, forcing update', { partsCount: parts.length }); + needsUpdate = true; } } catch (error) { logger.warn('Error reading UTXO cache', { error: error.message });