From c05da33161aca7c2b4fc55f6e68df82af5105e9c Mon Sep 17 00:00:00 2001 From: Roman Dvorkin <121502696+rdvorkin@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:59:07 +0300 Subject: [PATCH] Move the update fetching to the correct place --- packages/light-client/src/index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/light-client/src/index.ts b/packages/light-client/src/index.ts index ca7636d1a9a1..b38cc66894ae 100644 --- a/packages/light-client/src/index.ts +++ b/packages/light-client/src/index.ts @@ -244,21 +244,21 @@ export class Lightclient { } } - // 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 - try { - const update = await this.transport.getOptimisticUpdate(); - this.processOptimisticUpdate(update.data); - } 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"); + // 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 + try { + const update = await this.transport.getOptimisticUpdate(); + this.processOptimisticUpdate(update.data); + } catch (e) { + this.logger.error("Error fetching getLatestHeadUpdate", {currentPeriod}, e as Error); + } + this.transport.onOptimisticUpdate(this.processOptimisticUpdate.bind(this)); this.transport.onFinalityUpdate(this.processFinalizedUpdate.bind(this)); }