Merge pull request #3331 from mempool/mononaut/disk-cache-network-version
Add network versioning to disk cache
This commit is contained in:
commit
ce24b8bb0a
@ -55,6 +55,7 @@ class DiskCache {
|
|||||||
const chunkSize = Math.floor(mempoolArray.length / DiskCache.CHUNK_FILES);
|
const chunkSize = Math.floor(mempoolArray.length / DiskCache.CHUNK_FILES);
|
||||||
|
|
||||||
await fsPromises.writeFile(DiskCache.FILE_NAME, JSON.stringify({
|
await fsPromises.writeFile(DiskCache.FILE_NAME, JSON.stringify({
|
||||||
|
network: config.MEMPOOL.NETWORK,
|
||||||
cacheSchemaVersion: this.cacheSchemaVersion,
|
cacheSchemaVersion: this.cacheSchemaVersion,
|
||||||
blocks: blocks.getBlocks(),
|
blocks: blocks.getBlocks(),
|
||||||
blockSummaries: blocks.getBlockSummaries(),
|
blockSummaries: blocks.getBlockSummaries(),
|
||||||
@ -98,6 +99,7 @@ class DiskCache {
|
|||||||
const chunkSize = Math.floor(mempoolArray.length / DiskCache.CHUNK_FILES);
|
const chunkSize = Math.floor(mempoolArray.length / DiskCache.CHUNK_FILES);
|
||||||
|
|
||||||
fs.writeFileSync(DiskCache.TMP_FILE_NAME, JSON.stringify({
|
fs.writeFileSync(DiskCache.TMP_FILE_NAME, JSON.stringify({
|
||||||
|
network: config.MEMPOOL.NETWORK,
|
||||||
cacheSchemaVersion: this.cacheSchemaVersion,
|
cacheSchemaVersion: this.cacheSchemaVersion,
|
||||||
blocks: blocks.getBlocks(),
|
blocks: blocks.getBlocks(),
|
||||||
blockSummaries: blocks.getBlockSummaries(),
|
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.');
|
logger.notice('Disk cache contains an outdated schema version. Clearing it and skipping the cache loading.');
|
||||||
return this.wipeCache();
|
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) {
|
if (data.mempoolArray) {
|
||||||
for (const tx of data.mempoolArray) {
|
for (const tx of data.mempoolArray) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user