Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose head execution time metric #8092

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright contributors to Hyperledger Besu.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -22,6 +22,7 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.RequestValidatorProvider.getRequestsValidator;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.WithdrawalsValidatorProvider.getWithdrawalsValidator;
import static org.hyperledger.besu.metrics.BesuMetricCategory.BLOCK_PROCESSING;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.datatypes.BlobGas;
Expand Down Expand Up @@ -61,6 +62,7 @@
import org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalculator;
import org.hyperledger.besu.ethereum.rlp.RLPException;
import org.hyperledger.besu.ethereum.trie.MerkleTrieException;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.exception.StorageException;

import java.security.InvalidParameterException;
Expand All @@ -85,17 +87,24 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet
private static final BlockHeaderFunctions headerFunctions = new MainnetBlockHeaderFunctions();
private final MergeMiningCoordinator mergeCoordinator;
private final EthPeers ethPeers;
private long lastExecutionTime = 0L;

public AbstractEngineNewPayload(
final Vertx vertx,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeCoordinator,
final EthPeers ethPeers,
final EngineCallListener engineCallListener) {
final EngineCallListener engineCallListener,
final MetricsSystem metricsSystem) {
super(vertx, protocolSchedule, protocolContext, engineCallListener);
this.mergeCoordinator = mergeCoordinator;
this.ethPeers = ethPeers;
metricsSystem.createLongGauge(
BLOCK_PROCESSING,
"execution_time_head",
"The execution time of the last block (head)",
this::getLastExecutionTime);
}

@Override
Expand Down Expand Up @@ -347,16 +356,16 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
// execute block and return result response
final long startTimeMs = System.currentTimeMillis();
final BlockProcessingResult executionResult = mergeCoordinator.rememberBlock(block);

