Skip to content

Commit

Permalink
Move the update fetching to the correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvorkin committed Sep 21, 2023
1 parent 5d242d3 commit c05da33
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/light-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit c05da33

Please sign in to comment.