Skip to content

Commit

Permalink
feat: always try to fetch optimistic update when starting lc (#5977)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rdvorkin authored Sep 21, 2023
1 parent 900f6a7 commit 9dae25f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/light-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down

0 comments on commit 9dae25f

Please sign in to comment.