From a187851b6a7b1b9be446f71812401d16312719da Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Wed, 24 Jul 2024 08:39:58 +0100 Subject: [PATCH] fix: start clock last when initializing validator client (#6973) --- packages/validator/src/validator.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/validator/src/validator.ts b/packages/validator/src/validator.ts index 706cf7410b43..785d3de1db2a 100644 --- a/packages/validator/src/validator.ts +++ b/packages/validator/src/validator.ts @@ -128,23 +128,17 @@ export class Validator { if (opts.closed) { this.state = Status.closed; } else { - // "start" the validator - // Instantiates block and attestation services and runs them once the chain has been started. - this.state = Status.running; - this.clock.start(this.controller.signal); - this.chainHeaderTracker.start(this.controller.signal); - // Add notifier to warn user if primary node is unhealthy as there might // not be any errors in the logs due to fallback nodes handling the requests const {httpClient} = this.api; if (httpClient.urlsInits.length > 1) { const primaryNodeUrl = toSafePrintableUrl(httpClient.urlsInits[0].baseUrl); - this.clock?.runEveryEpoch(async () => { + this.clock.runEveryEpoch(async () => { // Only emit warning if URL score is 0 to prevent false positives // if just a single request fails which might happen due to other reasons if (httpClient.urlsScore[0] === 0) { - this.logger?.warn("Primary beacon node is unhealthy", {url: primaryNodeUrl}); + this.logger.warn("Primary beacon node is unhealthy", {url: primaryNodeUrl}); } }); } @@ -158,6 +152,11 @@ export class Validator { .catch((e) => this.logger.error("Error on fetchBeaconHealth", {}, e)) ); } + + // "start" the validator + this.state = Status.running; + this.clock.start(this.controller.signal); + this.chainHeaderTracker.start(this.controller.signal); } } @@ -178,8 +177,6 @@ export class Validator { let api: ApiClient; const {clientOrUrls, globalInit} = opts.api; if (typeof clientOrUrls === "string" || Array.isArray(clientOrUrls)) { - // This new api instance can make do with default timeout as a faster timeout is - // not necessary since this instance won't be used for validator duties api = getClient( { urls: typeof clientOrUrls === "string" ? [clientOrUrls] : clientOrUrls, @@ -329,6 +326,7 @@ export class Validator { strictFeeRecipientCheck, }); + // Instantiates block and attestation services and runs them once the chain has been started. return Validator.init(opts, genesis, metrics); }