Update rbf disk caching for new method
This commit is contained in:
parent
3355419761
commit
36c7697c2b
@ -17,6 +17,7 @@ class DiskCache {
|
|||||||
private static TMP_FILE_NAMES = config.MEMPOOL.CACHE_DIR + '/tmp-cache{number}.json';
|
private static TMP_FILE_NAMES = config.MEMPOOL.CACHE_DIR + '/tmp-cache{number}.json';
|
||||||
private static FILE_NAME = config.MEMPOOL.CACHE_DIR + '/cache.json';
|
private static FILE_NAME = config.MEMPOOL.CACHE_DIR + '/cache.json';
|
||||||
private static FILE_NAMES = config.MEMPOOL.CACHE_DIR + '/cache{number}.json';
|
private static FILE_NAMES = config.MEMPOOL.CACHE_DIR + '/cache{number}.json';
|
||||||
|
private static TMP_RBF_FILE_NAME = config.MEMPOOL.CACHE_DIR + '/tmp-rbfcache.json';
|
||||||
private static RBF_FILE_NAME = config.MEMPOOL.CACHE_DIR + '/rbfcache.json';
|
private static RBF_FILE_NAME = config.MEMPOOL.CACHE_DIR + '/rbfcache.json';
|
||||||
private static CHUNK_FILES = 25;
|
private static CHUNK_FILES = 25;
|
||||||
private isWritingCache = false;
|
private isWritingCache = false;
|
||||||
@ -103,14 +104,26 @@ class DiskCache {
|
|||||||
logger.warn('Error writing to cache file: ' + (e instanceof Error ? e.message : e));
|
logger.warn('Error writing to cache file: ' + (e instanceof Error ? e.message : e));
|
||||||
this.isWritingCache = false;
|
this.isWritingCache = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug('Writing rbf data to disk cache (async)...');
|
logger.debug('Writing rbf data to disk cache (async)...');
|
||||||
this.isWritingCache = true;
|
this.isWritingCache = true;
|
||||||
|
const rbfData = rbfCache.dump();
|
||||||
await fsPromises.writeFile(DiskCache.RBF_FILE_NAME, JSON.stringify({
|
if (sync) {
|
||||||
rbfCacheSchemaVersion: this.rbfCacheSchemaVersion,
|
fs.writeFileSync(DiskCache.TMP_RBF_FILE_NAME, JSON.stringify({
|
||||||
rbf: rbfCache.dump(),
|
network: config.MEMPOOL.NETWORK,
|
||||||
}), { flag: 'w' });
|
rbfCacheSchemaVersion: this.rbfCacheSchemaVersion,
|
||||||
|
rbf: rbfData,
|
||||||
|
}), { flag: 'w' });
|
||||||
|
fs.renameSync(DiskCache.TMP_RBF_FILE_NAME, DiskCache.RBF_FILE_NAME);
|
||||||
|
} else {
|
||||||
|
await fsPromises.writeFile(DiskCache.TMP_RBF_FILE_NAME, JSON.stringify({
|
||||||
|
network: config.MEMPOOL.NETWORK,
|
||||||
|
rbfCacheSchemaVersion: this.rbfCacheSchemaVersion,
|
||||||
|
rbf: rbfData,
|
||||||
|
}), { flag: 'w' });
|
||||||
|
await fsPromises.rename(DiskCache.TMP_RBF_FILE_NAME, DiskCache.RBF_FILE_NAME);
|
||||||
|
}
|
||||||
logger.debug('Rbf data saved to disk cache');
|
logger.debug('Rbf data saved to disk cache');
|
||||||
this.isWritingCache = false;
|
this.isWritingCache = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -214,9 +227,15 @@ class DiskCache {
|
|||||||
logger.notice('Rbf disk cache contains an outdated schema version. Clearing it and skipping the cache loading.');
|
logger.notice('Rbf disk cache contains an outdated schema version. Clearing it and skipping the cache loading.');
|
||||||
return this.wipeRbfCache();
|
return this.wipeRbfCache();
|
||||||
}
|
}
|
||||||
|
if (rbfData.network && rbfData.network !== config.MEMPOOL.NETWORK) {
|
||||||
|
logger.notice('Rbf disk cache contains data from a different network. Clearing it and skipping the cache loading.');
|
||||||
|
return this.wipeRbfCache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rbfCache.load(rbfData.rbf);
|
if (rbfData?.rbf) {
|
||||||
|
rbfCache.load(rbfData.rbf);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn('Failed to parse rbf cache. Skipping. Reason: ' + (e instanceof Error ? e.message : e));
|
logger.warn('Failed to parse rbf cache. Skipping. Reason: ' + (e instanceof Error ? e.message : e));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user