await for mempool change handler after loading disk cache

This commit is contained in:
Mononaut 2023-04-30 13:59:29 -06:00
parent ba4253da79
commit f30cf70226
No known key found for this signature in database
GPG key ID: A3F058E41374C04E
4 changed files with 6 additions and 6 deletions

View file

@ -124,7 +124,7 @@ class DiskCache {
}
}
loadMempoolCache(): void {
async loadMempoolCache(): Promise<void> {
if (!fs.existsSync(DiskCache.FILE_NAME)) {
return;
}
@ -168,7 +168,7 @@ class DiskCache {
}
}
memPool.setMempool(data.mempool);
await memPool.setMempool(data.mempool);
blocks.setBlocks(data.blocks);
blocks.setBlockSummaries(data.blockSummaries || []);
} catch (e) {

View file

@ -205,7 +205,7 @@ class MempoolBlocks {
public async updateBlockTemplates(newMempool: { [txid: string]: TransactionExtended }, added: TransactionExtended[], removed: string[], saveResults: boolean = false): Promise<void> {
if (!this.txSelectionWorker) {
// need to reset the worker
this.makeBlockTemplates(newMempool, saveResults);
await this.makeBlockTemplates(newMempool, saveResults);
return;
}
// prepare a stripped down version of the mempool with only the minimum necessary data

View file

@ -80,13 +80,13 @@ class Mempool {
return this.mempoolCache;
}
public setMempool(mempoolData: { [txId: string]: TransactionExtended }) {
public async setMempool(mempoolData: { [txId: string]: TransactionExtended }) {
this.mempoolCache = mempoolData;
if (this.mempoolChangedCallback) {
this.mempoolChangedCallback(this.mempoolCache, [], []);
}
if (this.asyncMempoolChangedCallback) {
this.asyncMempoolChangedCallback(this.mempoolCache, [], []);
await this.asyncMempoolChangedCallback(this.mempoolCache, [], []);
}
}

View file

@ -120,7 +120,7 @@ class Server {
await poolsUpdater.updatePoolsJson(); // Needs to be done before loading the disk cache because we sometimes wipe it
await syncAssets.syncAssets$();
if (config.MEMPOOL.ENABLED) {
diskCache.loadMempoolCache();
await diskCache.loadMempoolCache();
}
if (config.STATISTICS.ENABLED && config.DATABASE.ENABLED && cluster.isPrimary) {