fix gbt mempool size mismatch bug
This commit is contained in:
		
							parent
							
								
									a6edfcc272
								
							
						
					
					
						commit
						2d463326e0
					
				@ -104,10 +104,11 @@ class Mempool {
 | 
			
		||||
    this.addToSpendMap(Object.values(this.mempoolCache));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $reloadMempool(expectedCount: number): Promise<void> {
 | 
			
		||||
  public async $reloadMempool(expectedCount: number): Promise<MempoolTransactionExtended[]> {
 | 
			
		||||
    let count = 0;
 | 
			
		||||
    let done = false;
 | 
			
		||||
    let last_txid;
 | 
			
		||||
    const newTransactions: MempoolTransactionExtended[] = [];
 | 
			
		||||
    loadingIndicators.setProgress('mempool', count / expectedCount * 100);
 | 
			
		||||
    while (!done) {
 | 
			
		||||
      try {
 | 
			
		||||
@ -115,7 +116,10 @@ class Mempool {
 | 
			
		||||
        if (result) {
 | 
			
		||||
          for (const tx of result) {
 | 
			
		||||
            const extendedTransaction = transactionUtils.extendMempoolTransaction(tx);
 | 
			
		||||
            this.mempoolCache[extendedTransaction.txid] = extendedTransaction;
 | 
			
		||||
            if (!this.mempoolCache[extendedTransaction.txid]) {
 | 
			
		||||
              newTransactions.push(extendedTransaction);
 | 
			
		||||
              this.mempoolCache[extendedTransaction.txid] = extendedTransaction;
 | 
			
		||||
            }
 | 
			
		||||
            count++;
 | 
			
		||||
          }
 | 
			
		||||
          logger.info(`Fetched ${count} of ${expectedCount} mempool transactions from esplora`);
 | 
			
		||||
@ -134,6 +138,7 @@ class Mempool {
 | 
			
		||||
        logger.err('failed to fetch bulk mempool transactions from esplora');
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return newTransactions;
 | 
			
		||||
    logger.info(`Done inserting loaded mempool transactions into local cache`);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -177,7 +182,7 @@ class Mempool {
 | 
			
		||||
    const currentMempoolSize = Object.keys(this.mempoolCache).length;
 | 
			
		||||
    this.updateTimerProgress(timer, 'got raw mempool');
 | 
			
		||||
    const diff = transactions.length - currentMempoolSize;
 | 
			
		||||
    const newTransactions: MempoolTransactionExtended[] = [];
 | 
			
		||||
    let newTransactions: MempoolTransactionExtended[] = [];
 | 
			
		||||
 | 
			
		||||
    this.mempoolCacheDelta = Math.abs(diff);
 | 
			
		||||
 | 
			
		||||
@ -202,7 +207,7 @@ class Mempool {
 | 
			
		||||
      this.inSync = false;
 | 
			
		||||
      logger.info(`Missing ${transactions.length - currentMempoolSize} mempool transactions, attempting to reload in bulk from esplora`);
 | 
			
		||||
      try {
 | 
			
		||||
        await this.$reloadMempool(transactions.length);
 | 
			
		||||
        newTransactions = await this.$reloadMempool(transactions.length);
 | 
			
		||||
        loaded = true;
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
        logger.err('failed to load mempool in bulk from esplora, falling back to fetching individual transactions');
 | 
			
		||||
 | 
			
		||||
@ -604,7 +604,7 @@ class WebsocketHandler {
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (client['track-mempool-block'] >= 0) {
 | 
			
		||||
      if (client['track-mempool-block'] >= 0 && memPool.isInSync()) {
 | 
			
		||||
        const index = client['track-mempool-block'];
 | 
			
		||||
        if (mBlockDeltas[index]) {
 | 
			
		||||
          response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-${index}`, {
 | 
			
		||||
@ -858,7 +858,7 @@ class WebsocketHandler {
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (client['track-mempool-block'] >= 0) {
 | 
			
		||||
      if (client['track-mempool-block'] >= 0 && memPool.isInSync()) {
 | 
			
		||||
        const index = client['track-mempool-block'];
 | 
			
		||||
        if (mBlockDeltas && mBlockDeltas[index]) {
 | 
			
		||||
          response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-${index}`, {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user