Skip to content

Commit

Permalink
fix: start clock last when initializing validator client (#6973)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Jul 24, 2024
1 parent 27012f9 commit a187851
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/validator/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
});
}
Expand All @@ -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);
}
}

Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit a187851

Please sign in to comment.