mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 06:35:15 +01:00
Config file updates. electrs -> esplora
This commit is contained in:
parent
29dd6e5d8d
commit
dc63fd9428
6 changed files with 32 additions and 34 deletions
|
@ -5,16 +5,15 @@
|
|||
"HTTP_PORT": 8999,
|
||||
"SPAWN_CLUSTER_PROCS": 0,
|
||||
"API_URL_PREFIX": "/api/v1/",
|
||||
"WEBSOCKET_REFRESH_RATE_MS": 2000
|
||||
},
|
||||
"ELECTRS": {
|
||||
"REST_API_URL": "http://127.0.0.1:3000",
|
||||
"POLL_RATE_MS": 2000
|
||||
},
|
||||
"ESPLORA": {
|
||||
"REST_API_URL": "http://127.0.0.1:3000"
|
||||
},
|
||||
"ELECTRUM": {
|
||||
"HOST": "127.0.0.1",
|
||||
"PORT": 50002,
|
||||
"PROTOCOL": "tcl",
|
||||
"TLS_ENABLED": true,
|
||||
"TX_LOOKUPS": false
|
||||
},
|
||||
"BITCOIND": {
|
||||
|
|
|
@ -30,7 +30,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
|
|||
this.electrumClient = new ElectrumClient(
|
||||
config.ELECTRUM.PORT,
|
||||
config.ELECTRUM.HOST,
|
||||
config.ELECTRUM.PROTOCOL,
|
||||
config.ELECTRUM.TLS_ENABLED ? 'tls' : 'tcp',
|
||||
null,
|
||||
electrumCallbacks
|
||||
);
|
||||
|
|
|
@ -8,32 +8,32 @@ class ElectrsApi implements AbstractBitcoinApi {
|
|||
constructor() { }
|
||||
|
||||
$getRawMempool(): Promise<IEsploraApi.Transaction['txid'][]> {
|
||||
return axios.get<IEsploraApi.Transaction['txid'][]>(config.ELECTRS.REST_API_URL + '/mempool/txids')
|
||||
return axios.get<IEsploraApi.Transaction['txid'][]>(config.ESPLORA.REST_API_URL + '/mempool/txids')
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
$getRawTransaction(txId: string): Promise<IEsploraApi.Transaction> {
|
||||
return axios.get<IEsploraApi.Transaction>(config.ELECTRS.REST_API_URL + '/tx/' + txId)
|
||||
return axios.get<IEsploraApi.Transaction>(config.ESPLORA.REST_API_URL + '/tx/' + txId)
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
$getBlockHeightTip(): Promise<number> {
|
||||
return axios.get<number>(config.ELECTRS.REST_API_URL + '/blocks/tip/height')
|
||||
return axios.get<number>(config.ESPLORA.REST_API_URL + '/blocks/tip/height')
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
$getTxIdsForBlock(hash: string): Promise<string[]> {
|
||||
return axios.get<string[]>(config.ELECTRS.REST_API_URL + '/block/' + hash + '/txids')
|
||||
return axios.get<string[]>(config.ESPLORA.REST_API_URL + '/block/' + hash + '/txids')
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
$getBlockHash(height: number): Promise<string> {
|
||||
return axios.get<string>(config.ELECTRS.REST_API_URL + '/block-height/' + height)
|
||||
return axios.get<string>(config.ESPLORA.REST_API_URL + '/block-height/' + height)
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
$getBlock(hash: string): Promise<IEsploraApi.Block> {
|
||||
return axios.get<IEsploraApi.Block>(config.ELECTRS.REST_API_URL + '/block/' + hash)
|
||||
return axios.get<IEsploraApi.Block>(config.ESPLORA.REST_API_URL + '/block/' + hash)
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class ElectrsApi implements AbstractBitcoinApi {
|
|||
}
|
||||
|
||||
$getRawTransactionBitcoind(txId: string): Promise<IEsploraApi.Transaction> {
|
||||
return axios.get<IEsploraApi.Transaction>(config.ELECTRS.REST_API_URL + '/tx/' + txId)
|
||||
return axios.get<IEsploraApi.Transaction>(config.ESPLORA.REST_API_URL + '/tx/' + txId)
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import bitcoinBaseApi from './bitcoin/bitcoin-base.api';
|
|||
import loadingIndicators from './loading-indicators';
|
||||
|
||||
class Mempool {
|
||||
private static WEBSOCKET_REFRESH_RATE_MS = 10000;
|
||||
private inSync: boolean = false;
|
||||
private mempoolCache: { [txId: string]: TransactionExtended } = {};
|
||||
private mempoolInfo: IBitcoinApi.MempoolInfo = { loaded: false, size: 0, bytes: 0, usage: 0,
|
||||
|
@ -120,7 +121,7 @@ class Mempool {
|
|||
}
|
||||
}
|
||||
|
||||
if ((new Date().getTime()) - start > config.MEMPOOL.WEBSOCKET_REFRESH_RATE_MS * 10) {
|
||||
if ((new Date().getTime()) - start > Mempool.WEBSOCKET_REFRESH_RATE_MS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,15 @@ interface IConfig {
|
|||
HTTP_PORT: number;
|
||||
SPAWN_CLUSTER_PROCS: number;
|
||||
API_URL_PREFIX: string;
|
||||
WEBSOCKET_REFRESH_RATE_MS: number;
|
||||
};
|
||||
ELECTRS: {
|
||||
REST_API_URL: string;
|
||||
POLL_RATE_MS: number;
|
||||
};
|
||||
ESPLORA: {
|
||||
REST_API_URL: string;
|
||||
};
|
||||
ELECTRUM: {
|
||||
HOST: string;
|
||||
PORT: number;
|
||||
PROTOCOL: 'tls' | 'tcp';
|
||||
TLS_ENABLED: boolean;
|
||||
TX_LOOKUPS: boolean;
|
||||
};
|
||||
BITCOIND: {
|
||||
|
@ -61,16 +60,15 @@ const defaults: IConfig = {
|
|||
'HTTP_PORT': 8999,
|
||||
'SPAWN_CLUSTER_PROCS': 0,
|
||||
'API_URL_PREFIX': '/api/v1/',
|
||||
'WEBSOCKET_REFRESH_RATE_MS': 2000
|
||||
},
|
||||
'ELECTRS': {
|
||||
'REST_API_URL': 'http://127.0.0.1:3000',
|
||||
'POLL_RATE_MS': 2000
|
||||
},
|
||||
'ESPLORA': {
|
||||
'REST_API_URL': 'http://127.0.0.1:3000',
|
||||
},
|
||||
'ELECTRUM': {
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': 3306,
|
||||
'PROTOCOL': 'tls',
|
||||
'TLS_ENABLED': true,
|
||||
'TX_LOOKUPS': false
|
||||
},
|
||||
'BITCOIND': {
|
||||
|
@ -110,7 +108,7 @@ const defaults: IConfig = {
|
|||
|
||||
class Config implements IConfig {
|
||||
MEMPOOL: IConfig['MEMPOOL'];
|
||||
ELECTRS: IConfig['ELECTRS'];
|
||||
ESPLORA: IConfig['ESPLORA'];
|
||||
ELECTRUM: IConfig['ELECTRUM'];
|
||||
BITCOIND: IConfig['BITCOIND'];
|
||||
DATABASE: IConfig['DATABASE'];
|
||||
|
@ -122,7 +120,7 @@ class Config implements IConfig {
|
|||
constructor() {
|
||||
const configs = this.merge(configFile, defaults);
|
||||
this.MEMPOOL = configs.MEMPOOL;
|
||||
this.ELECTRS = configs.ELECTRS;
|
||||
this.ESPLORA = configs.ESPLORA;
|
||||
this.ELECTRUM = configs.ELECTRUM;
|
||||
this.BITCOIND = configs.BITCOIND;
|
||||
this.DATABASE = configs.DATABASE;
|
||||
|
|
|
@ -26,7 +26,7 @@ class Server {
|
|||
private wss: WebSocket.Server | undefined;
|
||||
private server: https.Server | http.Server | undefined;
|
||||
private app: Express;
|
||||
private retryOnElectrsErrorAfterSeconds = 5;
|
||||
private currentBackendRetryInterval = 5;
|
||||
|
||||
constructor() {
|
||||
this.app = express();
|
||||
|
@ -111,19 +111,19 @@ class Server {
|
|||
await memPool.$updateMemPoolInfo();
|
||||
await blocks.$updateBlocks();
|
||||
await memPool.$updateMempool();
|
||||
setTimeout(this.runMainUpdateLoop.bind(this), config.ELECTRS.POLL_RATE_MS);
|
||||
this.retryOnElectrsErrorAfterSeconds = 5;
|
||||
setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS);
|
||||
this.currentBackendRetryInterval = 5;
|
||||
} catch (e) {
|
||||
const loggerMsg = `runMainLoop error: ${(e.message || e)}. Retrying in ${this.retryOnElectrsErrorAfterSeconds} sec.`;
|
||||
if (this.retryOnElectrsErrorAfterSeconds > 5) {
|
||||
const loggerMsg = `runMainLoop error: ${(e.message || e)}. Retrying in ${this.currentBackendRetryInterval} sec.`;
|
||||
if (this.currentBackendRetryInterval > 5) {
|
||||
logger.warn(loggerMsg);
|
||||
} else {
|
||||
logger.debug(loggerMsg);
|
||||
}
|
||||
logger.debug(JSON.stringify(e));
|
||||
setTimeout(this.runMainUpdateLoop.bind(this), 1000 * this.retryOnElectrsErrorAfterSeconds);
|
||||
this.retryOnElectrsErrorAfterSeconds *= 2;
|
||||
this.retryOnElectrsErrorAfterSeconds = Math.min(this.retryOnElectrsErrorAfterSeconds, 60);
|
||||
setTimeout(this.runMainUpdateLoop.bind(this), 1000 * this.currentBackendRetryInterval);
|
||||
this.currentBackendRetryInterval *= 2;
|
||||
this.currentBackendRetryInterval = Math.min(this.currentBackendRetryInterval, 60);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue