Merge pull request #2777 from mempool/mononaut/ln-scan-throttle-config
Make forensics node backend call rate limiting configurable
This commit is contained in:
		
						commit
						906c599bd7
					
				@ -85,7 +85,8 @@
 | 
				
			|||||||
    "STATS_REFRESH_INTERVAL": 600,
 | 
					    "STATS_REFRESH_INTERVAL": 600,
 | 
				
			||||||
    "GRAPH_REFRESH_INTERVAL": 600,
 | 
					    "GRAPH_REFRESH_INTERVAL": 600,
 | 
				
			||||||
    "LOGGER_UPDATE_INTERVAL": 30,
 | 
					    "LOGGER_UPDATE_INTERVAL": 30,
 | 
				
			||||||
    "FORENSICS_INTERVAL": 43200
 | 
					    "FORENSICS_INTERVAL": 43200,
 | 
				
			||||||
 | 
					    "FORENSICS_RATE_LIMIT": 20
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "LND": {
 | 
					  "LND": {
 | 
				
			||||||
    "TLS_CERT_PATH": "tls.cert",
 | 
					    "TLS_CERT_PATH": "tls.cert",
 | 
				
			||||||
 | 
				
			|||||||
@ -101,7 +101,8 @@
 | 
				
			|||||||
    "STATS_REFRESH_INTERVAL": 600,
 | 
					    "STATS_REFRESH_INTERVAL": 600,
 | 
				
			||||||
    "GRAPH_REFRESH_INTERVAL": 600,
 | 
					    "GRAPH_REFRESH_INTERVAL": 600,
 | 
				
			||||||
    "LOGGER_UPDATE_INTERVAL": 30,
 | 
					    "LOGGER_UPDATE_INTERVAL": 30,
 | 
				
			||||||
    "FORENSICS_INTERVAL": 43200
 | 
					    "FORENSICS_INTERVAL": 43200,
 | 
				
			||||||
 | 
					    "FORENSICS_RATE_LIMIT": "__FORENSICS_RATE_LIMIT__"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "LND": {
 | 
					  "LND": {
 | 
				
			||||||
    "TLS_CERT_PATH": "",
 | 
					    "TLS_CERT_PATH": "",
 | 
				
			||||||
 | 
				
			|||||||
@ -44,6 +44,7 @@ interface IConfig {
 | 
				
			|||||||
    GRAPH_REFRESH_INTERVAL: number;
 | 
					    GRAPH_REFRESH_INTERVAL: number;
 | 
				
			||||||
    LOGGER_UPDATE_INTERVAL: number;
 | 
					    LOGGER_UPDATE_INTERVAL: number;
 | 
				
			||||||
    FORENSICS_INTERVAL: number;
 | 
					    FORENSICS_INTERVAL: number;
 | 
				
			||||||
 | 
					    FORENSICS_RATE_LIMIT: number;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  LND: {
 | 
					  LND: {
 | 
				
			||||||
    TLS_CERT_PATH: string;
 | 
					    TLS_CERT_PATH: string;
 | 
				
			||||||
@ -205,6 +206,7 @@ const defaults: IConfig = {
 | 
				
			|||||||
    'GRAPH_REFRESH_INTERVAL': 600,
 | 
					    'GRAPH_REFRESH_INTERVAL': 600,
 | 
				
			||||||
    'LOGGER_UPDATE_INTERVAL': 30,
 | 
					    'LOGGER_UPDATE_INTERVAL': 30,
 | 
				
			||||||
    'FORENSICS_INTERVAL': 43200,
 | 
					    'FORENSICS_INTERVAL': 43200,
 | 
				
			||||||
 | 
					    'FORENSICS_RATE_LIMIT': 20,
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'LND': {
 | 
					  'LND': {
 | 
				
			||||||
    'TLS_CERT_PATH': '',
 | 
					    'TLS_CERT_PATH': '',
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,6 @@ import { IEsploraApi } from '../../api/bitcoin/esplora-api.interface';
 | 
				
			|||||||
import { Common } from '../../api/common';
 | 
					import { Common } from '../../api/common';
 | 
				
			||||||
import { ILightningApi } from '../../api/lightning/lightning-api.interface';
 | 
					import { ILightningApi } from '../../api/lightning/lightning-api.interface';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const throttleDelay = 20; //ms
 | 
					 | 
				
			||||||
const tempCacheSize = 10000;
 | 
					const tempCacheSize = 10000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ForensicsService {
 | 
					class ForensicsService {
 | 
				
			||||||
@ -91,7 +90,7 @@ class ForensicsService {
 | 
				
			|||||||
          let outspends: IEsploraApi.Outspend[] | undefined;
 | 
					          let outspends: IEsploraApi.Outspend[] | undefined;
 | 
				
			||||||
          try {
 | 
					          try {
 | 
				
			||||||
            outspends = await bitcoinApi.$getOutspends(channel.closing_transaction_id);
 | 
					            outspends = await bitcoinApi.$getOutspends(channel.closing_transaction_id);
 | 
				
			||||||
            await Common.sleep$(throttleDelay);
 | 
					            await Common.sleep$(config.LIGHTNING.FORENSICS_RATE_LIMIT);
 | 
				
			||||||
          } catch (e) {
 | 
					          } catch (e) {
 | 
				
			||||||
            logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + channel.closing_transaction_id + '/outspends'}. Reason ${e instanceof Error ? e.message : e}`);
 | 
					            logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + channel.closing_transaction_id + '/outspends'}. Reason ${e instanceof Error ? e.message : e}`);
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
@ -340,7 +339,7 @@ class ForensicsService {
 | 
				
			|||||||
      let outspends: IEsploraApi.Outspend[] | undefined;
 | 
					      let outspends: IEsploraApi.Outspend[] | undefined;
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
        outspends = await bitcoinApi.$getOutspends(input.txid);
 | 
					        outspends = await bitcoinApi.$getOutspends(input.txid);
 | 
				
			||||||
        await Common.sleep$(throttleDelay);
 | 
					        await Common.sleep$(config.LIGHTNING.FORENSICS_RATE_LIMIT);
 | 
				
			||||||
      } catch (e) {
 | 
					      } catch (e) {
 | 
				
			||||||
        logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + input.txid + '/outspends'}. Reason ${e instanceof Error ? e.message : e}`);
 | 
					        logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + input.txid + '/outspends'}. Reason ${e instanceof Error ? e.message : e}`);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -429,7 +428,7 @@ class ForensicsService {
 | 
				
			|||||||
        if (temp) {
 | 
					        if (temp) {
 | 
				
			||||||
          this.tempCached.push(txid);
 | 
					          this.tempCached.push(txid);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        await Common.sleep$(throttleDelay);
 | 
					        await Common.sleep$(config.LIGHTNING.FORENSICS_RATE_LIMIT);
 | 
				
			||||||
      } catch (e) {
 | 
					      } catch (e) {
 | 
				
			||||||
        logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + txid + '/outspends'}. Reason ${e instanceof Error ? e.message : e}`);
 | 
					        logger.err(`Failed to call ${config.ESPLORA.REST_API_URL + '/tx/' + txid + '/outspends'}. Reason ${e instanceof Error ? e.message : e}`);
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user