await for mempool change handler after loading disk cache
This commit is contained in:
		
							parent
							
								
									ba4253da79
								
							
						
					
					
						commit
						f30cf70226
					
				@ -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) {
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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, [], []);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user