Improve UTXO cache format handling for backward compatibility
**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 <date> au lieu de <date>;<hauteur> - 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()
This commit is contained in:
parent
5186d1fab9
commit
bb28499e3f
@ -415,8 +415,12 @@ class BitcoinRPC {
|
|||||||
try {
|
try {
|
||||||
const cacheContent = readFileSync(cachePath, 'utf8').trim();
|
const cacheContent = readFileSync(cachePath, 'utf8').trim();
|
||||||
const parts = cacheContent.split(';');
|
const parts = cacheContent.split(';');
|
||||||
if (parts.length >= 1) {
|
// Format attendu : <date>;<hauteur> (2 parties)
|
||||||
const cachedHeight = parseInt(parts[1], 10) || 0;
|
// Format ancien : <date> (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) {
|
if (cachedHeight < currentHeight) {
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
logger.info('New blocks detected, updating UTXO list', {
|
logger.info('New blocks detected, updating UTXO list', {
|
||||||
@ -427,6 +431,19 @@ class BitcoinRPC {
|
|||||||
} else {
|
} else {
|
||||||
logger.debug('UTXO list up to date, no RPC call needed', { currentHeight });
|
logger.debug('UTXO list up to date, no RPC call needed', { currentHeight });
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 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) {
|
} catch (error) {
|
||||||
logger.warn('Error reading UTXO cache', { error: error.message });
|
logger.warn('Error reading UTXO cache', { error: error.message });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user