From 3bf96dafde8333c7c2616e567e6d71a5502e7824 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sun, 12 Mar 2023 19:20:29 +0900 Subject: [PATCH] Add network versioning to disk cache --- backend/src/api/disk-cache.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/api/disk-cache.ts b/backend/src/api/disk-cache.ts index af04d5acb..74b68b6be 100644 --- a/backend/src/api/disk-cache.ts +++ b/backend/src/api/disk-cache.ts @@ -55,6 +55,7 @@ class DiskCache { const chunkSize = Math.floor(mempoolArray.length / DiskCache.CHUNK_FILES); await fsPromises.writeFile(DiskCache.FILE_NAME, JSON.stringify({ + network: config.MEMPOOL.NETWORK, cacheSchemaVersion: this.cacheSchemaVersion, blocks: blocks.getBlocks(), blockSummaries: blocks.getBlockSummaries(), @@ -98,6 +99,7 @@ class DiskCache { const chunkSize = Math.floor(mempoolArray.length / DiskCache.CHUNK_FILES); fs.writeFileSync(DiskCache.TMP_FILE_NAME, JSON.stringify({ + network: config.MEMPOOL.NETWORK, cacheSchemaVersion: this.cacheSchemaVersion, blocks: blocks.getBlocks(), blockSummaries: blocks.getBlockSummaries(), @@ -160,6 +162,10 @@ class DiskCache { logger.notice('Disk cache contains an outdated schema version. Clearing it and skipping the cache loading.'); return this.wipeCache(); } + if (data.network && data.network !== config.MEMPOOL.NETWORK) { + logger.notice('Disk cache contains data from a different network. Clearing it and skipping the cache loading.'); + return this.wipeCache(); + } if (data.mempoolArray) { for (const tx of data.mempoolArray) {