diff --git a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/BatchImporterTest.java b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/BatchImporterTest.java index 08cfe32c5e3..b92a1c5d397 100644 --- a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/BatchImporterTest.java +++ b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/BatchImporterTest.java @@ -107,8 +107,10 @@ void shouldImportBlobSidecarsAndBlocksInOrder() { final SignedBeaconBlock block1 = dataStructureUtil.randomSignedBeaconBlock(1); final SignedBeaconBlock block2 = dataStructureUtil.randomSignedBeaconBlock(2); - final List blobSidecars1 = dataStructureUtil.randomBlobSidecarsForBlock(block1); - final List blobSidecars2 = dataStructureUtil.randomBlobSidecarsForBlock(block2); + final List blobSidecars1 = + dataStructureUtil.randomBlobSidecarsForBlockOld(block1); + final List blobSidecars2 = + dataStructureUtil.randomBlobSidecarsForBlockOld(block2); final SafeFuture importResult1 = new SafeFuture<>(); final SafeFuture importResult2 = new SafeFuture<>(); diff --git a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/batches/SyncSourceBatchTest.java b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/batches/SyncSourceBatchTest.java index afea5b1507c..06d631a4dba 100644 --- a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/batches/SyncSourceBatchTest.java +++ b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/forward/multipeer/batches/SyncSourceBatchTest.java @@ -146,7 +146,8 @@ void requestMoreBlocks_shouldRequestBlobSidecarsWhenRequired() { // only receiving last block (70 + 50 - 1) final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(119); - final List blobSidecars = dataStructureUtil.randomBlobSidecarsForBlock(block); + final List blobSidecars = + dataStructureUtil.randomBlobSidecarsForBlockOld(block); receiveBlocks(batch, block); receiveBlobSidecars(batch, blobSidecars); @@ -241,7 +242,7 @@ void shouldReportAsInvalidWhenUnexpectedNumberOfBlobSidecarsWereReceived() { final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(19); final List blobSidecars = - new ArrayList<>(dataStructureUtil.randomBlobSidecarsForBlock(block)); + new ArrayList<>(dataStructureUtil.randomBlobSidecarsForBlockOld(block)); // receiving more sidecars than expected blobSidecars.add( dataStructureUtil.createRandomBlobSidecarBuilderOld().blockRoot(block.getRoot()).build()); @@ -294,11 +295,12 @@ void shouldMarkBatchAsInconsistentWhenUnexpectedBlobSidecarsWithRootsWereReceive final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(19); - final List blobSidecars = dataStructureUtil.randomBlobSidecarsForBlock(block); + final List blobSidecars = + dataStructureUtil.randomBlobSidecarsForBlockOld(block); final List unexpectedBlobSidecars = new ArrayList<>(blobSidecars); // receiving sidecars with unknown roots unexpectedBlobSidecars.addAll( - dataStructureUtil.randomBlobSidecarsForBlock( + dataStructureUtil.randomBlobSidecarsForBlockOld( dataStructureUtil.randomSignedBeaconBlock(18))); receiveBlocks(batch, block); diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactory.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactory.java index d322208983b..d381a31a98d 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactory.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactory.java @@ -19,7 +19,7 @@ import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; public interface BlockFactory { @@ -38,6 +38,5 @@ SafeFuture createUnsignedBlock( BLSSignature randaoReveal, Optional optionalGraffiti); - SafeFuture unblindSignedBlockIfBlinded( - SignedBlockContainer maybeBlindedBlockContainer); + SafeFuture unblindSignedBlockIfBlinded(SignedBeaconBlock maybeBlindedBlock); } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java index 6fc37e6c567..750964b4941 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java @@ -16,7 +16,6 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.function.Function; import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.infrastructure.async.SafeFuture; @@ -27,12 +26,8 @@ import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; 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.BlockContents; -import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; -import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb; public class BlockFactoryDeneb extends BlockFactoryPhase0 { @@ -97,37 +92,8 @@ public SafeFuture createUnsignedBlock( }); } - /** - * Adding blobs and proofs after the block in order to use the cached value from the {@link - * ExecutionLayerChannel#builderGetPayload( SignedBlockContainer, Function)} call - */ - @Override - public SafeFuture unblindSignedBlockIfBlinded( - final SignedBlockContainer maybeBlindedBlockContainer) { - if (maybeBlindedBlockContainer.isBlinded()) { - return unblindBlock(maybeBlindedBlockContainer) - .thenApply(this::createUnblindedSignedBlockContents); - } - return SafeFuture.completedFuture(maybeBlindedBlockContainer); - } - private BlockContents createBlockContents( final BeaconBlock block, final List blobs, final List kzgProofs) { return schemaDefinitionsDeneb.getBlockContentsSchema().create(block, kzgProofs, blobs); } - - /** use {@link BlockFactoryPhase0} unblinding of the {@link SignedBeaconBlock} */ - private SafeFuture unblindBlock( - final SignedBlockContainer blindedBlockContainer) { - return super.unblindSignedBlockIfBlinded(blindedBlockContainer) - .thenApply(SignedBlockContainer::getSignedBlock); - } - - // TODO: add blobs and proofs - private SignedBlockContents createUnblindedSignedBlockContents( - final SignedBeaconBlock signedBlock) { - return schemaDefinitionsDeneb - .getSignedBlockContentsSchema() - .create(signedBlock, Collections.emptyList(), Collections.emptyList()); - } } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryPhase0.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryPhase0.java index f02d38de1c7..89fd8c75eed 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryPhase0.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryPhase0.java @@ -16,7 +16,6 @@ import static com.google.common.base.Preconditions.checkArgument; import java.util.Optional; -import java.util.function.Function; import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.infrastructure.async.SafeFuture; @@ -24,7 +23,7 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState; import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; public class BlockFactoryPhase0 implements BlockFactory { @@ -96,14 +95,12 @@ public SafeFuture createUnsignedBlock( } @Override - public SafeFuture unblindSignedBlockIfBlinded( - SignedBlockContainer maybeBlindedBlockContainer) { - if (maybeBlindedBlockContainer.isBlinded()) { + public SafeFuture unblindSignedBlockIfBlinded( + SignedBeaconBlock maybeBlindedBlock) { + if (maybeBlindedBlock.isBlinded()) { return spec.unblindSignedBeaconBlock( - maybeBlindedBlockContainer.getSignedBlock(), - operationSelector.createBlockUnblinderSelector()) - .thenApply(Function.identity()); + maybeBlindedBlock.getSignedBlock(), operationSelector.createBlockUnblinderSelector()); } - return SafeFuture.completedFuture(maybeBlindedBlockContainer); + return SafeFuture.completedFuture(maybeBlindedBlock); } } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java index c1ff38efa9c..bf657c6789e 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactory.java @@ -31,8 +31,8 @@ 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.SignedBeaconBlock; 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.BuilderPayload; import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle; @@ -302,10 +302,9 @@ private void builderSetKzgCommitments( public Consumer createBlockUnblinderSelector() { return bodyUnblinder -> { - final SignedBlockContainer signedBlindedBlockContainer = - bodyUnblinder.getSignedBlindedBeaconBlock(); + final SignedBeaconBlock signedBlindedBlock = bodyUnblinder.getSignedBlindedBeaconBlock(); - final BeaconBlock block = signedBlindedBlockContainer.getSignedBlock().getMessage(); + final BeaconBlock block = signedBlindedBlock.getMessage(); if (block .getBody() @@ -324,7 +323,7 @@ public Consumer createBlockUnblinderSelector() { bodyUnblinder.setExecutionPayloadSupplier( () -> executionLayerBlockProductionManager - .getUnblindedPayload(signedBlindedBlockContainer) + .getUnblindedPayload(signedBlindedBlock) .thenApply(BuilderPayload::getExecutionPayload)); } }; diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/MilestoneBasedBlockFactory.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/MilestoneBasedBlockFactory.java index f2fed8266a3..3fee772f75d 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/MilestoneBasedBlockFactory.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/MilestoneBasedBlockFactory.java @@ -25,7 +25,7 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; public class MilestoneBasedBlockFactory implements BlockFactory { @@ -83,12 +83,10 @@ public SafeFuture createUnsignedBlock( } @Override - public SafeFuture unblindSignedBlockIfBlinded( - final SignedBlockContainer maybeBlindedBlockContainer) { - final SpecMilestone milestone = getMilestone(maybeBlindedBlockContainer.getSlot()); - return registeredFactories - .get(milestone) - .unblindSignedBlockIfBlinded(maybeBlindedBlockContainer); + public SafeFuture unblindSignedBlockIfBlinded( + final SignedBeaconBlock maybeBlindedBlock) { + final SpecMilestone milestone = getMilestone(maybeBlindedBlock.getSlot()); + return registeredFactories.get(milestone).unblindSignedBlockIfBlinded(maybeBlindedBlock); } private SpecMilestone getMilestone(final UInt64 slot) { diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/DefaultPerformanceTracker.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/DefaultPerformanceTracker.java index bebda8e43d9..3ff741b8110 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/DefaultPerformanceTracker.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/DefaultPerformanceTracker.java @@ -47,7 +47,6 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage; @@ -416,11 +415,11 @@ public void saveProducedAttestation(final Attestation attestation) { } @Override - public void saveProducedBlock(final SignedBlockContainer blockContainer) { - final UInt64 epoch = spec.computeEpochAtSlot(blockContainer.getSlot()); + public void saveProducedBlock(final SignedBeaconBlock block) { + final UInt64 epoch = spec.computeEpochAtSlot(block.getSlot()); final Set blocksInEpoch = producedBlocksByEpoch.computeIfAbsent(epoch, __ -> concurrentSet()); - blocksInEpoch.add(blockContainer.getSignedBlock().getSlotAndBlockRoot()); + blocksInEpoch.add(block.getSlotAndBlockRoot()); } @Override diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/NoOpPerformanceTracker.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/NoOpPerformanceTracker.java index 314b508cd69..69e28006dcc 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/NoOpPerformanceTracker.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/NoOpPerformanceTracker.java @@ -15,7 +15,7 @@ import it.unimi.dsi.fastutil.ints.IntSet; import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage; @@ -28,7 +28,7 @@ public void start(final UInt64 nodeStartSlot) {} public void saveProducedAttestation(final Attestation attestation) {} @Override - public void saveProducedBlock(final SignedBlockContainer blockContainer) {} + public void saveProducedBlock(final SignedBeaconBlock block) {} @Override public void reportBlockProductionAttempt(final UInt64 epoch) {} diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/PerformanceTracker.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/PerformanceTracker.java index f8fca95c62d..955d3d45216 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/PerformanceTracker.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/performance/PerformanceTracker.java @@ -16,7 +16,7 @@ import it.unimi.dsi.fastutil.ints.IntSet; import tech.pegasys.teku.ethereum.events.SlotEventsChannel; import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage; @@ -26,7 +26,7 @@ public interface PerformanceTracker extends SlotEventsChannel { void saveProducedAttestation(Attestation attestation); - void saveProducedBlock(SignedBlockContainer blockContainer); + void saveProducedBlock(SignedBeaconBlock block); void reportBlockProductionAttempt(UInt64 epoch); diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisher.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisher.java index c30caa1a952..85dab0419a9 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisher.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisher.java @@ -15,9 +15,12 @@ import static tech.pegasys.teku.infrastructure.logging.ValidatorLogger.VALIDATOR_LOGGER; +import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import tech.pegasys.teku.infrastructure.async.SafeFuture; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason; @@ -50,17 +53,71 @@ public AbstractBlockPublisher( @Override public SafeFuture sendSignedBlock( - final SignedBlockContainer maybeBlindedBlockContainer, + final SignedBlockContainer blockContainer, final BroadcastValidationLevel broadcastValidationLevel) { return blockFactory - .unblindSignedBlockIfBlinded(maybeBlindedBlockContainer) + .unblindSignedBlockIfBlinded(blockContainer.getSignedBlock()) .thenPeek(performanceTracker::saveProducedBlock) .thenCompose( - signedBlockContainer -> - gossipAndImportUnblindedSignedBlock(signedBlockContainer, broadcastValidationLevel)) - .thenCompose(result -> calculateResult(maybeBlindedBlockContainer, result)); + signedBlock -> + // TODO: produce blob sidecars for Deneb (using BlockFactory) + gossipAndImportUnblindedSignedBlockAndBlobSidecars( + signedBlock, List.of(), broadcastValidationLevel)) + .thenCompose(result -> calculateResult(blockContainer, result)); } + private SafeFuture + gossipAndImportUnblindedSignedBlockAndBlobSidecars( + final SignedBeaconBlock block, + final List blobSidecars, + final BroadcastValidationLevel broadcastValidationLevel) { + + if (broadcastValidationLevel == BroadcastValidationLevel.NOT_REQUIRED) { + // when broadcast validation is disabled, we can publish the block (and blob sidecars) + // immediately and then import + publishBlockAndBlobSidecars(block, blobSidecars); + return importBlockAndBlobSidecars(block, blobSidecars, broadcastValidationLevel); + } + + // when broadcast validation is enabled, we need to wait for the validation to complete before + // publishing the block (and blob sidecars) + + final SafeFuture + blockImportAndBroadcastValidationResults = + importBlockAndBlobSidecars(block, blobSidecars, broadcastValidationLevel); + + blockImportAndBroadcastValidationResults + .thenCompose(BlockImportAndBroadcastValidationResults::broadcastValidationResult) + .thenAccept( + broadcastValidationResult -> { + if (broadcastValidationResult == BroadcastValidationResult.SUCCESS) { + publishBlockAndBlobSidecars(block, blobSidecars); + LOG.debug("Block (and blob sidecars) publishing initiated"); + } else { + LOG.warn( + "Block (and blob sidecars) publishing skipped due to broadcast validation result {} for slot {}", + broadcastValidationResult, + block.getSlot()); + } + }) + .finish( + err -> + LOG.error( + "Block (and blob sidecars) publishing failed for slot {}", + block.getSlot(), + err)); + + return blockImportAndBroadcastValidationResults; + } + + abstract SafeFuture importBlockAndBlobSidecars( + SignedBeaconBlock block, + List blobSidecars, + BroadcastValidationLevel broadcastValidationLevel); + + abstract void publishBlockAndBlobSidecars( + SignedBeaconBlock block, List blobSidecars); + private SafeFuture calculateResult( final SignedBlockContainer maybeBlindedBlockContainer, final BlockImportAndBroadcastValidationResults blockImportAndBroadcastValidationResults) { @@ -110,51 +167,4 @@ private SafeFuture calculateResult( }); }); } - - private SafeFuture gossipAndImportUnblindedSignedBlock( - final SignedBlockContainer blockContainer, - final BroadcastValidationLevel broadcastValidationLevel) { - - if (broadcastValidationLevel == BroadcastValidationLevel.NOT_REQUIRED) { - // when broadcast validation is disabled, we can publish the block immediately and then import - publishBlock(blockContainer); - return importBlock(blockContainer, broadcastValidationLevel); - } - - // when broadcast validation is enabled, we need to wait for the validation to complete before - // publishing the block - - final SafeFuture - blockImportAndBroadcastValidationResults = - importBlock(blockContainer, broadcastValidationLevel); - - blockImportAndBroadcastValidationResults - .thenCompose(BlockImportAndBroadcastValidationResults::broadcastValidationResult) - .thenAccept( - broadcastValidationResult -> { - if (broadcastValidationResult == BroadcastValidationResult.SUCCESS) { - publishBlock(blockContainer); - LOG.debug("Block (and blob sidecars) publishing initiated"); - } else { - LOG.warn( - "Block (and blob sidecars) publishing skipped due to broadcast validation result {} for slot {}", - broadcastValidationResult, - blockContainer.getSlot()); - } - }) - .finish( - err -> - LOG.error( - "Block (and blob sidecars) publishing failed for slot {}", - blockContainer.getSlot(), - err)); - - return blockImportAndBroadcastValidationResults; - } - - abstract SafeFuture importBlock( - final SignedBlockContainer blockContainer, - final BroadcastValidationLevel broadcastValidationLevel); - - abstract void publishBlock(final SignedBlockContainer blockContainer); } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisher.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisher.java index 89afcc46fd0..9741d209826 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisher.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisher.java @@ -18,8 +18,8 @@ import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; import tech.pegasys.teku.validator.api.SendSignedBlockResult; +/** Used to publish blocks (and blob sidecars) */ public interface BlockPublisher { SafeFuture sendSignedBlock( - SignedBlockContainer maybeBlindedBlockContainer, - BroadcastValidationLevel broadcastValidationLevel); + SignedBlockContainer blockContainer, BroadcastValidationLevel broadcastValidationLevel); } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherDeneb.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherDeneb.java index 4a00c927cb7..c334060cc36 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherDeneb.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherDeneb.java @@ -17,8 +17,8 @@ import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipChannel; import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; import tech.pegasys.teku.statetransition.blobs.BlobSidecarPool; import tech.pegasys.teku.statetransition.block.BlockImportChannel; @@ -48,19 +48,18 @@ public BlockPublisherDeneb( } @Override - protected SafeFuture importBlock( - final SignedBlockContainer blockContainer, + SafeFuture importBlockAndBlobSidecars( + final SignedBeaconBlock block, + final List blobSidecars, final BroadcastValidationLevel broadcastValidationLevel) { - final SignedBeaconBlock block = blockContainer.getSignedBlock(); - // TODO: import blob sidecars with inclusion proof - blobSidecarPool.onCompletedBlockAndBlobSidecars(block, List.of()); + blobSidecarPool.onCompletedBlockAndBlobSidecars(block, blobSidecars); return blockImportChannel.importBlock(block, broadcastValidationLevel); } @Override - void publishBlock(final SignedBlockContainer blockContainer) { - // TODO: publish blob sidecars with inclusion proof - blobSidecarGossipChannel.publishBlobSidecars(List.of()); - blockGossipChannel.publishBlock(blockContainer.getSignedBlock()); + void publishBlockAndBlobSidecars( + final SignedBeaconBlock block, final List blobSidecars) { + blockGossipChannel.publishBlock(block); + blobSidecarGossipChannel.publishBlobSidecars(blobSidecars); } } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherPhase0.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherPhase0.java index 35a9e084552..36dbb881309 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherPhase0.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/BlockPublisherPhase0.java @@ -13,9 +13,11 @@ package tech.pegasys.teku.validator.coordinator.publisher; +import java.util.List; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; import tech.pegasys.teku.statetransition.block.BlockImportChannel; import tech.pegasys.teku.statetransition.block.BlockImportChannel.BlockImportAndBroadcastValidationResults; @@ -37,15 +39,16 @@ public BlockPublisherPhase0( } @Override - protected SafeFuture importBlock( - final SignedBlockContainer blockContainer, + SafeFuture importBlockAndBlobSidecars( + final SignedBeaconBlock block, + final List blobSidecars, final BroadcastValidationLevel broadcastValidationLevel) { - return blockImportChannel.importBlock( - blockContainer.getSignedBlock(), broadcastValidationLevel); + return blockImportChannel.importBlock(block, broadcastValidationLevel); } @Override - void publishBlock(final SignedBlockContainer blockContainer) { - blockGossipChannel.publishBlock(blockContainer.getSignedBlock()); + void publishBlockAndBlobSidecars( + final SignedBeaconBlock block, final List blobSidecars) { + blockGossipChannel.publishBlock(block); } } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/MilestoneBasedBlockPublisher.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/MilestoneBasedBlockPublisher.java index a93d4d9a784..75e48cdb468 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/MilestoneBasedBlockPublisher.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/publisher/MilestoneBasedBlockPublisher.java @@ -78,12 +78,11 @@ public MilestoneBasedBlockPublisher( @Override public SafeFuture sendSignedBlock( - final SignedBlockContainer maybeBlindedBlockContainer, + final SignedBlockContainer blockContainer, final BroadcastValidationLevel broadcastValidationLevel) { - final SpecMilestone blockMilestone = - spec.atSlot(maybeBlindedBlockContainer.getSlot()).getMilestone(); + final SpecMilestone blockMilestone = spec.atSlot(blockContainer.getSlot()).getMilestone(); return registeredPublishers .get(blockMilestone) - .sendSignedBlock(maybeBlindedBlockContainer, broadcastValidationLevel); + .sendSignedBlock(blockContainer, broadcastValidationLevel); } } diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/AbstractBlockFactoryTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/AbstractBlockFactoryTest.java index 7836026c839..bb86edb9b26 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/AbstractBlockFactoryTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/AbstractBlockFactoryTest.java @@ -42,7 +42,6 @@ import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodyAltair; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair; @@ -244,38 +243,30 @@ protected SyncAggregate createEmptySyncAggregate(final Spec spec) { .createEmpty(); } - protected SignedBlockContainer assertBlockUnblinded( - final SignedBlockContainer blindedBlockContainer, final Spec spec) { + protected SignedBeaconBlock assertBlockUnblinded( + final SignedBeaconBlock blindedBlock, final Spec spec) { final BlockFactory blockFactory = createBlockFactory(spec); final BuilderPayload builderPayload = getBuilderPayload(spec); - when(executionLayer.getUnblindedPayload(blindedBlockContainer)) + when(executionLayer.getUnblindedPayload(blindedBlock)) .thenReturn(SafeFuture.completedFuture(builderPayload)); - // simulate caching of the unblinded payload - when(executionLayer.getCachedUnblindedPayload(blindedBlockContainer.getSlot())) - .thenReturn(Optional.ofNullable(builderPayload)); - // used for unblinding the blob sidecars - setupCachedBlobsBundle(blindedBlockContainer.getSlot()); - final SignedBlockContainer unblindedBlockContainer = - blockFactory.unblindSignedBlockIfBlinded(blindedBlockContainer).join(); + final SignedBeaconBlock unblindedBlock = + blockFactory.unblindSignedBlockIfBlinded(blindedBlock).join(); - final SignedBeaconBlock block = unblindedBlockContainer.getSignedBlock(); - - if (!blindedBlockContainer.isBlinded()) { + if (!blindedBlock.isBlinded()) { verifyNoInteractions(executionLayer); } else { - verify(executionLayer).getUnblindedPayload(blindedBlockContainer); + verify(executionLayer).getUnblindedPayload(blindedBlock); } - assertThat(block).isNotNull(); - assertThat(block.hashTreeRoot()) - .isEqualTo(blindedBlockContainer.getSignedBlock().hashTreeRoot()); - assertThat(block.getMessage().getBody().isBlinded()).isFalse(); - assertThat(block.getMessage().getBody().getOptionalExecutionPayloadHeader()) + assertThat(unblindedBlock).isNotNull(); + assertThat(unblindedBlock.hashTreeRoot()).isEqualTo(blindedBlock.hashTreeRoot()); + assertThat(unblindedBlock.getMessage().getBody().isBlinded()).isFalse(); + assertThat(unblindedBlock.getMessage().getBody().getOptionalExecutionPayloadHeader()) .isEqualTo(Optional.empty()); - return unblindedBlockContainer; + return unblindedBlock; } protected SignedBeaconBlock assertBlockBlinded( diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDenebTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDenebTest.java index dba06f87a68..95c3e5c530e 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDenebTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDenebTest.java @@ -14,23 +14,17 @@ package tech.pegasys.teku.validator.coordinator; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; -import java.util.Optional; 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.SszList; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; 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.BlockContents; -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; import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb; import tech.pegasys.teku.spec.util.DataStructureUtil; @@ -53,7 +47,7 @@ void shouldCreateBlockContents() { assertThat(blockContainer).isInstanceOf(BlockContents.class); assertThat(blockContainer.getBlock().getBody().getOptionalBlobKzgCommitments()) .hasValueSatisfying(blobKzgCommitments -> assertThat(blobKzgCommitments).hasSize(3)); - // TODO Add test for blobs and kzg proofs once added + // TODO Add assertions for blobs and proofs } @Test @@ -71,45 +65,31 @@ void shouldCreateBlindedBeaconBlockWhenBlindedBlockRequested() { } @Test - void unblindSignedBlock_shouldPassthroughUnblindedBlockContents() { + void unblindSignedBlock_shouldPassthroughUnblindedBlock() { - final SignedBlockContents signedBlockContents = dataStructureUtil.randomSignedBlockContents(); + final SignedBeaconBlock signedBlock = dataStructureUtil.randomSignedBeaconBlock(); - final SignedBlockContainer unblindedSignedBlockContainer = - assertBlockUnblinded(signedBlockContents, spec); + final SignedBeaconBlock unblindedSignedBlock = assertBlockUnblinded(signedBlock, spec); - assertThat(unblindedSignedBlockContainer).isEqualTo(signedBlockContents); + assertThat(unblindedSignedBlock).isEqualTo(signedBlock); } @Test - @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 SignedBeaconBlock unblindedBeaconBlock = dataStructureUtil.randomSignedBeaconBlock(); - final SignedBeaconBlock blindedBlock = assertBlockBlinded(unblindedBeaconBlock, spec); + final SignedBeaconBlock expectedUnblindedBlock = dataStructureUtil.randomSignedBeaconBlock(); + final SignedBeaconBlock blindedBlock = assertBlockBlinded(expectedUnblindedBlock, spec); // let the unblinder return a consistent execution payload executionPayload = - unblindedBeaconBlock.getMessage().getBody().getOptionalExecutionPayload().orElseThrow(); + expectedUnblindedBlock.getMessage().getBody().getOptionalExecutionPayload().orElseThrow(); - final SignedBlockContainer unblindedBlockContainer = assertBlockUnblinded(blindedBlock, spec); + final SignedBeaconBlock unblindedBlock = assertBlockUnblinded(blindedBlock, spec); - // make sure getCachedUnblindedPayload is second in order of method calling - final InOrder inOrder = Mockito.inOrder(executionLayer); - inOrder.verify(executionLayer).getUnblindedPayload(unblindedBlockContainer); - inOrder.verify(executionLayer).getCachedUnblindedPayload(unblindedBlockContainer.getSlot()); + verify(executionLayer).getUnblindedPayload(unblindedBlock); - assertThat(unblindedBlockContainer).isInstanceOf(SignedBlockContents.class); - assertThat(unblindedBlockContainer.isBlinded()).isFalse(); - assertThat(unblindedBlockContainer.getSignedBlock()).isEqualTo(unblindedBeaconBlock); - // TODO: add assertions for blobs and proofs + assertThat(unblindedBlock.isBlinded()).isFalse(); + assertThat(unblindedBlock).isEqualTo(expectedUnblindedBlock); } @Override diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisherTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisherTest.java index 90f0b4ee468..4e7391fee01 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisherTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/publisher/AbstractBlockPublisherTest.java @@ -20,12 +20,15 @@ import static org.mockito.Mockito.when; import static tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents; import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; import tech.pegasys.teku.spec.util.DataStructureUtil; @@ -50,19 +53,21 @@ public class AbstractBlockPublisherTest { new BlockPublisherTest( blockFactory, blockImportChannel, performanceTracker, dutyMetrics)); - final SignedBlockContainer signedBlockContents = dataStructureUtil.randomSignedBlockContents(); + final SignedBlockContents signedBlockContents = dataStructureUtil.randomSignedBlockContents(); + final SignedBeaconBlock signedBlock = signedBlockContents.getSignedBlock(); @BeforeEach public void setUp() { - when(blockFactory.unblindSignedBlockIfBlinded(signedBlockContents)) - .thenReturn(SafeFuture.completedFuture(signedBlockContents)); + when(blockFactory.unblindSignedBlockIfBlinded(signedBlock)) + .thenReturn(SafeFuture.completedFuture(signedBlock)); } @Test public void sendSignedBlock_shouldPublishImmediatelyAndImportWhenBroadcastValidationIsNotRequired() { - when(blockPublisher.importBlock(signedBlockContents, BroadcastValidationLevel.NOT_REQUIRED)) + when(blockPublisher.importBlockAndBlobSidecars( + signedBlock, List.of(), BroadcastValidationLevel.NOT_REQUIRED)) .thenReturn( SafeFuture.completedFuture( new BlockImportAndBroadcastValidationResults( @@ -74,15 +79,16 @@ public void setUp() { signedBlockContents, BroadcastValidationLevel.NOT_REQUIRED)) .isCompletedWithValue(SendSignedBlockResult.success(signedBlockContents.getRoot())); - verify(blockPublisher).publishBlock(signedBlockContents); - verify(blockPublisher).importBlock(signedBlockContents, BroadcastValidationLevel.NOT_REQUIRED); + verify(blockPublisher).publishBlockAndBlobSidecars(signedBlock, List.of()); + verify(blockPublisher) + .importBlockAndBlobSidecars(signedBlock, List.of(), BroadcastValidationLevel.NOT_REQUIRED); } @Test public void sendSignedBlock_shouldWaitToPublishWhenBroadcastValidationIsSpecified() { final SafeFuture validationResult = new SafeFuture<>(); - when(blockPublisher.importBlock( - signedBlockContents, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION)) + when(blockPublisher.importBlockAndBlobSidecars( + signedBlock, List.of(), BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION)) .thenReturn( SafeFuture.completedFuture( new BlockImportAndBroadcastValidationResults( @@ -97,13 +103,14 @@ public void sendSignedBlock_shouldWaitToPublishWhenBroadcastValidationIsSpecifie assertThatSafeFuture(sendSignedBlockResult).isNotCompleted(); verify(blockPublisher) - .importBlock(signedBlockContents, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION); + .importBlockAndBlobSidecars( + signedBlock, List.of(), BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION); - verify(blockPublisher, never()).publishBlock(signedBlockContents); + verify(blockPublisher, never()).publishBlockAndBlobSidecars(signedBlock, List.of()); validationResult.complete(BroadcastValidationResult.SUCCESS); - verify(blockPublisher).publishBlock(signedBlockContents); + verify(blockPublisher).publishBlockAndBlobSidecars(signedBlock, List.of()); assertThatSafeFuture(sendSignedBlockResult) .isCompletedWithValue(SendSignedBlockResult.success(signedBlockContents.getRoot())); } @@ -111,8 +118,8 @@ public void sendSignedBlock_shouldWaitToPublishWhenBroadcastValidationIsSpecifie @Test public void sendSignedBlock_shouldNotPublishWhenBroadcastValidationFails() { final SafeFuture validationResult = new SafeFuture<>(); - when(blockPublisher.importBlock( - signedBlockContents, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION)) + when(blockPublisher.importBlockAndBlobSidecars( + signedBlock, List.of(), BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION)) .thenReturn( SafeFuture.completedFuture( new BlockImportAndBroadcastValidationResults( @@ -127,13 +134,14 @@ public void sendSignedBlock_shouldNotPublishWhenBroadcastValidationFails() { assertThatSafeFuture(sendSignedBlockResult).isNotCompleted(); verify(blockPublisher) - .importBlock(signedBlockContents, BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION); + .importBlockAndBlobSidecars( + signedBlock, List.of(), BroadcastValidationLevel.CONSENSUS_AND_EQUIVOCATION); - verify(blockPublisher, never()).publishBlock(signedBlockContents); + verify(blockPublisher, never()).publishBlockAndBlobSidecars(signedBlock, List.of()); validationResult.complete(BroadcastValidationResult.CONSENSUS_FAILURE); - verify(blockPublisher, never()).publishBlock(signedBlockContents); + verify(blockPublisher, never()).publishBlockAndBlobSidecars(signedBlock, List.of()); assertThatSafeFuture(sendSignedBlockResult) .isCompletedWithValue( SendSignedBlockResult.rejected( @@ -151,13 +159,15 @@ public BlockPublisherTest( } @Override - SafeFuture importBlock( - final SignedBlockContainer blockContainer, + SafeFuture importBlockAndBlobSidecars( + final SignedBeaconBlock block, + final List blobSidecars, final BroadcastValidationLevel broadcastValidationLevel) { return null; } @Override - void publishBlock(final SignedBlockContainer blockContainer) {} + void publishBlockAndBlobSidecars( + final SignedBeaconBlock block, final List blobSidecars) {} } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/BlockContentsSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/BlockContentsSchema.java index 18fdb912e01..f0d0bee0657 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/BlockContentsSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/BlockContentsSchema.java @@ -40,14 +40,13 @@ public class BlockContentsSchema final String containerName, final SpecConfigDeneb specConfig, final BeaconBlockSchema beaconBlockSchema, - final SszKZGProofSchema sszKZGProofSchema, final BlobSchema blobSchema) { super( containerName, namedSchema("block", beaconBlockSchema), namedSchema( FIELD_KZG_PROOFS, - SszListSchema.create(sszKZGProofSchema, specConfig.getMaxBlobsPerBlock())), + SszListSchema.create(SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobsPerBlock())), namedSchema( FIELD_BLOBS, SszListSchema.create(blobSchema, specConfig.getMaxBlobsPerBlock()))); } @@ -55,11 +54,9 @@ public class BlockContentsSchema public static BlockContentsSchema create( final SpecConfigDeneb specConfig, final BeaconBlockSchema beaconBlockSchema, - final SszKZGProofSchema sszKZGProofSchema, final BlobSchema blobSchema, final String containerName) { - return new BlockContentsSchema( - containerName, specConfig, beaconBlockSchema, sszKZGProofSchema, blobSchema); + return new BlockContentsSchema(containerName, specConfig, beaconBlockSchema, blobSchema); } public BlockContents create( diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java index 29063f8873b..90899c0bc06 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java @@ -41,14 +41,13 @@ public class SignedBlockContentsSchema final String containerName, final SpecConfigDeneb specConfig, final SignedBeaconBlockSchema signedBeaconBlockSchema, - final SszKZGProofSchema sszKZGProofSchema, final BlobSchema blobSchema) { super( containerName, namedSchema("signed_block", signedBeaconBlockSchema), namedSchema( FIELD_KZG_PROOFS, - SszListSchema.create(sszKZGProofSchema, specConfig.getMaxBlobsPerBlock())), + SszListSchema.create(SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobsPerBlock())), namedSchema( FIELD_BLOBS, SszListSchema.create(blobSchema, specConfig.getMaxBlobsPerBlock()))); } @@ -56,11 +55,10 @@ public class SignedBlockContentsSchema public static SignedBlockContentsSchema create( final SpecConfigDeneb specConfig, final SignedBeaconBlockSchema signedBeaconBlockSchema, - final SszKZGProofSchema sszKZGProofSchema, final BlobSchema blobSchema, final String containerName) { return new SignedBlockContentsSchema( - containerName, specConfig, signedBeaconBlockSchema, sszKZGProofSchema, blobSchema); + containerName, specConfig, signedBeaconBlockSchema, blobSchema); } public SignedBlockContents create( diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java index 53e4c9d593e..c8d426d4d29 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java @@ -55,7 +55,6 @@ import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.deneb.BeaconStateDeneb; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.deneb.BeaconStateSchemaDeneb; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.deneb.MutableBeaconStateDeneb; -import tech.pegasys.teku.spec.datastructures.type.SszKZGProofSchema; public class SchemaDefinitionsDeneb extends SchemaDefinitionsCapella { @@ -81,7 +80,6 @@ public class SchemaDefinitionsDeneb extends SchemaDefinitionsCapella { private final SszListSchema> blobsInBlockSchema; private final BlobSidecarSchema blobSidecarSchema; private final BlobSidecarSchemaOld blobSidecarOldSchema; - private final SszKZGProofSchema sszKZGProofSchema; private final SignedBlobSidecarSchemaOld signedBlobSidecarOldSchema; private final BlockContentsSchema blockContentsSchema; private final SignedBlockContentsSchema signedBlockContentsSchema; @@ -134,18 +132,12 @@ public SchemaDefinitionsDeneb(final SpecConfigDeneb specConfig) { blobSchema, specConfig.getKzgCommitmentInclusionProofDepth()); this.blobSidecarOldSchema = BlobSidecarSchemaOld.create(blobSchema); - this.sszKZGProofSchema = SszKZGProofSchema.INSTANCE; this.signedBlobSidecarOldSchema = SignedBlobSidecarSchemaOld.create(blobSidecarOldSchema); this.blockContentsSchema = - BlockContentsSchema.create( - specConfig, beaconBlockSchema, sszKZGProofSchema, blobSchema, "BlockContentsDeneb"); + BlockContentsSchema.create(specConfig, beaconBlockSchema, blobSchema, "BlockContentsDeneb"); this.signedBlockContentsSchema = SignedBlockContentsSchema.create( - specConfig, - signedBeaconBlockSchema, - sszKZGProofSchema, - blobSchema, - "SignedBlockContentsDeneb"); + specConfig, signedBeaconBlockSchema, blobSchema, "SignedBlockContentsDeneb"); this.blobsBundleSchema = new BlobsBundleSchema("BlobsBundleDeneb", blobSchema, blobKzgCommitmentsSchema, specConfig); this.executionPayloadAndBlobsBundleSchema = diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebTest.java index e694e12fee9..38e3b46bb86 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebTest.java @@ -73,7 +73,8 @@ public void versionedHash() { @Test void validateBlobSidecarsAgainstBlock_shouldNotThrowOnValidBlobSidecar() { final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(); - final List blobSidecars = dataStructureUtil.randomBlobSidecarsForBlock(block); + final List blobSidecars = + dataStructureUtil.randomBlobSidecarsForBlockOld(block); // make sure we are testing something assertThat(blobSidecars).isNotEmpty(); @@ -106,7 +107,7 @@ void validateBlobSidecarsAgainstBlock_shouldThrowOnBlobSidecarNotMatching( // let's create blobs with only one altered with the given alteration final List blobSidecars = - dataStructureUtil.randomBlobSidecarsForBlock( + dataStructureUtil.randomBlobSidecarsForBlockOld( block, (index, randomBlobSidecarBuilder) -> { if (!index.equals(indexToBeAltered)) { diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java index c57a5d45fc1..ed9eeed1031 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java @@ -2115,20 +2115,35 @@ public Bytes randomBlobBytes() { return randomBlob().getBytes(); } - public List randomBlobSidecarsForBlock(final SignedBeaconBlock block) { - return randomBlobSidecarsForBlock(block, (__, builder) -> builder); + public List randomBlobSidecarsForBlock(final SignedBeaconBlock block) { + final SszList blobKzgCommitments = + BeaconBlockBodyDeneb.required(block.getBeaconBlock().orElseThrow().getBody()) + .getBlobKzgCommitments(); + + return IntStream.range(0, blobKzgCommitments.size()) + .mapToObj( + index -> + createRandomBlobSidecarBuilder() + .index(UInt64.valueOf(index)) + .signedBeaconBlockHeader(block.asHeader()) + .build()) + .collect(toList()); + } + + public List randomBlobSidecarsForBlockOld(final SignedBeaconBlock block) { + return randomBlobSidecarsForBlockOld(block, (__, builder) -> builder); } - public List randomBlobSidecarsForBlock( + public List randomBlobSidecarsForBlockOld( final SignedBeaconBlock block, final BiFunction modifier) { - return randomSignedBlobSidecarsForBlock(block, modifier).stream() + return randomSignedBlobSidecarsForBlockOld(block, modifier).stream() .map(SignedBlobSidecarOld::getBlobSidecar) .collect(toList()); } - public List randomSignedBlobSidecarsForBlock( + public List randomSignedBlobSidecarsForBlockOld( final SignedBeaconBlock block, final BiFunction modifier) { diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java index 80464617767..ef17737cad5 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java @@ -45,7 +45,7 @@ public class BlockBlobSidecarsTrackerTest { dataStructureUtil.randomSignedBeaconBlockWithCommitments(maxBlobsPerBlock.intValue()); private final SlotAndBlockRoot slotAndBlockRoot = block.getSlotAndBlockRoot(); private final List blobSidecarsForBlock = - dataStructureUtil.randomBlobSidecarsForBlock(block); + dataStructureUtil.randomBlobSidecarsForBlockOld(block); private final List blobIdentifiersForBlock = blobSidecarsForBlock.stream() .map( diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java index 82c5f69cc66..9b9f3fed4b7 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceBlobSidecarsAvailabilityCheckerTest.java @@ -491,7 +491,7 @@ private void prepareInitialAvailability( final Optional providedBlock, final Duration timeout) { block = providedBlock.orElse(dataStructureUtil.randomSignedBeaconBlockWithCommitments(4)); - blobSidecarsComplete = dataStructureUtil.randomBlobSidecarsForBlock(block); + blobSidecarsComplete = dataStructureUtil.randomBlobSidecarsForBlockOld(block); kzgCommitmentsComplete = block .getBeaconBlock() @@ -602,7 +602,7 @@ private void verifyDataAvailabilityNeverCalled() { private void prepareBlockAndBlobSidecarsOutsideAvailabilityWindow() { block = dataStructureUtil.randomSignedBeaconBlock(); - blobSidecarsComplete = dataStructureUtil.randomBlobSidecarsForBlock(block); + blobSidecarsComplete = dataStructureUtil.randomBlobSidecarsForBlockOld(block); final ImmutableSortedMap.Builder mapBuilder = ImmutableSortedMap.naturalOrder(); diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlobSidecarPoolImplTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlobSidecarPoolImplTest.java index 23373931969..3c8306f07db 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlobSidecarPoolImplTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlobSidecarPoolImplTest.java @@ -207,7 +207,8 @@ public void onNewBlobSidecar_shouldIgnoreBlobsForAlreadyImportedBlocks() { @Test public void onNewBlobSidecarOnNewBlock_addTrackerWithBothBlockAndBlobSidecar() { final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(currentSlot); - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarsForBlock(block).get(0); + final BlobSidecarOld blobSidecar = + dataStructureUtil.randomBlobSidecarsForBlockOld(block).get(0); blobSidecarPool.onNewBlobSidecar(blobSidecar); blobSidecarPool.onNewBlock(block); @@ -299,7 +300,8 @@ public void onCompletedBlockAndBlobSidecars_shouldCreateTrackerIgnoringHistorica final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(slot); - final List blobSidecars = dataStructureUtil.randomBlobSidecarsForBlock(block); + final List blobSidecars = + dataStructureUtil.randomBlobSidecarsForBlockOld(block); blobSidecarPool.onCompletedBlockAndBlobSidecarsOld(block, blobSidecars);