From 16121e1766315f433f306f3a7b5cf7ceca74f763 Mon Sep 17 00:00:00 2001 From: Jack Ellis Date: Wed, 14 Feb 2024 14:22:12 +0000 Subject: [PATCH] fix: only write to requiredBlock when necessary --- packages/api/src/utils/nsync.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/api/src/utils/nsync.ts b/packages/api/src/utils/nsync.ts index 05a2dc4..e49a3ef 100644 --- a/packages/api/src/utils/nsync.ts +++ b/packages/api/src/utils/nsync.ts @@ -100,6 +100,7 @@ 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({ @@ -107,6 +108,7 @@ export const syncApiBlock = throttleAsyncFn( requiredBlockNumber: getRequiredBlockNumber(network), }) ) { + wasBehind = true; if (config.internal.source !== 'live') { // Switch to live mode config.internal.source = 'live'; @@ -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 }); + } } );