Skip to content

Commit

Permalink
feat: exported metrics for current finalized and safe block number (h…
Browse files Browse the repository at this point in the history
…yperledger#7592)

* feat: exported metrics for current finalized and safe block number

Signed-off-by: Jones Ho <jones.ho@consensys.net>

* Update ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java

Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: jonesho <81145364+jonesho@users.noreply.github.com>

* Update ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java

Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: jonesho <81145364+jonesho@users.noreply.github.com>

* fix: spotless issue

Signed-off-by: Jones Ho <jones.ho@consensys.net>

---------

Signed-off-by: Jones Ho <jones.ho@consensys.net>
Signed-off-by: jonesho <81145364+jonesho@users.noreply.github.com>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
jonesho and fab-10 authored Sep 10, 2024
1 parent 01fcc7f commit 500a98b
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ private DefaultBlockchain(
"The current height of the canonical chain",
this::getChainHeadBlockNumber);

metricsSystem.createLongGauge(
BesuMetricCategory.ETHEREUM,
"blockchain_finalized_block",
"The current finalized block number",
this::getFinalizedBlockNumber);

metricsSystem.createLongGauge(
BesuMetricCategory.ETHEREUM,
"blockchain_safe_block",
"The current safe block number",
this::getSafeBlockNumber);

metricsSystem.createGauge(
BesuMetricCategory.BLOCKCHAIN,
"difficulty_total",
Expand Down Expand Up @@ -759,6 +771,14 @@ public void setSafeBlock(final Hash blockHash) {
updater.commit();
}

private long getFinalizedBlockNumber() {
return this.getFinalized().flatMap(this::getBlockHeader).map(BlockHeader::getNumber).orElse(0L);
}

private long getSafeBlockNumber() {
return this.getSafeBlock().flatMap(this::getBlockHeader).map(BlockHeader::getNumber).orElse(0L);
}

private void updateCacheForNewCanonicalHead(final Block block, final Difficulty uInt256) {
chainHeader = block.getHeader();
totalDifficulty = uInt256;
Expand Down

0 comments on commit 500a98b

Please sign in to comment.