Skip to content

Commit

Permalink
watcher: get finalizedBlock after sleeping
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Nov 21, 2024
1 parent 156da32 commit 1420b01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions watcher/src/watchers/NearArchiveWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions watcher/src/watchers/Watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1420b01

Please sign in to comment.