diff --git a/backend/src/api/pools-parser.ts b/backend/src/api/pools-parser.ts index c09f1ba1e..289389d5e 100644 --- a/backend/src/api/pools-parser.ts +++ b/backend/src/api/pools-parser.ts @@ -7,6 +7,7 @@ import diskCache from './disk-cache'; import mining from './mining/mining'; import transactionUtils from './transaction-utils'; import BlocksRepository from '../repositories/BlocksRepository'; +import redisCache from './redis-cache'; class PoolsParser { miningPools: any[] = []; @@ -45,6 +46,7 @@ class PoolsParser { // 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.setIgnoreBlocksCache(); + redisCache.setIgnoreBlocksCache(); await this.$insertUnknownPool(); diff --git a/backend/src/api/redis-cache.ts b/backend/src/api/redis-cache.ts index f4701688e..cbfa2f18b 100644 --- a/backend/src/api/redis-cache.ts +++ b/backend/src/api/redis-cache.ts @@ -27,6 +27,7 @@ class RedisCache { private rbfCacheQueue: { type: string, txid: string, value: any }[] = []; private rbfRemoveQueue: { type: string, txid: string }[] = []; private txFlushLimit: number = 10000; + private ignoreBlocksCache = false; constructor() { if (config.REDIS.ENABLED) { @@ -341,9 +342,7 @@ class RedisCache { return; } logger.info('Restoring mempool and blocks data from Redis cache'); - // Load block data - const loadedBlocks = await this.$getBlocks(); - const loadedBlockSummaries = await this.$getBlockSummaries(); + // Load mempool const loadedMempool = await this.$getMempool(); this.inflateLoadedTxs(loadedMempool); @@ -352,9 +351,14 @@ class RedisCache { const rbfTrees = await this.$getRbfEntries('tree'); const rbfExpirations = await this.$getRbfEntries('exp'); - // Set loaded data - blocks.setBlocks(loadedBlocks || []); - blocks.setBlockSummaries(loadedBlockSummaries || []); + // Load & set block data + if (!this.ignoreBlocksCache) { + const loadedBlocks = await this.$getBlocks(); + const loadedBlockSummaries = await this.$getBlockSummaries(); + blocks.setBlocks(loadedBlocks || []); + blocks.setBlockSummaries(loadedBlockSummaries || []); + } + // Set other data await memPool.$setMempool(loadedMempool); await rbfCache.load({ txs: rbfTxs, @@ -411,6 +415,10 @@ class RedisCache { } return result; } + + public setIgnoreBlocksCache(): void { + this.ignoreBlocksCache = true; + } } export default new RedisCache();