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