From 1420b01cc7001e5e03ca7207776bc5f79dbeeb4d Mon Sep 17 00:00:00 2001 From: Paul Noel Date: Thu, 21 Nov 2024 13:46:00 -0600 Subject: [PATCH] watcher: get finalizedBlock after sleeping --- watcher/src/watchers/NearArchiveWatcher.ts | 4 ++++ watcher/src/watchers/Watcher.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/watcher/src/watchers/NearArchiveWatcher.ts b/watcher/src/watchers/NearArchiveWatcher.ts index 57e3831c..510dfd1c 100644 --- a/watcher/src/watchers/NearArchiveWatcher.ts +++ b/watcher/src/watchers/NearArchiveWatcher.ts @@ -125,6 +125,10 @@ export class NearArchiveWatcher extends Watcher { blocks, quittingTimestamp ); + // This is the case where there are no transactions in the time window. + if (response.lastBlockHeight === 0) { + response.lastBlockHeight = toBlock; + } const lastBlockInfo = await fetchBlockByBlockId(provider, response.lastBlockHeight); // Make a block for the to_block, if it isn't already there const blockKey = makeBlockKey( diff --git a/watcher/src/watchers/Watcher.ts b/watcher/src/watchers/Watcher.ts index d98f59d9..cf62e98e 100644 --- a/watcher/src/watchers/Watcher.ts +++ b/watcher/src/watchers/Watcher.ts @@ -138,6 +138,14 @@ export class Watcher { } await sleep(HB_INTERVAL / 2); } + // After sleeping for 1 hour, need to get the latest finalized block + try { + toBlock = await this.getFinalizedBlockNumber(); + this.logger.debug(`finalized block after 1 hour = ${toBlock}`); + } catch (e) { + this.logger.error(`error fetching finalized block after 1 hour: ${e}`); + // If this throws, the loop will continue and try again. + } } firstTime = false; }