mirror of
https://github.com/mempool/mempool.git
synced 2025-03-04 01:54:14 +01:00
Reset scrolling blockchain cache when network changes
This commit is contained in:
parent
ec7f0d1143
commit
f09a2aab24
1 changed files with 20 additions and 5 deletions
|
@ -17,6 +17,7 @@ export class CacheService {
|
||||||
|
|
||||||
txCache: { [txid: string]: Transaction } = {};
|
txCache: { [txid: string]: Transaction } = {};
|
||||||
|
|
||||||
|
network: string;
|
||||||
blockCache: { [height: number]: BlockExtended } = {};
|
blockCache: { [height: number]: BlockExtended } = {};
|
||||||
blockLoading: { [height: number]: boolean } = {};
|
blockLoading: { [height: number]: boolean } = {};
|
||||||
copiesInBlockQueue: { [height: number]: number } = {};
|
copiesInBlockQueue: { [height: number]: number } = {};
|
||||||
|
@ -33,6 +34,10 @@ export class CacheService {
|
||||||
this.stateService.chainTip$.subscribe((height) => {
|
this.stateService.chainTip$.subscribe((height) => {
|
||||||
this.tip = height;
|
this.tip = height;
|
||||||
});
|
});
|
||||||
|
this.stateService.networkChanged$.subscribe((network) => {
|
||||||
|
this.network = network;
|
||||||
|
this.resetBlockCache();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTxCache(transactions) {
|
setTxCache(transactions) {
|
||||||
|
@ -68,15 +73,17 @@ export class CacheService {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("failed to load blocks: ", e.message);
|
console.log("failed to load blocks: ", e.message);
|
||||||
}
|
}
|
||||||
for (let i = 0; i < chunkSize; i++) {
|
|
||||||
delete this.blockLoading[maxHeight - i];
|
|
||||||
}
|
|
||||||
if (result && result.length) {
|
if (result && result.length) {
|
||||||
result.forEach(block => {
|
result.forEach(block => {
|
||||||
this.addBlockToCache(block);
|
if (this.blockLoading[block.height]) {
|
||||||
this.loadedBlocks$.next(block);
|
this.addBlockToCache(block);
|
||||||
|
this.loadedBlocks$.next(block);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
for (let i = 0; i < chunkSize; i++) {
|
||||||
|
delete this.blockLoading[maxHeight - i];
|
||||||
|
}
|
||||||
this.clearBlocks();
|
this.clearBlocks();
|
||||||
} else {
|
} else {
|
||||||
this.bumpBlockPriority(height);
|
this.bumpBlockPriority(height);
|
||||||
|
@ -104,6 +111,14 @@ export class CacheService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove all blocks from the cache
|
||||||
|
resetBlockCache() {
|
||||||
|
this.blockCache = {};
|
||||||
|
this.blockLoading = {};
|
||||||
|
this.copiesInBlockQueue = {};
|
||||||
|
this.blockPriorities = [];
|
||||||
|
}
|
||||||
|
|
||||||
getCachedBlock(height) {
|
getCachedBlock(height) {
|
||||||
return this.blockCache[height];
|
return this.blockCache[height];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue