diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/ExecutionPayloadResult.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/ExecutionPayloadResult.java index c9f6b6e2364..497003d00b4 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/ExecutionPayloadResult.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/ExecutionPayloadResult.java @@ -21,31 +21,37 @@ import tech.pegasys.teku.spec.datastructures.builder.BuilderBid; /** - * In non-blinded flow, both {@link #executionPayloadFuture} and {@link #blobsBundleFuture} would be - * present. The {@link #blobsBundleFuture} will have a value when the future is complete only after - * Deneb, otherwise it will be empty. + * In non-blinded flow, {@link #getPayloadResponseFuture} will be present. * - *

In blinded flow, {@link #builderBidOrFallbackDataFuture} would be present + *

In blinded flow, {@link #builderBidOrFallbackDataFuture} would be present. */ public class ExecutionPayloadResult { private final ExecutionPayloadContext executionPayloadContext; - private final Optional> executionPayloadFuture; - private final Optional>> blobsBundleFuture; + private final Optional> getPayloadResponseFuture; private final Optional> builderBidOrFallbackDataFuture; - private final SafeFuture executionPayloadValueFuture; private ExecutionPayloadResult( final ExecutionPayloadContext executionPayloadContext, - final Optional> executionPayloadFuture, - final Optional>> blobsBundleFuture, - final Optional> builderBidOrFallbackDataFuture, - final SafeFuture executionPayloadValueFuture) { + final Optional> getPayloadResponseFuture, + final Optional> builderBidOrFallbackDataFuture) { this.executionPayloadContext = executionPayloadContext; - this.executionPayloadFuture = executionPayloadFuture; - this.blobsBundleFuture = blobsBundleFuture; + this.getPayloadResponseFuture = getPayloadResponseFuture; this.builderBidOrFallbackDataFuture = builderBidOrFallbackDataFuture; - this.executionPayloadValueFuture = executionPayloadValueFuture; + } + + public static ExecutionPayloadResult createForLocalFlow( + final ExecutionPayloadContext executionPayloadContext, + final SafeFuture getPayloadResponseFuture) { + return new ExecutionPayloadResult( + executionPayloadContext, Optional.of(getPayloadResponseFuture), Optional.empty()); + } + + public static ExecutionPayloadResult createForBuilderFlow( + final ExecutionPayloadContext executionPayloadContext, + final SafeFuture builderBidOrFallbackDataFuture) { + return new ExecutionPayloadResult( + executionPayloadContext, Optional.empty(), Optional.of(builderBidOrFallbackDataFuture)); } public ExecutionPayloadContext getExecutionPayloadContext() { @@ -53,11 +59,14 @@ public ExecutionPayloadContext getExecutionPayloadContext() { } public Optional> getExecutionPayloadFutureFromLocalFlow() { - return executionPayloadFuture; + return getPayloadResponseFuture.map( + getPayloadResponse -> + getPayloadResponse.thenApply(GetPayloadResponse::getExecutionPayload)); } public Optional>> getBlobsBundleFutureFromLocalFlow() { - return blobsBundleFuture; + return getPayloadResponseFuture.map( + getPayloadResponse -> getPayloadResponse.thenApply(GetPayloadResponse::getBlobsBundle)); } public Optional> getBuilderBidOrFallbackDataFuture() { @@ -68,31 +77,21 @@ public Optional> getBuilderBidOrFallbackDat * @return the value from the local payload, the builder bid or the local fallback payload */ public SafeFuture getExecutionPayloadValueFuture() { - return executionPayloadValueFuture; + return getPayloadResponseFuture + .map( + getPayloadResponse -> + getPayloadResponse.thenApply(GetPayloadResponse::getExecutionPayloadValue)) + .orElseGet(this::getExecutionPayloadValueFutureFromBuilderFlow); } public boolean isFromLocalFlow() { - return executionPayloadFuture.isPresent(); + return getPayloadResponseFuture.isPresent(); } - public static ExecutionPayloadResult createForLocalFlow( - final ExecutionPayloadContext executionPayloadContext, - final SafeFuture getPayloadResponseFuture) { - final SafeFuture executionPayloadValueFuture = - getPayloadResponseFuture.thenApply(GetPayloadResponse::getExecutionPayloadValue); - return new ExecutionPayloadResult( - executionPayloadContext, - Optional.of(getPayloadResponseFuture.thenApply(GetPayloadResponse::getExecutionPayload)), - Optional.of(getPayloadResponseFuture.thenApply(GetPayloadResponse::getBlobsBundle)), - Optional.empty(), - executionPayloadValueFuture); - } - - public static ExecutionPayloadResult createForBuilderFlow( - final ExecutionPayloadContext executionPayloadContext, - final SafeFuture builderBidOrFallbackDataFuture) { - final SafeFuture executionPayloadValueFuture = - builderBidOrFallbackDataFuture.thenApply( + private SafeFuture getExecutionPayloadValueFutureFromBuilderFlow() { + return builderBidOrFallbackDataFuture + .orElseThrow() + .thenApply( builderBidOrFallbackData -> builderBidOrFallbackData .getBuilderBid() @@ -104,12 +103,6 @@ public static ExecutionPayloadResult createForBuilderFlow( builderBidOrFallbackData .getFallbackDataRequired() .getExecutionPayloadValue())); - return new ExecutionPayloadResult( - executionPayloadContext, - Optional.empty(), - Optional.empty(), - Optional.of(builderBidOrFallbackDataFuture), - executionPayloadValueFuture); } @Override @@ -122,30 +115,22 @@ public boolean equals(final Object o) { } final ExecutionPayloadResult that = (ExecutionPayloadResult) o; return Objects.equals(executionPayloadContext, that.executionPayloadContext) - && Objects.equals(executionPayloadFuture, that.executionPayloadFuture) - && Objects.equals(blobsBundleFuture, that.blobsBundleFuture) - && Objects.equals(builderBidOrFallbackDataFuture, that.builderBidOrFallbackDataFuture) - && Objects.equals(executionPayloadValueFuture, that.executionPayloadValueFuture); + && Objects.equals(getPayloadResponseFuture, that.getPayloadResponseFuture) + && Objects.equals(builderBidOrFallbackDataFuture, that.builderBidOrFallbackDataFuture); } @Override public int hashCode() { return Objects.hash( - executionPayloadContext, - executionPayloadFuture, - blobsBundleFuture, - builderBidOrFallbackDataFuture, - executionPayloadValueFuture); + executionPayloadContext, getPayloadResponseFuture, builderBidOrFallbackDataFuture); } @Override public String toString() { return MoreObjects.toStringHelper(this) .add("executionPayloadContext", executionPayloadContext) - .add("executionPayloadFuture", executionPayloadFuture) - .add("blobsBundleFuture", blobsBundleFuture) + .add("getPayloadResponseFuture", getPayloadResponseFuture) .add("builderBidOrFallbackDataFuture", builderBidOrFallbackDataFuture) - .add("executionPayloadValueFuture", executionPayloadValueFuture) .toString(); } }