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