Skip to content

Commit

Permalink
Remove BlindedBlobsBundle from the BuilderBid
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 7, 2023
1 parent 2f66238 commit 57dcf79
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlindedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle;
import tech.pegasys.teku.spec.datastructures.builder.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBid;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayload;
Expand All @@ -51,6 +50,7 @@
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;
import tech.pegasys.teku.spec.datastructures.execution.HeaderWithFallbackData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;

Expand Down Expand Up @@ -249,11 +249,11 @@ private SafeFuture<HeaderWithFallbackData> getResultFromSignedBuilderBid(
final ExecutionPayloadHeader executionPayloadHeader =
builderBidValidator.validateAndGetPayloadHeader(
spec, signedBuilderBid, validatorRegistration, state, localExecutionPayload);
final Optional<BlindedBlobsBundle> blindedBlobsBundle =
signedBuilderBid.getMessage().getOptionalBlindedBlobsBundle();
final Optional<SszList<SszKZGCommitment>> blobKzgCommitments =
signedBuilderBid.getMessage().getOptionalBlobKzgCommitments();
payloadValueResult.complete(signedBuilderBid.getMessage().getValue());
return SafeFuture.completedFuture(
HeaderWithFallbackData.create(executionPayloadHeader, blindedBlobsBundle));
HeaderWithFallbackData.create(executionPayloadHeader, blobKzgCommitments));
}

public SafeFuture<Void> builderRegisterValidators(
Expand Down Expand Up @@ -351,21 +351,18 @@ private SafeFuture<HeaderWithFallbackData> getResultFromLocalGetPayloadResponse(
.orElseThrow()
.getExecutionPayloadHeaderSchema()
.createFromExecutionPayload(executionPayload);
final Optional<BlindedBlobsBundle> blindedBlobsBundle =
final Optional<SszList<SszKZGCommitment>> blobKzgCommitments =
getPayloadResponse
.getBlobsBundle()
.map(
executionBlobsBundle -> {
final SchemaDefinitionsDeneb schemaDefinitionsDeneb =
SchemaDefinitionsDeneb.required(schemaDefinitions);
return schemaDefinitionsDeneb
.getBlindedBlobsBundleSchema()
.createFromExecutionBlobsBundle(executionBlobsBundle);
});
blobsBundle ->
SchemaDefinitionsDeneb.required(schemaDefinitions)
.getBlobKzgCommitmentsSchema()
.createFromBlobsBundle(blobsBundle));
final FallbackData fallbackData =
new FallbackData(executionPayload, getPayloadResponse.getBlobsBundle(), reason);
return HeaderWithFallbackData.create(
executionPayloadHeader, blindedBlobsBundle, fallbackData);
executionPayloadHeader, blobKzgCommitments, fallbackData);
});
}

