mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 22:46:54 +01:00
Make forensics backend call rate limiting configurable
This commit is contained in:
parent
5ff5275b36
commit
3126a559a0
4 changed files with 9 additions and 6 deletions
|
@ -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…
Add table
Reference in a new issue