Skip to content

Commit

Permalink
Block Production\Publishing Performance threshold based on flow (#8242)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov authored Apr 23, 2024
1 parent 36cbb82 commit fc7bc96
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 90 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ the [releases page](https://github.com/Consensys/teku/releases).
## Unreleased Changes

### Breaking Changes
- Removed support for Goerli test network `--network=goerli`.
- Removed support for the Goerli network `--network=goerli`.

### Additions and Improvements
- Increased the executor queue default maximum size to 40_000 (previously 20_000), and other queues to 10_000 (previously 5_000). If you have custom settings for these queues, check to ensure they're still required.
Expand All @@ -19,7 +19,7 @@ the [releases page](https://github.com/Consensys/teku/releases).
- Added hidden option `--Xdeposit-contract-logs-syncing-enabled` to allow disabling the syncing of the deposit contract logs from the EL. This is useful when running a non-validating node. It is advisable to be used alongside with `--Xeth1-missing-deposits-event-logging-enabled=false` to avoid unnecessary logging of missing deposits.
- Updated the bootnodes for Chiado and Gnosis networks.
- Added hidden option `--Xp2p-dumps-to-file-enabled` to enable saving p2p dumps to file.
- Appends consensus layer (CL) and execution layer (EL) clients' information to the validator graffiti. Check [documentation](https://docs.teku.consensys.io/development/reference/cli#validators-graffiti-client-append-format) for available configuration options.
- Consensus layer (CL) and execution layer (EL) clients' information will be appended to the validator graffiti. Check [documentation](https://docs.teku.consensys.io/development/reference/cli#validators-graffiti-client-append-format) for the available configuration options.
- Added support for [Graffiti management](https://ethereum.github.io/keymanager-APIs/?urls.primaryName=dev#/Graffiti) in the Key Manager API.

### Bug Fixes
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class ValidatorApiHandlerIntegrationTest {
syncCommitteeContributionPool,
syncCommitteeSubscriptionManager,
new BlockProductionAndPublishingPerformanceFactory(
new SystemTimeProvider(), __ -> UInt64.ZERO, true, 0, 0));
new SystemTimeProvider(), __ -> UInt64.ZERO, true, 0, 0, 0, 0));

@BeforeEach
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ public Function<BeaconBlockBodyBuilder, SafeFuture<Void>> createSelector(

// Optional fields introduced in later forks

// Sync aggregate
// Post-Altair: Sync aggregate
if (bodyBuilder.supportsSyncAggregate()) {
bodyBuilder.syncAggregate(
contributionPool.createSyncAggregateForBlock(blockSlotState.getSlot(), parentRoot));
}

// BLS to Execution changes
// Post-Capella: BLS to Execution changes
if (bodyBuilder.supportsBlsToExecutionChanges()) {
bodyBuilder.blsToExecutionChanges(
blsToExecutionChangePool.getItemsForBlock(blockSlotState));
Expand All @@ -177,17 +177,20 @@ public Function<BeaconBlockBodyBuilder, SafeFuture<Void>> createSelector(
final SchemaDefinitions schemaDefinitions =
spec.atSlot(blockSlotState.getSlot()).getSchemaDefinitions();

// Post-electra: consolidations supported
// Post-Electra: Consolidations
if (bodyBuilder.supportsConsolidations()) {
// devnet0 blocks are empty of consolidations, so just default their list.
// devnet-0 blocks are empty of consolidations, so just default their list.
bodyBuilder.consolidations(
SchemaDefinitionsElectra.required(schemaDefinitions)
.getConsolidationsSchema()
.createFromElements(List.of()));
}

// Execution Payload / Execution Payload Header / KZG Commitments
final SafeFuture<Void> blockProductionComplete;

// In `setExecutionData` the following fields are set:
// Post-Bellatrix: Execution Payload / Execution Payload Header
// Post-Deneb: KZG Commitments
if (bodyBuilder.supportsExecutionPayload()) {
blockProductionComplete =
forkChoiceNotifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class ValidatorApiHandlerTest {

private final BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory =
new BlockProductionAndPublishingPerformanceFactory(
StubTimeProvider.withTimeInMillis(0), __ -> ZERO, false, 0, 0);
StubTimeProvider.withTimeInMillis(0), __ -> ZERO, false, 0, 0, 0, 0);

private Spec spec;
private UInt64 epochStartSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public SafeFuture<BuilderBidOrFallbackData> builderGetHeader(
final SafeFuture<GetPayloadResponse> localGetPayloadResponse =
executionLayerManager
.engineGetPayloadForFallback(executionPayloadContext, state.getSlot())
.thenPeek(__ -> blockProductionPerformance.engineGetPayload());
.alwaysRun(blockProductionPerformance::engineGetPayload);

final Optional<SafeFuture<BuilderBidOrFallbackData>> maybeFallback =
isBuilderFlowViable(executionPayloadContext, state, localGetPayloadResponse);
Expand Down Expand Up @@ -165,15 +165,14 @@ public SafeFuture<BuilderBidOrFallbackData> builderGetHeader(
.getHeader(slot, validatorPublicKey, executionPayloadContext.getParentHash())
.thenApply(ResponseUnwrapper::unwrapBuilderResponseOrThrow)
.thenPeek(
signedBuilderBidMaybe -> {
blockProductionPerformance.builderGetHeader();
LOG.trace(
"builderGetHeader(slot={}, pubKey={}, parentHash={}) -> {}",
slot,
validatorPublicKey,
executionPayloadContext.getParentHash(),
signedBuilderBidMaybe);
})
signedBuilderBidMaybe ->
LOG.trace(
"builderGetHeader(slot={}, pubKey={}, parentHash={}) -> {}",
slot,
validatorPublicKey,
executionPayloadContext.getParentHash(),
signedBuilderBidMaybe))
.alwaysRun(blockProductionPerformance::builderGetHeader)
.thenComposeCombined(
safeLocalGetPayloadResponse,
(signedBuilderBidMaybe, maybeLocalGetPayloadResponse) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ public SafeFuture<BuilderPayloadOrFallbackData> getUnblindedPayload(
return executionLayerChannel
.builderGetPayload(signedBeaconBlock, this::getCachedPayloadResult)
.thenPeek(
builderPayloadOrFallbackData -> {
builderResultCache.put(signedBeaconBlock.getSlot(), builderPayloadOrFallbackData);
blockPublishingPerformance.builderGetPayload();
});
builderPayloadOrFallbackData ->
builderResultCache.put(signedBeaconBlock.getSlot(), builderPayloadOrFallbackData))
.alwaysRun(blockPublishingPerformance::builderGetPayload);
}

@Override
Expand All @@ -109,7 +108,7 @@ private ExecutionPayloadResult executeLocalFlow(
final SafeFuture<GetPayloadResponse> getPayloadResponseFuture =
executionLayerChannel
.engineGetPayload(context, blockSlotState)
.thenPeek(__ -> blockProductionPerformance.engineGetPayload());
.alwaysRun(blockProductionPerformance::engineGetPayload);

return ExecutionPayloadResult.createForLocalFlow(context, getPayloadResponseFuture);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,48 @@

package tech.pegasys.teku.ethereum.performance.trackers;

import java.util.Map;
import java.util.function.Function;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class BlockProductionAndPublishingPerformanceFactory {

private final TimeProvider timeProvider;
private final boolean enabled;
private final int lateProductionEventThreshold;
private final int latePublishingEventThreshold;
private final Function<UInt64, UInt64> slotTimeCalculator;
private final boolean enabled;
private final Map<Flow, Integer> lateProductionEventThresholds;
private final Map<Flow, Integer> latePublishingEventThresholds;

public BlockProductionAndPublishingPerformanceFactory(
final TimeProvider timeProvider,
final Function<UInt64, UInt64> slotTimeCalculator,
final boolean enabled,
final int lateProductionEventThreshold,
final int latePublishingEventThreshold) {
final int lateProductionEventLocalThreshold,
final int lateProductionEventBuilderThreshold,
final int latePublishingEventLocalThreshold,
final int latePublishingEvenBuilderThreshold) {
this.timeProvider = timeProvider;
this.slotTimeCalculator = slotTimeCalculator;
this.enabled = enabled;
this.lateProductionEventThreshold = lateProductionEventThreshold;
this.latePublishingEventThreshold = latePublishingEventThreshold;
this.lateProductionEventThresholds =
Map.of(
Flow.LOCAL,
lateProductionEventLocalThreshold,
Flow.BUILDER,
lateProductionEventBuilderThreshold);
this.latePublishingEventThresholds =
Map.of(
Flow.LOCAL,
latePublishingEventLocalThreshold,
Flow.BUILDER,
latePublishingEvenBuilderThreshold);
}

public BlockProductionPerformance createForProduction(final UInt64 slot) {
if (enabled) {
return new BlockProductionPerformanceImpl(
timeProvider, slot, slotTimeCalculator.apply(slot), lateProductionEventThreshold);
timeProvider, slot, slotTimeCalculator.apply(slot), lateProductionEventThresholds);
} else {
return BlockProductionPerformance.NOOP;
}
Expand All @@ -49,7 +63,7 @@ public BlockProductionPerformance createForProduction(final UInt64 slot) {
public BlockPublishingPerformance createForPublishing(final UInt64 slot) {
if (enabled) {
return new BlockPublishingPerformanceImpl(
timeProvider, slot, slotTimeCalculator.apply(slot), latePublishingEventThreshold);
timeProvider, slot, slotTimeCalculator.apply(slot), latePublishingEventThresholds);
} else {
return BlockPublishingPerformance.NOOP;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@

package tech.pegasys.teku.ethereum.performance.trackers;

import java.util.Map;
import tech.pegasys.teku.infrastructure.logging.EventLogger;
import tech.pegasys.teku.infrastructure.time.PerformanceTracker;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class BlockProductionPerformanceImpl implements BlockProductionPerformance {

private final PerformanceTracker performanceTracker;
private final UInt64 slot;
private final UInt64 slotTime;
private final int lateThreshold;
private final Map<Flow, Integer> lateThresholds;

private volatile Flow flow = Flow.LOCAL;

BlockProductionPerformanceImpl(
final TimeProvider timeProvider,
final UInt64 slot,
final UInt64 slotTime,
final int lateThreshold) {
final Map<Flow, Integer> lateThresholds) {
this.performanceTracker = new PerformanceTracker(timeProvider);
this.lateThreshold = lateThreshold;
this.lateThresholds = lateThresholds;
this.slot = slot;
this.slotTime = slotTime;
performanceTracker.addEvent("start");
Expand All @@ -39,7 +43,8 @@ public class BlockProductionPerformanceImpl implements BlockProductionPerformanc
@Override
public void complete() {
final UInt64 completionTime = performanceTracker.addEvent(COMPLETE_LABEL);
final boolean isLateEvent = completionTime.minusMinZero(slotTime).isGreaterThan(lateThreshold);
final boolean isLateEvent =
completionTime.minusMinZero(slotTime).isGreaterThan(lateThresholds.get(flow));
performanceTracker.report(
slotTime,
isLateEvent,
Expand Down Expand Up @@ -82,6 +87,8 @@ public void engineGetPayload() {
@Override
public void builderGetHeader() {
performanceTracker.addEvent("builder_get_header");
// set the flow to BUILDER when builderGetHeader has been called
flow = Flow.BUILDER;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@

package tech.pegasys.teku.ethereum.performance.trackers;

import java.util.Map;
import tech.pegasys.teku.infrastructure.logging.EventLogger;
import tech.pegasys.teku.infrastructure.time.PerformanceTracker;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class BlockPublishingPerformanceImpl implements BlockPublishingPerformance {

private final PerformanceTracker performanceTracker;
private final UInt64 slot;
private final UInt64 slotTime;
private final int lateThreshold;
private final Map<Flow, Integer> lateThresholds;

private volatile Flow flow = Flow.LOCAL;

BlockPublishingPerformanceImpl(
final TimeProvider timeProvider,
final UInt64 slot,
final UInt64 slotTime,
final int lateThreshold) {
final Map<Flow, Integer> lateThresholds) {
this.performanceTracker = new PerformanceTracker(timeProvider);
this.lateThreshold = lateThreshold;
this.lateThresholds = lateThresholds;
this.slot = slot;
this.slotTime = slotTime;
performanceTracker.addEvent("start");
Expand All @@ -39,7 +43,8 @@ public class BlockPublishingPerformanceImpl implements BlockPublishingPerformanc
@Override
public void complete() {
final UInt64 completionTime = performanceTracker.addEvent(COMPLETE_LABEL);
final boolean isLateEvent = completionTime.minusMinZero(slotTime).isGreaterThan(lateThreshold);
final boolean isLateEvent =
completionTime.minusMinZero(slotTime).isGreaterThan(lateThresholds.get(flow));
performanceTracker.report(
slotTime,
isLateEvent,
Expand All @@ -52,6 +57,8 @@ public void complete() {
@Override
public void builderGetPayload() {
performanceTracker.addEvent("builder_get_payload");
// set the flow to BUILDER when builderGetPayload has been called
flow = Flow.BUILDER;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Consensys Software Inc., 2024
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.ethereum.performance.trackers;

public enum Flow {
LOCAL,
BUILDER
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public SafeFuture<BuilderBidOrFallbackData> builderGetHeader(
SchemaDefinitionsBellatrix.required(spec.atSlot(slot).getSchemaDefinitions());

return engineGetPayload(executionPayloadContext, state)
.thenPeek(__ -> blockProductionPerformance.engineGetPayload())
.alwaysRun(blockProductionPerformance::engineGetPayload)
.thenApply(
getPayloadResponse -> {
final ExecutionPayload executionPayload = getPayloadResponse.getExecutionPayload();
Expand Down Expand Up @@ -415,7 +415,7 @@ public SafeFuture<BuilderBidOrFallbackData> builderGetHeader(
});
return BuilderBidOrFallbackData.create(builderBid);
})
.thenPeek(__ -> blockProductionPerformance.builderGetHeader());
.alwaysRun(blockProductionPerformance::builderGetHeader);
}

@Override
Expand Down
Loading

0 comments on commit fc7bc96

Please sign in to comment.