Bugfix: Mempool and blocks disk cache not saved on exit when using cluster.

This commit is contained in:
softsimon 2020-09-29 23:13:22 +07:00
parent 7c6c330b02
commit 140fc0c5e1
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -7,17 +7,15 @@ class DiskCache {
static FILE_NAME = './cache.json'; static FILE_NAME = './cache.json';
constructor() { constructor() {
if (cluster.isMaster) { process.on('SIGINT', () => {
process.on('SIGINT', () => { this.saveCacheToDisk();
this.saveCacheToDisk(); process.exit(2);
process.exit(2); });
});
process.on('SIGTERM', () => { process.on('SIGTERM', () => {
this.saveCacheToDisk(); this.saveCacheToDisk();
process.exit(2); process.exit(2);
}); });
}
} }
saveCacheToDisk() { saveCacheToDisk() {
@ -33,12 +31,8 @@ class DiskCache {
if (cacheData) { if (cacheData) {
console.log('Restoring mempool and blocks data from disk cache'); console.log('Restoring mempool and blocks data from disk cache');
const data = JSON.parse(cacheData); const data = JSON.parse(cacheData);
if (data.mempool) { memPool.setMempool(data.mempool);
memPool.setMempool(data.mempool); blocks.setBlocks(data.blocks);
blocks.setBlocks(data.blocks);
} else {
memPool.setMempool(data);
}
} }
} }