if (executionResult.isSuccessful()) {
lastExecutionTime = System.currentTimeMillis() - startTimeMs;
logImportedBlockInfo(
block,
blobTransactions.stream()
.map(Transaction::getVersionedHashes)
.flatMap(Optional::stream)
.mapToInt(List::size)
.sum(),
(System.currentTimeMillis() - startTimeMs) / 1000.0,
lastExecutionTime / 1000.0,
executionResult.getNbParallelizedTransations());
return respondWith(reqId, blockParam, newBlockHeader.getHash(), VALID);
} else {
Expand Down Expand Up @@ -629,4 +638,8 @@ private void logImportedBlockInfo(
messageArgs.add(ethPeers.peerCount());
LOG.info(String.format(message.toString(), messageArgs.toArray()));
}

private long getLastExecutionTime() {
return this.lastExecutionTime;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright contributors to Hyperledger Besu.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -27,6 +27,7 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.List;
import java.util.Optional;
Expand All @@ -41,8 +42,16 @@ public EngineNewPayloadV1(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeCoordinator,
final EthPeers ethPeers,
final EngineCallListener engineCallListener) {
super(vertx, protocolSchedule, protocolContext, mergeCoordinator, ethPeers, engineCallListener);
final EngineCallListener engineCallListener,
final MetricsSystem metricsSystem) {
super(
vertx,
protocolSchedule,
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener,
metricsSystem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright contributors to Hyperledger Besu.
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.List;
import java.util.Optional;
Expand All @@ -43,8 +44,16 @@ public EngineNewPayloadV2(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeCoordinator,
final EthPeers ethPeers,
final EngineCallListener engineCallListener) {
super(vertx, protocolSchedule, protocolContext, mergeCoordinator, ethPeers, engineCallListener);
final EngineCallListener engineCallListener,
final MetricsSystem metricsSystem) {
super(
vertx,
protocolSchedule,
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener,
metricsSystem);
cancunMilestone = protocolSchedule.milestoneFor(CANCUN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.List;
import java.util.Optional;
Expand All @@ -40,9 +41,16 @@ public EngineNewPayloadV3(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeCoordinator,
final EthPeers ethPeers,
final EngineCallListener engineCallListener) {
final EngineCallListener engineCallListener,
final MetricsSystem metricsSystem) {
super(
vertx, timestampSchedule, protocolContext, mergeCoordinator, ethPeers, engineCallListener);
vertx,
timestampSchedule,
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener,
metricsSystem);
this.cancunMilestone = timestampSchedule.milestoneFor(CANCUN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.List;
import java.util.Optional;
Expand All @@ -40,9 +41,16 @@ public EngineNewPayloadV4(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeCoordinator,
final EthPeers ethPeers,
final EngineCallListener engineCallListener) {
final EngineCallListener engineCallListener,
final MetricsSystem metricsSystem) {
super(
vertx, timestampSchedule, protocolContext, mergeCoordinator, ethPeers, engineCallListener);
vertx,
timestampSchedule,
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener,
metricsSystem);
pragueMilestone = timestampSchedule.milestoneFor(PRAGUE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -63,6 +64,7 @@ public class ExecutionEngineJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final String clientVersion;
private final String commit;
private final TransactionPool transactionPool;
private final MetricsSystem metricsSystem;

ExecutionEngineJsonRpcMethods(
final MiningCoordinator miningCoordinator,
Expand All @@ -72,7 +74,8 @@ public class ExecutionEngineJsonRpcMethods extends ApiGroupJsonRpcMethods {
final Vertx consensusEngineServer,
final String clientVersion,
final String commit,
final TransactionPool transactionPool) {
final TransactionPool transactionPool,
final MetricsSystem metricsSystem) {
this.mergeCoordinator =
Optional.ofNullable(miningCoordinator)
.filter(mc -> mc.isCompatibleWithEngineApi())
Expand All @@ -84,6 +87,7 @@ public class ExecutionEngineJsonRpcMethods extends ApiGroupJsonRpcMethods {
this.clientVersion = clientVersion;
this.commit = commit;
this.transactionPool = transactionPool;
this.metricsSystem = metricsSystem;
}

@Override
Expand Down Expand Up @@ -117,21 +121,24 @@ protected Map<String, JsonRpcMethod> create() {
protocolContext,
mergeCoordinator.get(),
ethPeers,
engineQosTimer),
engineQosTimer,
metricsSystem),
new EngineNewPayloadV2(
consensusEngineServer,
protocolSchedule,
protocolContext,
mergeCoordinator.get(),
ethPeers,
engineQosTimer),
engineQosTimer,
metricsSystem),
new EngineNewPayloadV3(
consensusEngineServer,
protocolSchedule,
protocolContext,
mergeCoordinator.get(),
ethPeers,
engineQosTimer),
engineQosTimer,
metricsSystem),
new EngineForkchoiceUpdatedV1(
consensusEngineServer,
protocolSchedule,
Expand Down Expand Up @@ -193,7 +200,8 @@ protected Map<String, JsonRpcMethod> create() {
protocolContext,
mergeCoordinator.get(),
ethPeers,
engineQosTimer));
engineQosTimer,
metricsSystem));
}

return mapOf(executionEngineApisSupported);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public Map<String, JsonRpcMethod> methods(
consensusEngineServer,
clientVersion,
commit,
transactionPool),
transactionPool,
metricsSystem),
new EthJsonRpcMethods(
blockchainQueries,
synchronizer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_BLOCK_HASH;

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -43,7 +44,8 @@ public void before() {
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener);
engineCallListener,
new NoOpMetricsSystem());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Withdrawal;
import org.hyperledger.besu.ethereum.mainnet.WithdrawalsValidator;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -64,7 +65,8 @@ public void before() {
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener);
engineCallListener,
new NoOpMetricsSystem());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.hyperledger.besu.ethereum.mainnet.CancunTargetingGasLimitCalculator;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;

import java.math.BigInteger;
import java.util.List;
Expand Down Expand Up @@ -95,7 +96,8 @@ public void before() {
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener);
engineCallListener,
new NoOpMetricsSystem());
lenient().when(protocolSpec.getGasCalculator()).thenReturn(new CancunGasCalculator());
lenient()
.when(protocolSpec.getGasLimitCalculator())
Expand All @@ -120,7 +122,8 @@ public void shouldInvalidVersionedHash_whenShortVersionedHash() {
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener);
engineCallListener,
new NoOpMetricsSystem());
final JsonRpcResponse badParam =
methodV3.response(
new JsonRpcRequestContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.hyperledger.besu.ethereum.mainnet.requests.MainnetRequestsValidator;
import org.hyperledger.besu.ethereum.mainnet.requests.ProhibitedRequestValidator;
import org.hyperledger.besu.evm.gascalculator.PragueGasCalculator;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;

import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -78,7 +79,8 @@ public void before() {
protocolContext,
mergeCoordinator,
ethPeers,
engineCallListener);
engineCallListener,
new NoOpMetricsSystem());
lenient().when(protocolSchedule.hardforkFor(any())).thenReturn(Optional.of(pragueHardfork));
lenient().when(protocolSpec.getGasCalculator()).thenReturn(new PragueGasCalculator());
mockAllowedRequestsValidator();
Expand Down
Loading