From fb879b49f3ac1d8d3caf4e759dcaad294734e121 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Fri, 15 Jul 2022 08:20:57 +0200 Subject: [PATCH] builder fallback improvements (#5935) * builder fallback improvements * fix compilation --- .../BlockOperationSelectorFactory.java | 12 ++---------- .../ExecutionLayerManagerImpl.java | 18 +++++++++++++----- .../ExecutionLayerManagerImplTest.java | 2 +- .../executionlayer/ExecutionLayerChannel.java | 4 ++-- .../ExecutionLayerChannelStub.java | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java index 0797fe030c3..21932a61a1b 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java @@ -19,8 +19,6 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.infrastructure.async.SafeFuture; @@ -47,8 +45,6 @@ import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; public class BlockOperationSelectorFactory { - private static final Logger LOG = LogManager.getLogger(); - private final Spec spec; private final AggregatingAttestationPool attestationPool; private final OperationPool attesterSlashingPool; @@ -153,18 +149,14 @@ public Consumer createSelector( .getExecutionPayloadHeaderSchema() .getHeaderOfDefaultPayload(), (executionPayloadContext) -> { - final boolean forceLocalFallback = + final boolean transitionNotFinalized = executionPayloadContext .getForkChoiceState() .getFinalizedExecutionBlockHash() .isZero(); - if (forceLocalFallback) { - LOG.info( - "Merge transition not finalized: forcing block production using local execution engine"); - } return executionLayerChannel.builderGetHeader( - executionPayloadContext, blockSlotState, forceLocalFallback); + executionPayloadContext, blockSlotState, transitionNotFinalized); })); return; } diff --git a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImpl.java b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImpl.java index 7908acbab63..c28337c5ce5 100644 --- a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImpl.java +++ b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImpl.java @@ -24,6 +24,7 @@ import java.util.Optional; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes32; @@ -337,7 +338,7 @@ public SafeFuture builderRegisterValidators( public SafeFuture builderGetHeader( final ExecutionPayloadContext executionPayloadContext, final BeaconState state, - final boolean forceLocalFallback) { + final boolean transitionNotFinalized) { final UInt64 slot = state.getSlot(); final SafeFuture localExecutionPayload = @@ -348,8 +349,12 @@ public SafeFuture builderGetHeader( // fallback conditions final FallbackReason fallbackReason; - if (forceLocalFallback) { - fallbackReason = FallbackReason.FORCED; + if (executionBuilderClient.isEmpty() && validatorRegistration.isEmpty()) { + fallbackReason = FallbackReason.NOT_NEEDED; + } else if (transitionNotFinalized) { + fallbackReason = FallbackReason.TRANSITION_NOT_FINALIZED; + } else if (executionBuilderClient.isEmpty()) { + fallbackReason = FallbackReason.BUILDER_NOT_CONFIGURED; } else if (!isBuilderAvailable()) { fallbackReason = FallbackReason.BUILDER_NOT_AVAILABLE; } else if (validatorRegistration.isEmpty()) { @@ -521,7 +526,8 @@ private void markBuilderAsNotAvailable(final String errorMessage) { } private void logFallbackToLocalExecutionPayload(final FallbackData fallbackData) { - LOG.info( + LOG.log( + fallbackData.reason == FallbackReason.NOT_NEEDED ? Level.DEBUG : Level.INFO, "Falling back to locally produced execution payload (Block Number {}, Block Hash = {}, Fallback Reason = {})", fallbackData.executionPayload.getBlockNumber(), fallbackData.executionPayload.getBlockHash(), @@ -581,9 +587,11 @@ public String toString() { // Metric - fallback "reason" label values protected enum FallbackReason { + NOT_NEEDED("not_needed"), VALIDATOR_NOT_REGISTERED("validator_not_registered"), - FORCED("forced"), + TRANSITION_NOT_FINALIZED("transition_not_finalized"), BUILDER_NOT_AVAILABLE("builder_not_available"), + BUILDER_NOT_CONFIGURED("builder_not_configured"), BUILDER_HEADER_NOT_AVAILABLE("builder_header_not_available"), BUILDER_ERROR("builder_error"), NONE(""); diff --git a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java index 142d08e55c8..0767ae638c0 100644 --- a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java +++ b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java @@ -403,7 +403,7 @@ public void builderGetHeaderGetPayload_shouldReturnHeaderAndPayloadViaEngineIfBu verifyNoMoreInteractions(executionBuilderClient); verifyNoMoreInteractions(executionEngineClient); - verifySourceCounter(Source.BUILDER_LOCAL_EL_FALLBACK, FallbackReason.FORCED); + verifySourceCounter(Source.BUILDER_LOCAL_EL_FALLBACK, FallbackReason.TRANSITION_NOT_FINALIZED); } @Test diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannel.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannel.java index e2509602098..7fda6d87892 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannel.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannel.java @@ -77,7 +77,7 @@ public SafeFuture builderRegisterValidators( public SafeFuture builderGetHeader( final ExecutionPayloadContext executionPayloadContext, final BeaconState state, - final boolean forceLocalFallback) { + final boolean transitionNotFinalized) { return SafeFuture.completedFuture(null); } @@ -113,7 +113,7 @@ SafeFuture builderRegisterValidators( SafeFuture builderGetHeader( ExecutionPayloadContext executionPayloadContext, BeaconState state, - boolean forceLocalFallback); + boolean transitionNotFinalized); SafeFuture builderGetPayload(SignedBeaconBlock signedBlindedBeaconBlock); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java index bbb163a7ee1..1f83aac3df1 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java @@ -272,7 +272,7 @@ public SafeFuture builderRegisterValidators( public SafeFuture builderGetHeader( final ExecutionPayloadContext executionPayloadContext, final BeaconState state, - final boolean forceLocalFallback) { + final boolean transitionNotFinalized) { final UInt64 slot = state.getSlot(); LOG.info( "getPayloadHeader: payloadId: {} slot: {} ... delegating to getPayload ...",