Skip to content

Commit

Permalink
[Builder API] Update for Electra spec
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Oct 14, 2024
1 parent dfd7f9d commit 67e30df
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,38 @@ private SafeFuture<Void> setExecutionRequests(
if (!bodyBuilder.supportsExecutionRequests()) {
return SafeFuture.COMPLETE;
}

final SafeFuture<ExecutionRequests> executionRequestsFuture;
final SafeFuture<ExecutionRequests> executionRequests;
if (executionPayloadResult.isFromLocalFlow()) {
executionRequestsFuture =
// local, non-blinded flow
executionRequests =
executionPayloadResult
.getExecutionRequestsFromLocalFlow()
.getExecutionRequestsFutureFromLocalFlow()
.orElseThrow()
.thenApply(Optional::orElseThrow);
} else {
// TODO Add support for builder flow in Electra
// (https://github.com/Consensys/teku/issues/8624)
executionRequestsFuture = SafeFuture.completedFuture(null);
// builder, blinded flow
executionRequests =
executionPayloadResult
.getBuilderBidOrFallbackDataFuture()
.orElseThrow()
.thenApply(this::getExecutionRequestsFromBuilderFlow);
}

return executionRequestsFuture.thenAccept(bodyBuilder::executionRequests);
return executionRequests.thenAccept(bodyBuilder::executionRequests);
}

private ExecutionRequests getExecutionRequestsFromBuilderFlow(
final BuilderBidOrFallbackData builderBidOrFallbackData) {
return builderBidOrFallbackData
.getBuilderBid()
// from the builder bid
.flatMap(BuilderBid::getOptionalExecutionRequests)
// from the local fallback
.orElse(
builderBidOrFallbackData
.getFallbackDataRequired()
.getExecutionRequests()
.orElseThrow());
}

public Consumer<SignedBeaconBlockUnblinder> createBlockUnblinderSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
package tech.pegasys.teku.api.schema.electra;

import static com.google.common.base.Preconditions.checkNotNull;
import static tech.pegasys.teku.api.schema.SchemaConstants.DESCRIPTION_BYTES32;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.api.schema.Attestation;
Expand All @@ -39,6 +37,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra.BlindedBeaconBlockBodySchemaElectra;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsSchema;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;

