Skip to content

Commit

Permalink
Don't sign BlobSidecar and delete BlindedBlockContents (#7688)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 10, 2023
1 parent be3c490 commit ee1e1aa
Show file tree
Hide file tree
Showing 59 changed files with 116 additions and 1,476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
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 @@ -32,7 +31,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.blocks.versions.deneb.BlindedBlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
Expand Down Expand Up @@ -60,17 +58,13 @@ public SafeFuture<BlockContainer> createUnsignedBlock(
final boolean blinded) {
return super.createUnsignedBlock(
blockSlotState, newSlot, randaoReveal, optionalGraffiti, blinded)
.thenApply(BlockContainer::getBlock)
.thenCompose(
block -> {
if (block.isBlinded()) {
return operationSelector
.createBlindedBlobSidecarsSelector()
.apply(block)
.thenApply(
blindedBlobSidecars ->
createBlindedBlockContents(block, blindedBlobSidecars));
blockContainer -> {
if (blockContainer.isBlinded()) {
return SafeFuture.completedFuture(blockContainer);
}
// TODO: add blobs and proofs
final BeaconBlock block = blockContainer.getBlock();
return operationSelector
.createBlobSidecarsSelector()
.apply(block)
Expand All @@ -85,17 +79,13 @@ public SafeFuture<BlockContainer> createUnsignedBlock(
final BLSSignature randaoReveal,
final Optional<Bytes32> optionalGraffiti) {
return super.createUnsignedBlock(blockSlotState, newSlot, randaoReveal, optionalGraffiti)
.thenApply(BlockContainer::getBlock)
.thenCompose(
block -> {
if (block.isBlinded()) {
return operationSelector
.createBlindedBlobSidecarsSelector()
.apply(block)
.thenApply(
blindedBlobSidecars ->
createBlindedBlockContents(block, blindedBlobSidecars));
blockContainer -> {
if (blockContainer.isBlinded()) {
return SafeFuture.completedFuture(blockContainer);
}
// TODO: add blobs and proofs
final BeaconBlock block = blockContainer.getBlock();
return operationSelector
.createBlobSidecarsSelector()
.apply(block)
Expand Down Expand Up @@ -127,13 +117,6 @@ private BlockContents createBlockContents(
return schemaDefinitionsDeneb.getBlockContentsSchema().create(block, blobSidecars);
}

private BlindedBlockContents createBlindedBlockContents(
final BeaconBlock block, final List<BlindedBlobSidecar> blindedBlobSidecars) {
return schemaDefinitionsDeneb
.getBlindedBlockContentsSchema()
.create(block, blindedBlobSidecars);
}

/** use {@link BlockFactoryPhase0} unblinding of the {@link SignedBeaconBlock} */
private SafeFuture<SignedBeaconBlock> unblindBlock(
final SignedBlockContainer blindedBlockContainer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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.BlobSidecarOld;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchemaOld;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
Expand Down Expand Up @@ -381,12 +380,6 @@ public Function<BeaconBlock, SafeFuture<List<BlobSidecarOld>>> createBlobSidecar
};
}

@Deprecated
public Function<BeaconBlock, SafeFuture<List<BlindedBlobSidecar>>>
createBlindedBlobSidecarsSelector() {
return block -> SafeFuture.completedFuture(List.of());
}

private SafeFuture<BlobsBundle> getBlobsBundle(
final ExecutionPayloadResult executionPayloadResult) {
return executionPayloadResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
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;
Expand All @@ -27,15 +25,11 @@
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
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;
import tech.pegasys.teku.spec.datastructures.blocks.BlindedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlindedBlockContents;
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.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
Expand Down Expand Up @@ -70,20 +64,17 @@ void shouldCreateBlockContents() {
}

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

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())
assertThat(blockContainer).isInstanceOf(BeaconBlock.class);
final BeaconBlock blindedBeaconBlock = (BeaconBlock) blockContainer;
assertThat(blindedBeaconBlock.getBlock().getBody().getOptionalBlobKzgCommitments())
.hasValue(blobKzgCommitments);
assertThat(blindedBlockContainer.getBlindedBlobSidecars())
.hasValueSatisfying(blindedBlobSidecars -> assertThat(blindedBlobSidecars).hasSize(3));
}

@Test
Expand All @@ -98,51 +89,35 @@ void unblindSignedBlock_shouldPassthroughUnblindedBlockContents() {
}

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

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

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

final SignedBeaconBlock unblindedBeaconBlock = dataStructureUtil.randomSignedBeaconBlock();
final SignedBeaconBlock blindedBlock = assertBlockBlinded(unblindedBeaconBlock, spec);

final SignedBlindedBlockContents blindedBlockContents =
schemaDefinitions
.getSignedBlindedBlockContentsSchema()
.create(blindedBlock, blindedBlobSidecars);
// let the unblinder return a consistent execution payload
executionPayload =
unblindedBeaconBlock.getMessage().getBody().getOptionalExecutionPayload().orElseThrow();

final SignedBlockContainer unblindedBlockContents =
assertBlockUnblinded(blindedBlockContents, spec);
final SignedBlockContainer unblindedBlockContainer = assertBlockUnblinded(blindedBlock, spec);

// make sure getCachedUnblindedPayload is second in order of method calling
final InOrder inOrder = Mockito.inOrder(executionLayer);
inOrder.verify(executionLayer).getUnblindedPayload(blindedBlockContents);
inOrder.verify(executionLayer).getCachedUnblindedPayload(blindedBlockContents.getSlot());

assertThat(unblindedBlockContents).isInstanceOf(SignedBlockContents.class);
assertThat(unblindedBlockContents.isBlinded()).isFalse();
assertThat(unblindedBlockContents.getSignedBlock()).isEqualTo(unblindedBeaconBlock);
assertThat(unblindedBlockContents.getSignedBlobSidecars())
.hasValueSatisfying(
blobSidecars ->
assertThat(blobSidecars)
.map(SignedBlobSidecarOld::getBlobSidecar)
.map(
blobSidecar ->
schemaDefinitions.getBlindedBlobSidecarSchema().create(blobSidecar))
.hasSameElementsAs(
blindedBlobSidecars.stream()
.map(SignedBlindedBlobSidecar::getBlindedBlobSidecar)
.collect(Collectors.toList())));
inOrder.verify(executionLayer).getUnblindedPayload(unblindedBlockContainer);
inOrder.verify(executionLayer).getCachedUnblindedPayload(unblindedBlockContainer.getSlot());

assertThat(unblindedBlockContainer).isInstanceOf(SignedBlockContents.class);
assertThat(unblindedBlockContainer.isBlinded()).isFalse();
assertThat(unblindedBlockContainer.getSignedBlock()).isEqualTo(unblindedBeaconBlock);
assertThat(unblindedBlockContainer.getSignedBlobSidecars())
.hasValueSatisfying(blobSidecars -> assertThat(blobSidecars).isEmpty());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void shouldReturnOkPostDeneb(
final SignedBlockContainer request;

if (isBlindedBlock) {
request = dataStructureUtil.randomSignedBlindedBlockContents(UInt64.ONE);
request = dataStructureUtil.randomSignedBlindedBeaconBlock(UInt64.ONE);
signedBlockContainerSchema =
spec.atSlot(UInt64.ONE).getSchemaDefinitions().getSignedBlindedBlockContainerSchema();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_EXECUTION_PAYLOAD_VALUE;
import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE;
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 com.google.common.io.Resources;
Expand All @@ -53,7 +52,6 @@
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider;
import tech.pegasys.teku.spec.constants.EthConstants;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlindedBlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContents;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadResult;
Expand Down Expand Up @@ -121,7 +119,7 @@ void shouldGetUnblindedBeaconBlockAsSsz() throws IOException {

@TestTemplate
void shouldGetBlindedBeaconBlockAsJson() throws IOException {
assumeThat(specMilestone).isGreaterThanOrEqualTo(BELLATRIX).isLessThanOrEqualTo(CAPELLA);
assumeThat(specMilestone).isGreaterThanOrEqualTo(BELLATRIX);
final BeaconBlock blindedBeaconBlock = dataStructureUtil.randomBlindedBeaconBlock(ONE);
final BLSSignature signature = blindedBeaconBlock.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
Expand All @@ -134,7 +132,7 @@ void shouldGetBlindedBeaconBlockAsJson() throws IOException {

@TestTemplate
void shouldGetBlindedBeaconBlockAsSsz() throws IOException {
assumeThat(specMilestone).isGreaterThanOrEqualTo(BELLATRIX).isLessThanOrEqualTo(CAPELLA);
assumeThat(specMilestone).isGreaterThanOrEqualTo(BELLATRIX);
final BeaconBlock blindedBeaconBlock = dataStructureUtil.randomBlindedBeaconBlock(ONE);
final BLSSignature signature = blindedBeaconBlock.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
Expand Down Expand Up @@ -178,38 +176,6 @@ void shouldGetUnBlindedBlockContentPostDenebAsSsz() throws IOException {
assertThat(result).isEqualTo(blockContents);
}

@TestTemplate
void shouldGetBlindedBlockContentPostDenebAsJson() throws IOException {
assumeThat(specMilestone).isEqualTo(DENEB);
final BlindedBlockContents blindedBlockContents =
dataStructureUtil.randomBlindedBlockContents(ONE);
final BLSSignature signature = blindedBlockContents.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blindedBlockContents)));
Response response = get(signature, ContentTypes.JSON);
assertResponseWithHeaders(response, true);
final String body = response.body().string();
assertThat(body).isEqualTo(getExpectedBlockAsJson(specMilestone, true, true));
}

@TestTemplate
void shouldGetBlindedBlockContentPostDenebAsSsz() throws IOException {
assumeThat(specMilestone).isEqualTo(DENEB);
final BlindedBlockContents blindedBlockContents =
dataStructureUtil.randomBlindedBlockContents(ONE);
final BLSSignature signature = blindedBlockContents.getBlock().getBody().getRandaoReveal();
when(validatorApiChannel.createUnsignedBlock(eq(UInt64.ONE), eq(signature), any()))
.thenReturn(SafeFuture.completedFuture(Optional.of(blindedBlockContents)));
Response response = get(signature, ContentTypes.OCTET_STREAM);
assertResponseWithHeaders(response, true);
final BlindedBlockContents result =
(BlindedBlockContents)
spec.getGenesisSchemaDefinitions()
.getBlindedBlockContainerSchema()
.sszDeserialize(Bytes.of(response.body().bytes()));
assertThat(result).isEqualTo(blindedBlockContents);
}

@TestTemplate
void shouldFailWhenNoBlockProduced() throws IOException {
final BeaconBlock beaconBlock = dataStructureUtil.randomBeaconBlock(ONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tags" : [ "Validator", "Validator Required Api"],
"operationId" : "publishBlindedBlock",
"summary" : "Publish a signed blinded block",
"description" : "Submit a signed blinded beacon block to the beacon node to be broadcast and imported. After Deneb, this additionally instructs the beacon node to broadcast and import all given signed blinded blobs. The beacon node performs the required validation.",
"description" : "Submit a signed blinded beacon block to the beacon node to be broadcast and imported. The beacon node performs the required validation.",
"requestBody" : {
"content" : {
"application/octet-stream" : {
Expand All @@ -25,7 +25,7 @@
}, {
"$ref" : "#/components/schemas/SignedBlindedBlockCapella"
}, {
"$ref" : "#/components/schemas/SignedBlindedBlockContentsDeneb"
"$ref" : "#/components/schemas/SignedBlindedBlockDeneb"
} ]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tags" : [ "Beacon", "Validator Required Api" ],
"operationId" : "publishBlock",
"summary" : "Publish a signed block",
"description" : "Submit a signed beacon block to the beacon node to be broadcast and imported. After Deneb, this additionally instructs the beacon node to broadcast and import all given signed blobs. The beacon node performs the required validation.",
"description" : "Submit a signed beacon block to the beacon node to be broadcast and imported. After Deneb, this additionally instructs the beacon node to broadcast and import all given blobs. The beacon node performs the required validation.",
"requestBody" : {
"content" : {
"application/octet-stream" : {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit ee1e1aa

Please sign in to comment.