Avoid logging statistics while affected by esplora failover
This commit is contained in:
parent
83c285e17d
commit
9a8e5b7896
@ -25,6 +25,7 @@ export interface AbstractBitcoinApi {
|
|||||||
$getBatchedOutspends(txId: string[]): Promise<IEsploraApi.Outspend[][]>;
|
$getBatchedOutspends(txId: string[]): Promise<IEsploraApi.Outspend[][]>;
|
||||||
|
|
||||||
startHealthChecks(): void;
|
startHealthChecks(): void;
|
||||||
|
isFailedOver(): boolean;
|
||||||
}
|
}
|
||||||
export interface BitcoinRpcCredentials {
|
export interface BitcoinRpcCredentials {
|
||||||
host: string;
|
host: string;
|
||||||
|
@ -356,6 +356,9 @@ class BitcoinApi implements AbstractBitcoinApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public startHealthChecks(): void {};
|
public startHealthChecks(): void {};
|
||||||
|
public isFailedOver(): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BitcoinApi;
|
export default BitcoinApi;
|
||||||
|
@ -17,6 +17,8 @@ interface FailoverHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FailoverRouter {
|
class FailoverRouter {
|
||||||
|
isFailedOver: boolean = false;
|
||||||
|
preferredHost: FailoverHost;
|
||||||
activeHost: FailoverHost;
|
activeHost: FailoverHost;
|
||||||
fallbackHost: FailoverHost;
|
fallbackHost: FailoverHost;
|
||||||
hosts: FailoverHost[];
|
hosts: FailoverHost[];
|
||||||
@ -46,6 +48,7 @@ class FailoverRouter {
|
|||||||
socket: !!config.ESPLORA.UNIX_SOCKET_PATH,
|
socket: !!config.ESPLORA.UNIX_SOCKET_PATH,
|
||||||
preferred: true,
|
preferred: true,
|
||||||
};
|
};
|
||||||
|
this.preferredHost = this.activeHost;
|
||||||
this.fallbackHost = this.activeHost;
|
this.fallbackHost = this.activeHost;
|
||||||
this.hosts.unshift(this.activeHost);
|
this.hosts.unshift(this.activeHost);
|
||||||
this.multihost = this.hosts.length > 1;
|
this.multihost = this.hosts.length > 1;
|
||||||
@ -151,6 +154,7 @@ class FailoverRouter {
|
|||||||
this.sortHosts();
|
this.sortHosts();
|
||||||
this.activeHost = this.hosts[0];
|
this.activeHost = this.hosts[0];
|
||||||
logger.warn(`Switching esplora host to ${this.activeHost.host}`);
|
logger.warn(`Switching esplora host to ${this.activeHost.host}`);
|
||||||
|
this.isFailedOver = this.activeHost !== this.preferredHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private addFailure(host: FailoverHost): FailoverHost {
|
private addFailure(host: FailoverHost): FailoverHost {
|
||||||
@ -302,6 +306,10 @@ class ElectrsApi implements AbstractBitcoinApi {
|
|||||||
public startHealthChecks(): void {
|
public startHealthChecks(): void {
|
||||||
this.failoverRouter.startHealthChecks();
|
this.failoverRouter.startHealthChecks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isFailedOver(): boolean {
|
||||||
|
return this.failoverRouter.isFailedOver;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ElectrsApi;
|
export default ElectrsApi;
|
||||||
|
@ -26,6 +26,9 @@ class Mempool {
|
|||||||
|
|
||||||
private accelerations: { [txId: string]: Acceleration } = {};
|
private accelerations: { [txId: string]: Acceleration } = {};
|
||||||
|
|
||||||
|
private failoverTimes: number[] = [];
|
||||||
|
private statisticsPaused: boolean = false;
|
||||||
|
|
||||||
private txPerSecondArray: number[] = [];
|
private txPerSecondArray: number[] = [];
|
||||||
private txPerSecond: number = 0;
|
private txPerSecond: number = 0;
|
||||||
|
|
||||||
@ -164,6 +167,10 @@ class Mempool {
|
|||||||
return this.mempoolInfo;
|
return this.mempoolInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getStatisticsIsPaused(): boolean {
|
||||||
|
return this.statisticsPaused;
|
||||||
|
}
|
||||||
|
|
||||||
public getTxPerSecond(): number {
|
public getTxPerSecond(): number {
|
||||||
return this.txPerSecond;
|
return this.txPerSecond;
|
||||||
}
|
}
|
||||||
@ -242,6 +249,10 @@ class Mempool {
|
|||||||
logger.debug(`fetched ${txs.length} transactions`);
|
logger.debug(`fetched ${txs.length} transactions`);
|
||||||
this.updateTimerProgress(timer, 'fetched new transactions');
|
this.updateTimerProgress(timer, 'fetched new transactions');
|
||||||
|
|
||||||
|
if (bitcoinApi.isFailedOver()) {
|
||||||
|
this.failoverTimes.push(Date.now());
|
||||||
|
}
|
||||||
|
|
||||||
for (const transaction of txs) {
|
for (const transaction of txs) {
|
||||||
this.mempoolCache[transaction.txid] = transaction;
|
this.mempoolCache[transaction.txid] = transaction;
|
||||||
if (this.inSync) {
|
if (this.inSync) {
|
||||||
@ -259,6 +270,10 @@ class Mempool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bitcoinApi.isFailedOver()) {
|
||||||
|
this.failoverTimes.push(Date.now());
|
||||||
|
}
|
||||||
|
|
||||||
if (txs.length < slice.length) {
|
if (txs.length < slice.length) {
|
||||||
const missing = slice.length - txs.length;
|
const missing = slice.length - txs.length;
|
||||||
if (config.MEMPOOL.BACKEND === 'esplora') {
|
if (config.MEMPOOL.BACKEND === 'esplora') {
|
||||||
@ -491,6 +506,10 @@ class Mempool {
|
|||||||
|
|
||||||
private updateTxPerSecond() {
|
private updateTxPerSecond() {
|
||||||
const nowMinusTimeSpan = new Date().getTime() - (1000 * config.STATISTICS.TX_PER_SECOND_SAMPLE_PERIOD);
|
const nowMinusTimeSpan = new Date().getTime() - (1000 * config.STATISTICS.TX_PER_SECOND_SAMPLE_PERIOD);
|
||||||
|
|
||||||
|
this.failoverTimes = this.failoverTimes.filter((unixTime) => unixTime > nowMinusTimeSpan);
|
||||||
|
this.statisticsPaused = this.failoverTimes.length > 0;
|
||||||
|
|
||||||
this.txPerSecondArray = this.txPerSecondArray.filter((unixTime) => unixTime > nowMinusTimeSpan);
|
this.txPerSecondArray = this.txPerSecondArray.filter((unixTime) => unixTime > nowMinusTimeSpan);
|
||||||
this.txPerSecond = this.txPerSecondArray.length / config.STATISTICS.TX_PER_SECOND_SAMPLE_PERIOD || 0;
|
this.txPerSecond = this.txPerSecondArray.length / config.STATISTICS.TX_PER_SECOND_SAMPLE_PERIOD || 0;
|
||||||
|
|
||||||
|
@ -29,9 +29,10 @@ class Statistics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async runStatistics(): Promise<void> {
|
private async runStatistics(): Promise<void> {
|
||||||
if (!memPool.isInSync()) {
|
if (!memPool.isInSync() || memPool.getStatisticsIsPaused()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentMempool = memPool.getMempool();
|
const currentMempool = memPool.getMempool();
|
||||||
const txPerSecond = memPool.getTxPerSecond();
|
const txPerSecond = memPool.getTxPerSecond();
|
||||||
const vBytesPerSecond = memPool.getVBytesPerSecond();
|
const vBytesPerSecond = memPool.getVBytesPerSecond();
|
||||||
|
@ -73,7 +73,7 @@ class WebsocketHandler {
|
|||||||
const da = difficultyAdjustment.getDifficultyAdjustment();
|
const da = difficultyAdjustment.getDifficultyAdjustment();
|
||||||
this.updateSocketDataFields({
|
this.updateSocketDataFields({
|
||||||
'mempoolInfo': memPool.getMempoolInfo(),
|
'mempoolInfo': memPool.getMempoolInfo(),
|
||||||
'vBytesPerSecond': memPool.getVBytesPerSecond(),
|
'vBytesPerSecond': memPool.getStatisticsIsPaused() ? null : memPool.getVBytesPerSecond(),
|
||||||
'blocks': _blocks,
|
'blocks': _blocks,
|
||||||
'conversions': priceUpdater.getLatestPrices(),
|
'conversions': priceUpdater.getLatestPrices(),
|
||||||
'mempool-blocks': mempoolBlocks.getMempoolBlocks(),
|
'mempool-blocks': mempoolBlocks.getMempoolBlocks(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user