public class BlindedBeaconBlockBodyElectra extends BeaconBlockBodyAltair {
Expand All @@ -52,9 +51,8 @@ public class BlindedBeaconBlockBodyElectra extends BeaconBlockBodyAltair {
@JsonProperty("blob_kzg_commitments")
public final List<KZGCommitment> blobKZGCommitments;

@JsonProperty("execution_requests_root")
@Schema(type = "string", format = "byte", description = DESCRIPTION_BYTES32)
public final Bytes32 executionRequestsRoot;
@JsonProperty("execution_requests")
public final ExecutionRequests executionRequests;

@JsonCreator
public BlindedBeaconBlockBodyElectra(
Expand All @@ -72,7 +70,7 @@ public BlindedBeaconBlockBodyElectra(
@JsonProperty("bls_to_execution_changes")
final List<SignedBlsToExecutionChange> blsToExecutionChanges,
@JsonProperty("blob_kzg_commitments") final List<KZGCommitment> blobKZGCommitments,
@JsonProperty("execution_requests_root") final Bytes32 executionRequestsRoot) {
@JsonProperty("execution_requests") final ExecutionRequests executionRequests) {
super(
randaoReveal,
eth1Data,
Expand All @@ -91,9 +89,8 @@ public BlindedBeaconBlockBodyElectra(
this.blsToExecutionChanges = blsToExecutionChanges;
checkNotNull(blobKZGCommitments, "BlobKZGCommitments is required for Electra blinded blocks");
this.blobKZGCommitments = blobKZGCommitments;
checkNotNull(
executionRequestsRoot, "ExecutionRequestsRoot is required for Electra blinded blocks");
this.executionRequestsRoot = executionRequestsRoot;
checkNotNull(executionRequests, "ExecutionRequests is required for Electra blinded blocks");
this.executionRequests = executionRequests;
}

public BlindedBeaconBlockBodyElectra(
Expand All @@ -110,9 +107,7 @@ public BlindedBeaconBlockBodyElectra(
.map(SszKZGCommitment::getKZGCommitment)
.map(KZGCommitment::new)
.toList();
// TODO Electra Builder API changes
// (https://github.com/Consensys/teku/issues/8624)
this.executionRequestsRoot = Bytes32.ZERO;
this.executionRequests = new ExecutionRequests(blockBody.getExecutionRequests());
}

@Override
Expand All @@ -139,6 +134,9 @@ public BeaconBlockBody asInternalBeaconBlockBody(final SpecVersion spec) {
final SszListSchema<SszKZGCommitment, ?> blobKZGCommitmentsSchema =
getBeaconBlockBodySchema(spec).getBlobKzgCommitmentsSchema();

final ExecutionRequestsSchema executionRequestsSchema =
getBeaconBlockBodySchema(spec).getExecutionRequestsSchema();

return super.asInternalBeaconBlockBody(
spec,
builder -> {
Expand All @@ -154,7 +152,8 @@ public BeaconBlockBody asInternalBeaconBlockBody(final SpecVersion spec) {
.map(KZGCommitment::asInternalKZGCommitment)
.map(SszKZGCommitment::new)
.collect(blobKZGCommitmentsSchema.collector()));
// TODO Electra Builder API changes (https://github.com/Consensys/teku/pull/8600)
builder.executionRequests(
this.executionRequests.asInternalConsolidationRequest(executionRequestsSchema));
return SafeFuture.COMPLETE;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static tech.pegasys.teku.spec.SpecMilestone.BELLATRIX;
import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
import static tech.pegasys.teku.spec.SpecMilestone.DENEB;
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
import static tech.pegasys.teku.spec.schemas.ApiSchemas.SIGNED_VALIDATOR_REGISTRATIONS_SCHEMA;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -60,9 +61,8 @@
import tech.pegasys.teku.spec.networks.Eth2Network;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;

// TODO Re-enable electra as part of https://github.com/Consensys/teku/issues/8624
@TestSpecContext(
milestone = {BELLATRIX, CAPELLA, DENEB},
milestone = {BELLATRIX, CAPELLA, DENEB, ELECTRA},
network = Eth2Network.MAINNET)
class RestBuilderClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tech.pegasys.teku.infrastructure.ssz.SszContainer;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequests;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;

public interface BuilderBid extends SszContainer {
Expand All @@ -27,6 +28,8 @@ public interface BuilderBid extends SszContainer {

Optional<SszList<SszKZGCommitment>> getOptionalBlobKzgCommitments();

Optional<ExecutionRequests> getOptionalExecutionRequests();

UInt256 getValue();

BLSPublicKey getPublicKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequests;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;

public interface BuilderBidBuilder {
Expand All @@ -25,6 +26,8 @@ public interface BuilderBidBuilder {

BuilderBidBuilder blobKzgCommitments(SszList<SszKZGCommitment> blobKzgCommitments);

BuilderBidBuilder executionRequests(ExecutionRequests executionRequests);

BuilderBidBuilder value(UInt256 value);

BuilderBidBuilder publicKey(BLSPublicKey publicKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public class ExecutionPayloadAndBlobsBundleSchema
extends ContainerSchema2<ExecutionPayloadAndBlobsBundle, ExecutionPayload, BlobsBundle>
implements BuilderPayloadSchema<ExecutionPayloadAndBlobsBundle> {

// TODO Update as part of Builder API Electra updates
// (https://github.com/Consensys/teku/issues/8624)

public ExecutionPayloadAndBlobsBundleSchema(
final ExecutionPayloadSchema<? extends ExecutionPayload> executionPayloadSchema,
final BlobsBundleSchema blobsBundleSchema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBid;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequests;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszPublicKey;

Expand Down Expand Up @@ -51,6 +52,11 @@ public Optional<SszList<SszKZGCommitment>> getOptionalBlobKzgCommitments() {
return Optional.empty();
}

@Override
public Optional<ExecutionRequests> getOptionalExecutionRequests() {
return Optional.empty();
}

@Override
public UInt256 getValue() {
return getField1().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tech.pegasys.teku.spec.datastructures.builder.BuilderBid;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBidBuilder;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequests;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszPublicKey;

Expand Down Expand Up @@ -49,6 +50,11 @@ public BuilderBidBuilder blobKzgCommitments(final SszList<SszKZGCommitment> blob
return this;
}

@Override
public BuilderBidBuilder executionRequests(final ExecutionRequests executionRequests) {
return this;
}

@Override
public BuilderBidBuilder value(final UInt256 value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

package tech.pegasys.teku.spec.datastructures.builder.versions.deneb;

import java.util.Optional;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.Container4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt256;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequests;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszPublicKey;

Expand Down Expand Up @@ -50,6 +52,11 @@ public ExecutionPayloadHeader getHeader() {
return getField0();
}

@Override
public Optional<ExecutionRequests> getOptionalExecutionRequests() {
return Optional.empty();
}

@Override
public SszList<SszKZGCommitment> getBlobKzgCommitments() {
return getField1();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Consensys Software Inc., 2023
*
* 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.spec.datastructures.builder.versions.electra;

import static com.google.common.base.Preconditions.checkNotNull;

import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt256;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBid;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBidBuilder;
import tech.pegasys.teku.spec.datastructures.builder.versions.deneb.BuilderBidBuilderDeneb;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequests;
import tech.pegasys.teku.spec.datastructures.type.SszPublicKey;

public class BuilderBidBuilderElectra extends BuilderBidBuilderDeneb {

private BuilderBidSchemaElectra schema;

protected ExecutionRequests executionRequests;

public BuilderBidBuilderElectra schema(final BuilderBidSchemaElectra schema) {
this.schema = schema;
return this;
}

@Override
public BuilderBidBuilder executionRequests(final ExecutionRequests executionRequests) {
this.executionRequests = executionRequests;
return this;
}

@Override
public BuilderBid build() {
return new BuilderBidElectraImpl(
schema,
header,
blobKzgCommitments,
executionRequests,
SszUInt256.of(value),
new SszPublicKey(publicKey));
}

@Override
protected void validate() {
super.validate();
checkNotNull(blobKzgCommitments, "blobKzgCommitments must be specified");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tech.pegasys.teku.spec.datastructures.builder.versions.electra;

import java.util.Optional;
import tech.pegasys.teku.spec.datastructures.builder.versions.deneb.BuilderBidDeneb;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequests;

public interface BuilderBidElectra extends BuilderBidDeneb {

ExecutionRequests getExecutionRequests();

@Override
default Optional<ExecutionRequests> getOptionalExecutionRequests() {
return Optional.of(getExecutionRequests());
}
}
Loading

0 comments on commit 67e30df

Please sign in to comment.