From aeb896e200281af1bdb2190c9dd64612eac583a0 Mon Sep 17 00:00:00 2001 From: softsimon Date: Thu, 25 May 2023 19:05:29 +0400 Subject: [PATCH 1/2] Don't wipe mempool cache in pools updater --- backend/src/api/disk-cache.ts | 11 +++++++++-- backend/src/api/pools-parser.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/src/api/disk-cache.ts b/backend/src/api/disk-cache.ts index 0264fe1a3..2e3ff6fb1 100644 --- a/backend/src/api/disk-cache.ts +++ b/backend/src/api/disk-cache.ts @@ -21,6 +21,7 @@ class DiskCache { private static RBF_FILE_NAME = config.MEMPOOL.CACHE_DIR + '/rbfcache.json'; private static CHUNK_FILES = 25; private isWritingCache = false; + private ignoreBlocksCache = false; private semaphore: { resume: (() => void)[], locks: number } = { resume: [], @@ -218,8 +219,10 @@ class DiskCache { } await memPool.$setMempool(data.mempool); - blocks.setBlocks(data.blocks); - blocks.setBlockSummaries(data.blockSummaries || []); + if (!this.ignoreBlocksCache) { + blocks.setBlocks(data.blocks); + blocks.setBlockSummaries(data.blockSummaries || []); + } } catch (e) { logger.warn('Failed to parse mempoool and blocks cache. Skipping. Reason: ' + (e instanceof Error ? e.message : e)); } @@ -273,6 +276,10 @@ class DiskCache { } } } + + public setIgnoreBlocksCache(): void { + this.ignoreBlocksCache = true; + } } export default new DiskCache(); diff --git a/backend/src/api/pools-parser.ts b/backend/src/api/pools-parser.ts index f94c147a2..7397c5639 100644 --- a/backend/src/api/pools-parser.ts +++ b/backend/src/api/pools-parser.ts @@ -41,7 +41,7 @@ class PoolsParser { public async migratePoolsJson(): Promise { // 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(); + diskCache.setIgnoreBlocksCache(); await this.$insertUnknownPool(); From 038f9659bb9b55c5634729f5e6aef1a8a5160256 Mon Sep 17 00:00:00 2001 From: softsimon Date: Thu, 25 May 2023 19:19:14 +0400 Subject: [PATCH 2/2] Save new disk cache after ignoring blocks --- backend/src/api/disk-cache.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/api/disk-cache.ts b/backend/src/api/disk-cache.ts index 2e3ff6fb1..17d75d07b 100644 --- a/backend/src/api/disk-cache.ts +++ b/backend/src/api/disk-cache.ts @@ -222,6 +222,9 @@ class DiskCache { if (!this.ignoreBlocksCache) { blocks.setBlocks(data.blocks); blocks.setBlockSummaries(data.blockSummaries || []); + } else { + logger.info('Re-saving cache with empty recent blocks data'); + await this.$saveCacheToDisk(true); } } catch (e) { logger.warn('Failed to parse mempoool and blocks cache. Skipping. Reason: ' + (e instanceof Error ? e.message : e));