From 0d4e302f44c2ee52e9e14d24552499b7fb04306e Mon Sep 17 00:00:00 2001 From: alvarius Date: Wed, 8 May 2024 13:39:36 +0100 Subject: [PATCH] fix(store-indexer): fix distance from follow block metric (#2791) --- .changeset/lazy-rivers-live.md | 5 +++++ packages/store-indexer/bin/postgres-indexer.ts | 2 +- packages/store-indexer/bin/sqlite-indexer.ts | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/lazy-rivers-live.md diff --git a/.changeset/lazy-rivers-live.md b/.changeset/lazy-rivers-live.md new file mode 100644 index 0000000000..9ad8dbb0ce --- /dev/null +++ b/.changeset/lazy-rivers-live.md @@ -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. diff --git a/packages/store-indexer/bin/postgres-indexer.ts b/packages/store-indexer/bin/postgres-indexer.ts index d95c4cca50..2e92ef3fdd 100644 --- a/packages/store-indexer/bin/postgres-indexer.ts +++ b/packages/store-indexer/bin/postgres-indexer.ts @@ -71,7 +71,7 @@ async function getDistanceFromFollowBlock(): Promise { getLatestStoredBlockNumber(), publicClient.getBlock({ blockTag: env.FOLLOW_BLOCK_TAG }), ]); - return (latestStoredBlockNumber ?? -1n) - latestFollowBlock.number; + return latestFollowBlock.number - (latestStoredBlockNumber ?? -1n); } const latestStoredBlockNumber = await getLatestStoredBlockNumber(); diff --git a/packages/store-indexer/bin/sqlite-indexer.ts b/packages/store-indexer/bin/sqlite-indexer.ts index 3b55093363..e2198cbec6 100644 --- a/packages/store-indexer/bin/sqlite-indexer.ts +++ b/packages/store-indexer/bin/sqlite-indexer.ts @@ -78,7 +78,7 @@ async function getDistanceFromFollowBlock(): Promise { getLatestStoredBlockNumber(), publicClient.getBlock({ blockTag: env.FOLLOW_BLOCK_TAG }), ]); - return (latestStoredBlockNumber ?? -1n) - latestFollowBlock.number; + return latestFollowBlock.number - (latestStoredBlockNumber ?? -1n); } const currentChainState = await getCurrentChainState();