From bb28499e3f3406546ffeafcaccb3c3ba5b5fd01b Mon Sep 17 00:00:00 2001 From: ncantu Date: Mon, 26 Jan 2026 00:42:47 +0100 Subject: [PATCH] Improve UTXO cache format handling for backward compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations:** - Le cache UTXO existant a l'ancien format (seulement la date) - Le code ne gérait pas correctement l'ancien format - Nécessité de gérer la transition entre ancien et nouveau format **Root causes:** - Le cache UTXO avait l'ancien format au lieu de ; - Le code lisait parts[1] qui était undefined pour l'ancien format - Cela causait une détection permanente de nouveaux blocs **Correctifs:** - Amélioration du code de lecture pour gérer l'ancien format (1 partie) et le nouveau format (2 parties) - Détection automatique de l'ancien format et mise à jour forcée pour réécrire avec le bon format - Validation de la hauteur pour éviter les valeurs invalides **Evolutions:** - Compatibilité avec l'ancien format du cache - Migration automatique vers le nouveau format lors de la prochaine mise à jour - Meilleure robustesse du code de lecture du cache **Pages affectées:** - signet-dashboard/src/bitcoin-rpc.js : Méthode getUtxoList() --- signet-dashboard/src/bitcoin-rpc.js | 37 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) 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 });