Merge pull request #1797 from mempool/nymkappa/feature/automatic-disk-cache-reset
Skip blocks disk cache loading after db migration
This commit is contained in:
		
						commit
						7764cceb86
					
				| @ -9,6 +9,8 @@ import { TransactionExtended } from '../mempool.interfaces'; | |||||||
| import { Common } from './common'; | import { Common } from './common'; | ||||||
| 
 | 
 | ||||||
| class DiskCache { | class DiskCache { | ||||||
|  |   private cacheSchemaVersion = 1; | ||||||
|  | 
 | ||||||
|   private static FILE_NAME = config.MEMPOOL.CACHE_DIR + '/cache.json'; |   private static FILE_NAME = config.MEMPOOL.CACHE_DIR + '/cache.json'; | ||||||
|   private static FILE_NAMES = config.MEMPOOL.CACHE_DIR + '/cache{number}.json'; |   private static FILE_NAMES = config.MEMPOOL.CACHE_DIR + '/cache{number}.json'; | ||||||
|   private static CHUNK_FILES = 25; |   private static CHUNK_FILES = 25; | ||||||
| @ -57,6 +59,13 @@ class DiskCache { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   wipeCache() { | ||||||
|  |     fs.unlinkSync(DiskCache.FILE_NAME); | ||||||
|  |     for (let i = 1; i < DiskCache.CHUNK_FILES; i++) { | ||||||
|  |       fs.unlinkSync(DiskCache.FILE_NAMES.replace('{number}', i.toString())); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|   loadMempoolCache() { |   loadMempoolCache() { | ||||||
|     if (!fs.existsSync(DiskCache.FILE_NAME)) { |     if (!fs.existsSync(DiskCache.FILE_NAME)) { | ||||||
|       return; |       return; | ||||||
| @ -67,6 +76,11 @@ class DiskCache { | |||||||
|       if (cacheData) { |       if (cacheData) { | ||||||
|         logger.info('Restoring mempool and blocks data from disk cache'); |         logger.info('Restoring mempool and blocks data from disk cache'); | ||||||
|         data = JSON.parse(cacheData); |         data = JSON.parse(cacheData); | ||||||
|  |         if (data.cacheSchemaVersion === undefined || data.cacheSchemaVersion !== this.cacheSchemaVersion) { | ||||||
|  |           logger.notice('Disk cache contains an outdated schema version. Clearing it and skipping the cache loading.'); | ||||||
|  |           return this.wipeCache(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         if (data.mempoolArray) { |         if (data.mempoolArray) { | ||||||
|           for (const tx of data.mempoolArray) { |           for (const tx of data.mempoolArray) { | ||||||
|             data.mempool[tx.txid] = tx; |             data.mempool[tx.txid] = tx; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user