Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: start clock last when initializing validator client #6973

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading