Skip to content

Commit

Permalink
fixup! Change test to tease NPEs during DefaultBlockchain.<init>() ca…
Browse files Browse the repository at this point in the history
…used by initilization order

 move counters into their own method

Signed-off-by: Luis Pinto <[email protected]>
  • Loading branch information
lu-pinto committed Sep 12, 2024
1 parent 4f301ee commit ab90a1b
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
Expand Down Expand Up @@ -84,8 +85,8 @@ public class DefaultBlockchain implements MutableBlockchain {
private final Optional<Cache<Hash, List<TransactionReceipt>>> transactionReceiptsCache;
private final Optional<Cache<Hash, Difficulty>> totalDifficultyCache;

private final Counter gasUsedCounter;
private final Counter numberOfTransactionsCounter;
private Counter gasUsedCounter = NoOpMetricsSystem.NO_OP_COUNTER;
private Counter numberOfTransactionsCounter = NoOpMetricsSystem.NO_OP_COUNTER;

private DefaultBlockchain(
final Optional<Block> genesisBlock,
Expand Down Expand Up @@ -147,6 +148,11 @@ private DefaultBlockchain(
totalDifficultyCache = Optional.empty();
}

createCounters(metricsSystem);
createGauges(metricsSystem);
}

private void createCounters(final MetricsSystem metricsSystem) {
gasUsedCounter =
metricsSystem.createCounter(
BesuMetricCategory.BLOCKCHAIN, "chain_head_gas_used_counter", "Counter for Gas used");
Expand All @@ -156,8 +162,6 @@ private DefaultBlockchain(
BesuMetricCategory.BLOCKCHAIN,
"chain_head_transaction_count_counter",
"Counter for the number of transactions");

createGauges(metricsSystem);
}

private void createGauges(final MetricsSystem metricsSystem) {
Expand Down

0 comments on commit ab90a1b

Please sign in to comment.