diff --git a/src/services/chain.ts b/src/services/chain.ts index d030e4f..940f18e 100644 --- a/src/services/chain.ts +++ b/src/services/chain.ts @@ -189,7 +189,11 @@ export class ChainContext { let fromBlock = lastProcessedBlock ? lastProcessedBlock.number + 1 : this.deploymentBlock; + let currentBlock = await provider.getBlock("latest"); + metrics.blockHeightLatest + .labels(chainId.toString()) + .set(currentBlock.number); let printSyncInfo = true; // Print sync info only once let toBlock: "latest" | number = 0; @@ -199,6 +203,9 @@ export class ChainContext { if (typeof toBlock === "number" && toBlock > currentBlock.number) { // refresh the current block currentBlock = await provider.getBlock("latest"); + metrics.blockHeightLatest + .labels(chainId.toString()) + .set(currentBlock.number); toBlock = toBlock > currentBlock.number ? currentBlock.number : toBlock; @@ -283,6 +290,9 @@ export class ChainContext { // It may have taken some time to process the blocks, so refresh the current block number // and check if we are in sync currentBlock = await provider.getBlock("latest"); + metrics.blockHeightLatest + .labels(chainId.toString()) + .set(currentBlock.number); // If we are in sync, let it be known const lastProcessedBlockNumber = lastProcessedBlock?.number || 0; diff --git a/src/utils/metrics.ts b/src/utils/metrics.ts index d2bfdd1..79b70f3 100644 --- a/src/utils/metrics.ts +++ b/src/utils/metrics.ts @@ -57,6 +57,12 @@ export const blockHeight = new client.Gauge({ labelNames: ["chain_id"], }); +export const blockHeightLatest = new client.Gauge({ + name: "watch_tower_block_height_latest", + help: "Block height of the last block (tip of the chain)", + labelNames: ["chain_id"], +}); + export const reorgDepth = new client.Gauge({ name: "watch_tower_latest_reorg_depth", help: "Depth of the most recent reorg",