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