When we re-index blocks due to mining pools change, wipe the nodejs backend cache

This commit is contained in:
nymkappa 2023-02-26 11:30:12 +09:00
parent b6c7c02a2d
commit 32733a3023
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
2 changed files with 10 additions and 0 deletions

View File

@ -62,6 +62,7 @@ class DiskCache {
} }
wipeCache() { wipeCache() {
logger.notice(`Wipping nodejs backend cache/cache*.json files`);
fs.unlinkSync(DiskCache.FILE_NAME); fs.unlinkSync(DiskCache.FILE_NAME);
for (let i = 1; i < DiskCache.CHUNK_FILES; i++) { for (let i = 1; i < DiskCache.CHUNK_FILES; i++) {
fs.unlinkSync(DiskCache.FILE_NAMES.replace('{number}', i.toString())); fs.unlinkSync(DiskCache.FILE_NAMES.replace('{number}', i.toString()));

View File

@ -3,6 +3,7 @@ import logger from '../logger';
import config from '../config'; import config from '../config';
import PoolsRepository from '../repositories/PoolsRepository'; import PoolsRepository from '../repositories/PoolsRepository';
import { PoolTag } from '../mempool.interfaces'; import { PoolTag } from '../mempool.interfaces';
import diskCache from './disk-cache';
class PoolsParser { class PoolsParser {
miningPools: any[] = []; miningPools: any[] = [];
@ -139,6 +140,10 @@ class PoolsParser {
WHERE pool_id = ?`, WHERE pool_id = ?`,
[pool.id] [pool.id]
); );
// We also need to wipe the backend cache to make sure we don't serve blocks with
// the wrong mining pool (usually happen with unknown blocks)
diskCache.wipeCache();
} }
private async $deleteUnknownBlocks(): Promise<void> { private async $deleteUnknownBlocks(): Promise<void> {
@ -149,6 +154,10 @@ class PoolsParser {
WHERE pool_id = ? AND height >= 130635`, WHERE pool_id = ? AND height >= 130635`,
[unknownPool[0].id] [unknownPool[0].id]
); );
// We also need to wipe the backend cache to make sure we don't serve blocks with
// the wrong mining pool (usually happen with unknown blocks)
diskCache.wipeCache();
} }
} }