Skip to content

Commit

Permalink
fix: only write to requiredBlock when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Feb 14, 2024
1 parent 5b011af commit 16121e1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/api/src/utils/nsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ export const syncApiBlock = throttleAsyncFn(
// We throttle this method so even if 1k requests are made in quick succession,
// we'll only attempt to sync the api one time

let wasBehind = false;
// Keep looping while the api is behind the current block
while (
isApiBehind({
network,
requiredBlockNumber: getRequiredBlockNumber(network),
})
) {
wasBehind = true;
if (config.internal.source !== 'live') {
// Switch to live mode
config.internal.source = 'live';
Expand All @@ -117,7 +119,9 @@ export const syncApiBlock = throttleAsyncFn(
await updateLastIndexedBlock({ network });
}

// The api has caught up and we no longer need to be in live mode
resetRequiredBlock({ network });
if (wasBehind) {
// The api has caught up and we no longer need to be in live mode
resetRequiredBlock({ network });
}
}
);

0 comments on commit 16121e1

Please sign in to comment.