Avoid logging statistics while affected by esplora failover
This commit is contained in:
@@ -25,6 +25,7 @@ export interface AbstractBitcoinApi {
|
||||
$getBatchedOutspends(txId: string[]): Promise<IEsploraApi.Outspend[][]>;
|
||||
|
||||
startHealthChecks(): void;
|
||||
isFailedOver(): boolean;
|
||||
}
|
||||
export interface BitcoinRpcCredentials {
|
||||
host: string;
|
||||
|
||||
@@ -356,6 +356,9 @@ class BitcoinApi implements AbstractBitcoinApi {
|
||||
}
|
||||
|
||||
public startHealthChecks(): void {};
|
||||
public isFailedOver(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default BitcoinApi;
|
||||
|
||||
@@ -17,6 +17,8 @@ interface FailoverHost {
|
||||
}
|
||||
|
||||
class FailoverRouter {
|
||||
isFailedOver: boolean = false;
|
||||
preferredHost: FailoverHost;
|
||||
activeHost: FailoverHost;
|
||||
fallbackHost: FailoverHost;
|
||||
hosts: FailoverHost[];
|
||||
@@ -46,6 +48,7 @@ class FailoverRouter {
|
||||
socket: !!config.ESPLORA.UNIX_SOCKET_PATH,
|
||||
preferred: true,
|
||||
};
|
||||
this.preferredHost = this.activeHost;
|
||||
this.fallbackHost = this.activeHost;
|
||||
this.hosts.unshift(this.activeHost);
|
||||
this.multihost = this.hosts.length > 1;
|
||||
@@ -151,6 +154,7 @@ class FailoverRouter {
|
||||
this.sortHosts();
|
||||
this.activeHost = this.hosts[0];
|
||||
logger.warn(`Switching esplora host to ${this.activeHost.host}`);
|
||||
this.isFailedOver = this.activeHost !== this.preferredHost;
|
||||
}
|
||||
|
||||
private addFailure(host: FailoverHost): FailoverHost {
|
||||
@@ -302,6 +306,10 @@ class ElectrsApi implements AbstractBitcoinApi {
|
||||
public startHealthChecks(): void {
|
||||
this.failoverRouter.startHealthChecks();
|
||||
}
|
||||
|
||||
public isFailedOver(): boolean {
|
||||
return this.failoverRouter.isFailedOver;
|
||||
}
|
||||
}
|
||||
|
||||
export default ElectrsApi;
|
||||
|
||||
Reference in New Issue
Block a user