From 9dae25f817648635d39761b57cf2474e4abe7787 Mon Sep 17 00:00:00 2001 From: Roman Dvorkin <121502696+rdvorkin@users.noreply.github.com> Date: Thu, 21 Sep 2023 18:04:15 +0300 Subject: [PATCH] feat: always try to fetch optimistic update when starting lc (#5977) * feat: Always try to fetch optimistic update when starting lc Currently fetching an optimistic update at client start happens only if a sync is needed. The proposed change tries to fetch an optimistic update even if no sync is needed, e.g. the client was initialized with a recent checkpoint * Move the update fetching to the correct place --- packages/light-client/src/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/light-client/src/index.ts b/packages/light-client/src/index.ts index 67dc86762ede..b38cc66894ae 100644 --- a/packages/light-client/src/index.ts +++ b/packages/light-client/src/index.ts @@ -242,6 +242,13 @@ export class Lightclient { await new Promise((r) => setTimeout(r, ON_ERROR_RETRY_MS)); continue; } + } + + // After successfully syncing, track head if not already + if (this.runStatus.code !== RunStatusCode.started) { + const controller = new AbortController(); + this.updateRunStatus({code: RunStatusCode.started, controller}); + this.logger.debug("Started tracking the head"); // Fetch latest optimistic head to prevent a potential 12 seconds lag between syncing and getting the first head, // Don't retry, this is a non-critical UX improvement @@ -251,13 +258,6 @@ export class Lightclient { } catch (e) { this.logger.error("Error fetching getLatestHeadUpdate", {currentPeriod}, e as Error); } - } - - // After successfully syncing, track head if not already - if (this.runStatus.code !== RunStatusCode.started) { - const controller = new AbortController(); - this.updateRunStatus({code: RunStatusCode.started, controller}); - this.logger.debug("Started tracking the head"); this.transport.onOptimisticUpdate(this.processOptimisticUpdate.bind(this)); this.transport.onFinalityUpdate(this.processFinalizedUpdate.bind(this));