Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove notion of BlindedBlobsBundle #7674

Merged
merged 14 commits into from
Nov 8, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blobs.SignedBlobSidecarsUnblinder;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlindedBlobSidecar;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlindedBlobSidecarSchema;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarOld;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchemaOld;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockUnblinder;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayload;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
Expand Down Expand Up @@ -291,26 +288,15 @@ private void builderSetKzgCommitments(
final SafeFuture<SszList<SszKZGCommitment>> blobKzgCommitments =
executionPayloadResultFuture.thenCompose(
executionPayloadResult -> {
final SszListSchema<SszKZGCommitment, ?> blobKzgCommitmentsSchema =
schemaDefinitionsDeneb
.getBeaconBlockBodySchema()
.toVersionDeneb()
.orElseThrow()
.getBlobKzgCommitmentsSchema();
if (bodyBuilder.isBlinded()) {
return getBlindedBlobsBundle(executionPayloadResult)
.thenApply(
blindedBlobsBundle ->
blobKzgCommitmentsSchema.createFromElements(
blindedBlobsBundle.getCommitments().asList()));
return getBlobKzgCommitments(executionPayloadResult);
} else {
return getBlobsBundle(executionPayloadResult)
.thenApply(
blobsBundle ->
blobKzgCommitmentsSchema.createFromElements(
blobsBundle.getCommitments().stream()
.map(SszKZGCommitment::new)
.toList()));
schemaDefinitionsDeneb
.getBlobKzgCommitmentsSchema()
.createFromBlobsBundle(blobsBundle));
}
});
bodyBuilder.blobKzgCommitments(blobKzgCommitments);
Expand Down Expand Up @@ -346,6 +332,7 @@ public Consumer<SignedBeaconBlockUnblinder> createBlockUnblinderSelector() {
};
}

@Deprecated
public Consumer<SignedBlobSidecarsUnblinder> createBlobSidecarsUnblinderSelector(
final UInt64 slot) {
return blobSidecarsUnblinder ->
Expand Down Expand Up @@ -394,70 +381,46 @@ public Function<BeaconBlock, SafeFuture<List<BlobSidecarOld>>> createBlobSidecar
};
}

@Deprecated
public Function<BeaconBlock, SafeFuture<List<BlindedBlobSidecar>>>
createBlindedBlobSidecarsSelector() {
return block -> {
final BlindedBlobSidecarSchema blindedBlobSidecarSchema =
SchemaDefinitionsDeneb.required(spec.atSlot(block.getSlot()).getSchemaDefinitions())
.getBlindedBlobSidecarSchema();
return getCachedBlindedBlobsBundle(block.getSlot())
.thenApply(
blindedBlobsBundle ->
IntStream.range(0, blindedBlobsBundle.getNumberOfBlobs())
.mapToObj(
index ->
blindedBlobSidecarSchema.create(
block.getRoot(),
UInt64.valueOf(index),
block.getSlot(),
block.getParentRoot(),
block.getProposerIndex(),
blindedBlobsBundle.getBlobRoots().get(index).get(),
blindedBlobsBundle.getCommitments().get(index).getKZGCommitment(),
blindedBlobsBundle.getProofs().get(index).getKZGProof()))
.toList());
};
return block -> SafeFuture.completedFuture(List.of());
}

private SafeFuture<BlobsBundle> getBlobsBundle(
final ExecutionPayloadResult executionPayloadResult) {
return executionPayloadResult
.getBlobsBundleFuture()
.orElseThrow(() -> blobsBundleIsNotAvailableException(false))
.orElseThrow(this::blobsBundleIsNotAvailableException)
.thenApply(
blobsBundle ->
blobsBundle.orElseThrow(() -> blobsBundleIsNotAvailableException(false)));
blobsBundle -> blobsBundle.orElseThrow(this::blobsBundleIsNotAvailableException));
}

private SafeFuture<BlindedBlobsBundle> getBlindedBlobsBundle(
private SafeFuture<SszList<SszKZGCommitment>> getBlobKzgCommitments(
final ExecutionPayloadResult executionPayloadResult) {
return executionPayloadResult
.getHeaderWithFallbackDataFuture()
.orElseThrow(() -> new IllegalStateException("HeaderWithFallbackData is not available"))
.thenApply(
headerWithFallbackData ->
headerWithFallbackData
.getBlindedBlobsBundle()
.orElseThrow(() -> blobsBundleIsNotAvailableException(true)));
.getBlobKzgCommitments()
.orElseThrow(
() -> new IllegalStateException("BlobKzgCommitments are not available")));
}

private SafeFuture<BlobsBundle> getCachedBlobsBundle(final UInt64 slot) {
final ExecutionPayloadResult executionPayloadResult = getCachedPayloadResult(slot);
return getBlobsBundle(executionPayloadResult);
}

private SafeFuture<BlindedBlobsBundle> getCachedBlindedBlobsBundle(final UInt64 slot) {
final ExecutionPayloadResult executionPayloadResult = getCachedPayloadResult(slot);
return getBlindedBlobsBundle(executionPayloadResult);
}

private ExecutionPayloadResult getCachedPayloadResult(final UInt64 slot) {
return executionLayerBlockProductionManager
.getCachedPayloadResult(slot)
.orElseThrow(() -> new IllegalStateException("ExecutionPayloadResult is not available"));
}

