diff --git a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/fetch/FetchBlobSidecarTaskTest.java b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/fetch/FetchBlobSidecarTaskTest.java index 41474652e16..f550d3e3a92 100644 --- a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/fetch/FetchBlobSidecarTaskTest.java +++ b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/fetch/FetchBlobSidecarTaskTest.java @@ -28,7 +28,7 @@ public class FetchBlobSidecarTaskTest extends AbstractFetchTaskTest { @Test public void run_successful() { - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); final FetchBlobSidecarTask task = new FetchBlobSidecarTask(eth2P2PNetwork, blobIdentifier); @@ -48,7 +48,7 @@ public void run_successful() { @Test public void run_noPeers() { - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); final FetchBlobSidecarTask task = new FetchBlobSidecarTask(eth2P2PNetwork, blobIdentifier); @@ -63,7 +63,7 @@ public void run_noPeers() { @Test public void run_failAndRetryWithNoNewPeers() { - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); final FetchBlobSidecarTask task = new FetchBlobSidecarTask(eth2P2PNetwork, blobIdentifier); @@ -92,7 +92,7 @@ public void run_failAndRetryWithNoNewPeers() { @Test public void run_failAndRetryWithNewPeer() { - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); final FetchBlobSidecarTask task = new FetchBlobSidecarTask(eth2P2PNetwork, blobIdentifier); @@ -126,7 +126,7 @@ public void run_failAndRetryWithNewPeer() { @Test public void run_withMultiplesPeersAvailable() { - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); final FetchBlobSidecarTask task = new FetchBlobSidecarTask(eth2P2PNetwork, blobIdentifier); @@ -153,7 +153,7 @@ public void run_withMultiplesPeersAvailable() { @Test public void run_withPreferredPeer() { final Eth2Peer preferredPeer = createNewPeer(1); - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); when(preferredPeer.requestBlobSidecarByRoot(blobIdentifier)) @@ -176,7 +176,7 @@ public void run_withPreferredPeer() { @Test public void run_withRandomPeerWhenFetchingWithPreferredPeerFails() { final Eth2Peer preferredPeer = createNewPeer(1); - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); when(preferredPeer.requestBlobSidecarByRoot(blobIdentifier)) @@ -210,7 +210,7 @@ public void run_withRandomPeerWhenFetchingWithPreferredPeerFails() { @Test public void cancel() { - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BlobIdentifier blobIdentifier = new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); final FetchBlobSidecarTask task = new FetchBlobSidecarTask(eth2P2PNetwork, blobIdentifier); diff --git a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/gossip/blobs/RecentBlobSidecarsFetchServiceTest.java b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/gossip/blobs/RecentBlobSidecarsFetchServiceTest.java index 0ba3b1d38ea..ae6ed5babf5 100644 --- a/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/gossip/blobs/RecentBlobSidecarsFetchServiceTest.java +++ b/beacon/sync/src/test/java/tech/pegasys/teku/beacon/sync/gossip/blobs/RecentBlobSidecarsFetchServiceTest.java @@ -89,7 +89,7 @@ public void fetchSingleBlobSidecarSuccessfully() { assertThat(importedBlobSidecars).isEmpty(); final SafeFuture> future = taskFutures.get(0); - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(blobIdentifier); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(blobIdentifier); future.complete(FetchResult.createSuccessful(blobSidecar)); assertThat(importedBlobSidecars).containsExactly(blobSidecar); @@ -107,7 +107,7 @@ public void handleDuplicateRequiredBlobSidecars() { assertThat(importedBlobSidecars).isEmpty(); final SafeFuture> future = taskFutures.get(0); - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(blobIdentifier); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(blobIdentifier); future.complete(FetchResult.createSuccessful(blobSidecar)); assertThat(importedBlobSidecars).containsExactly(blobSidecar); @@ -222,7 +222,7 @@ public void queueFetchTaskWhenConcurrencyLimitReached() { // Complete first task final SafeFuture> future = taskFutures.get(0); - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); future.complete(FetchResult.createSuccessful(blobSidecar)); // After first task completes, remaining pending count should become active diff --git a/beacon/sync/src/testFixtures/java/tech/pegasys/teku/beacon/sync/SyncingNodeManager.java b/beacon/sync/src/testFixtures/java/tech/pegasys/teku/beacon/sync/SyncingNodeManager.java index 58199ffb8ea..eb4073ca71f 100644 --- a/beacon/sync/src/testFixtures/java/tech/pegasys/teku/beacon/sync/SyncingNodeManager.java +++ b/beacon/sync/src/testFixtures/java/tech/pegasys/teku/beacon/sync/SyncingNodeManager.java @@ -136,7 +136,7 @@ public static SyncingNodeManager create( poolFactory.createPendingPoolForBlocks(spec); final FutureItems futureBlocks = FutureItems.create(SignedBeaconBlock::getSlot, mock(SettableLabelledGauge.class), "blocks"); - final Map invalidBlockRoots = LimitedMap.createSynchronized(500); + final Map invalidBlockRoots = LimitedMap.createSynchronizedLRU(500); final BlockImporter blockImporter = new BlockImporter( 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 295efe73872..5a412bb9b1e 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 @@ -25,12 +25,10 @@ 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; @@ -38,7 +36,6 @@ 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; @@ -291,26 +288,15 @@ private void builderSetKzgCommitments( final SafeFuture> blobKzgCommitments = executionPayloadResultFuture.thenCompose( executionPayloadResult -> { - final SszListSchema 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); @@ -346,6 +332,7 @@ public Consumer createBlockUnblinderSelector() { }; } + @Deprecated public Consumer createBlobSidecarsUnblinderSelector( final UInt64 slot) { return blobSidecarsUnblinder -> @@ -374,7 +361,7 @@ public Function>> createBlobSidecar return block -> { final BlobSidecarSchemaOld blobSidecarSchema = SchemaDefinitionsDeneb.required(spec.atSlot(block.getSlot()).getSchemaDefinitions()) - .getBlobSidecarSchema(); + .getBlobSidecarOldSchema(); return getCachedBlobsBundle(block.getSlot()) .thenApply( blobsBundle -> @@ -394,42 +381,22 @@ public Function>> createBlobSidecar }; } + @Deprecated public Function>> 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 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 getBlindedBlobsBundle( + private SafeFuture> getBlobKzgCommitments( final ExecutionPayloadResult executionPayloadResult) { return executionPayloadResult .getHeaderWithFallbackDataFuture() @@ -437,8 +404,9 @@ private SafeFuture getBlindedBlobsBundle( .thenApply( headerWithFallbackData -> headerWithFallbackData - .getBlindedBlobsBundle() - .orElseThrow(() -> blobsBundleIsNotAvailableException(true))); + .getBlobKzgCommitments() + .orElseThrow( + () -> new IllegalStateException("BlobKzgCommitments are not available"))); } private SafeFuture getCachedBlobsBundle(final UInt64 slot) { @@ -446,18 +414,13 @@ private SafeFuture getCachedBlobsBundle(final UInt64 slot) { return getBlobsBundle(executionPayloadResult); } - private SafeFuture 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"); } } 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 282dde5f687..7836026c839 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 @@ -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; @@ -104,8 +103,9 @@ public abstract class AbstractBlockFactoryTest { protected ExecutionPayload executionPayload = null; protected Optional blobsBundle = Optional.empty(); + // builder context protected ExecutionPayloadHeader executionPayloadHeader = null; - protected Optional blindedBlobsBundle = Optional.empty(); + protected Optional> blobKzgCommitments = Optional.empty(); protected ExecutionPayloadResult cachedExecutionPayloadResult = null; @@ -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 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 blobKzgCommitments = + dataStructureUtil.randomBlobKzgCommitments(count); + this.blobKzgCommitments = Optional.of(blobKzgCommitments); + return blobKzgCommitments; } private void setupExecutionLayerBlockAndBlobsProduction() { @@ -405,7 +406,7 @@ private void setupExecutionLayerBlockAndBlobsProduction() { Optional.of( SafeFuture.completedFuture( HeaderWithFallbackData.create( - executionPayloadHeader, blindedBlobsBundle))), + executionPayloadHeader, blobKzgCommitments))), Optional.empty()); cachedExecutionPayloadResult = executionPayloadResult; return executionPayloadResult; @@ -435,14 +436,11 @@ private List 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) { 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 a459f5df710..be3ad0cfeaa 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 @@ -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; @@ -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; @@ -70,9 +70,10 @@ 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 blobKzgCommitments = prepareBlobKzgCommitments(spec, 3); final BlockContainer blockContainer = assertBlockCreated(1, spec, false, state -> prepareValidPayload(spec, state), true); @@ -80,17 +81,9 @@ void shouldCreateBlindedBlockContentsWhenBlindedBlockRequested() { 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 @@ -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 blindedBlobSidecars = dataStructureUtil.randomSignedBlindedBlobSidecars(blobsBundle); diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java index 3202f8e56d9..4299c41b37f 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java @@ -37,7 +37,6 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; 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.SignedBlobSidecarOld; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; @@ -49,7 +48,6 @@ import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.common.AbstractSignedBeaconBlockUnblinder; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate; -import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle; import tech.pegasys.teku.spec.datastructures.builder.ExecutionPayloadAndBlobsBundle; import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle; import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload; @@ -472,10 +470,11 @@ void shouldIncludeKzgCommitmentsInBlindedBlock() { when(forkChoiceNotifier.getPayloadId(any(), any())) .thenReturn(SafeFuture.completedFuture(Optional.of(executionPayloadContext))); - final BlindedBlobsBundle blindedBlobsBundle = dataStructureUtil.randomBlindedBlobsBundle(); + final SszList blobKzgCommitments = + dataStructureUtil.randomBlobKzgCommitments(); prepareBlindedBlockAndBlobsProduction( - randomExecutionPayloadHeader, executionPayloadContext, blockSlotState, blindedBlobsBundle); + randomExecutionPayloadHeader, executionPayloadContext, blockSlotState, blobKzgCommitments); final CapturingBeaconBlockBodyBuilder bodyBuilder = new CapturingBeaconBlockBodyBuilder(true, true); @@ -485,8 +484,7 @@ void shouldIncludeKzgCommitmentsInBlindedBlock() { parentRoot, blockSlotState, dataStructureUtil.randomSignature(), Optional.empty()) .accept(bodyBuilder); - assertThat(bodyBuilder.blobKzgCommitments) - .hasSameElementsAs(blindedBlobsBundle.getCommitments()); + assertThat(bodyBuilder.blobKzgCommitments).hasSameElementsAs(blobKzgCommitments); } @Test @@ -524,46 +522,7 @@ void shouldCreateBlobSidecarsForBlockFromCachedPayloadResult() { } @Test - void shouldCreateBlindedBlobSidecarsForBlindedBlockFromCachedPayloadResult() { - final BeaconBlock block = dataStructureUtil.randomBlindedBeaconBlock(); - - final BlindedBlobsBundle blindedBlobsBundle = dataStructureUtil.randomBlindedBlobsBundle(); - - // the BlindedBlobsBundle is stored in the HeaderWithFallbackData (retrieved via builder flow) - final HeaderWithFallbackData headerWithFallbackData = - HeaderWithFallbackData.create( - dataStructureUtil.randomExecutionPayloadHeader(), Optional.of(blindedBlobsBundle)); - - prepareCachedPayloadResult( - block.getSlot(), - dataStructureUtil.randomPayloadExecutionContext(false), - headerWithFallbackData); - - final List blindedBlobSidecars = - safeJoin(factory.createBlindedBlobSidecarsSelector().apply(block)); - - assertThat(blindedBlobSidecars) - .hasSize(blindedBlobsBundle.getNumberOfBlobs()) - .first() - .satisfies( - // assert on one of the blinded sidecars - blindedBlobSidecar -> { - assertThat(blindedBlobSidecar.getBlockRoot()).isEqualTo(block.getRoot()); - assertThat(blindedBlobSidecar.getBlockParentRoot()).isEqualTo(block.getParentRoot()); - assertThat(blindedBlobSidecar.getIndex()).isEqualTo(UInt64.ZERO); - assertThat(blindedBlobSidecar.getSlot()).isEqualTo(block.getSlot()); - assertThat(blindedBlobSidecar.getProposerIndex()).isEqualTo(block.getProposerIndex()); - assertThat(blindedBlobSidecar.getBlobRoot()) - .isEqualTo(blindedBlobsBundle.getBlobRoots().get(0).get()); - assertThat(blindedBlobSidecar.getKZGCommitment()) - .isEqualTo(blindedBlobsBundle.getCommitments().get(0).getKZGCommitment()); - assertThat(blindedBlobSidecar.getKZGProof()) - .isEqualTo(blindedBlobsBundle.getProofs().get(0).getKZGProof()); - }); - } - - @Test - void shouldSetBlindedBlobsBundle_whenAcceptingTheBlobSidecarsUnblinderSelector() { + void shouldSetBlobsBundle_whenAcceptingTheBlobSidecarsUnblinderSelector() { final ExecutionPayloadAndBlobsBundle executionPayloadAndBlobsBundle = dataStructureUtil.randomExecutionPayloadAndBlobsBundle(); final UInt64 slot = dataStructureUtil.randomUInt64(); @@ -630,9 +589,9 @@ private void prepareBlindedBlockAndBlobsProduction( final ExecutionPayloadHeader executionPayloadHeader, final ExecutionPayloadContext executionPayloadContext, final BeaconState blockSlotState, - final BlindedBlobsBundle blindedBlobsBundle) { + final SszList blobKzgCommitments) { final HeaderWithFallbackData headerWithFallbackData = - HeaderWithFallbackData.create(executionPayloadHeader, Optional.of(blindedBlobsBundle)); + HeaderWithFallbackData.create(executionPayloadHeader, Optional.of(blobKzgCommitments)); when(executionLayer.initiateBlockAndBlobsProduction( executionPayloadContext, blockSlotState, true)) .thenReturn( @@ -660,21 +619,6 @@ private void prepareCachedPayloadResult( Optional.empty()))); } - private void prepareCachedPayloadResult( - final UInt64 slot, - final ExecutionPayloadContext executionPayloadContext, - final HeaderWithFallbackData headerWithFallbackData) { - when(executionLayer.getCachedPayloadResult(slot)) - .thenReturn( - Optional.of( - new ExecutionPayloadResult( - executionPayloadContext, - Optional.empty(), - Optional.empty(), - Optional.of(SafeFuture.completedFuture(headerWithFallbackData)), - Optional.empty()))); - } - private static class CapturingBeaconBlockBodyBuilder implements BeaconBlockBodyBuilder { private final boolean blinded; diff --git a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/tekuv1/beacon/GetAllBlobSidecarsAtSlotIntegrationTest.java b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/tekuv1/beacon/GetAllBlobSidecarsAtSlotIntegrationTest.java index cd211531a8a..375d51c093b 100644 --- a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/tekuv1/beacon/GetAllBlobSidecarsAtSlotIntegrationTest.java +++ b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/tekuv1/beacon/GetAllBlobSidecarsAtSlotIntegrationTest.java @@ -168,7 +168,7 @@ public Response get(final UInt64 slot) throws IOException { private List parseBlobSidecars(final Response response) throws IOException { final DeserializableTypeDefinition blobSidecarTypeDefinition = SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()) - .getBlobSidecarSchema() + .getBlobSidecarOldSchema() .getJsonTypeDefinition(); final DeserializableTypeDefinition> jsonTypeDefinition = SharedApiTypes.withDataWrapper("blobSidecars", listOf(blobSidecarTypeDefinition)); @@ -181,7 +181,8 @@ private List parseBlobSidecars(final Response response) throws I private List parseBlobSidecarsFromSsz(final Response response) throws IOException { final BlobSidecarSchemaOld blobSidecarSchema = - SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()).getBlobSidecarSchema(); + SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()) + .getBlobSidecarOldSchema(); SszListSchema> blobSidecarSszListSchema = SszListSchema.create( blobSidecarSchema, SpecConfigDeneb.required(specConfig).getMaxBlobsPerBlock()); diff --git a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/GetBlobSidecarsIntegrationTest.java b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/GetBlobSidecarsIntegrationTest.java index d82d572b57a..daab700ed00 100644 --- a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/GetBlobSidecarsIntegrationTest.java +++ b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/GetBlobSidecarsIntegrationTest.java @@ -195,7 +195,7 @@ public Response get(final String blockIdString, final List indices) thro private List parseBlobSidecars(final Response response) throws IOException { final DeserializableTypeDefinition blobSidecarTypeDefinition = SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()) - .getBlobSidecarSchema() + .getBlobSidecarOldSchema() .getJsonTypeDefinition(); final DeserializableTypeDefinition> jsonTypeDefinition = SharedApiTypes.withDataWrapper("blobSidecars", listOf(blobSidecarTypeDefinition)); @@ -208,7 +208,8 @@ private List parseBlobSidecars(final Response response) throws I private List parseBlobSidecarsFromSsz(final Response response) throws IOException { final BlobSidecarSchemaOld blobSidecarSchema = - SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()).getBlobSidecarSchema(); + SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()) + .getBlobSidecarOldSchema(); SszListSchema> blobSidecarSszListSchema = SszListSchema.create( blobSidecarSchema, SpecConfigDeneb.required(specConfig).getMaxBlobsPerBlock()); diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/tekuv1/beacon/GetAllBlobSidecarsAtSlot.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/tekuv1/beacon/GetAllBlobSidecarsAtSlot.java index 25f4b5d8de0..fa82eb2e586 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/tekuv1/beacon/GetAllBlobSidecarsAtSlot.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/tekuv1/beacon/GetAllBlobSidecarsAtSlot.java @@ -90,7 +90,7 @@ private static SerializableTypeDefinition> getResponseType( final SchemaDefinitionCache schemaCache) { final DeserializableTypeDefinition blobSidecarType = SchemaDefinitionsDeneb.required(schemaCache.getSchemaDefinition(SpecMilestone.DENEB)) - .getBlobSidecarSchema() + .getBlobSidecarOldSchema() .getJsonTypeDefinition(); return SerializableTypeDefinition.>object() .name("GetAllBlobSidecarsAtSlotResponse") diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java index 53cdb308682..dab1531db33 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java @@ -90,7 +90,7 @@ private static SerializableTypeDefinition> getResponseType( final SchemaDefinitionCache schemaCache) { final DeserializableTypeDefinition blobSidecarType = SchemaDefinitionsDeneb.required(schemaCache.getSchemaDefinition(SpecMilestone.DENEB)) - .getBlobSidecarSchema() + .getBlobSidecarOldSchema() .getJsonTypeDefinition(); return SerializableTypeDefinition.>object() .name("GetBlobSidecarsResponse") diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/EventSubscriptionManagerTest.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/EventSubscriptionManagerTest.java index 04749a5eea7..ff77e31a652 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/EventSubscriptionManagerTest.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/EventSubscriptionManagerTest.java @@ -95,7 +95,7 @@ public class EventSubscriptionManagerTest { private final SyncState sampleSyncState = SyncState.IN_SYNC; private final SignedBeaconBlock sampleBlock = SignedBeaconBlock.create(data.randomSignedBeaconBlock(0)); - private final BlobSidecarOld sampleBlobSidecar = data.randomBlobSidecar(); + private final BlobSidecarOld sampleBlobSidecar = data.randomBlobSidecarOld(); private final Attestation sampleAttestation = data.randomAttestation(0); private final SignedVoluntaryExit sampleVoluntaryExit = data.randomSignedVoluntaryExit(); private final SignedBlsToExecutionChange sampleBlsToExecutionChange = diff --git a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/phase0/ssz_static/SszTestExecutor.java b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/phase0/ssz_static/SszTestExecutor.java index 2a5f8e8871c..5c1c6a27cc3 100644 --- a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/phase0/ssz_static/SszTestExecutor.java +++ b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/phase0/ssz_static/SszTestExecutor.java @@ -179,11 +179,12 @@ public class SszTestExecutor implements TestExecutor { .put( "ssz_static/BlobSidecar", new SszTestExecutor<>( - schemas -> SchemaDefinitionsDeneb.required(schemas).getBlobSidecarSchema())) + schemas -> SchemaDefinitionsDeneb.required(schemas).getBlobSidecarOldSchema())) .put( "ssz_static/SignedBlobSidecar", new SszTestExecutor<>( - schemas -> SchemaDefinitionsDeneb.required(schemas).getSignedBlobSidecarSchema())) + schemas -> + SchemaDefinitionsDeneb.required(schemas).getSignedBlobSidecarOldSchema())) .put( "ssz_static/BlobIdentifier", new SszTestExecutor<>(schemas -> BlobIdentifier.SSZ_SCHEMA)) diff --git a/ethereum/dataproviders/src/main/java/tech/pegasys/teku/dataproviders/generators/StateCache.java b/ethereum/dataproviders/src/main/java/tech/pegasys/teku/dataproviders/generators/StateCache.java index ba7bd381312..4e4c89a001b 100644 --- a/ethereum/dataproviders/src/main/java/tech/pegasys/teku/dataproviders/generators/StateCache.java +++ b/ethereum/dataproviders/src/main/java/tech/pegasys/teku/dataproviders/generators/StateCache.java @@ -25,7 +25,7 @@ class StateCache { private final Map knownStates; public StateCache(final int maxCachedStates, final Map knownStates) { - this.cache = LimitedMap.createSynchronized(maxCachedStates); + this.cache = LimitedMap.createSynchronizedLRU(maxCachedStates); this.knownStates = knownStates; } diff --git a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionBuilderModule.java b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionBuilderModule.java index aeed1282e6e..0bcac27a0a8 100644 --- a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionBuilderModule.java +++ b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionBuilderModule.java @@ -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; @@ -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; @@ -249,11 +249,11 @@ private SafeFuture getResultFromSignedBuilderBid( final ExecutionPayloadHeader executionPayloadHeader = builderBidValidator.validateAndGetPayloadHeader( spec, signedBuilderBid, validatorRegistration, state, localExecutionPayload); - final Optional blindedBlobsBundle = - signedBuilderBid.getMessage().getOptionalBlindedBlobsBundle(); + final Optional> blobKzgCommitments = + signedBuilderBid.getMessage().getOptionalBlobKzgCommitments(); payloadValueResult.complete(signedBuilderBid.getMessage().getValue()); return SafeFuture.completedFuture( - HeaderWithFallbackData.create(executionPayloadHeader, blindedBlobsBundle)); + HeaderWithFallbackData.create(executionPayloadHeader, blobKzgCommitments)); } public SafeFuture builderRegisterValidators( @@ -351,21 +351,18 @@ private SafeFuture getResultFromLocalGetPayloadResponse( .orElseThrow() .getExecutionPayloadHeaderSchema() .createFromExecutionPayload(executionPayload); - final Optional blindedBlobsBundle = + final Optional> 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); }); } @@ -404,11 +401,10 @@ private SafeFuture 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()); @@ -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 = {}{})", diff --git a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerBlockProductionManagerImplTest.java b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerBlockProductionManagerImplTest.java index 197fd38f8d7..87a366fdb9e 100644 --- a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerBlockProductionManagerImplTest.java +++ b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerBlockProductionManagerImplTest.java @@ -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; @@ -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; @@ -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 blobKzgCommitments = + schemaDefinitions.getBlobKzgCommitmentsSchema().createFromBlobsBundle(blobsBundle); final ExecutionPayloadResult executionPayloadResult = blockProductionManager.initiateBlockAndBlobsProduction( @@ -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 headerWithFallbackDataFuture = @@ -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( @@ -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 diff --git a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java index cc51ca4e5ab..b399289b1cf 100644 --- a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java +++ b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionLayerManagerImplTest.java @@ -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; @@ -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; @@ -556,19 +557,19 @@ public void builderGetHeaderGetPayload_shouldReturnHeaderAndPayloadViaEngineOnBu .orElseThrow() .getExecutionPayloadHeaderSchema() .createFromExecutionPayload(getPayloadResponse.getExecutionPayload()); - final BlindedBlobsBundle expectedBlindedBlobsBundle = + final SszList 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(), @@ -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 diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java index a9aed57d823..e9cdd9ba0cf 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java @@ -395,7 +395,7 @@ public BlobSidecarOld deserializeBlobSidecar( .toVersionDeneb() .orElseThrow( () -> new RuntimeException("Deneb milestone is required to deserialize blob sidecar")) - .getBlobSidecarSchema() + .getBlobSidecarOldSchema() .sszDeserialize(serializedBlobSidecar); } @@ -962,10 +962,6 @@ public Optional getMaxBlobsPerBlock() { return getSpecConfigDeneb().map(SpecConfigDeneb::getMaxBlobsPerBlock); } - public Optional getMaxBlobCommitmentsPerBlock() { - return getSpecConfigDeneb().map(SpecConfigDeneb::getMaxBlobCommitmentsPerBlock); - } - public Optional getMaxBlobsPerBlock(final UInt64 slot) { return getSpecConfigDeneb(slot).map(SpecConfigDeneb::getMaxBlobsPerBlock); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDeneb.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDeneb.java index b70d574b005..aa4296251be 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDeneb.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDeneb.java @@ -54,6 +54,8 @@ static SpecConfigDeneb required(final SpecConfig specConfig) { int getMaxBlobsPerBlock(); + int getKzgCommitmentInclusionProofDepth(); + int getEpochsStoreBlobs(); @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java index 663dfb26056..53ced36b5af 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigDenebImpl.java @@ -27,6 +27,7 @@ public class SpecConfigDenebImpl extends DelegatingSpecConfigCapella implements private final int fieldElementsPerBlob; private final int maxBlobCommitmentsPerBlock; private final int maxBlobsPerBlock; + private final int kzgCommitmentInclusionProofDepth; private final int maxRequestBlocksDeneb; private final int maxRequestBlobSidecars; private final int minEpochsForBlobSidecarsRequests; @@ -41,6 +42,7 @@ public SpecConfigDenebImpl( final int fieldElementsPerBlob, final int maxBlobCommitmentsPerBlock, final int maxBlobsPerBlock, + final int kzgCommitmentInclusionProofDepth, final int maxRequestBlocksDeneb, final int maxRequestBlobSidecars, final int minEpochsForBlobSidecarsRequests, @@ -53,6 +55,7 @@ public SpecConfigDenebImpl( this.fieldElementsPerBlob = fieldElementsPerBlob; this.maxBlobCommitmentsPerBlock = maxBlobCommitmentsPerBlock; this.maxBlobsPerBlock = maxBlobsPerBlock; + this.kzgCommitmentInclusionProofDepth = kzgCommitmentInclusionProofDepth; this.maxRequestBlocksDeneb = maxRequestBlocksDeneb; this.maxRequestBlobSidecars = maxRequestBlobSidecars; this.minEpochsForBlobSidecarsRequests = minEpochsForBlobSidecarsRequests; @@ -90,6 +93,11 @@ public int getMaxBlobsPerBlock() { return maxBlobsPerBlock; } + @Override + public int getKzgCommitmentInclusionProofDepth() { + return kzgCommitmentInclusionProofDepth; + } + @Override public int getMaxRequestBlocksDeneb() { return maxRequestBlocksDeneb; @@ -138,6 +146,7 @@ public boolean equals(final Object o) { && fieldElementsPerBlob == that.fieldElementsPerBlob && maxBlobCommitmentsPerBlock == that.maxBlobCommitmentsPerBlock && maxBlobsPerBlock == that.maxBlobsPerBlock + && kzgCommitmentInclusionProofDepth == that.kzgCommitmentInclusionProofDepth && maxRequestBlocksDeneb == that.maxRequestBlocksDeneb && maxRequestBlobSidecars == that.maxRequestBlobSidecars && minEpochsForBlobSidecarsRequests == that.minEpochsForBlobSidecarsRequests @@ -153,6 +162,7 @@ public int hashCode() { fieldElementsPerBlob, maxBlobCommitmentsPerBlock, maxBlobsPerBlock, + kzgCommitmentInclusionProofDepth, maxRequestBlocksDeneb, maxRequestBlobSidecars, minEpochsForBlobSidecarsRequests, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java index 3a6d7ac8a4a..2ddd5990e00 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/DenebBuilder.java @@ -36,11 +36,12 @@ public class DenebBuilder implements ForkConfigBuilder epochsStoreBlobs = Optional.empty(); private Integer blobSidecarSubnetCount; + private Optional epochsStoreBlobs = Optional.empty(); DenebBuilder() {} @@ -54,6 +55,7 @@ public SpecConfigDeneb build(final SpecConfigCapella specConfig) { fieldElementsPerBlob, maxBlobCommitmentsPerBlock, maxBlobsPerBlock, + kzgCommitmentInclusionProofDepth, maxRequestBlocksDeneb, maxRequestBlobSidecars, minEpochsForBlobSidecarsRequests, @@ -95,6 +97,12 @@ public DenebBuilder maxBlobsPerBlock(final Integer maxBlobsPerBlock) { return this; } + public DenebBuilder kzgCommitmentInclusionProofDepth( + final Integer kzgCommitmentInclusionProofDepth) { + this.kzgCommitmentInclusionProofDepth = kzgCommitmentInclusionProofDepth; + return this; + } + public DenebBuilder maxRequestBlocksDeneb(final Integer maxRequestBlocksDeneb) { this.maxRequestBlocksDeneb = maxRequestBlocksDeneb; return this; @@ -146,6 +154,7 @@ public Map getValidationMap() { constants.put("fieldElementsPerBlob", fieldElementsPerBlob); constants.put("maxBlobCommitmentsPerBlock", maxBlobCommitmentsPerBlock); constants.put("maxBlobsPerBlock", maxBlobsPerBlock); + constants.put("kzgCommitmentInclusionProofDepth", kzgCommitmentInclusionProofDepth); constants.put("maxRequestBlocksDeneb", maxRequestBlocksDeneb); constants.put("maxRequestBlobSidecars", maxRequestBlobSidecars); constants.put("minEpochsForBlobSidecarsRequests", minEpochsForBlobSidecarsRequests); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobKzgCommitmentsSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobKzgCommitmentsSchema.java new file mode 100644 index 00000000000..2f2db973074 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobKzgCommitmentsSchema.java @@ -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> { + + public BlobKzgCommitmentsSchema(final SpecConfigDeneb specConfig) { + super(SszKZGCommitmentSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock()); + } + + @Override + public SszList createFromBackingNode(final TreeNode node) { + return new SszListImpl<>(this, node); + } + + public SszList createFromBlobsBundle(final BlobsBundle blobsBundle) { + return createFromElements( + blobsBundle.getCommitments().stream().map(SszKZGCommitment::new).toList()); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecar.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecar.java new file mode 100644 index 00000000000..80ee8b2e985 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecar.java @@ -0,0 +1,112 @@ +/* + * 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 java.util.List; +import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.infrastructure.logging.LogFormatter; +import tech.pegasys.teku.infrastructure.ssz.collections.SszBytes32Vector; +import tech.pegasys.teku.infrastructure.ssz.containers.Container6; +import tech.pegasys.teku.infrastructure.ssz.impl.AbstractSszPrimitive; +import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32; +import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64; +import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.kzg.KZGCommitment; +import tech.pegasys.teku.kzg.KZGProof; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; +import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot; +import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; +import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; + +public class BlobSidecar + extends Container6< + BlobSidecar, + SszUInt64, + Blob, + SszKZGCommitment, + SszKZGProof, + SignedBeaconBlockHeader, + SszBytes32Vector> { + + BlobSidecar(final BlobSidecarSchema blobSidecarSchema, final TreeNode backingTreeNode) { + super(blobSidecarSchema, backingTreeNode); + } + + public BlobSidecar( + final BlobSidecarSchema schema, + final UInt64 index, + final Blob blob, + final KZGCommitment kzgCommitment, + final KZGProof kzgProof, + final SignedBeaconBlockHeader signedBeaconBlockHeader, + final List kzgCommitmentInclusionProof) { + super( + schema, + SszUInt64.of(index), + schema.getBlobSchema().create(blob.getBytes()), + new SszKZGCommitment(kzgCommitment), + new SszKZGProof(kzgProof), + signedBeaconBlockHeader, + schema + .getKzgCommitmentInclusionProofSchema() + .createFromElements(kzgCommitmentInclusionProof.stream().map(SszBytes32::of).toList())); + } + + public UInt64 getIndex() { + return getField0().get(); + } + + public Blob getBlob() { + return getField1(); + } + + public KZGCommitment getKZGCommitment() { + return getField2().getKZGCommitment(); + } + + public KZGProof getKZGProof() { + return getField3().getKZGProof(); + } + + public SignedBeaconBlockHeader getSignedBeaconBlockHeader() { + return getField4(); + } + + public List getKzgCommitmentInclusionProof() { + return getField5().stream().map(AbstractSszPrimitive::get).toList(); + } + + public UInt64 getSlot() { + return getSignedBeaconBlockHeader().getMessage().getSlot(); + } + + public Bytes32 getBlockRoot() { + return getSignedBeaconBlockHeader().getMessage().getRoot(); + } + + public SlotAndBlockRoot getSlotAndBlockRoot() { + return new SlotAndBlockRoot(getSlot(), getBlockRoot()); + } + + public String toLogString() { + return LogFormatter.formatBlobSidecar( + getSlot(), + getBlockRoot(), + getIndex(), + getBlob().toBriefString(), + getKZGCommitment().toHexString(), + getKZGProof().toAbbreviatedString()); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarOld.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarOld.java index c0a92014802..a78b911d187 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarOld.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarOld.java @@ -26,6 +26,7 @@ import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; +@Deprecated public class BlobSidecarOld extends Container8< BlobSidecarOld, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarSchema.java new file mode 100644 index 00000000000..3cbfe26deae --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarSchema.java @@ -0,0 +1,132 @@ +/* + * 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 java.util.List; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.bytes.Bytes48; +import tech.pegasys.teku.infrastructure.ssz.collections.SszBytes32Vector; +import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema6; +import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64; +import tech.pegasys.teku.infrastructure.ssz.schema.SszFieldName; +import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas; +import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema; +import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBytes32VectorSchema; +import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.kzg.KZGCommitment; +import tech.pegasys.teku.kzg.KZGProof; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeaderSchema; +import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; +import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitmentSchema; +import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; +import tech.pegasys.teku.spec.datastructures.type.SszKZGProofSchema; + +public class BlobSidecarSchema + extends ContainerSchema6< + BlobSidecar, + SszUInt64, + Blob, + SszKZGCommitment, + SszKZGProof, + SignedBeaconBlockHeader, + SszBytes32Vector> { + + static final SszFieldName FIELD_BLOB = () -> "blob"; + static final SszFieldName FIELD_SIGNED_BLOCK_HEADER = () -> "signed_block_header"; + static final SszFieldName FIELD_KZG_COMMITMENT_INCLUSION_PROOF = + () -> "kzg_commitment_inclusion_proof"; + + BlobSidecarSchema( + final SignedBeaconBlockHeaderSchema signedBeaconBlockHeaderSchema, + final BlobSchema blobSchema, + final int kzgCommitmentInclusionProofDepth) { + super( + "BlobSidecar", + namedSchema("index", SszPrimitiveSchemas.UINT64_SCHEMA), + namedSchema(FIELD_BLOB, blobSchema), + namedSchema("kzg_commitment", SszKZGCommitmentSchema.INSTANCE), + namedSchema("kzg_proof", SszKZGProofSchema.INSTANCE), + namedSchema(FIELD_SIGNED_BLOCK_HEADER, signedBeaconBlockHeaderSchema), + namedSchema( + FIELD_KZG_COMMITMENT_INCLUSION_PROOF, + SszBytes32VectorSchema.create(kzgCommitmentInclusionProofDepth))); + } + + @SuppressWarnings("unchecked") + public SszSchema getBlobSszSchema() { + return (SszSchema) getChildSchema(getFieldIndex(FIELD_BLOB)); + } + + public BlobSchema getBlobSchema() { + return (BlobSchema) getBlobSszSchema(); + } + + public SignedBeaconBlockHeaderSchema getSignedBlockHeaderSchema() { + return (SignedBeaconBlockHeaderSchema) getFieldSchema4(); + } + + public SszBytes32VectorSchema getKzgCommitmentInclusionProofSchema() { + return (SszBytes32VectorSchema) + getChildSchema(getFieldIndex(FIELD_KZG_COMMITMENT_INCLUSION_PROOF)); + } + + public BlobSidecar create( + final UInt64 index, + final Bytes blob, + final Bytes48 kzgCommitment, + final Bytes48 kzgProof, + final SignedBeaconBlockHeader signedBeaconBlockHeader, + final List kzgCommitmentInclusionProof) { + return create( + index, + new Blob(getBlobSchema(), blob), + KZGCommitment.fromBytesCompressed(kzgCommitment), + KZGProof.fromBytesCompressed(kzgProof), + signedBeaconBlockHeader, + kzgCommitmentInclusionProof); + } + + public BlobSidecar create( + final UInt64 index, + final Blob blob, + final KZGCommitment kzgCommitment, + final KZGProof kzgProof, + final SignedBeaconBlockHeader signedBeaconBlockHeader, + final List kzgCommitmentInclusionProof) { + return new BlobSidecar( + this, + index, + blob, + kzgCommitment, + kzgProof, + signedBeaconBlockHeader, + kzgCommitmentInclusionProof); + } + + public static BlobSidecarSchema create( + final SignedBeaconBlockHeaderSchema signedBeaconBlockHeaderSchema, + final BlobSchema blobSchema, + final int kzgCommitmentInclusionProofDepth) { + return new BlobSidecarSchema( + signedBeaconBlockHeaderSchema, blobSchema, kzgCommitmentInclusionProofDepth); + } + + @Override + public BlobSidecar createFromBackingNode(TreeNode node) { + return new BlobSidecar(this, node); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarSchemaOld.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarSchemaOld.java index 3ead65b00f0..14ba3aa4f78 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarSchemaOld.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarSchemaOld.java @@ -31,6 +31,7 @@ import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; import tech.pegasys.teku.spec.datastructures.type.SszKZGProofSchema; +@Deprecated public class BlobSidecarSchemaOld extends ContainerSchema8< BlobSidecarOld, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarOld.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarOld.java index a404134334e..ec84f4d10c7 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarOld.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarOld.java @@ -19,6 +19,7 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.datastructures.type.SszSignature; +@Deprecated public class SignedBlobSidecarOld extends Container2 { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarSchemaOld.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarSchemaOld.java index 8b3285b9c18..21f215bf994 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarSchemaOld.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarSchemaOld.java @@ -20,6 +20,7 @@ import tech.pegasys.teku.spec.datastructures.type.SszSignature; import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; +@Deprecated public class SignedBlobSidecarSchemaOld extends ContainerSchema2 { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarsUnblinderDeneb.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarsUnblinderDeneb.java index 92941614745..fc5ef845621 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarsUnblinderDeneb.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarsUnblinderDeneb.java @@ -33,8 +33,8 @@ public class SignedBlobSidecarsUnblinderDeneb implements SignedBlobSidecarsUnbli public SignedBlobSidecarsUnblinderDeneb( final SchemaDefinitionsDeneb schemaDefinitions, final List signedBlindedBlobSidecars) { - this.blobSidecarSchema = schemaDefinitions.getBlobSidecarSchema(); - this.signedBlobSidecarSchema = schemaDefinitions.getSignedBlobSidecarSchema(); + this.blobSidecarSchema = schemaDefinitions.getBlobSidecarOldSchema(); + this.signedBlobSidecarSchema = schemaDefinitions.getSignedBlobSidecarOldSchema(); this.signedBlindedBlobSidecars = signedBlindedBlobSidecars; } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlockHeader.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlockHeader.java index 2be873b8569..6516bcfd560 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlockHeader.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlockHeader.java @@ -15,34 +15,16 @@ import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.infrastructure.ssz.containers.Container2; -import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2; import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; import tech.pegasys.teku.spec.datastructures.type.SszSignature; -import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; public class SignedBeaconBlockHeader extends Container2 { - public static class SignedBeaconBlockHeaderSchema - extends ContainerSchema2 { - - public SignedBeaconBlockHeaderSchema() { - super( - "SignedBeaconBlockHeader", - namedSchema("message", BeaconBlockHeader.SSZ_SCHEMA), - namedSchema("signature", SszSignatureSchema.INSTANCE)); - } - - @Override - public SignedBeaconBlockHeader createFromBackingNode(TreeNode node) { - return new SignedBeaconBlockHeader(this, node); - } - } - public static final SignedBeaconBlockHeaderSchema SSZ_SCHEMA = new SignedBeaconBlockHeaderSchema(); - private SignedBeaconBlockHeader(SignedBeaconBlockHeaderSchema type, TreeNode backingNode) { + SignedBeaconBlockHeader(SignedBeaconBlockHeaderSchema type, TreeNode backingNode) { super(type, backingNode); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlockHeaderSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlockHeaderSchema.java new file mode 100644 index 00000000000..fa911dfc78e --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBeaconBlockHeaderSchema.java @@ -0,0 +1,35 @@ +/* + * 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.blocks; + +import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2; +import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; +import tech.pegasys.teku.spec.datastructures.type.SszSignature; +import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; + +public class SignedBeaconBlockHeaderSchema + extends ContainerSchema2 { + + public SignedBeaconBlockHeaderSchema() { + super( + "SignedBeaconBlockHeader", + namedSchema("message", BeaconBlockHeader.SSZ_SCHEMA), + namedSchema("signature", SszSignatureSchema.INSTANCE)); + } + + @Override + public SignedBeaconBlockHeader createFromBackingNode(TreeNode node) { + return new SignedBeaconBlockHeader(this, node); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java index 2a49cfe336c..e86e723f1fc 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java @@ -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; @@ -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; @@ -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, @@ -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 diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java index 09b43899495..7239f413c4b 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java @@ -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; @@ -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; @@ -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, @@ -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 diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundle.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundle.java deleted file mode 100644 index 1e4404e38eb..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundle.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2023 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.builder; - -import tech.pegasys.teku.infrastructure.ssz.SszList; -import tech.pegasys.teku.infrastructure.ssz.containers.Container3; -import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; -import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; - -public class BlindedBlobsBundle - extends Container3< - BlindedBlobsBundle, SszList, SszList, SszList> { - - BlindedBlobsBundle(final BlindedBlobsBundleSchema type, final TreeNode backingTreeNode) { - super(type, backingTreeNode); - } - - public BlindedBlobsBundle( - final BlindedBlobsBundleSchema schema, - final SszList commitments, - final SszList proofs, - final SszList blobRoots) { - super(schema, commitments, proofs, blobRoots); - } - - public SszList getCommitments() { - return getField0(); - } - - public SszList getProofs() { - return getField1(); - } - - public SszList getBlobRoots() { - return getField2(); - } - - public int getNumberOfBlobs() { - return getBlobRoots().size(); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundleSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundleSchema.java deleted file mode 100644 index 4edfc26498a..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundleSchema.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2023 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.builder; - -import tech.pegasys.teku.infrastructure.ssz.SszList; -import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3; -import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32; -import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema; -import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.config.SpecConfigDeneb; -import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; -import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; -import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitmentSchema; -import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; -import tech.pegasys.teku.spec.datastructures.type.SszKZGProofSchema; - -public class BlindedBlobsBundleSchema - extends ContainerSchema3< - BlindedBlobsBundle, SszList, SszList, SszList> { - - public BlindedBlobsBundleSchema(final String containerName, final SpecConfigDeneb specConfig) { - super( - containerName, - namedSchema( - "commitments", - SszListSchema.create( - SszKZGCommitmentSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock())), - namedSchema( - "proofs", - SszListSchema.create( - SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock())), - namedSchema( - "blob_roots", - SszListSchema.create( - SszPrimitiveSchemas.BYTES32_SCHEMA, specConfig.getMaxBlobCommitmentsPerBlock()))); - } - - @SuppressWarnings("unchecked") - public SszListSchema getCommitmentsSchema() { - return (SszListSchema) getChildSchema(getFieldIndex("commitments")); - } - - @SuppressWarnings("unchecked") - public SszListSchema getProofsSchema() { - return (SszListSchema) getChildSchema(getFieldIndex("proofs")); - } - - @SuppressWarnings("unchecked") - public SszListSchema getBlobRootsSchema() { - return (SszListSchema) getChildSchema(getFieldIndex("blob_roots")); - } - - @Override - public BlindedBlobsBundle createFromBackingNode(final TreeNode node) { - return new BlindedBlobsBundle(this, node); - } - - public BlindedBlobsBundle createFromExecutionBlobsBundle( - final tech.pegasys.teku.spec.datastructures.execution.BlobsBundle blobsBundle) { - return new BlindedBlobsBundle( - this, - getCommitmentsSchema() - .createFromElements( - blobsBundle.getCommitments().stream().map(SszKZGCommitment::new).toList()), - getProofsSchema() - .createFromElements(blobsBundle.getProofs().stream().map(SszKZGProof::new).toList()), - getBlobRootsSchema() - .createFromElements( - blobsBundle.getBlobs().stream() - .map(Blob::hashTreeRoot) - .map(SszBytes32::of) - .toList())); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlobsBundleSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlobsBundleSchema.java index 8e9917a68ad..7110879d5bc 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlobsBundleSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BlobsBundleSchema.java @@ -19,9 +19,9 @@ import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema; import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; -import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitmentSchema; import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; import tech.pegasys.teku.spec.datastructures.type.SszKZGProofSchema; @@ -30,17 +30,19 @@ public class BlobsBundleSchema BlobsBundle, SszList, SszList, SszList> { public BlobsBundleSchema( - final String containerName, final BlobSchema blobSchema, final SpecConfigDeneb specConfig) { + final String containerName, + final BlobSchema blobSchema, + final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema, + final SpecConfigDeneb specConfig) { super( containerName, + namedSchema("commitments", blobKzgCommitmentsSchema), namedSchema( - "commitments", + "proofs", SszListSchema.create( - SszKZGCommitmentSchema.INSTANCE, specConfig.getMaxBlobsPerBlock())), + SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobCommitmentsPerBlock())), namedSchema( - "proofs", - SszListSchema.create(SszKZGProofSchema.INSTANCE, specConfig.getMaxBlobsPerBlock())), - namedSchema("blobs", SszListSchema.create(blobSchema, specConfig.getMaxBlobsPerBlock()))); + "blobs", SszListSchema.create(blobSchema, specConfig.getMaxBlobCommitmentsPerBlock()))); } @SuppressWarnings("unchecked") diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BuilderBid.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BuilderBid.java index fa6c256fd00..2b1cab3dd2e 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BuilderBid.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/BuilderBid.java @@ -25,11 +25,6 @@ public interface BuilderBid extends SszContainer { ExecutionPayloadHeader getHeader(); - @Deprecated - default Optional getOptionalBlindedBlobsBundle() { - return Optional.empty(); - } - Optional> getOptionalBlobKzgCommitments(); UInt256 getValue(); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/versions/deneb/BuilderBidSchemaDeneb.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/versions/deneb/BuilderBidSchemaDeneb.java index 863ac456ed2..1b4f9c7749e 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/versions/deneb/BuilderBidSchemaDeneb.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/builder/versions/deneb/BuilderBidSchemaDeneb.java @@ -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; @@ -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)); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/HeaderWithFallbackData.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/HeaderWithFallbackData.java index 59074971e6a..d65be64ff81 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/HeaderWithFallbackData.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/HeaderWithFallbackData.java @@ -16,7 +16,8 @@ import com.google.common.base.MoreObjects; import java.util.Objects; import java.util.Optional; -import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle; +import tech.pegasys.teku.infrastructure.ssz.SszList; +import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; /** * if we serve unblind production, external optional is empty @@ -30,16 +31,16 @@ public class HeaderWithFallbackData { private final ExecutionPayloadHeader executionPayloadHeader; - private final Optional blindedBlobsBundle; - private final Optional fallbackDataOptional; + private final Optional> blobKzgCommitments; + private final Optional fallbackData; private HeaderWithFallbackData( final ExecutionPayloadHeader executionPayloadHeader, - final Optional blindedBlobsBundle, - final Optional fallbackDataOptional) { + final Optional> blobKzgCommitments, + final Optional fallbackData) { this.executionPayloadHeader = executionPayloadHeader; - this.blindedBlobsBundle = blindedBlobsBundle; - this.fallbackDataOptional = fallbackDataOptional; + this.blobKzgCommitments = blobKzgCommitments; + this.fallbackData = fallbackData; } public static HeaderWithFallbackData create( @@ -54,28 +55,28 @@ public static HeaderWithFallbackData create(final ExecutionPayloadHeader executi public static HeaderWithFallbackData create( final ExecutionPayloadHeader executionPayloadHeader, - final Optional blindedBlobsBundle, + final Optional> blobKzgCommitments, final FallbackData fallbackData) { return new HeaderWithFallbackData( - executionPayloadHeader, blindedBlobsBundle, Optional.of(fallbackData)); + executionPayloadHeader, blobKzgCommitments, Optional.of(fallbackData)); } public static HeaderWithFallbackData create( final ExecutionPayloadHeader executionPayloadHeader, - final Optional blindedBlobsBundle) { - return new HeaderWithFallbackData(executionPayloadHeader, blindedBlobsBundle, Optional.empty()); + final Optional> blobKzgCommitments) { + return new HeaderWithFallbackData(executionPayloadHeader, blobKzgCommitments, Optional.empty()); } public ExecutionPayloadHeader getExecutionPayloadHeader() { return executionPayloadHeader; } - public Optional getBlindedBlobsBundle() { - return blindedBlobsBundle; + public Optional> getBlobKzgCommitments() { + return blobKzgCommitments; } - public Optional getFallbackDataOptional() { - return fallbackDataOptional; + public Optional getFallbackData() { + return fallbackData; } @Override @@ -88,21 +89,21 @@ public boolean equals(final Object o) { } final HeaderWithFallbackData that = (HeaderWithFallbackData) o; return Objects.equals(executionPayloadHeader, that.executionPayloadHeader) - && Objects.equals(blindedBlobsBundle, that.blindedBlobsBundle) - && Objects.equals(fallbackDataOptional, that.fallbackDataOptional); + && Objects.equals(blobKzgCommitments, that.blobKzgCommitments) + && Objects.equals(fallbackData, that.fallbackData); } @Override public int hashCode() { - return Objects.hash(executionPayloadHeader, blindedBlobsBundle, fallbackDataOptional); + return Objects.hash(executionPayloadHeader, blobKzgCommitments, fallbackData); } @Override public String toString() { return MoreObjects.toStringHelper(this) .add("executionPayloadHeader", executionPayloadHeader) - .add("blindedBlobsBundle", blindedBlobsBundle) - .add("fallbackDataOptional", fallbackDataOptional) + .add("blobKzgCommitments", blobKzgCommitments) + .add("fallbackData", fallbackData) .toString(); } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java index 47b7850c34f..75c247872bb 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/executionlayer/ExecutionLayerChannelStub.java @@ -47,7 +47,6 @@ import tech.pegasys.teku.spec.config.SpecConfigBellatrix; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; -import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle; import tech.pegasys.teku.spec.datastructures.builder.BuilderPayload; import tech.pegasys.teku.spec.datastructures.builder.SignedValidatorRegistration; import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle; @@ -60,6 +59,7 @@ import tech.pegasys.teku.spec.datastructures.execution.NewPayloadRequest; import tech.pegasys.teku.spec.datastructures.execution.PowBlock; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; import tech.pegasys.teku.spec.datastructures.util.BlobsUtil; import tech.pegasys.teku.spec.schemas.SchemaDefinitions; import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix; @@ -94,7 +94,7 @@ public class ExecutionLayerChannelStub implements ExecutionLayerChannel { // block, payload and blobs tracking private Optional lastBuilderPayloadToBeUnblinded = Optional.empty(); private Optional - lastBuilderBlobsBundleToBeUnblinded = Optional.empty(); + lastBuilderBlobsBundle = Optional.empty(); private Optional lastValidBlock = Optional.empty(); public ExecutionLayerChannelStub( @@ -345,23 +345,23 @@ public SafeFuture builderGetHeader( SchemaDefinitionsBellatrix.required(schemaDefinitions) .getExecutionPayloadHeaderSchema() .createFromExecutionPayload(executionPayload); - final Optional blindedBlobsBundle = + final Optional> blobKzgCommitments = getPayloadResponse .getBlobsBundle() .map( blobsBundle -> { final SchemaDefinitionsDeneb schemaDefinitionsDeneb = SchemaDefinitionsDeneb.required(schemaDefinitions); - lastBuilderBlobsBundleToBeUnblinded = + lastBuilderBlobsBundle = Optional.of( schemaDefinitionsDeneb .getBlobsBundleSchema() .createFromExecutionBlobsBundle(blobsBundle)); return schemaDefinitionsDeneb - .getBlindedBlobsBundleSchema() - .createFromExecutionBlobsBundle(blobsBundle); + .getBlobKzgCommitmentsSchema() + .createFromBlobsBundle(blobsBundle); }); - return HeaderWithFallbackData.create(payloadHeader, blindedBlobsBundle); + return HeaderWithFallbackData.create(payloadHeader, blobKzgCommitments); }); } @@ -408,7 +408,7 @@ public SafeFuture builderGetPayload( lastBuilderPayloadToBeUnblinded.get().getBlockHash()); final BuilderPayload builderPayload = - lastBuilderBlobsBundleToBeUnblinded + lastBuilderBlobsBundle // post Deneb .map( blobsBundle -> { 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 1fe72d4c714..5723aab1048 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 @@ -21,13 +21,16 @@ import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlindedBlobSidecarSchema; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchema; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchemaOld; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.SignedBlindedBlobSidecarSchema; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.SignedBlobSidecarSchemaOld; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema; import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; import tech.pegasys.teku.spec.datastructures.blocks.BlockContainerSchema; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema; import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer; import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainerSchema; @@ -40,7 +43,6 @@ import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContentsSchema; import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlindedBlockContentsSchema; import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContentsSchema; -import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundleSchema; import tech.pegasys.teku.spec.datastructures.builder.BlobsBundleSchema; import tech.pegasys.teku.spec.datastructures.builder.BuilderBidSchema; import tech.pegasys.teku.spec.datastructures.builder.BuilderPayloadSchema; @@ -65,6 +67,8 @@ public class SchemaDefinitionsDeneb extends SchemaDefinitionsCapella { private final ExecutionPayloadSchemaDeneb executionPayloadSchemaDeneb; private final ExecutionPayloadHeaderSchemaDeneb executionPayloadHeaderSchemaDeneb; + private final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema; + private final BeaconBlockBodySchemaDeneb beaconBlockBodySchema; private final BlindedBeaconBlockBodySchemaDeneb blindedBeaconBlockBodySchema; @@ -78,8 +82,9 @@ public class SchemaDefinitionsDeneb extends SchemaDefinitionsCapella { private final BlobSchema blobSchema; private final SszListSchema> blobsInBlockSchema; - private final BlobSidecarSchemaOld blobSidecarSchema; - private final SignedBlobSidecarSchemaOld signedBlobSidecarSchema; + private final BlobSidecarSchema blobSidecarSchema; + private final BlobSidecarSchemaOld blobSidecarOldSchema; + private final SignedBlobSidecarSchemaOld signedBlobSidecarOldSchema; private final BlindedBlobSidecarSchema blindedBlobSidecarSchema; private final SignedBlindedBlobSidecarSchema signedBlindedBlobSidecarSchema; private final BlockContentsSchema blockContentsSchema; @@ -87,7 +92,6 @@ public class SchemaDefinitionsDeneb extends SchemaDefinitionsCapella { private final BlindedBlockContentsSchema blindedBlockContentsSchema; private final SignedBlindedBlockContentsSchema signedBlindedBlockContentsSchema; private final BlobsBundleSchema blobsBundleSchema; - private final BlindedBlobsBundleSchema blindedBlobsBundleSchema; private final ExecutionPayloadAndBlobsBundleSchema executionPayloadAndBlobsBundleSchema; private final BlobSidecarsByRootRequestMessageSchema blobSidecarsByRootRequestMessageSchema; @@ -100,17 +104,20 @@ public SchemaDefinitionsDeneb(final SpecConfigDeneb specConfig) { this.beaconStateSchema = BeaconStateSchemaDeneb.create(specConfig); this.executionPayloadHeaderSchemaDeneb = beaconStateSchema.getLastExecutionPayloadHeaderSchema(); + this.blobKzgCommitmentsSchema = new BlobKzgCommitmentsSchema(specConfig); this.beaconBlockBodySchema = BeaconBlockBodySchemaDenebImpl.create( specConfig, getAttesterSlashingSchema(), signedBlsToExecutionChangeSchema, + blobKzgCommitmentsSchema, "BeaconBlockBodyDeneb"); this.blindedBeaconBlockBodySchema = BlindedBeaconBlockBodySchemaDenebImpl.create( specConfig, getAttesterSlashingSchema(), signedBlsToExecutionChangeSchema, + blobKzgCommitmentsSchema, "BlindedBlockBodyDeneb"); this.beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema, "BeaconBlockDeneb"); this.blindedBeaconBlockSchema = @@ -119,27 +126,31 @@ public SchemaDefinitionsDeneb(final SpecConfigDeneb specConfig) { new SignedBeaconBlockSchema(beaconBlockSchema, "SignedBeaconBlockDeneb"); this.signedBlindedBeaconBlockSchema = new SignedBeaconBlockSchema(blindedBeaconBlockSchema, "SignedBlindedBlockDeneb"); - this.blindedBlobsBundleSchema = - new BlindedBlobsBundleSchema("BlindedBlobsBundleDeneb", specConfig); this.builderBidSchemaDeneb = - new BuilderBidSchemaDeneb("BuilderBidDeneb", specConfig, executionPayloadHeaderSchemaDeneb); + new BuilderBidSchemaDeneb( + "BuilderBidDeneb", executionPayloadHeaderSchemaDeneb, blobKzgCommitmentsSchema); this.signedBuilderBidSchemaDeneb = new SignedBuilderBidSchema("SignedBuilderBidDeneb", builderBidSchemaDeneb); this.blobSchema = new BlobSchema(specConfig); this.blobsInBlockSchema = SszListSchema.create(blobSchema, specConfig.getMaxBlobsPerBlock()); - this.blobSidecarSchema = BlobSidecarSchemaOld.create(blobSchema); - this.signedBlobSidecarSchema = SignedBlobSidecarSchemaOld.create(blobSidecarSchema); + this.blobSidecarSchema = + BlobSidecarSchema.create( + SignedBeaconBlockHeader.SSZ_SCHEMA, + blobSchema, + specConfig.getKzgCommitmentInclusionProofDepth()); + this.blobSidecarOldSchema = BlobSidecarSchemaOld.create(blobSchema); + this.signedBlobSidecarOldSchema = SignedBlobSidecarSchemaOld.create(blobSidecarOldSchema); this.blindedBlobSidecarSchema = BlindedBlobSidecarSchema.create(); this.signedBlindedBlobSidecarSchema = SignedBlindedBlobSidecarSchema.create(blindedBlobSidecarSchema); this.blockContentsSchema = BlockContentsSchema.create( - specConfig, beaconBlockSchema, blobSidecarSchema, "BlockContentsDeneb"); + specConfig, beaconBlockSchema, blobSidecarOldSchema, "BlockContentsDeneb"); this.signedBlockContentsSchema = SignedBlockContentsSchema.create( specConfig, - signedBlobSidecarSchema, + signedBlobSidecarOldSchema, signedBeaconBlockSchema, "SignedBlockContentsDeneb"); this.blindedBlockContentsSchema = @@ -154,7 +165,8 @@ public SchemaDefinitionsDeneb(final SpecConfigDeneb specConfig) { signedBlindedBlobSidecarSchema, signedBlindedBeaconBlockSchema, "SignedBlindedBlockContentsDeneb"); - this.blobsBundleSchema = new BlobsBundleSchema("BlobsBundleDeneb", blobSchema, specConfig); + this.blobsBundleSchema = + new BlobsBundleSchema("BlobsBundleDeneb", blobSchema, blobKzgCommitmentsSchema, specConfig); this.executionPayloadAndBlobsBundleSchema = new ExecutionPayloadAndBlobsBundleSchema(executionPayloadSchemaDeneb, blobsBundleSchema); this.blobSidecarsByRootRequestMessageSchema = @@ -255,16 +267,24 @@ public BlobSchema getBlobSchema() { return blobSchema; } + public BlobKzgCommitmentsSchema getBlobKzgCommitmentsSchema() { + return blobKzgCommitmentsSchema; + } + public SszListSchema> getBlobsInBlockSchema() { return blobsInBlockSchema; } - public BlobSidecarSchemaOld getBlobSidecarSchema() { + public BlobSidecarSchema getBlobSidecarSchema() { return blobSidecarSchema; } - public SignedBlobSidecarSchemaOld getSignedBlobSidecarSchema() { - return signedBlobSidecarSchema; + public BlobSidecarSchemaOld getBlobSidecarOldSchema() { + return blobSidecarOldSchema; + } + + public SignedBlobSidecarSchemaOld getSignedBlobSidecarOldSchema() { + return signedBlobSidecarOldSchema; } public BlindedBlobSidecarSchema getBlindedBlobSidecarSchema() { @@ -295,10 +315,6 @@ public BlobsBundleSchema getBlobsBundleSchema() { return blobsBundleSchema; } - public BlindedBlobsBundleSchema getBlindedBlobsBundleSchema() { - return blindedBlobsBundleSchema; - } - public ExecutionPayloadAndBlobsBundleSchema getExecutionPayloadAndBlobsBundleSchema() { return executionPayloadAndBlobsBundleSchema; } diff --git a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/deneb.yaml b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/deneb.yaml index 0714c4967e0..8dfd353076c 100644 --- a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/deneb.yaml +++ b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/deneb.yaml @@ -7,4 +7,6 @@ FIELD_ELEMENTS_PER_BLOB: 4096 # `uint64(2**12)` (= 4096) MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096 # `uint64(6)` -MAX_BLOBS_PER_BLOCK: 6 \ No newline at end of file +MAX_BLOBS_PER_BLOCK: 6 +# `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 12 = 17 +KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 17 \ No newline at end of file diff --git a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/deneb.yaml b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/deneb.yaml index 398c30e084e..03d2cd3bc05 100644 --- a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/deneb.yaml +++ b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/deneb.yaml @@ -7,4 +7,6 @@ FIELD_ELEMENTS_PER_BLOB: 4096 # [customized] MAX_BLOB_COMMITMENTS_PER_BLOCK: 16 # `uint64(6)` -MAX_BLOBS_PER_BLOCK: 6 \ No newline at end of file +MAX_BLOBS_PER_BLOCK: 6 +# [customized] `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9 +KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 9 \ No newline at end of file diff --git a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/deneb.yaml b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/deneb.yaml index 398c30e084e..03d2cd3bc05 100644 --- a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/deneb.yaml +++ b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/deneb.yaml @@ -7,4 +7,6 @@ FIELD_ELEMENTS_PER_BLOB: 4096 # [customized] MAX_BLOB_COMMITMENTS_PER_BLOCK: 16 # `uint64(6)` -MAX_BLOBS_PER_BLOCK: 6 \ No newline at end of file +MAX_BLOBS_PER_BLOCK: 6 +# [customized] `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9 +KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 9 \ No newline at end of file diff --git a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundlePropertyTest.java b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarOldPropertyTest.java similarity index 65% rename from ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundlePropertyTest.java rename to ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarOldPropertyTest.java index 1832156d8b8..b46a1e79c5e 100644 --- a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/builder/BlindedBlobsBundlePropertyTest.java +++ b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarOldPropertyTest.java @@ -11,7 +11,7 @@ * specific language governing permissions and limitations under the License. */ -package tech.pegasys.teku.spec.datastructures.builder; +package tech.pegasys.teku.spec.datastructures.blobs.versions.deneb; import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertDeserializeMutatedThrowsExpected; import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertRoundTrip; @@ -19,22 +19,20 @@ import com.fasterxml.jackson.core.JsonProcessingException; import net.jqwik.api.ForAll; import net.jqwik.api.Property; -import tech.pegasys.teku.spec.propertytest.suppliers.builder.BlindedBlobsBundleSupplier; +import tech.pegasys.teku.spec.propertytest.suppliers.blobs.versions.deneb.BlobSidecarOldSupplier; + +public class BlobSidecarOldPropertyTest { -public class BlindedBlobsBundlePropertyTest { @Property - void roundTrip( - @ForAll(supplier = BlindedBlobsBundleSupplier.class) - final BlindedBlobsBundle blindedBlobsBundle) + void roundTrip(@ForAll(supplier = BlobSidecarOldSupplier.class) final BlobSidecarOld blobSidecar) throws JsonProcessingException { - assertRoundTrip(blindedBlobsBundle); + assertRoundTrip(blobSidecar); } @Property void deserializeMutated( - @ForAll(supplier = BlindedBlobsBundleSupplier.class) - final BlindedBlobsBundle blindedBlobsBundle, + @ForAll(supplier = BlobSidecarOldSupplier.class) final BlobSidecarOld blobSidecar, @ForAll final int seed) { - assertDeserializeMutatedThrowsExpected(blindedBlobsBundle, seed); + assertDeserializeMutatedThrowsExpected(blobSidecar, seed); } } diff --git a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarPropertyTest.java b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarPropertyTest.java index 2378ab35c9a..305caacc241 100644 --- a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarPropertyTest.java +++ b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/BlobSidecarPropertyTest.java @@ -24,14 +24,14 @@ public class BlobSidecarPropertyTest { @Property - void roundTrip(@ForAll(supplier = BlobSidecarSupplier.class) final BlobSidecarOld blobSidecar) + void roundTrip(@ForAll(supplier = BlobSidecarSupplier.class) final BlobSidecar blobSidecar) throws JsonProcessingException { assertRoundTrip(blobSidecar); } @Property void deserializeMutated( - @ForAll(supplier = BlobSidecarSupplier.class) final BlobSidecarOld blobSidecar, + @ForAll(supplier = BlobSidecarSupplier.class) final BlobSidecar blobSidecar, @ForAll final int seed) { assertDeserializeMutatedThrowsExpected(blobSidecar, seed); } diff --git a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarPropertyTest.java b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarOldPropertyTest.java similarity index 87% rename from ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarPropertyTest.java rename to ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarOldPropertyTest.java index 53e485d0580..31a2ef4a549 100644 --- a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarPropertyTest.java +++ b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/datastructures/blobs/versions/deneb/SignedBlobSidecarOldPropertyTest.java @@ -19,13 +19,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; import net.jqwik.api.ForAll; import net.jqwik.api.Property; -import tech.pegasys.teku.spec.propertytest.suppliers.blobs.versions.deneb.SignedBlobSidecarSupplier; +import tech.pegasys.teku.spec.propertytest.suppliers.blobs.versions.deneb.SignedBlobSidecarOldSupplier; -public class SignedBlobSidecarPropertyTest { +public class SignedBlobSidecarOldPropertyTest { @Property void roundTrip( - @ForAll(supplier = SignedBlobSidecarSupplier.class) + @ForAll(supplier = SignedBlobSidecarOldSupplier.class) final SignedBlobSidecarOld signedBlobSidecar) throws JsonProcessingException { assertRoundTrip(signedBlobSidecar); @@ -33,7 +33,7 @@ void roundTrip( @Property void deserializeMutated( - @ForAll(supplier = SignedBlobSidecarSupplier.class) + @ForAll(supplier = SignedBlobSidecarOldSupplier.class) final SignedBlobSidecarOld signedBlobSidecar, @ForAll final int seed) { assertDeserializeMutatedThrowsExpected(signedBlobSidecar, seed); diff --git a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebPropertyTest.java b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebPropertyTest.java index 79d329eb97d..ac455c1b806 100644 --- a/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebPropertyTest.java +++ b/ethereum/spec/src/property-test/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDenebPropertyTest.java @@ -29,7 +29,7 @@ import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarOld; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; import tech.pegasys.teku.spec.propertytest.suppliers.SpecSupplier; -import tech.pegasys.teku.spec.propertytest.suppliers.blobs.versions.deneb.BlobSidecarSupplier; +import tech.pegasys.teku.spec.propertytest.suppliers.blobs.versions.deneb.BlobSidecarOldSupplier; import tech.pegasys.teku.spec.propertytest.suppliers.blocks.versions.deneb.BeaconBlockSupplier; import tech.pegasys.teku.spec.propertytest.suppliers.type.KZGCommitmentSupplier; @@ -52,7 +52,7 @@ void fuzzKzgCommitmentToVersionedHash( @AddLifecycleHook(KzgResolver.class) @Property(tries = 100) void fuzzVerifyBlobKzgProof( - final KZG kzg, @ForAll(supplier = BlobSidecarSupplier.class) BlobSidecarOld blobSidecar) { + final KZG kzg, @ForAll(supplier = BlobSidecarOldSupplier.class) BlobSidecarOld blobSidecar) { try { miscHelpers.verifyBlobKzgProof(kzg, blobSidecar); } catch (Exception e) { @@ -64,7 +64,8 @@ void fuzzVerifyBlobKzgProof( @Property(tries = 100) void fuzzVerifyBlobKzgProofBatch( final KZG kzg, - @ForAll final List<@From(supplier = BlobSidecarSupplier.class) BlobSidecarOld> blobSidecars) { + @ForAll + final List<@From(supplier = BlobSidecarOldSupplier.class) BlobSidecarOld> blobSidecars) { try { miscHelpers.verifyBlobKzgProofBatch(kzg, blobSidecars); } catch (Exception e) { @@ -74,7 +75,8 @@ void fuzzVerifyBlobKzgProofBatch( @Property(tries = 100) void fuzzValidateBlobSidecarsBatchAgainstBlock( - @ForAll final List<@From(supplier = BlobSidecarSupplier.class) BlobSidecarOld> blobSidecars, + @ForAll + final List<@From(supplier = BlobSidecarOldSupplier.class) BlobSidecarOld> blobSidecars, @ForAll(supplier = BeaconBlockSupplier.class) final BeaconBlock block, @ForAll final List<@From(supplier = KZGCommitmentSupplier.class) KZGCommitment> kzgCommitments) { @@ -87,7 +89,8 @@ void fuzzValidateBlobSidecarsBatchAgainstBlock( @Property(tries = 100) void fuzzVerifyBlobSidecarCompleteness( - @ForAll final List<@From(supplier = BlobSidecarSupplier.class) BlobSidecarOld> blobSidecars, + @ForAll + final List<@From(supplier = BlobSidecarOldSupplier.class) BlobSidecarOld> blobSidecars, @ForAll final List<@From(supplier = KZGCommitmentSupplier.class) KZGCommitment> kzgCommitments) { try { diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java index a837a2d217f..6e73567060c 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigDenebTest.java @@ -93,6 +93,7 @@ private SpecConfigDeneb createRandomDenebConfig( dataStructureUtil.randomPositiveInt(), dataStructureUtil.randomPositiveInt(), dataStructureUtil.randomPositiveInt(), + dataStructureUtil.randomPositiveInt(), Optional.empty()); } } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/BeaconBlockInvariantsTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/BeaconBlockInvariantsTest.java index dbad2c52ef1..6b7d16c44f8 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/BeaconBlockInvariantsTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/BeaconBlockInvariantsTest.java @@ -15,14 +15,17 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.util.Arrays; import java.util.List; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.TestSpecFactory; 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.networks.Eth2Network; import tech.pegasys.teku.spec.util.DataStructureUtil; class BeaconBlockInvariantsTest { @@ -79,6 +82,13 @@ void shouldExtractSlotFromSignedBlindedBlockContents(final UInt64 slot) { .isEqualTo(slot); } + @ParameterizedTest + @MethodSource("blocksFromMilestones") + void shouldExtractSlotFromAllMilestones(final SignedBeaconBlock block) { + assertThat(BeaconBlockInvariants.extractSignedBlockContainerSlot(block.sszSerialize())) + .isEqualTo(block.getSlot()); + } + static List slotNumbers() { return List.of( Arguments.of(UInt64.ZERO), @@ -87,4 +97,13 @@ static List slotNumbers() { Arguments.of(UInt64.valueOf(1234582)), Arguments.of(UInt64.valueOf(42))); } + + static List blocksFromMilestones() { + return Arrays.stream(SpecMilestone.values()) + .map(milestone -> TestSpecFactory.create(milestone, Eth2Network.MINIMAL)) + .map(DataStructureUtil::new) + .map(DataStructureUtil::randomSignedBeaconBlock) + .map(Arguments::of) + .toList(); + } } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodyDenebTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodyDenebTest.java index 8dbe12b98ec..db0c6cc5e6c 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodyDenebTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodyDenebTest.java @@ -51,13 +51,13 @@ void setup() { syncAggregate = dataStructureUtil.randomSyncAggregate(); executionPayload = dataStructureUtil.randomExecutionPayload(); blsToExecutionChanges = dataStructureUtil.randomSignedBlsToExecutionChangesList(); - blobKzgCommitments = dataStructureUtil.randomSszKzgCommitmentList(); + blobKzgCommitments = dataStructureUtil.randomBlobKzgCommitments(); }); } @Test void equalsReturnsFalseWhenBlobKzgCommitmentsIsDifferent() { - blobKzgCommitments = dataStructureUtil.randomSszKzgCommitmentList(); + blobKzgCommitments = dataStructureUtil.randomBlobKzgCommitments(); BeaconBlockBodyAltair testBeaconBlockBody = safeJoin(createBlockBody()); assertNotEquals(defaultBlockBody, testBeaconBlockBody); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/SignedBlobSidecarTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/SignedBlobSidecarTest.java index a94feee1613..fa0756adc02 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/SignedBlobSidecarTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/SignedBlobSidecarTest.java @@ -33,8 +33,8 @@ public class SignedBlobSidecarTest { final SchemaDefinitions schemaDefinitions = dataStructureUtil.getSpec().getGenesisSchemaDefinitions(); private final SignedBlobSidecarSchemaOld signedBlobSidecarSchema = - schemaDefinitions.toVersionDeneb().orElseThrow().getSignedBlobSidecarSchema(); - private final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + schemaDefinitions.toVersionDeneb().orElseThrow().getSignedBlobSidecarOldSchema(); + private final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); private final BLSSignature signature = dataStructureUtil.randomSignature(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/DeletableSignerTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/DeletableSignerTest.java index 151c2dd7c21..fee8da66755 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/DeletableSignerTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/DeletableSignerTest.java @@ -77,7 +77,7 @@ void signBlock_shouldNotSignWhenDisabled() { void signBlobSidecar_shouldSignWhenActive() { final BeaconBlock block = dataStructureUtilDeneb.randomBeaconBlock(6); final BlobSidecarOld blobSidecar = - dataStructureUtilDeneb.randomBlobSidecar(block.getRoot(), UInt64.valueOf(2)); + dataStructureUtilDeneb.randomBlobSidecarOld(block.getRoot(), UInt64.valueOf(2)); when(delegate.signBlobSidecar(blobSidecar, forkInfo)).thenReturn(signatureFuture); assertThatSafeFuture(signer.signBlobSidecar(blobSidecar, forkInfo)) .isCompletedWithValue(signature); @@ -87,7 +87,7 @@ void signBlobSidecar_shouldSignWhenActive() { void signBlobSidecar_shouldNotSignWhenDisabled() { final BeaconBlock block = dataStructureUtilDeneb.randomBeaconBlock(6); final BlobSidecarOld blobSidecar = - dataStructureUtilDeneb.randomBlobSidecar(block.getRoot(), UInt64.valueOf(2)); + dataStructureUtilDeneb.randomBlobSidecarOld(block.getRoot(), UInt64.valueOf(2)); signer.delete(); assertThatSafeFuture(signer.signBlobSidecar(blobSidecar, forkInfo)) .isCompletedExceptionallyWith(SignerNotActiveException.class); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/SlashingProtectedSignerTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/SlashingProtectedSignerTest.java index bfb7bf4418d..b872fed63e1 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/SlashingProtectedSignerTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/signatures/SlashingProtectedSignerTest.java @@ -79,7 +79,7 @@ void signBlock_shouldNotSignWhenSlashingProtectionRejects() { void signBlobSidecar_shouldAlwaysSign() { final BeaconBlock block = dataStructureUtilDeneb.randomBeaconBlock(6); final BlobSidecarOld blobSidecar = - dataStructureUtilDeneb.randomBlobSidecar(block.getRoot(), UInt64.valueOf(2)); + dataStructureUtilDeneb.randomBlobSidecarOld(block.getRoot(), UInt64.valueOf(2)); when(delegate.signBlobSidecar(blobSidecar, forkInfo)).thenReturn(signatureFuture); assertThatSafeFuture(signer.signBlobSidecar(blobSidecar, forkInfo)) .isCompletedWithValue(signature); diff --git a/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/mainnet/deneb.yaml b/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/mainnet/deneb.yaml index 0714c4967e0..8dfd353076c 100644 --- a/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/mainnet/deneb.yaml +++ b/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/mainnet/deneb.yaml @@ -7,4 +7,6 @@ FIELD_ELEMENTS_PER_BLOB: 4096 # `uint64(2**12)` (= 4096) MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096 # `uint64(6)` -MAX_BLOBS_PER_BLOCK: 6 \ No newline at end of file +MAX_BLOBS_PER_BLOCK: 6 +# `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 12 = 17 +KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 17 \ No newline at end of file diff --git a/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/minimal/deneb.yaml b/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/minimal/deneb.yaml index 398c30e084e..03d2cd3bc05 100644 --- a/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/minimal/deneb.yaml +++ b/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/minimal/deneb.yaml @@ -7,4 +7,6 @@ FIELD_ELEMENTS_PER_BLOB: 4096 # [customized] MAX_BLOB_COMMITMENTS_PER_BLOCK: 16 # `uint64(6)` -MAX_BLOBS_PER_BLOCK: 6 \ No newline at end of file +MAX_BLOBS_PER_BLOCK: 6 +# [customized] `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9 +KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 9 \ No newline at end of file diff --git a/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/swift/deneb.yaml b/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/swift/deneb.yaml index 398c30e084e..03d2cd3bc05 100644 --- a/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/swift/deneb.yaml +++ b/ethereum/spec/src/test/resources/tech/pegasys/teku/spec/config/standard/presets/swift/deneb.yaml @@ -7,4 +7,6 @@ FIELD_ELEMENTS_PER_BLOB: 4096 # [customized] MAX_BLOB_COMMITMENTS_PER_BLOCK: 16 # `uint64(6)` -MAX_BLOBS_PER_BLOCK: 6 \ No newline at end of file +MAX_BLOBS_PER_BLOCK: 6 +# [customized] `floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9 +KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 9 \ No newline at end of file diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/BlockProposalTestUtil.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/BlockProposalTestUtil.java index 9163082aae4..14c05c904b9 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/BlockProposalTestUtil.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/BlockProposalTestUtil.java @@ -129,7 +129,7 @@ public SafeFuture createNewBlock( if (builder.supportsKzgCommitments()) { builder.blobKzgCommitments( SafeFuture.completedFuture( - kzgCommitments.orElseGet(dataStructureUtil::emptySszKzgCommitmentList))); + kzgCommitments.orElseGet(dataStructureUtil::emptyBlobKzgCommitments))); } }, false) @@ -205,7 +205,7 @@ public SafeFuture createNewBlockSkippingStateTransition( if (builder.supportsKzgCommitments()) { builder.blobKzgCommitments( SafeFuture.completedFuture( - kzgCommitments.orElseGet(dataStructureUtil::emptySszKzgCommitmentList))); + kzgCommitments.orElseGet(dataStructureUtil::emptyBlobKzgCommitments))); } }) .thenApply( @@ -354,7 +354,7 @@ public SafeFuture createBlockWithBlobs( final boolean skipStateTransition) throws EpochProcessingException, SlotProcessingException { final UInt64 newEpoch = spec.computeEpochAtSlot(newSlot); - List generatedBlobsKzgCommitments = blobsUtil.blobsToKzgCommitments(blobs); + final List generatedBlobKzgCommitments = blobsUtil.blobsToKzgCommitments(blobs); final SszListSchema blobKZGCommitmentsSchema = ((BeaconBlockBodySchemaDeneb) @@ -362,7 +362,7 @@ public SafeFuture createBlockWithBlobs( .getBlobKzgCommitmentsSchema(); final SszList kzgCommitments = - generatedBlobsKzgCommitments.stream() + generatedBlobKzgCommitments.stream() .map(SszKZGCommitment::new) .collect(blobKZGCommitmentsSchema.collector()); diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/ChainBuilder.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/ChainBuilder.java index 53c62c42c46..f9394d79f95 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/ChainBuilder.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/ChainBuilder.java @@ -662,7 +662,7 @@ private SignedBlockAndState generateBlockWithBlobSidecar( final BlobSidecarSchemaOld blobSidecarSchema = SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions()) - .getBlobSidecarSchema(); + .getBlobSidecarOldSchema(); if (options.isStoreBlobSidecarsEnabled()) { final List blobSidecars = @@ -734,7 +734,7 @@ private SignedBlockAndState generateBlockWithRandomBlobSidecars( final BlobSidecarSchemaOld blobSidecarSchema = SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions()) - .getBlobSidecarSchema(); + .getBlobSidecarOldSchema(); if (options.isStoreBlobSidecarsEnabled()) { final List blobSidecars = diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/execution/versions/deneb/BlobSidecarSupplier.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/BlobSidecarOldSupplier.java similarity index 76% rename from ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/execution/versions/deneb/BlobSidecarSupplier.java rename to ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/BlobSidecarOldSupplier.java index 2d7c6b8a1b5..b3fcff20411 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/execution/versions/deneb/BlobSidecarSupplier.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/BlobSidecarOldSupplier.java @@ -11,16 +11,16 @@ * specific language governing permissions and limitations under the License. */ -package tech.pegasys.teku.spec.propertytest.suppliers.execution.versions.deneb; +package tech.pegasys.teku.spec.propertytest.suppliers.blobs.versions.deneb; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarOld; import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; import tech.pegasys.teku.spec.util.DataStructureUtil; -public class BlobSidecarSupplier extends DataStructureUtilSupplier { +public class BlobSidecarOldSupplier extends DataStructureUtilSupplier { - public BlobSidecarSupplier() { - super(DataStructureUtil::randomBlobSidecar, SpecMilestone.DENEB); + public BlobSidecarOldSupplier() { + super(DataStructureUtil::randomBlobSidecarOld, SpecMilestone.DENEB); } } diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/BlobSidecarSupplier.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/BlobSidecarSupplier.java index ceb183a1bd2..be5324d516a 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/BlobSidecarSupplier.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/BlobSidecarSupplier.java @@ -14,11 +14,11 @@ package tech.pegasys.teku.spec.propertytest.suppliers.blobs.versions.deneb; import tech.pegasys.teku.spec.SpecMilestone; -import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarOld; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; import tech.pegasys.teku.spec.util.DataStructureUtil; -public class BlobSidecarSupplier extends DataStructureUtilSupplier { +public class BlobSidecarSupplier extends DataStructureUtilSupplier { public BlobSidecarSupplier() { super(DataStructureUtil::randomBlobSidecar, SpecMilestone.DENEB); diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/SignedBlobSidecarSupplier.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/SignedBlobSidecarOldSupplier.java similarity index 87% rename from ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/SignedBlobSidecarSupplier.java rename to ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/SignedBlobSidecarOldSupplier.java index aafc85a85d7..25b9b197f93 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/SignedBlobSidecarSupplier.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/blobs/versions/deneb/SignedBlobSidecarOldSupplier.java @@ -18,9 +18,9 @@ import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; import tech.pegasys.teku.spec.util.DataStructureUtil; -public class SignedBlobSidecarSupplier extends DataStructureUtilSupplier { +public class SignedBlobSidecarOldSupplier extends DataStructureUtilSupplier { - public SignedBlobSidecarSupplier() { + public SignedBlobSidecarOldSupplier() { super(DataStructureUtil::randomSignedBlobSidecar, SpecMilestone.DENEB); } } diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/builder/BlindedBlobsBundleSupplier.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/builder/BlindedBlobsBundleSupplier.java deleted file mode 100644 index eea8fe5a74b..00000000000 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/propertytest/suppliers/builder/BlindedBlobsBundleSupplier.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.propertytest.suppliers.builder; - -import tech.pegasys.teku.spec.SpecMilestone; -import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundle; -import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; -import tech.pegasys.teku.spec.util.DataStructureUtil; - -public class BlindedBlobsBundleSupplier extends DataStructureUtilSupplier { - public BlindedBlobsBundleSupplier() { - super(DataStructureUtil::randomBlindedBlobsBundle, SpecMilestone.DENEB); - } -} 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 534cf59d22c..91c5cd9c9c0 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 @@ -88,8 +88,11 @@ 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.Blob; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarOld; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchema; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchemaOld; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.SignedBlindedBlobSidecar; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.SignedBlindedBlobSidecarSchema; @@ -109,13 +112,10 @@ import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.deneb.BeaconBlockBodyDeneb; -import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.deneb.BeaconBlockBodySchemaDeneb; 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.builder.BlindedBlobsBundle; -import tech.pegasys.teku.spec.datastructures.builder.BlindedBlobsBundleSchema; import tech.pegasys.teku.spec.datastructures.builder.BlobsBundleSchema; import tech.pegasys.teku.spec.datastructures.builder.BuilderBid; import tech.pegasys.teku.spec.datastructures.builder.ExecutionPayloadAndBlobsBundle; @@ -617,7 +617,7 @@ public BuilderBid randomBuilderBid(final BLSPublicKey builderPublicKey, final UI .publicKey(builderPublicKey); schemaDefinitions .toVersionDeneb() - .ifPresent(__ -> builder.blobKzgCommitments(randomSszKzgCommitmentList())); + .ifPresent(__ -> builder.blobKzgCommitments(randomBlobKzgCommitments())); }); } @@ -634,7 +634,7 @@ public BuilderBid randomBuilderBid(final Bytes32 withdrawalsRoot) { .publicKey(randomPublicKey()); schemaDefinitions .toVersionDeneb() - .ifPresent(__ -> builder.blobKzgCommitments(randomSszKzgCommitmentList())); + .ifPresent(__ -> builder.blobKzgCommitments(randomBlobKzgCommitments())); }); } @@ -1220,8 +1220,7 @@ public BeaconBlockBody randomBlindedBeaconBlockBody(UInt64 slotNum) { builder.blsToExecutionChanges(randomSignedBlsToExecutionChangesList()); } if (builder.supportsKzgCommitments()) { - builder.blobKzgCommitments( - SafeFuture.completedFuture(randomSszKzgCommitmentList())); + builder.blobKzgCommitments(SafeFuture.completedFuture(randomBlobKzgCommitments())); } }) .join(); @@ -1262,8 +1261,7 @@ public BeaconBlockBody randomBeaconBlockBody(final UInt64 slotNum) { builder.blsToExecutionChanges(randomSignedBlsToExecutionChangesList()); } if (builder.supportsKzgCommitments()) { - builder.blobKzgCommitments( - SafeFuture.completedFuture(randomSszKzgCommitmentList())); + builder.blobKzgCommitments(SafeFuture.completedFuture(randomBlobKzgCommitments())); } }) .join(); @@ -1302,8 +1300,7 @@ public BeaconBlockBody randomBeaconBlockBody() { builder.blsToExecutionChanges(randomSignedBlsToExecutionChangesList()); } if (builder.supportsKzgCommitments()) { - builder.blobKzgCommitments( - SafeFuture.completedFuture(randomSszKzgCommitmentList())); + builder.blobKzgCommitments(SafeFuture.completedFuture(randomBlobKzgCommitments())); } }) .join(); @@ -1353,8 +1350,7 @@ public BeaconBlockBody randomBeaconBlockBody( builder.blsToExecutionChanges(randomSignedBlsToExecutionChangesList()); } if (builder.supportsKzgCommitments()) { - builder.blobKzgCommitments( - SafeFuture.completedFuture(randomSszKzgCommitmentList())); + builder.blobKzgCommitments(SafeFuture.completedFuture(randomBlobKzgCommitments())); } }) .join(); @@ -1387,8 +1383,7 @@ public BeaconBlockBody randomBeaconBlockBodyWithEmptyCommitments() { .syncAggregate(this.randomSyncAggregateIfRequiredBySchema(schema)) .executionPayload(SafeFuture.completedFuture(randomExecutionPayload())) .blsToExecutionChanges(this.randomSignedBlsToExecutionChangesList()) - .blobKzgCommitments( - SafeFuture.completedFuture(this.emptySszKzgCommitmentList()))) + .blobKzgCommitments(SafeFuture.completedFuture(this.emptyBlobKzgCommitments()))) .join(); } @@ -1420,7 +1415,7 @@ public BeaconBlockBody randomBeaconBlockBodyWithCommitments(final int count) { .executionPayload(SafeFuture.completedFuture(randomExecutionPayload())) .blsToExecutionChanges(this.randomSignedBlsToExecutionChangesList()) .blobKzgCommitments( - SafeFuture.completedFuture(randomSszKzgCommitmentList(count)))) + SafeFuture.completedFuture(randomBlobKzgCommitments(count)))) .join(); } @@ -1458,8 +1453,7 @@ public BeaconBlockBody randomFullBeaconBlockBody() { builder.blsToExecutionChanges(randomSignedBlsToExecutionChangesList()); } if (builder.supportsKzgCommitments()) { - builder.blobKzgCommitments( - SafeFuture.completedFuture(randomSszKzgCommitmentList())); + builder.blobKzgCommitments(SafeFuture.completedFuture(randomBlobKzgCommitments())); } }) .join(); @@ -2140,7 +2134,8 @@ public List randomBlobSidecarsForBlock(final SignedBeaconBlock b public List randomBlobSidecarsForBlock( final SignedBeaconBlock block, - final BiFunction modifier) { + final BiFunction + modifier) { return randomSignedBlobSidecarsForBlock(block, modifier).stream() .map(SignedBlobSidecarOld::getBlobSidecar) .collect(toList()); @@ -2148,7 +2143,8 @@ public List randomBlobSidecarsForBlock( public List randomSignedBlobSidecarsForBlock( final SignedBeaconBlock block, - final BiFunction modifier) { + final BiFunction + modifier) { final SszList blobKzgCommitments = BeaconBlockBodyDeneb.required(block.getBeaconBlock().orElseThrow().getBody()) .getBlobKzgCommitments(); @@ -2156,7 +2152,7 @@ public List randomSignedBlobSidecarsForBlock( return IntStream.range(0, blobKzgCommitments.size()) .mapToObj( index -> { - final RandomBlobSidecarBuilder builder = + final RandomBlobSidecarOldBuilder builder = createRandomBlobSidecarBuilder() .slot(block.getSlot()) .blockRoot(block.getRoot()) @@ -2170,12 +2166,16 @@ public List randomSignedBlobSidecarsForBlock( .collect(toList()); } - public BlobSidecarOld randomBlobSidecar() { + public BlobSidecar randomBlobSidecar() { return new RandomBlobSidecarBuilder().build(); } - public BlobSidecarOld randomBlobSidecar(final BlobIdentifier blobIdentifier) { - return new RandomBlobSidecarBuilder() + public BlobSidecarOld randomBlobSidecarOld() { + return new RandomBlobSidecarOldBuilder().build(); + } + + public BlobSidecarOld randomBlobSidecarOld(final BlobIdentifier blobIdentifier) { + return new RandomBlobSidecarOldBuilder() .index(blobIdentifier.getIndex()) .blockRoot(blobIdentifier.getBlockRoot()) .build(); @@ -2184,22 +2184,22 @@ public BlobSidecarOld randomBlobSidecar(final BlobIdentifier blobIdentifier) { public List randomBlobSidecars(int count) { List blobSidecars = new ArrayList<>(); for (int i = 0; i < count; i++) { - blobSidecars.add(new RandomBlobSidecarBuilder().build()); + blobSidecars.add(new RandomBlobSidecarOldBuilder().build()); } return blobSidecars; } - public BlobSidecarOld randomBlobSidecar( + public BlobSidecarOld randomBlobSidecarOld( final UInt64 slot, final Bytes32 blockRoot, final UInt64 index) { - return new RandomBlobSidecarBuilder().slot(slot).index(index).blockRoot(blockRoot).build(); + return new RandomBlobSidecarOldBuilder().slot(slot).index(index).blockRoot(blockRoot).build(); } - public BlobSidecarOld randomBlobSidecar( + public BlobSidecarOld randomBlobSidecarOld( final UInt64 slot, final Bytes32 blockRoot, final Bytes32 parentBlockRoot, final UInt64 index) { - return new RandomBlobSidecarBuilder() + return new RandomBlobSidecarOldBuilder() .slot(slot) .index(index) .blockRoot(blockRoot) @@ -2207,8 +2207,8 @@ public BlobSidecarOld randomBlobSidecar( .build(); } - public BlobSidecarOld randomBlobSidecar(final Bytes32 blockRoot, final UInt64 index) { - return new RandomBlobSidecarBuilder().index(index).blockRoot(blockRoot).build(); + public BlobSidecarOld randomBlobSidecarOld(final Bytes32 blockRoot, final UInt64 index) { + return new RandomBlobSidecarOldBuilder().index(index).blockRoot(blockRoot).build(); } public BlobIdentifier randomBlobIdentifier() { @@ -2240,22 +2240,6 @@ public tech.pegasys.teku.spec.datastructures.builder.BlobsBundle randomBuilderBl randomSszList(schema.getBlobsSchema(), this::randomBlob, numberOfBlobs)); } - public BlindedBlobsBundle randomBlindedBlobsBundle(final int count) { - final UInt64 slot = randomSlot(); - final SchemaDefinitionsDeneb schemaDefinitions = getDenebSchemaDefinitions(slot); - final BlindedBlobsBundleSchema schema = schemaDefinitions.getBlindedBlobsBundleSchema(); - - return new BlindedBlobsBundle( - schema, - randomSszList(schema.getCommitmentsSchema(), this::randomSszKZGCommitment, count), - randomSszList(schema.getProofsSchema(), this::randomSszKZGProof, count), - randomSszList(schema.getBlobRootsSchema(), count, this::randomSszBytes32)); - } - - public BlindedBlobsBundle randomBlindedBlobsBundle() { - return randomBlindedBlobsBundle(randomNumberOfBlobCommitmentsPerBlock()); - } - public BlobsBundle randomBlobsBundle() { return randomBlobsBundle(Optional.empty(), randomSlot()); } @@ -2267,8 +2251,9 @@ public BlobsBundle randomBlobsBundle(final int count) { private BlobsBundle randomBlobsBundle(final Optional count, final UInt64 slot) { final BlobSchema blobSchema = getDenebSchemaDefinitions(slot).getBlobSchema(); final List commitments = - (count.isPresent() ? randomSszKzgCommitmentList(count.get()) : randomSszKzgCommitmentList()) - .stream().map(SszKZGCommitment::getKZGCommitment).collect(toList()); + count.map(this::randomBlobKzgCommitments).orElse(randomBlobKzgCommitments()).stream() + .map(SszKZGCommitment::getKZGCommitment) + .toList(); final List proofs = IntStream.range(0, commitments.size()).mapToObj(__ -> randomKZGProof()).collect(toList()); return new BlobsBundle( @@ -2280,21 +2265,21 @@ private BlobsBundle randomBlobsBundle(final Optional count, final UInt6 } public SignedBlobSidecarOld randomSignedBlobSidecar() { - return new RandomBlobSidecarBuilder().buildSigned(); + return new RandomBlobSidecarOldBuilder().buildSigned(); } public BlindedBlobSidecar randomBlindedBlobSidecar() { - return new RandomBlobSidecarBuilder().buildBlinded(); + return new RandomBlobSidecarOldBuilder().buildBlinded(); } public SignedBlindedBlobSidecar randomSignedBlindedBlobSidecar() { - return new RandomBlobSidecarBuilder().buildSignedBlinded(); + return new RandomBlobSidecarOldBuilder().buildSignedBlinded(); } public List randomBlindedBlobSidecars(final int count) { final List blindedBlobSidecars = new ArrayList<>(); for (int i = 0; i < count; i++) { - blindedBlobSidecars.add(new RandomBlobSidecarBuilder().buildBlinded()); + blindedBlobSidecars.add(new RandomBlobSidecarOldBuilder().buildBlinded()); } return blindedBlobSidecars; } @@ -2302,7 +2287,7 @@ public List randomBlindedBlobSidecars(final int count) { public List randomSignedBlobSidecars(final int count) { final List signedBlobSidecars = new ArrayList<>(); for (int i = 0; i < count; i++) { - signedBlobSidecars.add(new RandomBlobSidecarBuilder().buildSigned()); + signedBlobSidecars.add(new RandomBlobSidecarOldBuilder().buildSigned()); } return signedBlobSidecars; } @@ -2312,7 +2297,7 @@ public List randomSignedBlindedBlobSidecars( final List signedBlindedBlobSidecars = new ArrayList<>(); for (int i = 0; i < blobsBundle.getNumberOfBlobs(); i++) { signedBlindedBlobSidecars.add( - new RandomBlobSidecarBuilder() + new RandomBlobSidecarOldBuilder() .index(UInt64.valueOf(i)) .blob(blobsBundle.getBlobs().get(i).getBytes()) .kzgCommitment(blobsBundle.getCommitments().get(i).getBytesCompressed()) @@ -2325,7 +2310,7 @@ public List randomSignedBlindedBlobSidecars( public List randomSignedBlindedBlobSidecars(final int count) { final List signedBlindedBlobSidecars = new ArrayList<>(); for (int i = 0; i < count; i++) { - signedBlindedBlobSidecars.add(new RandomBlobSidecarBuilder().buildSignedBlinded()); + signedBlindedBlobSidecars.add(new RandomBlobSidecarOldBuilder().buildSignedBlinded()); } return signedBlindedBlobSidecars; } @@ -2392,11 +2377,11 @@ public SignedBlindedBlockContents randomSignedBlindedBlockContents(final UInt64 } public SignedBlobSidecarOld randomSignedBlobSidecar(final UInt64 index) { - return new RandomBlobSidecarBuilder().index(index).buildSigned(); + return new RandomBlobSidecarOldBuilder().index(index).buildSigned(); } - public RandomBlobSidecarBuilder createRandomBlobSidecarBuilder() { - return new RandomBlobSidecarBuilder(); + public RandomBlobSidecarOldBuilder createRandomBlobSidecarBuilder() { + return new RandomBlobSidecarOldBuilder(); } public SszList randomProposerSlashings( @@ -2422,7 +2407,7 @@ public SszList randomAttestations(final int count, final UInt64 slo count); } - public class RandomBlobSidecarBuilder { + public class RandomBlobSidecarOldBuilder { private Optional blockRoot = Optional.empty(); private Optional index = Optional.empty(); private Optional slot = Optional.empty(); @@ -2432,47 +2417,47 @@ public class RandomBlobSidecarBuilder { private Optional kzgCommitment = Optional.empty(); private Optional kzgProof = Optional.empty(); - public RandomBlobSidecarBuilder blockRoot(final Bytes32 blockRoot) { + public RandomBlobSidecarOldBuilder blockRoot(final Bytes32 blockRoot) { this.blockRoot = Optional.of(blockRoot); return this; } - public RandomBlobSidecarBuilder index(final UInt64 index) { + public RandomBlobSidecarOldBuilder index(final UInt64 index) { this.index = Optional.of(index); return this; } - public RandomBlobSidecarBuilder slot(final UInt64 slot) { + public RandomBlobSidecarOldBuilder slot(final UInt64 slot) { this.slot = Optional.of(slot); return this; } - public RandomBlobSidecarBuilder blockParentRoot(final Bytes32 blockParentRoot) { + public RandomBlobSidecarOldBuilder blockParentRoot(final Bytes32 blockParentRoot) { this.blockParentRoot = Optional.of(blockParentRoot); return this; } - public RandomBlobSidecarBuilder proposerIndex(final UInt64 proposerIndex) { + public RandomBlobSidecarOldBuilder proposerIndex(final UInt64 proposerIndex) { this.proposerIndex = Optional.of(proposerIndex); return this; } - public RandomBlobSidecarBuilder blob(final Bytes blob) { + public RandomBlobSidecarOldBuilder blob(final Bytes blob) { this.blob = Optional.of(blob); return this; } - public RandomBlobSidecarBuilder kzgCommitment(final Bytes48 kzgCommitment) { + public RandomBlobSidecarOldBuilder kzgCommitment(final Bytes48 kzgCommitment) { this.kzgCommitment = Optional.of(kzgCommitment); return this; } - public RandomBlobSidecarBuilder kzgProof(final Bytes48 kzgProof) { + public RandomBlobSidecarOldBuilder kzgProof(final Bytes48 kzgProof) { this.kzgProof = Optional.of(kzgProof); return this; } - public RandomBlobSidecarBuilder forBlock(final BeaconBlock block) { + public RandomBlobSidecarOldBuilder forBlock(final BeaconBlock block) { this.slot = Optional.of(block.getSlot()); this.blockRoot = Optional.of(block.getRoot()); this.blockParentRoot = Optional.of(block.getParentRoot()); @@ -2482,7 +2467,7 @@ public RandomBlobSidecarBuilder forBlock(final BeaconBlock block) { public BlobSidecarOld build() { final BlobSidecarSchemaOld blobSidecarSchema = - getDenebSchemaDefinitions(slot.orElse(randomUInt64())).getBlobSidecarSchema(); + getDenebSchemaDefinitions(slot.orElse(randomUInt64())).getBlobSidecarOldSchema(); return blobSidecarSchema.create( blockRoot.orElse(randomBytes32()), @@ -2498,7 +2483,7 @@ public BlobSidecarOld build() { public SignedBlobSidecarOld buildSigned(final Optional blsSignature) { BlobSidecarOld blobSidecar = build(); final SignedBlobSidecarSchemaOld blobSidecarSchema = - getDenebSchemaDefinitions(slot.orElse(randomUInt64())).getSignedBlobSidecarSchema(); + getDenebSchemaDefinitions(slot.orElse(randomUInt64())).getSignedBlobSidecarOldSchema(); return blobSidecarSchema.create(blobSidecar, blsSignature.orElse(randomSignature())); } @@ -2530,30 +2515,87 @@ public SignedBlindedBlobSidecar buildSignedBlinded() { } } - public SszList randomSszKzgCommitmentList() { - final int count = randomInt(spec.getMaxBlobsPerBlock().orElseThrow()) + 1; - return randomSszKzgCommitmentList(count); + public class RandomBlobSidecarBuilder { + private Optional index = Optional.empty(); + private Optional blob = Optional.empty(); + private Optional kzgCommitment = Optional.empty(); + private Optional kzgProof = Optional.empty(); + private Optional signedBeaconBlockHeader = Optional.empty(); + private Optional> kzgCommitmentInclusionProof = Optional.empty(); + + public RandomBlobSidecarBuilder index(final UInt64 index) { + this.index = Optional.of(index); + return this; + } + + public RandomBlobSidecarBuilder blob(final Bytes blob) { + this.blob = Optional.of(blob); + return this; + } + + public RandomBlobSidecarBuilder kzgCommitment(final Bytes48 kzgCommitment) { + this.kzgCommitment = Optional.of(kzgCommitment); + return this; + } + + public RandomBlobSidecarBuilder kzgProof(final Bytes48 kzgProof) { + this.kzgProof = Optional.of(kzgProof); + return this; + } + + public RandomBlobSidecarBuilder signedBeaconBlockHeader( + final SignedBeaconBlockHeader signedBeaconBlockHeader) { + this.signedBeaconBlockHeader = Optional.of(signedBeaconBlockHeader); + return this; + } + + public RandomBlobSidecarBuilder kzgCommitmentInclusionProof( + final List kzgCommitmentInclusionProof) { + this.kzgCommitmentInclusionProof = Optional.of(kzgCommitmentInclusionProof); + return this; + } + + public BlobSidecar build() { + final BlobSidecarSchema blobSidecarSchema = + getDenebSchemaDefinitions( + signedBeaconBlockHeader + .map(header -> header.getMessage().getSlot()) + .orElse(randomUInt64())) + .getBlobSidecarSchema(); + + return blobSidecarSchema.create( + index.orElse(randomUInt64()), + blob.orElse(randomBytes(blobSidecarSchema.getBlobSchema().getLength())), + kzgCommitment.orElse(randomBytes48()), + kzgProof.orElse(randomBytes48()), + signedBeaconBlockHeader.orElse(randomSignedBeaconBlockHeader()), + kzgCommitmentInclusionProof.orElse( + IntStream.range( + 0, blobSidecarSchema.getKzgCommitmentInclusionProofSchema().getLength()) + .mapToObj(__ -> randomBytes32()) + .toList())); + } + } + + public SszList randomBlobKzgCommitments() { + // use MAX_BLOBS_PER_BLOCK as a limit + return randomBlobKzgCommitments(randomNumberOfBlobsPerBlock()); } - public SszList randomSszKzgCommitmentList(final int count) { - final SszListSchema kzgCommitmentsSchema = - BeaconBlockBodySchemaDeneb.required( - spec.forMilestone(SpecMilestone.DENEB) - .getSchemaDefinitions() - .getBeaconBlockBodySchema()) + public SszList randomBlobKzgCommitments(final int count) { + final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema = + SchemaDefinitionsDeneb.required( + spec.forMilestone(SpecMilestone.DENEB).getSchemaDefinitions()) .getBlobKzgCommitmentsSchema(); - return randomSszList(kzgCommitmentsSchema, count, this::randomSszKZGCommitment); + return randomSszList(blobKzgCommitmentsSchema, count, this::randomSszKZGCommitment); } - public SszList emptySszKzgCommitmentList() { + public SszList emptyBlobKzgCommitments() { return SchemaDefinitionsDeneb.required( spec.forMilestone(SpecMilestone.DENEB).getSchemaDefinitions()) - .getBeaconBlockBodySchema() - .toVersionDeneb() - .orElseThrow() .getBlobKzgCommitmentsSchema() - .createFromElements(List.of()); + .of(); } public RewardAndPenaltyDeltas randomRewardAndPenaltyDeltas(final int validatorCount) { @@ -2574,11 +2616,6 @@ private int randomNumberOfBlobsPerBlock() { return randomInt(1, spec.getMaxBlobsPerBlock().orElseThrow() + 1); } - private int randomNumberOfBlobCommitmentsPerBlock() { - // minimum 1 commitment - return randomInt(1, spec.getMaxBlobCommitmentsPerBlock().orElseThrow() + 1); - } - private int randomInt(final int origin, final int bound) { return new Random(nextSeed()).ints(origin, bound).findFirst().orElse(0); } diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/MappedOperationPool.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/MappedOperationPool.java index 111827f1899..fa2149d31a7 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/MappedOperationPool.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/MappedOperationPool.java @@ -87,7 +87,7 @@ public MappedOperationPool( final int operationPoolSize) { this.slotToSszListSchemaSupplier = slotToSszListSchemaSupplier; - this.operations = LimitedMap.createSynchronized(operationPoolSize); + this.operations = LimitedMap.createSynchronizedLRU(operationPoolSize); this.operationValidator = operationValidator; this.metricType = metricType; metricsSystem.createIntegerGauge( diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/SeenAggregatesCache.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/SeenAggregatesCache.java index c13d21af108..d810e6b5b31 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/SeenAggregatesCache.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/SeenAggregatesCache.java @@ -25,7 +25,7 @@ public class SeenAggregatesCache { private final Map> seenAggregationBitsByDataRoot; public SeenAggregatesCache(final int rootCacheSize) { - this.seenAggregationBitsByDataRoot = LimitedMap.createSynchronized(rootCacheSize); + this.seenAggregationBitsByDataRoot = LimitedMap.createSynchronizedLRU(rootCacheSize); } public boolean add(final KeyT root, final SszBitSet aggregationBits) { 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 b24deebcc19..a1dc86957b2 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 @@ -240,7 +240,7 @@ void add_shouldWorkWhenBlockIsSetFirst() { void add_shouldThrowWhenAddingInconsistentBlobSidecar() { BlockBlobSidecarsTracker blockBlobSidecarsTracker = new BlockBlobSidecarsTracker(dataStructureUtil.randomSlotAndBlockRoot(), maxBlobsPerBlock); - assertThatThrownBy(() -> blockBlobSidecarsTracker.add(dataStructureUtil.randomBlobSidecar())) + assertThatThrownBy(() -> blockBlobSidecarsTracker.add(dataStructureUtil.randomBlobSidecarOld())) .isInstanceOf(IllegalArgumentException.class); } diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java index bd8a05a529e..cb5572e0282 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java @@ -122,7 +122,7 @@ public class BlockManagerTest { private final FutureItems futureBlocks = FutureItems.create(SignedBeaconBlock::getSlot, mock(SettableLabelledGauge.class), "blocks"); private final Map invalidBlockRoots = - LimitedMap.createSynchronized(500); + LimitedMap.createSynchronizedLRU(500); private StorageSystem localChain; private RecentChainData localRecentChainData = mock(RecentChainData.class); diff --git a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/AbstractLimitedMap.java b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/AbstractLimitedMap.java index 5fa068219fd..2403ca7d76e 100644 --- a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/AbstractLimitedMap.java +++ b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/AbstractLimitedMap.java @@ -23,8 +23,8 @@ abstract class AbstractLimitedMap implements LimitedMap { - protected static Map createLimitedMap(final int maxSize) { - return new LinkedHashMap<>(16, 0.75f, true) { + protected static Map createLimitedMap(final int maxSize, final boolean accessOrder) { + return new LinkedHashMap<>(16, 0.75f, accessOrder) { @Override protected boolean removeEldestEntry(final Map.Entry eldest) { return this.size() > maxSize; diff --git a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedMap.java b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedMap.java index b8f8d01c4b8..359c024154f 100644 --- a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedMap.java +++ b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedMap.java @@ -35,7 +35,8 @@ static LimitedMap createNonSynchronized(final int maxSize) { * Creates a limited map. * *

The returned map is safe for concurrent access except iteration and evicts - * the least recently used items. Iteration requires synchronizing on the map instance. + * the least recently accessed items like LRU cache. Iteration requires synchronizing on the map + * instance. * *

Synchronized instances are generally faster than iterable versions. * @@ -44,8 +45,25 @@ static LimitedMap createNonSynchronized(final int maxSize) { * @param The value type of the map. * @return A map that will evict elements when the max size is exceeded. */ - static LimitedMap createSynchronized(final int maxSize) { - return new SynchronizedLimitedMap<>(maxSize); + static LimitedMap createSynchronizedLRU(final int maxSize) { + return new SynchronizedLimitedMap<>(maxSize, true); + } + + /** + * Creates a limited map. + * + *

The returned map is safe for concurrent access except iteration and evicts + * the oldest inserted items. Iteration requires synchronizing on the map instance. + * + *

Synchronized instances are generally faster than iterable versions. + * + * @param maxSize The maximum number of elements to keep in the map. + * @param The key type of the map. + * @param The value type of the map. + * @return A map that will evict elements when the max size is exceeded. + */ + static LimitedMap createSynchronizedNatural(final int maxSize) { + return new SynchronizedLimitedMap<>(maxSize, false); } /** diff --git a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedSet.java b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedSet.java index 6c008e18902..1a910f19861 100644 --- a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedSet.java +++ b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/LimitedSet.java @@ -34,7 +34,7 @@ private LimitedSet() {} * @return A set that will evict elements when the max size is exceeded. */ public static Set createSynchronized(final int maxSize) { - return Collections.newSetFromMap(LimitedMap.createSynchronized(maxSize)); + return Collections.newSetFromMap(LimitedMap.createSynchronizedLRU(maxSize)); } /** diff --git a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/NonSynchronizedLimitedMap.java b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/NonSynchronizedLimitedMap.java index 7439ea0ba1b..576142d88b3 100644 --- a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/NonSynchronizedLimitedMap.java +++ b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/NonSynchronizedLimitedMap.java @@ -17,7 +17,7 @@ final class NonSynchronizedLimitedMap extends AbstractLimitedMap { public NonSynchronizedLimitedMap(final int maxSize) { - super(createLimitedMap(maxSize), maxSize); + super(createLimitedMap(maxSize, true), maxSize); } @Override diff --git a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/SynchronizedLimitedMap.java b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/SynchronizedLimitedMap.java index d2455a06a79..b0d7ff67e85 100644 --- a/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/SynchronizedLimitedMap.java +++ b/infrastructure/collections/src/main/java/tech/pegasys/teku/infrastructure/collections/SynchronizedLimitedMap.java @@ -17,14 +17,16 @@ /** Helper that creates a thread-safe map with a maximum capacity. */ final class SynchronizedLimitedMap extends AbstractLimitedMap { + final boolean accessOrder; - public SynchronizedLimitedMap(final int maxSize) { - super(Collections.synchronizedMap(createLimitedMap(maxSize)), maxSize); + public SynchronizedLimitedMap(final int maxSize, final boolean accessOrder) { + super(Collections.synchronizedMap(createLimitedMap(maxSize, accessOrder)), maxSize); + this.accessOrder = accessOrder; } @Override public LimitedMap copy() { - SynchronizedLimitedMap map = new SynchronizedLimitedMap<>(getMaxSize()); + SynchronizedLimitedMap map = new SynchronizedLimitedMap<>(getMaxSize(), accessOrder); synchronized (delegate) { map.putAll(delegate); } diff --git a/infrastructure/collections/src/test/java/tech/pegasys/teku/infrastructure/collections/LimitedMapTest.java b/infrastructure/collections/src/test/java/tech/pegasys/teku/infrastructure/collections/LimitedMapTest.java index f838efbd671..2f0392bf645 100644 --- a/infrastructure/collections/src/test/java/tech/pegasys/teku/infrastructure/collections/LimitedMapTest.java +++ b/infrastructure/collections/src/test/java/tech/pegasys/teku/infrastructure/collections/LimitedMapTest.java @@ -21,8 +21,8 @@ public class LimitedMapTest { @Test - public void create_evictLeastRecentlyAccessed() { - final Map map = LimitedMap.createSynchronized(2); + public void createSynchronizedLRU_evictLeastRecentlyAccessed() { + final Map map = LimitedMap.createSynchronizedLRU(2); map.put(1, 1); assertThat(map.size()).isEqualTo(1); map.put(2, 2); @@ -37,4 +37,22 @@ public void create_evictLeastRecentlyAccessed() { assertThat(map.containsKey(3)).isTrue(); assertThat(map.containsKey(1)).isTrue(); } + + @Test + public void createSynchronizedNatural_evictNaturalOrder() { + final Map map = LimitedMap.createSynchronizedNatural(2); + map.put(1, 1); + assertThat(map.size()).isEqualTo(1); + map.put(2, 2); + assertThat(map.size()).isEqualTo(2); + + // Access element 1 then add a new element that will put us over the limit + map.get(1); + + map.put(3, 3); + assertThat(map.size()).isEqualTo(2); + // Element 2 should have been evicted + assertThat(map.containsKey(3)).isTrue(); + assertThat(map.containsKey(2)).isTrue(); + } } diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/BlobSidecarGossipManager.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/BlobSidecarGossipManager.java index b5131619cd6..c98ebc85e88 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/BlobSidecarGossipManager.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/BlobSidecarGossipManager.java @@ -58,7 +58,7 @@ public static BlobSidecarGossipManager create( final SpecVersion forkSpecVersion = spec.atEpoch(forkInfo.getFork().getEpoch()); final SignedBlobSidecarSchemaOld gossipType = SchemaDefinitionsDeneb.required(forkSpecVersion.getSchemaDefinitions()) - .getSignedBlobSidecarSchema(); + .getSignedBlobSidecarOldSchema(); final Int2ObjectMap> subnetIdToTopicHandler = new Int2ObjectOpenHashMap<>(); final SpecConfigDeneb specConfigDeneb = SpecConfigDeneb.required(forkSpecVersion.getConfig()); diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/core/encodings/context/ForkDigestPayloadContext.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/core/encodings/context/ForkDigestPayloadContext.java index 52fae684393..1d7c723b387 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/core/encodings/context/ForkDigestPayloadContext.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/core/encodings/context/ForkDigestPayloadContext.java @@ -46,7 +46,7 @@ public UInt64 getSlotFromPayload(final BlobSidecarOld responsePayload) { @Override public SszSchema getSchemaFromSchemaDefinitions( final SchemaDefinitions schemaDefinitions) { - return schemaDefinitions.toVersionDeneb().orElseThrow().getBlobSidecarSchema(); + return schemaDefinitions.toVersionDeneb().orElseThrow().getBlobSidecarOldSchema(); } }; diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java index 6d5d5a1343c..aff26194326 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java @@ -61,7 +61,7 @@ void blobSidecarFailsKzgVerification() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final SafeFuture result = listenerWrapper.onResponse(blobSidecar1); assertThat(result).isCompletedExceptionally(); @@ -83,7 +83,7 @@ void blobSidecarSlotSmallerThanFromSlot() { spec, peer, listener, maxBlobsPerBlock, kzg, startSlot, count); final BlobSidecarOld blobSidecar0 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ZERO, dataStructureUtil.randomBytes32(), UInt64.ZERO); final SafeFuture result = listenerWrapper.onResponse(blobSidecar0); @@ -107,18 +107,21 @@ void blobSidecarsSlotsAreCorrect() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar10 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final BlobSidecarOld blobSidecar11 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); final Bytes32 blockRoot2 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ZERO); final Bytes32 blockRoot3 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar3 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(3), blockRoot3, blockRoot2, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(3), blockRoot3, blockRoot2, UInt64.ZERO); final Bytes32 blockRoot4 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar4 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(4), blockRoot4, blockRoot3, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(4), blockRoot4, blockRoot3, UInt64.ZERO); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar10).join()); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar11).join()); @@ -138,19 +141,23 @@ void blobSidecarSlotGreaterThanToSlot() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final Bytes32 blockRoot2 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(3), blockRoot2, blockRoot1, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(3), blockRoot2, blockRoot1, UInt64.ZERO); final Bytes32 blockRoot3 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar3 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(5), blockRoot3, blockRoot2, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(5), blockRoot3, blockRoot2, UInt64.ZERO); final Bytes32 blockRoot4 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar4 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(8), blockRoot4, blockRoot3, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(8), blockRoot4, blockRoot3, UInt64.ZERO); final Bytes32 blockRoot5 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar5 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(9), blockRoot5, blockRoot4, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(9), blockRoot5, blockRoot4, UInt64.ZERO); listenerWrapper.onResponse(blobSidecar1).join(); listenerWrapper.onResponse(blobSidecar2).join(); @@ -178,10 +185,10 @@ void blobSidecarParentRootDoesNotMatch() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final Bytes32 blockRoot2 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(2), blockRoot2, dataStructureUtil.randomBytes32(), UInt64.ZERO); listenerWrapper.onResponse(blobSidecar1).join(); @@ -208,23 +215,23 @@ void blobSidecarIndexIsGreaterOrEqualThanMaxBlobs() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); final BlobSidecarOld blobSidecar3 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.valueOf(2)); final BlobSidecarOld blobSidecar4 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.valueOf(3)); final BlobSidecarOld blobSidecar5 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.valueOf(4)); final BlobSidecarOld blobSidecar6 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.valueOf(5)); final BlobSidecarOld blobSidecar7 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.valueOf(6)); listenerWrapper.onResponse(blobSidecar1).join(); @@ -256,11 +263,11 @@ void blobSidecarIndexIsInTheSameBlockButNotNext() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); final BlobSidecarOld blobSidecar3 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.valueOf(3)); listenerWrapper.onResponse(blobSidecar1).join(); @@ -287,7 +294,7 @@ void firstBlobSidecarIndexIsINotZero() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, UInt64.ONE); final SafeFuture result = listenerWrapper.onResponse(blobSidecar1); assertThat(result).isCompletedExceptionally(); @@ -310,10 +317,11 @@ void firstBlobSidecarIndexInNextBlockIsNotZero() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final Bytes32 blockRoot2 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ONE); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar1).join()); @@ -339,11 +347,11 @@ void missedBlobSidecarIndex() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); final BlobSidecarOld blobSidecar4 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.valueOf(3)); listenerWrapper.onResponse(blobSidecar1).join(); @@ -370,10 +378,10 @@ void blobSidecarUnexpectedSlot() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final Bytes32 blockRoot2 = dataStructureUtil.randomBytes32(); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot2, blockRoot1, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot2, blockRoot1, UInt64.ZERO); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar1).join()); diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java index a77e8455d8c..e21ef357dc4 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java @@ -69,15 +69,18 @@ void blobSidecarsAreCorrect() { new BlobSidecarsByRootListenerValidatingProxy(peer, spec, listener, kzg, blobIdentifiers); final BlobSidecarOld blobSidecar10 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final BlobSidecarOld blobSidecar11 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ZERO); final BlobSidecarOld blobSidecar3 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(3), blockRoot3, blockRoot2, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(3), blockRoot3, blockRoot2, UInt64.ZERO); final BlobSidecarOld blobSidecar4 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(4), blockRoot4, blockRoot3, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(4), blockRoot4, blockRoot3, UInt64.ZERO); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar10).join()); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar11).join()); @@ -98,11 +101,12 @@ void blobSidecarIdentifierNotRequested() { new BlobSidecarsByRootListenerValidatingProxy(peer, spec, listener, kzg, blobIdentifiers); final BlobSidecarOld blobSidecar10 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final BlobSidecarOld blobSidecar11 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ONE); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld( + UInt64.valueOf(2), blockRoot2, blockRoot1, UInt64.ZERO); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar10).join()); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar11).join()); @@ -127,7 +131,7 @@ void blobSidecarFailsKzgVerification() { peer, spec, listener, kzg, List.of(blobIdentifier)); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); final SafeFuture result = listenerWrapper.onResponse(blobSidecar1); assertThat(result).isCompletedExceptionally(); diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java index 69751496f38..e8d88d658cb 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootMessageHandlerTest.java @@ -124,7 +124,7 @@ public void setup() { final UInt64 index = i.getArgument(1); return SafeFuture.completedFuture( Optional.of( - dataStructureUtil.randomBlobSidecar(denebFirstSlot, blockRoot, index))); + dataStructureUtil.randomBlobSidecarOld(denebFirstSlot, blockRoot, index))); }); when(callback.respond(any())).thenReturn(SafeFuture.COMPLETE); diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java index 2d3aeb69756..ba70e486ee4 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java @@ -49,7 +49,7 @@ void blobSidecarIsCorrect() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobIdentifier blobIdentifier1 = new BlobIdentifier(blockRoot1, UInt64.ZERO); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); validator = new BlobSidecarsByRootValidator(peer, spec, kzg, List.of(blobIdentifier1)); assertDoesNotThrow(() -> validator.validate(blobSidecar1)); @@ -61,7 +61,7 @@ void blobSidecarIdentifierNotRequested() { final BlobIdentifier blobIdentifier2 = new BlobIdentifier(dataStructureUtil.randomBytes32(), UInt64.ZERO); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); validator = new BlobSidecarsByRootValidator(peer, spec, kzg, List.of(blobIdentifier2)); assertThatThrownBy(() -> validator.validate(blobSidecar1)) @@ -78,7 +78,7 @@ void blobSidecarFailsKzgVerification() { final Bytes32 blockRoot1 = dataStructureUtil.randomBytes32(); final BlobIdentifier blobIdentifier1 = new BlobIdentifier(blockRoot1, UInt64.ZERO); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); + dataStructureUtil.randomBlobSidecarOld(UInt64.ONE, blockRoot1, Bytes32.ZERO, UInt64.ZERO); validator = new BlobSidecarsByRootValidator(peer, spec, kzg, List.of(blobIdentifier1)); assertThatThrownBy(() -> validator.validate(blobSidecar1)) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index d44f65edba6..b10de289305 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -503,7 +503,7 @@ protected void initBlobSidecarManager() { FutureItems.create(SignedBlobSidecarOld::getSlot, futureItemsMetric, "blob_sidecars"); final Map invalidBlobSidecarRoots = - LimitedMap.createSynchronized(500); + LimitedMap.createSynchronizedLRU(500); final BlobSidecarGossipValidator blobSidecarValidator = BlobSidecarGossipValidator.create(spec, invalidBlockRoots, gossipValidationHelper); @@ -544,7 +544,7 @@ protected void initBlockPoolsAndCaches() { LOG.debug("BeaconChainController.initBlockPoolsAndCaches()"); pendingBlocks = poolFactory.createPendingPoolForBlocks(spec); eventChannels.subscribe(FinalizedCheckpointChannel.class, pendingBlocks); - invalidBlockRoots = LimitedMap.createSynchronized(500); + invalidBlockRoots = LimitedMap.createSynchronizedLRU(500); } protected void initBlobSidecarPool() { diff --git a/storage/src/integration-test/java/tech/pegasys/teku/storage/server/kvstore/DatabaseTest.java b/storage/src/integration-test/java/tech/pegasys/teku/storage/server/kvstore/DatabaseTest.java index 3638df69cf5..bfe087ed26d 100644 --- a/storage/src/integration-test/java/tech/pegasys/teku/storage/server/kvstore/DatabaseTest.java +++ b/storage/src/integration-test/java/tech/pegasys/teku/storage/server/kvstore/DatabaseTest.java @@ -204,20 +204,20 @@ public void verifyBlobsLifecycle(final DatabaseContext context) throws IOExcepti assertThat(database.getEarliestBlobSidecarSlot()).contains(ZERO); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(1), dataStructureUtil.randomBytes32(), UInt64.valueOf(0)); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(2), Bytes32.ZERO, UInt64.valueOf(0)); + dataStructureUtil.randomBlobSidecarOld(UInt64.valueOf(2), Bytes32.ZERO, UInt64.valueOf(0)); final BlobSidecarOld blobSidecar2bis = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(2), Bytes32.fromHexString("0x01"), UInt64.valueOf(1)); final BlobSidecarOld blobSidecar3 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(3), dataStructureUtil.randomBytes32(), UInt64.valueOf(0)); final BlobSidecarOld blobSidecar5 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(5), dataStructureUtil.randomBytes32(), UInt64.valueOf(0)); - final BlobSidecarOld blobSidecarNotAdded = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecarNotAdded = dataStructureUtil.randomBlobSidecarOld(); // add blobs out of order database.storeBlobSidecar(blobSidecar2); @@ -345,20 +345,20 @@ public void verifyNonCanonicalBlobsLifecycle(final DatabaseContext context) thro initialize(context); final BlobSidecarOld blobSidecar1 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(1), dataStructureUtil.randomBytes32(), UInt64.valueOf(0)); final BlobSidecarOld blobSidecar2 = - dataStructureUtil.randomBlobSidecar(UInt64.valueOf(2), Bytes32.ZERO, UInt64.valueOf(0)); + dataStructureUtil.randomBlobSidecarOld(UInt64.valueOf(2), Bytes32.ZERO, UInt64.valueOf(0)); final BlobSidecarOld blobSidecar2bis = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(2), Bytes32.fromHexString("0x01"), UInt64.valueOf(1)); final BlobSidecarOld blobSidecar3 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(3), dataStructureUtil.randomBytes32(), UInt64.valueOf(0)); final BlobSidecarOld blobSidecar5 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(5), dataStructureUtil.randomBytes32(), UInt64.valueOf(0)); - final BlobSidecarOld blobSidecarNotAdded = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecarNotAdded = dataStructureUtil.randomBlobSidecarOld(); // add non-canonical blobs out of order database.storeNonCanonicalBlobSidecar(blobSidecar2); @@ -1324,11 +1324,11 @@ public void storeNonCanonicalBlobsTest_multiple(final DatabaseContext context) final ChainBuilder secondFork = primaryChain.fork(); final BlobSidecarOld blobSidecarPrimary2Slot2Index0 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(2), primaryChain.getBlockAtSlot(2).getRoot(), UInt64.valueOf(0)); database.storeBlobSidecar(blobSidecarPrimary2Slot2Index0); final BlobSidecarOld blobSidecarPrimary2Slot2Index1 = - dataStructureUtil.randomBlobSidecar( + dataStructureUtil.randomBlobSidecarOld( UInt64.valueOf(2), primaryChain.getBlockAtSlot(2).getRoot(), UInt64.valueOf(1)); database.storeBlobSidecar(blobSidecarPrimary2Slot2Index1); diff --git a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/KvStoreDatabase.java b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/KvStoreDatabase.java index dd2b9a8e924..ecde8916839 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/KvStoreDatabase.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/KvStoreDatabase.java @@ -42,16 +42,15 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.plugin.services.MetricsSystem; -import tech.pegasys.teku.dataproviders.lookup.BlockProvider; import tech.pegasys.teku.ethereum.pow.api.DepositTreeSnapshot; import tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent; import tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent; -import tech.pegasys.teku.infrastructure.async.SafeFuture; 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.BlobSidecarOld; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader; +import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockInvariants; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary; import tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpoints; import tech.pegasys.teku.spec.datastructures.blocks.BlockCheckpoints; @@ -1135,9 +1134,6 @@ private void updateFinalizedDataArchiveMode( Map finalizedChildToParentMap, final Map finalizedBlocks, final Map finalizedStates) { - final BlockProvider blockProvider = - BlockProvider.withKnownBlocks( - roots -> SafeFuture.completedFuture(getHotBlocks(roots)), finalizedBlocks); final Optional initialCheckpoint = dao.getAnchor(); final Optional initialBlockRoot = initialCheckpoint.map(Checkpoint::getRoot); @@ -1163,12 +1159,8 @@ private void updateFinalizedDataArchiveMode( while (i < finalizedRoots.size() && (i - start) < TX_BATCH_SIZE) { final Bytes32 blockRoot = finalizedRoots.get(i); - final Optional maybeBlock = blockProvider.getBlock(blockRoot).join(); - maybeBlock.ifPresent(block -> addFinalizedBlock(block, updater)); - // If block is missing and doesn't match the initial anchor, throw - if (maybeBlock.isEmpty() && initialBlockRoot.filter(r -> r.equals(blockRoot)).isEmpty()) { - throw new IllegalStateException("Missing finalized block"); - } + final Optional maybeBlockSlot = + addFinalizedBlock(blockRoot, finalizedBlocks, updater, initialBlockRoot); Optional.ofNullable(finalizedStates.get(blockRoot)) .or(() -> getHotState(blockRoot)) @@ -1179,9 +1171,8 @@ private void updateFinalizedDataArchiveMode( }); lastSlot = - maybeBlock - .map(SignedBeaconBlock::getSlot) - .orElseGet(() -> initialCheckpoint.orElseThrow().getEpochStartSlot(spec)); + maybeBlockSlot.orElseGet( + () -> initialCheckpoint.orElseThrow().getEpochStartSlot(spec)); i++; } updater.commit(); @@ -1196,9 +1187,6 @@ private void updateFinalizedDataPruneMode( Map finalizedChildToParentMap, final Map finalizedBlocks) { final Optional initialBlockRoot = dao.getAnchor().map(Checkpoint::getRoot); - final BlockProvider blockProvider = - BlockProvider.withKnownBlocks( - roots -> SafeFuture.completedFuture(getHotBlocks(roots)), finalizedBlocks); final List finalizedRoots = new ArrayList<>(finalizedChildToParentMap.keySet()); int i = 0; @@ -1207,13 +1195,9 @@ private void updateFinalizedDataPruneMode( final int start = i; while (i < finalizedRoots.size() && (i - start) < TX_BATCH_SIZE) { final Bytes32 root = finalizedRoots.get(i); - final Optional maybeBlock = blockProvider.getBlock(root).join(); - maybeBlock.ifPresent(block -> addFinalizedBlock(block, updater)); - // If block is missing and doesn't match the initial anchor, throw - if (maybeBlock.isEmpty() && initialBlockRoot.filter(r -> r.equals(root)).isEmpty()) { - throw new IllegalStateException("Missing finalized block"); - } + addFinalizedBlock(root, finalizedBlocks, updater, initialBlockRoot); + i++; } updater.commit(); @@ -1224,6 +1208,32 @@ private void updateFinalizedDataPruneMode( } } + private Optional addFinalizedBlock( + final Bytes32 blockRoot, + final Map finalizedBlocks, + final FinalizedUpdater updater, + final Optional initialBlockRoot) { + final SignedBeaconBlock block = finalizedBlocks.get(blockRoot); + if (block != null) { + addFinalizedBlock(block, updater); + return Optional.of(block.getSlot()); + } + + final Optional rawBlock = dao.getHotBlockAsSsz(blockRoot); + if (rawBlock.isPresent()) { + final UInt64 slot = BeaconBlockInvariants.extractSignedBlockContainerSlot(rawBlock.get()); + updater.addFinalizedBlockRaw(slot, blockRoot, rawBlock.get()); + return Optional.of(slot); + } + + // If block is missing and doesn't match the initial anchor, throw + if (initialBlockRoot.filter(r -> r.equals(blockRoot)).isEmpty()) { + throw new IllegalStateException("Missing finalized block"); + } + + return Optional.empty(); + } + private BeaconBlockSummary getLatestFinalizedBlockOrSummary() { final Bytes32 baseBlockRoot = dao.getFinalizedCheckpoint().orElseThrow().getRoot(); return getFinalizedBlock(baseBlockRoot) diff --git a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/CombinedKvStoreDao.java b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/CombinedKvStoreDao.java index bec8169dfde..2c8bec0568a 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/CombinedKvStoreDao.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/CombinedKvStoreDao.java @@ -95,6 +95,11 @@ public Optional getHotBlock(final Bytes32 root) { return db.get(schema.getColumnHotBlocksByRoot(), root); } + @Override + public Optional getHotBlockAsSsz(final Bytes32 root) { + return db.getRaw(schema.getColumnHotBlocksByRoot(), root); + } + @Override public Optional getHotBlockCheckpointEpochs(final Bytes32 root) { return db.get(schema.getColumnHotBlockCheckpointEpochsByRoot(), root); @@ -666,6 +671,18 @@ public void addFinalizedBlock(final SignedBeaconBlock block) { transaction.put(schema.getColumnFinalizedBlocksBySlot(), block.getSlot(), block); } + @Override + public void addFinalizedBlockRaw( + final UInt64 slot, final Bytes32 blockRoot, final Bytes blockBytes) { + transaction.put(schema.getColumnSlotsByFinalizedRoot(), blockRoot, slot); + final KvStoreColumn columnFinalizedBlocksBySlot = + schema.getColumnFinalizedBlocksBySlot(); + transaction.putRaw( + columnFinalizedBlocksBySlot, + Bytes.wrap(columnFinalizedBlocksBySlot.getKeySerializer().serialize(slot)), + blockBytes); + } + @Override public void addNonCanonicalBlock(final SignedBeaconBlock block) { transaction.put(schema.getColumnNonCanonicalBlocksByRoot(), block.getRoot(), block); diff --git a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDao.java b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDao.java index 3b4a916383a..a3bd818092c 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDao.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDao.java @@ -52,6 +52,8 @@ public interface KvStoreCombinedDao extends AutoCloseable { Optional getHotBlock(Bytes32 root); + Optional getHotBlockAsSsz(Bytes32 root); + @MustBeClosed Stream streamHotBlocks(); @@ -222,6 +224,8 @@ interface FinalizedUpdater extends AutoCloseable { void addFinalizedBlock(final SignedBeaconBlock block); + void addFinalizedBlockRaw(UInt64 slot, Bytes32 blockRoot, Bytes blockBytes); + void addNonCanonicalBlock(final SignedBeaconBlock block); void deleteFinalizedBlock(final UInt64 slot, final Bytes32 blockRoot); diff --git a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDaoAdapter.java b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDaoAdapter.java index f061a0056eb..a6de62ac0fc 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDaoAdapter.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/KvStoreCombinedDaoAdapter.java @@ -93,6 +93,11 @@ public Optional getHotBlock(final Bytes32 root) { return hotDao.getHotBlock(root); } + @Override + public Optional getHotBlockAsSsz(final Bytes32 root) { + return hotDao.getHotBlockRaw(root); + } + @Override public Optional getHotBlockCheckpointEpochs(final Bytes32 root) { return hotDao.getHotBlockCheckpointEpochs(root); @@ -517,6 +522,12 @@ public void addFinalizedBlock(final SignedBeaconBlock block) { finalizedUpdater.addFinalizedBlock(block); } + @Override + public void addFinalizedBlockRaw( + final UInt64 slot, final Bytes32 blockRoot, final Bytes blockBytes) { + finalizedUpdater.addFinalizedBlockRaw(slot, blockRoot, blockBytes); + } + @Override public void addNonCanonicalBlock(final SignedBeaconBlock block) { finalizedUpdater.addNonCanonicalBlock(block); diff --git a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4FinalizedKvStoreDao.java b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4FinalizedKvStoreDao.java index bc7ac5e2b17..9f877defa07 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4FinalizedKvStoreDao.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4FinalizedKvStoreDao.java @@ -295,6 +295,18 @@ public void addFinalizedBlock(final SignedBeaconBlock block) { transaction.put(schema.getColumnFinalizedBlocksBySlot(), block.getSlot(), block); } + @Override + public void addFinalizedBlockRaw( + final UInt64 slot, final Bytes32 blockRoot, final Bytes blockBytes) { + transaction.put(schema.getColumnSlotsByFinalizedRoot(), blockRoot, slot); + final KvStoreColumn columnFinalizedBlocksBySlot = + schema.getColumnFinalizedBlocksBySlot(); + transaction.putRaw( + columnFinalizedBlocksBySlot, + Bytes.wrap(columnFinalizedBlocksBySlot.getKeySerializer().serialize(slot)), + blockBytes); + } + @Override public void addNonCanonicalBlock(final SignedBeaconBlock block) { transaction.put(schema.getColumnNonCanonicalBlocksByRoot(), block.getRoot(), block); diff --git a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4HotKvStoreDao.java b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4HotKvStoreDao.java index 28aeda16748..eb4d6fed011 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4HotKvStoreDao.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/dataaccess/V4HotKvStoreDao.java @@ -75,6 +75,10 @@ public Optional getHotBlock(final Bytes32 root) { return db.get(schema.getColumnHotBlocksByRoot(), root); } + public Optional getHotBlockRaw(final Bytes32 root) { + return db.getRaw(schema.getColumnHotBlocksByRoot(), root); + } + public Optional getHotBlockCheckpointEpochs(final Bytes32 root) { return db.get(schema.getColumnHotBlockCheckpointEpochsByRoot(), root); } diff --git a/storage/src/main/java/tech/pegasys/teku/storage/store/Store.java b/storage/src/main/java/tech/pegasys/teku/storage/store/Store.java index c8114d0d585..65fbd00d6e8 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/store/Store.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/store/Store.java @@ -204,7 +204,7 @@ public static UpdatableStore create( // Create limited collections for non-final data final Map blocks = - LimitedMap.createSynchronized(config.getBlockCacheSize()); + LimitedMap.createSynchronizedNatural(config.getBlockCacheSize()); final CachingTaskQueue checkpointStateTaskQueue = CachingTaskQueue.create( asyncRunner, @@ -216,10 +216,10 @@ public static UpdatableStore create( asyncRunner, metricsSystem, "memory_states", config.getStateCacheSize()); final Optional> maybeEpochStates = config.getEpochStateCacheSize() > 0 - ? Optional.of(LimitedMap.createSynchronized(config.getEpochStateCacheSize())) + ? Optional.of(LimitedMap.createSynchronizedLRU(config.getEpochStateCacheSize())) : Optional.empty(); final Map> blobSidecars = - LimitedMap.createSynchronized(config.getBlockCacheSize()); + LimitedMap.createSynchronizedNatural(config.getBlockCacheSize()); final UInt64 currentEpoch = spec.computeEpochAtSlot(spec.getCurrentSlot(time, genesisTime)); final ForkChoiceStrategy forkChoiceStrategy = diff --git a/storage/src/test/java/tech/pegasys/teku/storage/client/CombinedChainDataClientTest.java b/storage/src/test/java/tech/pegasys/teku/storage/client/CombinedChainDataClientTest.java index 04153a0dab6..1c5b58e76e6 100644 --- a/storage/src/test/java/tech/pegasys/teku/storage/client/CombinedChainDataClientTest.java +++ b/storage/src/test/java/tech/pegasys/teku/storage/client/CombinedChainDataClientTest.java @@ -59,7 +59,7 @@ class CombinedChainDataClientTest { final List nonCanonicalBlocks = new ArrayList<>(); final SignedBeaconBlock firstBlock = dataStructureUtil.randomSignedBeaconBlock(1); final SignedBeaconBlock secondBlock = dataStructureUtil.randomSignedBeaconBlock(1); - final BlobSidecarOld sidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld sidecar = dataStructureUtil.randomBlobSidecarOld(); @BeforeEach void setUp() { diff --git a/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/SszObjectType.java b/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/SszObjectType.java index 9914cfe6f5d..eadb6be64a2 100644 --- a/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/SszObjectType.java +++ b/teku/src/main/java/tech/pegasys/teku/cli/subcommand/debug/SszObjectType.java @@ -20,7 +20,7 @@ import tech.pegasys.teku.spec.config.SpecConfigAltair; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader.BeaconBlockHeaderSchema; import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data.Eth1DataSchema; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader.SignedBeaconBlockHeaderSchema; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeaderSchema; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema; import tech.pegasys.teku.spec.datastructures.operations.AttestationData.AttestationDataSchema; import tech.pegasys.teku.spec.datastructures.operations.Deposit.DepositSchema; diff --git a/validator/client/src/integration-test/java/tech/pegasys/teku/validator/client/signer/ExternalSignerDenebIntegrationTest.java b/validator/client/src/integration-test/java/tech/pegasys/teku/validator/client/signer/ExternalSignerDenebIntegrationTest.java index c9df9ff4af0..062499888cf 100644 --- a/validator/client/src/integration-test/java/tech/pegasys/teku/validator/client/signer/ExternalSignerDenebIntegrationTest.java +++ b/validator/client/src/integration-test/java/tech/pegasys/teku/validator/client/signer/ExternalSignerDenebIntegrationTest.java @@ -40,7 +40,7 @@ public Spec getSpec() { @Test void shouldSignBlobSidecar() throws Exception { - final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecar(); + final BlobSidecarOld blobSidecar = dataStructureUtil.randomBlobSidecarOld(); final BLSSignature expectedSignature = BLSSignature.fromBytesCompressed( Bytes.fromBase64String( diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java index fdc2a44d59f..9917d71c3e5 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java @@ -110,7 +110,7 @@ private SafeFuture signBlobSidecar( .thenApply( signature -> schemaDefinitions - .getSignedBlobSidecarSchema() + .getSignedBlobSidecarOldSchema() .create(unsignedBlobSidecar, signature)); } diff --git a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java index 4028831e0ee..7897dbe2e4b 100644 --- a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java +++ b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/FailoverValidatorApiHandler.java @@ -69,7 +69,7 @@ public class FailoverValidatorApiHandler implements ValidatorApiChannel { "remote_beacon_nodes_requests_total"; private final Map blindedBlockCreatorCache = - LimitedMap.createSynchronized(2); + LimitedMap.createSynchronizedLRU(2); private final BeaconNodeReadinessManager beaconNodeReadinessManager; private final RemoteValidatorApiChannel primaryDelegate;