3131import org .hyperledger .besu .ethereum .core .Transaction ;
3232import org .hyperledger .besu .ethereum .core .TransactionReceipt ;
3333import org .hyperledger .besu .metrics .BesuMetricCategory ;
34+ import org .hyperledger .besu .metrics .noop .NoOpMetricsSystem ;
3435import org .hyperledger .besu .metrics .prometheus .PrometheusMetricsSystem ;
3536import org .hyperledger .besu .plugin .services .MetricsSystem ;
3637import org .hyperledger .besu .plugin .services .metrics .Counter ;
@@ -84,8 +85,8 @@ public class DefaultBlockchain implements MutableBlockchain {
8485 private final Optional <Cache <Hash , List <TransactionReceipt >>> transactionReceiptsCache ;
8586 private final Optional <Cache <Hash , Difficulty >> totalDifficultyCache ;
8687
87- private final Counter gasUsedCounter ;
88- private final Counter numberOfTransactionsCounter ;
88+ private Counter gasUsedCounter = NoOpMetricsSystem . NO_OP_COUNTER ;
89+ private Counter numberOfTransactionsCounter = NoOpMetricsSystem . NO_OP_COUNTER ;
8990
9091 private DefaultBlockchain (
9192 final Optional <Block > genesisBlock ,
@@ -147,6 +148,11 @@ private DefaultBlockchain(
147148 totalDifficultyCache = Optional .empty ();
148149 }
149150
151+ createCounters (metricsSystem );
152+ createGauges (metricsSystem );
153+ }
154+
155+ private void createCounters (final MetricsSystem metricsSystem ) {
150156 gasUsedCounter =
151157 metricsSystem .createCounter (
152158 BesuMetricCategory .BLOCKCHAIN , "chain_head_gas_used_counter" , "Counter for Gas used" );
@@ -156,8 +162,6 @@ private DefaultBlockchain(
156162 BesuMetricCategory .BLOCKCHAIN ,
157163 "chain_head_transaction_count_counter" ,
158164 "Counter for the number of transactions" );
159-
160- createGauges (metricsSystem );
161165 }
162166
163167 private void createGauges (final MetricsSystem metricsSystem ) {
0 commit comments