private IllegalStateException blobsBundleIsNotAvailableException(final boolean blinded) {
return new IllegalStateException((blinded ? "Blinded" : "") + "BlobsBundle is not available");
private IllegalStateException blobsBundleIsNotAvailableException() {
return new IllegalStateException("BlobsBundle is not available");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.bellatrix.BeaconBlockBodyBellatrix;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.bellatrix.BlindedBeaconBlockBodyBellatrix;
import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle;
import tech.pegasys.teku.spec.datastructures.builder.BuilderPayload;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
Expand Down Expand Up @@ -104,8 +103,9 @@ public abstract class AbstractBlockFactoryTest {
protected ExecutionPayload executionPayload = null;
protected Optional<BlobsBundle> blobsBundle = Optional.empty();

// builder context
protected ExecutionPayloadHeader executionPayloadHeader = null;
protected Optional<BlindedBlobsBundle> blindedBlobsBundle = Optional.empty();
protected Optional<SszList<SszKZGCommitment>> blobKzgCommitments = Optional.empty();

protected ExecutionPayloadResult cachedExecutionPayloadResult = null;

Expand Down Expand Up @@ -343,11 +343,12 @@ protected BlobsBundle prepareBlobsBundle(final Spec spec, final int count) {
return blobsBundle;
}

protected BlindedBlobsBundle prepareBlindedBlobsBundle(final Spec spec, final int count) {
protected SszList<SszKZGCommitment> prepareBlobKzgCommitments(final Spec spec, final int count) {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final BlindedBlobsBundle blindedBlobsBundle = dataStructureUtil.randomBlindedBlobsBundle(count);
this.blindedBlobsBundle = Optional.of(blindedBlobsBundle);
return blindedBlobsBundle;
final SszList<SszKZGCommitment> blobKzgCommitments =
dataStructureUtil.randomBlobKzgCommitments(count);
this.blobKzgCommitments = Optional.of(blobKzgCommitments);
return blobKzgCommitments;
}

private void setupExecutionLayerBlockAndBlobsProduction() {
Expand Down Expand Up @@ -405,7 +406,7 @@ private void setupExecutionLayerBlockAndBlobsProduction() {
Optional.of(
SafeFuture.completedFuture(
HeaderWithFallbackData.create(
executionPayloadHeader, blindedBlobsBundle))),
executionPayloadHeader, blobKzgCommitments))),
Optional.empty());
cachedExecutionPayloadResult = executionPayloadResult;
return executionPayloadResult;
Expand Down Expand Up @@ -435,14 +436,11 @@ private List<SszKZGCommitment> getCommitmentsFromBlobsBundle() {
blobsBundle.getCommitments().stream()
.map(SszKZGCommitment::new)
.collect(Collectors.toList()))
.or(
() ->
blindedBlobsBundle.map(
blindedBlobsBundle -> blindedBlobsBundle.getCommitments().asList()))
.or(() -> blobKzgCommitments.map(SszList::asList))
.orElseThrow(
() ->
new IllegalStateException(
"Neither BlobsBundle or BlindedBlobsBundle were prepared"));
"Neither BlobsBundle or BlobKzgCommitments were prepared"));
}

private BuilderPayload getBuilderPayload(final Spec spec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlindedBlobSidecar;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarOld;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.SignedBlindedBlobSidecar;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.SignedBlobSidecarOld;
Expand All @@ -37,8 +37,8 @@
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlindedBlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents;
import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
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 @@ -70,27 +70,20 @@ void shouldCreateBlockContents() {
}

@Test
@Disabled("enable when block production flow for blob sidecar inclusion proof is implemented")
void shouldCreateBlindedBlockContentsWhenBlindedBlockRequested() {

final BlindedBlobsBundle blindedBlobsBundle = prepareBlindedBlobsBundle(spec, 3);
final SszList<SszKZGCommitment> blobKzgCommitments = prepareBlobKzgCommitments(spec, 3);

final BlockContainer blockContainer =
assertBlockCreated(1, spec, false, state -> prepareValidPayload(spec, state), true);

assertThat(blockContainer).isInstanceOf(BlindedBlockContents.class);
final BlindedBlockContainer blindedBlockContainer = blockContainer.toBlinded().orElseThrow();
assertThat(blindedBlockContainer.getBlock().getBody().getOptionalBlobKzgCommitments())
.hasValueSatisfying(blobKzgCommitments -> assertThat(blobKzgCommitments).hasSize(3));
.hasValue(blobKzgCommitments);
assertThat(blindedBlockContainer.getBlindedBlobSidecars())
.hasValueSatisfying(
blindedBlobSidecars ->
assertThat(blindedBlobSidecars)
.hasSize(3)
.map(BlindedBlobSidecar::getBlobRoot)
.hasSameElementsAs(
blindedBlobsBundle.getBlobRoots().stream()
.map(SszBytes32::get)
.collect(Collectors.toList())));
.hasValueSatisfying(blindedBlobSidecars -> assertThat(blindedBlobSidecars).hasSize(3));
}

@Test
Expand All @@ -108,12 +101,10 @@ void unblindSignedBlock_shouldPassthroughUnblindedBlockContents() {
void unblindSignedBlock_shouldUnblindBlockContents() {

final BlobsBundle blobsBundle = prepareBlobsBundle(spec, 3);
// let the unblinder return consistent BlindedBlobsBundle
blindedBlobsBundle =
// let the unblinder verify the kzg commitments
blobKzgCommitments =
Optional.of(
schemaDefinitions
.getBlindedBlobsBundleSchema()
.createFromExecutionBlobsBundle(blobsBundle));
schemaDefinitions.getBlobKzgCommitmentsSchema().createFromBlobsBundle(blobsBundle));

final List<SignedBlindedBlobSidecar> blindedBlobSidecars =
dataStructureUtil.randomSignedBlindedBlobSidecars(blobsBundle);
Expand Down
Loading
Loading