From b8817f724269a4087875c9bb595595b64f70d19e Mon Sep 17 00:00:00 2001 From: Naveen V Date: Mon, 30 Jan 2023 07:32:39 +0000 Subject: [PATCH 1/6] add blockTime to NodeConfig --- packages/node-core/src/configure/NodeConfig.ts | 6 ++++++ packages/node-core/src/meta/health.service.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/node-core/src/configure/NodeConfig.ts b/packages/node-core/src/configure/NodeConfig.ts index 829c4b8a4b..664a692567 100644 --- a/packages/node-core/src/configure/NodeConfig.ts +++ b/packages/node-core/src/configure/NodeConfig.ts @@ -19,6 +19,7 @@ export interface IConfig { readonly localMode: boolean; readonly batchSize: number; readonly timeout: number; + readonly blockTime: number; readonly debug: boolean; readonly preferRange: boolean; readonly networkEndpoint?: string; @@ -49,6 +50,7 @@ const DEFAULT_CONFIG = { localMode: false, batchSize: 100, timeout: 900, + blockTime: 6000, preferRange: false, debug: false, queryLimit: 100, @@ -120,6 +122,10 @@ export class NodeConfig implements IConfig { return this._config.timeout; } + get blockTime(): number { + return this._config.blockTime; + } + get debug(): boolean { return this._config.debug; } diff --git a/packages/node-core/src/meta/health.service.ts b/packages/node-core/src/meta/health.service.ts index 4df05a816d..767a0276e8 100644 --- a/packages/node-core/src/meta/health.service.ts +++ b/packages/node-core/src/meta/health.service.ts @@ -9,6 +9,7 @@ import {IndexerEvent, ProcessBlockPayload, TargetBlockPayload} from '../events'; import {StoreService} from '../indexer'; const DEFAULT_TIMEOUT = 900000; +const DEFAULT_BLOCK_TIME = 6000; const CHECK_HEALTH_INTERVAL = 60000; @Injectable() @@ -17,12 +18,13 @@ export class HealthService { private recordBlockTimestamp?: number; private currentProcessingHeight?: number; private currentProcessingTimestamp?: number; - private blockTime = 6000; + private blockTime: number; private healthTimeout: number; private indexerHealthy: boolean; constructor(protected nodeConfig: NodeConfig, private storeService: StoreService) { this.healthTimeout = Math.max(DEFAULT_TIMEOUT, this.nodeConfig.timeout * 1000); + this.blockTime = Math.max(DEFAULT_BLOCK_TIME, this.nodeConfig.blockTime); } @Interval(CHECK_HEALTH_INTERVAL) From 266f80a4cce679d36478ac0dd15551a71ef5cf35 Mon Sep 17 00:00:00 2001 From: Naveen V Date: Tue, 31 Jan 2023 07:17:59 +0000 Subject: [PATCH 2/6] check target height sync for endpoint health check --- packages/node-core/src/meta/health.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/node-core/src/meta/health.service.ts b/packages/node-core/src/meta/health.service.ts index 767a0276e8..1fc6abc214 100644 --- a/packages/node-core/src/meta/health.service.ts +++ b/packages/node-core/src/meta/health.service.ts @@ -61,7 +61,12 @@ export class HealthService { } getHealth(): void { - if (this.recordBlockTimestamp && Date.now() - this.recordBlockTimestamp > this.blockTime * 10) { + if ( + (this.recordBlockTimestamp && Date.now() - this.recordBlockTimestamp > this.blockTime * 10) || + (this.recordBlockHeight && + this.currentProcessingHeight && + this.recordBlockHeight !== this.currentProcessingHeight) + ) { throw new Error('Endpoint is not healthy'); } if (this.currentProcessingTimestamp && Date.now() - this.currentProcessingTimestamp > this.healthTimeout) { From bce993ce15036ef5fa41e8836d005b9016114d5b Mon Sep 17 00:00:00 2001 From: Naveen V Date: Tue, 31 Jan 2023 07:22:03 +0000 Subject: [PATCH 3/6] revert add blockTime to NodeConfig --- packages/node-core/src/configure/NodeConfig.ts | 6 ------ packages/node-core/src/meta/health.service.ts | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/node-core/src/configure/NodeConfig.ts b/packages/node-core/src/configure/NodeConfig.ts index 664a692567..829c4b8a4b 100644 --- a/packages/node-core/src/configure/NodeConfig.ts +++ b/packages/node-core/src/configure/NodeConfig.ts @@ -19,7 +19,6 @@ export interface IConfig { readonly localMode: boolean; readonly batchSize: number; readonly timeout: number; - readonly blockTime: number; readonly debug: boolean; readonly preferRange: boolean; readonly networkEndpoint?: string; @@ -50,7 +49,6 @@ const DEFAULT_CONFIG = { localMode: false, batchSize: 100, timeout: 900, - blockTime: 6000, preferRange: false, debug: false, queryLimit: 100, @@ -122,10 +120,6 @@ export class NodeConfig implements IConfig { return this._config.timeout; } - get blockTime(): number { - return this._config.blockTime; - } - get debug(): boolean { return this._config.debug; } diff --git a/packages/node-core/src/meta/health.service.ts b/packages/node-core/src/meta/health.service.ts index 1fc6abc214..c30dd146d5 100644 --- a/packages/node-core/src/meta/health.service.ts +++ b/packages/node-core/src/meta/health.service.ts @@ -9,7 +9,6 @@ import {IndexerEvent, ProcessBlockPayload, TargetBlockPayload} from '../events'; import {StoreService} from '../indexer'; const DEFAULT_TIMEOUT = 900000; -const DEFAULT_BLOCK_TIME = 6000; const CHECK_HEALTH_INTERVAL = 60000; @Injectable() @@ -18,13 +17,12 @@ export class HealthService { private recordBlockTimestamp?: number; private currentProcessingHeight?: number; private currentProcessingTimestamp?: number; - private blockTime: number; + private blockTime = 6000; private healthTimeout: number; private indexerHealthy: boolean; constructor(protected nodeConfig: NodeConfig, private storeService: StoreService) { this.healthTimeout = Math.max(DEFAULT_TIMEOUT, this.nodeConfig.timeout * 1000); - this.blockTime = Math.max(DEFAULT_BLOCK_TIME, this.nodeConfig.blockTime); } @Interval(CHECK_HEALTH_INTERVAL) From da98d2bfc82d3178aefcdcef92019e3ad26802c5 Mon Sep 17 00:00:00 2001 From: Naveen V Date: Tue, 31 Jan 2023 09:45:08 +0000 Subject: [PATCH 4/6] bug fix --- packages/node-core/src/meta/health.service.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/node-core/src/meta/health.service.ts b/packages/node-core/src/meta/health.service.ts index c30dd146d5..f690b99ce2 100644 --- a/packages/node-core/src/meta/health.service.ts +++ b/packages/node-core/src/meta/health.service.ts @@ -60,10 +60,11 @@ export class HealthService { getHealth(): void { if ( - (this.recordBlockTimestamp && Date.now() - this.recordBlockTimestamp > this.blockTime * 10) || - (this.recordBlockHeight && - this.currentProcessingHeight && - this.recordBlockHeight !== this.currentProcessingHeight) + this.recordBlockTimestamp && + Date.now() - this.recordBlockTimestamp > this.blockTime * 10 && + this.recordBlockHeight && + this.currentProcessingHeight && + this.recordBlockHeight !== this.currentProcessingHeight ) { throw new Error('Endpoint is not healthy'); } From fb7a0f7d913ecb27ebf8ee9e2bc6b1d93dc5c0f0 Mon Sep 17 00:00:00 2001 From: Naveen V Date: Tue, 31 Jan 2023 09:46:54 +0000 Subject: [PATCH 5/6] code cleanup --- packages/node-core/src/meta/health.service.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/node-core/src/meta/health.service.ts b/packages/node-core/src/meta/health.service.ts index f690b99ce2..b0f94129ff 100644 --- a/packages/node-core/src/meta/health.service.ts +++ b/packages/node-core/src/meta/health.service.ts @@ -59,14 +59,15 @@ export class HealthService { } getHealth(): void { - if ( - this.recordBlockTimestamp && - Date.now() - this.recordBlockTimestamp > this.blockTime * 10 && - this.recordBlockHeight && - this.currentProcessingHeight && - this.recordBlockHeight !== this.currentProcessingHeight - ) { - throw new Error('Endpoint is not healthy'); + if (this.recordBlockTimestamp && Date.now() - this.recordBlockTimestamp > this.blockTime * 10) { + //check if current processing height reached target height + if ( + this.recordBlockHeight && + this.currentProcessingHeight && + this.recordBlockHeight !== this.currentProcessingHeight + ) { + throw new Error('Endpoint is not healthy'); + } } if (this.currentProcessingTimestamp && Date.now() - this.currentProcessingTimestamp > this.healthTimeout) { throw new Error('Indexer is not healthy'); From 2b497af5075e3f47ff12a66fe2b6a94c5e8b0786 Mon Sep 17 00:00:00 2001 From: Naveen V Date: Thu, 2 Feb 2023 07:25:29 +0000 Subject: [PATCH 6/6] bug fix --- packages/node-core/src/meta/health.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node-core/src/meta/health.service.ts b/packages/node-core/src/meta/health.service.ts index b0f94129ff..8678242984 100644 --- a/packages/node-core/src/meta/health.service.ts +++ b/packages/node-core/src/meta/health.service.ts @@ -64,7 +64,7 @@ export class HealthService { if ( this.recordBlockHeight && this.currentProcessingHeight && - this.recordBlockHeight !== this.currentProcessingHeight + this.recordBlockHeight > this.currentProcessingHeight ) { throw new Error('Endpoint is not healthy'); }