Skip to content

Commit ab90a1b

Browse files
committed
fixup! Change test to tease NPEs during DefaultBlockchain.<init>() caused by initilization order
move counters into their own method Signed-off-by: Luis Pinto <luis.pinto@consensys.net>
1 parent 4f301ee commit ab90a1b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.hyperledger.besu.ethereum.core.Transaction;
3232
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
3333
import org.hyperledger.besu.metrics.BesuMetricCategory;
34+
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
3435
import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem;
3536
import org.hyperledger.besu.plugin.services.MetricsSystem;
3637
import 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

Comments
 (0)