Expand Down Expand Up @@ -404,11 +401,10 @@ private SafeFuture<BuilderPayload> getPayloadFromBuilderOrFallbackData(
// the blobs bundle compatibility is done by SignedBlobSidecarsUnblinder
return headerWithFallbackDataFuture.thenCompose(
headerWithFallbackData -> {
if (headerWithFallbackData.getFallbackDataOptional().isEmpty()) {
if (headerWithFallbackData.getFallbackData().isEmpty()) {
return getPayloadFromBuilder(signedBlindedBlockContainer.getSignedBlock());
} else {
final FallbackData fallbackData =
headerWithFallbackData.getFallbackDataOptional().get();
final FallbackData fallbackData = headerWithFallbackData.getFallbackData().get();
logFallbackToLocalExecutionPayloadAndBlobsBundle(fallbackData);
executionLayerManager.recordExecutionPayloadFallbackSource(
Source.BUILDER_LOCAL_EL_FALLBACK, fallbackData.getReason());
Expand Down Expand Up @@ -505,8 +501,8 @@ private void logReceivedBuilderBid(final BuilderBid builderBid) {
final ExecutionPayloadHeader payloadHeader = builderBid.getHeader();
final String blobsLog =
builderBid
.getOptionalBlindedBlobsBundle()
.map(blindedBlobsBundle -> ", Blobs count = " + blindedBlobsBundle.getNumberOfBlobs())
.getOptionalBlobKzgCommitments()
.map(blobKzgCommitments -> ", Blobs count = " + blobKzgCommitments.size())
.orElse("");
LOG.info(
"Received Builder Bid (Block Number = {}, Block Hash = {}, MEV Reward (ETH) = {}, Gas Limit = {}, Gas Used = {}{})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
import tech.pegasys.teku.infrastructure.logging.EventLogger;
import tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlindedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlindedBlockContents;
import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBid;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayload;
import tech.pegasys.teku.spec.datastructures.builder.ExecutionPayloadAndBlobsBundle;
Expand All @@ -57,6 +57,7 @@
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;
import tech.pegasys.teku.spec.datastructures.execution.HeaderWithFallbackData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.spec.util.DataStructureUtil;

Expand Down Expand Up @@ -251,8 +252,8 @@ public void postDeneb_builderOffline() throws Exception {
final ExecutionPayloadHeader header =
schemaDefinitions.getExecutionPayloadHeaderSchema().createFromExecutionPayload(payload);

final BlindedBlobsBundle blindedBlobsBundle =
schemaDefinitions.getBlindedBlobsBundleSchema().createFromExecutionBlobsBundle(blobsBundle);
final SszList<SszKZGCommitment> blobKzgCommitments =
schemaDefinitions.getBlobKzgCommitmentsSchema().createFromBlobsBundle(blobsBundle);

final ExecutionPayloadResult executionPayloadResult =
blockProductionManager.initiateBlockAndBlobsProduction(
Expand All @@ -269,7 +270,7 @@ public void postDeneb_builderOffline() throws Exception {
final HeaderWithFallbackData expectedResult =
HeaderWithFallbackData.create(
header,
Optional.of(blindedBlobsBundle),
Optional.of(blobKzgCommitments),
new FallbackData(
payload, Optional.of(blobsBundle), FallbackReason.BUILDER_NOT_AVAILABLE));
final SafeFuture<HeaderWithFallbackData> headerWithFallbackDataFuture =
Expand Down Expand Up @@ -305,7 +306,8 @@ public void postDeneb_builderOnline() throws Exception {
prepareEngineGetPayloadResponseWithBlobs(executionPayloadContext, executionPayloadValue, slot);

final HeaderWithFallbackData expectedResult =
HeaderWithFallbackData.create(builderBid.getHeader(), Optional.empty());
HeaderWithFallbackData.create(
builderBid.getHeader(), builderBid.getOptionalBlobKzgCommitments());

final ExecutionPayloadResult executionPayloadResult =
blockProductionManager.initiateBlockAndBlobsProduction(
Expand Down Expand Up @@ -419,8 +421,7 @@ private BuilderPayload verifyFallbackToLocalEL(
final UInt64 slot,
final ExecutionPayloadContext executionPayloadContext,
final HeaderWithFallbackData headerWithFallbackData) {
final FallbackData fallbackData =
headerWithFallbackData.getFallbackDataOptional().orElseThrow();
final FallbackData fallbackData = headerWithFallbackData.getFallbackData().orElseThrow();
final FallbackReason fallbackReason = fallbackData.getReason();
if (fallbackReason == FallbackReason.BUILDER_HEADER_NOT_AVAILABLE
|| fallbackReason == FallbackReason.BUILDER_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import tech.pegasys.teku.infrastructure.logging.EventLogger;
import tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBid;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayload;
import tech.pegasys.teku.spec.datastructures.builder.SignedBuilderBid;
Expand All @@ -56,6 +56,7 @@
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;
import tech.pegasys.teku.spec.datastructures.execution.HeaderWithFallbackData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.spec.util.DataStructureUtil;

Expand Down Expand Up @@ -556,19 +557,19 @@ public void builderGetHeaderGetPayload_shouldReturnHeaderAndPayloadViaEngineOnBu
.orElseThrow()
.getExecutionPayloadHeaderSchema()
.createFromExecutionPayload(getPayloadResponse.getExecutionPayload());
final BlindedBlobsBundle expectedBlindedBlobsBundle =
final SszList<SszKZGCommitment> expectedBlobKzgCommitments =
spec.atSlot(slot)
.getSchemaDefinitions()
.toVersionDeneb()
.orElseThrow()
.getBlindedBlobsBundleSchema()
.createFromExecutionBlobsBundle(getPayloadResponse.getBlobsBundle().orElseThrow());
.getBlobKzgCommitmentsSchema()
.createFromBlobsBundle(getPayloadResponse.getBlobsBundle().orElseThrow());

// we expect local engine header as result
final HeaderWithFallbackData expectedResult =
HeaderWithFallbackData.create(
expectedHeader,
Optional.of(expectedBlindedBlobsBundle),
Optional.of(expectedBlobKzgCommitments),
new FallbackData(
getPayloadResponse.getExecutionPayload(),
getPayloadResponse.getBlobsBundle(),
Expand Down Expand Up @@ -926,8 +927,7 @@ private void verifyFallbackToLocalEL(
final UInt64 slot,
final ExecutionPayloadContext executionPayloadContext,
final HeaderWithFallbackData headerWithFallbackData) {
final FallbackData fallbackData =
headerWithFallbackData.getFallbackDataOptional().orElseThrow();
final FallbackData fallbackData = headerWithFallbackData.getFallbackData().orElseThrow();
final FallbackReason fallbackReason = fallbackData.getReason();
if (fallbackReason == FallbackReason.BUILDER_HEADER_NOT_AVAILABLE
|| fallbackReason == FallbackReason.BUILDER_ERROR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.blobs.versions.deneb;

import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.impl.SszListImpl;
import tech.pegasys.teku.infrastructure.ssz.schema.impl.AbstractSszListSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitmentSchema;

public class BlobKzgCommitmentsSchema
extends AbstractSszListSchema<SszKZGCommitment, SszList<SszKZGCommitment>> {

public BlobKzgCommitmentsSchema(final SpecConfigDeneb specConfig) {
super(SszKZGCommitmentSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock());
}

@Override
public SszList<SszKZGCommitment> createFromBackingNode(final TreeNode node) {
return new SszListImpl<>(this, node);
}

public SszList<SszKZGCommitment> createFromBlobsBundle(final BlobsBundle blobsBundle) {
return createFromElements(
blobsBundle.getCommitments().stream().map(SszKZGCommitment::new).toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tech.pegasys.teku.infrastructure.ssz.tree.GIndexUtil;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
Expand All @@ -43,7 +44,6 @@
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitmentSchema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;

Expand Down Expand Up @@ -98,6 +98,7 @@ public static BeaconBlockBodySchemaDenebImpl create(
final SpecConfigDeneb specConfig,
final AttesterSlashingSchema attesterSlashingSchema,
final SignedBlsToExecutionChangeSchema blsToExecutionChangeSchema,
final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema,
final String containerName) {
return new BeaconBlockBodySchemaDenebImpl(
containerName,
Expand Down Expand Up @@ -130,10 +131,7 @@ public static BeaconBlockBodySchemaDenebImpl create(
BlockBodyFields.BLS_TO_EXECUTION_CHANGES,
SszListSchema.create(
blsToExecutionChangeSchema, specConfig.getMaxBlsToExecutionChanges())),
namedSchema(
BlockBodyFields.BLOB_KZG_COMMITMENTS,
SszListSchema.create(
SszKZGCommitmentSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock())));
namedSchema(BlockBodyFields.BLOB_KZG_COMMITMENTS, blobKzgCommitmentsSchema));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tech.pegasys.teku.infrastructure.ssz.tree.GIndexUtil;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
Expand All @@ -42,7 +43,6 @@
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitmentSchema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;

Expand Down Expand Up @@ -97,6 +97,7 @@ public static BlindedBeaconBlockBodySchemaDenebImpl create(
final SpecConfigDeneb specConfig,
final AttesterSlashingSchema attesterSlashingSchema,
final SignedBlsToExecutionChangeSchema signedBlsToExecutionChangeSchema,
final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema,
final String containerName) {
return new BlindedBeaconBlockBodySchemaDenebImpl(
containerName,
Expand Down Expand Up @@ -131,10 +132,7 @@ public static BlindedBeaconBlockBodySchemaDenebImpl create(
BlockBodyFields.BLS_TO_EXECUTION_CHANGES,
SszListSchema.create(
signedBlsToExecutionChangeSchema, specConfig.getMaxBlsToExecutionChanges())),
namedSchema(
BlockBodyFields.BLOB_KZG_COMMITMENTS,
SszListSchema.create(
SszKZGCommitmentSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock())));
namedSchema(BlockBodyFields.BLOB_KZG_COMMITMENTS, blobKzgCommitmentsSchema));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public interface BuilderBid extends SszContainer {

ExecutionPayloadHeader getHeader();

@Deprecated
default Optional<BlindedBlobsBundle> getOptionalBlindedBlobsBundle() {
return Optional.empty();
}

Optional<SszList<SszKZGCommitment>> getOptionalBlobKzgCommitments();

UInt256 getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt256;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBid;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBidBuilder;
import tech.pegasys.teku.spec.datastructures.builder.BuilderBidSchema;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitmentSchema;
import tech.pegasys.teku.spec.datastructures.type.SszPublicKey;
import tech.pegasys.teku.spec.datastructures.type.SszPublicKeySchema;

Expand All @@ -43,16 +41,13 @@ public class BuilderBidSchemaDeneb

public BuilderBidSchemaDeneb(
final String containerName,
final SpecConfigDeneb specConfig,
final ExecutionPayloadHeaderSchema<?> executionPayloadHeaderSchema) {
final ExecutionPayloadHeaderSchema<?> executionPayloadHeaderSchema,
final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema) {
super(
containerName,
namedSchema(
"header", SszSchema.as(ExecutionPayloadHeader.class, executionPayloadHeaderSchema)),
namedSchema(
"blob_kzg_commitments",
SszListSchema.create(
SszKZGCommitmentSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock())),
namedSchema("blob_kzg_commitments", blobKzgCommitmentsSchema),
namedSchema("value", SszPrimitiveSchemas.UINT256_SCHEMA),
namedSchema("pubkey", SszPublicKeySchema.INSTANCE));
}
Expand Down
Loading

0 comments on commit 57dcf79

Please sign in to comment.