Skip to content

Commit

Permalink
fix(store-indexer): fix distance from follow block metric (#2791)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed May 8, 2024
1 parent 51b137d commit 0d4e302
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-rivers-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-indexer": patch
---

Fixed the `distance_from_follow_block` gauge to be a positive number if the latest processed block is lagging behind the latest remote block.
2 changes: 1 addition & 1 deletion packages/store-indexer/bin/postgres-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function getDistanceFromFollowBlock(): Promise<bigint> {
getLatestStoredBlockNumber(),
publicClient.getBlock({ blockTag: env.FOLLOW_BLOCK_TAG }),
]);
return (latestStoredBlockNumber ?? -1n) - latestFollowBlock.number;
return latestFollowBlock.number - (latestStoredBlockNumber ?? -1n);
}

const latestStoredBlockNumber = await getLatestStoredBlockNumber();
Expand Down
2 changes: 1 addition & 1 deletion packages/store-indexer/bin/sqlite-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function getDistanceFromFollowBlock(): Promise<bigint> {
getLatestStoredBlockNumber(),
publicClient.getBlock({ blockTag: env.FOLLOW_BLOCK_TAG }),
]);
return (latestStoredBlockNumber ?? -1n) - latestFollowBlock.number;
return latestFollowBlock.number - (latestStoredBlockNumber ?? -1n);
}

const currentChainState = await getCurrentChainState();
Expand Down

0 comments on commit 0d4e302

Please sign in to comment.