Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into arg-no-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Nov 9, 2023
2 parents e67047e + 5ce164c commit 09741ba
Show file tree
Hide file tree
Showing 94 changed files with 957 additions and 720 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void fetchSingleBlobSidecarSuccessfully() {
assertThat(importedBlobSidecars).isEmpty();

final SafeFuture<FetchResult<BlobSidecarOld>> 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);
Expand All @@ -107,7 +107,7 @@ public void handleDuplicateRequiredBlobSidecars() {
assertThat(importedBlobSidecars).isEmpty();

final SafeFuture<FetchResult<BlobSidecarOld>> 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);
Expand Down Expand Up @@ -222,7 +222,7 @@ public void queueFetchTaskWhenConcurrencyLimitReached() {

// Complete first task
final SafeFuture<FetchResult<BlobSidecarOld>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static SyncingNodeManager create(
poolFactory.createPendingPoolForBlocks(spec);
final FutureItems<SignedBeaconBlock> futureBlocks =
FutureItems.create(SignedBeaconBlock::getSlot, mock(SettableLabelledGauge.class), "blocks");
final Map<Bytes32, BlockImportResult> invalidBlockRoots = LimitedMap.createSynchronized(500);
final Map<Bytes32, BlockImportResult> invalidBlockRoots = LimitedMap.createSynchronizedLRU(500);

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

@Deprecated
public Consumer<SignedBlobSidecarsUnblinder> createBlobSidecarsUnblinderSelector(
final UInt64 slot) {
return blobSidecarsUnblinder ->
Expand Down Expand Up @@ -374,7 +361,7 @@ public Function<BeaconBlock, SafeFuture<List<BlobSidecarOld>>> createBlobSidecar
return block -> {
final BlobSidecarSchemaOld blobSidecarSchema =
SchemaDefinitionsDeneb.required(spec.atSlot(block.getSlot()).getSchemaDefinitions())
.getBlobSidecarSchema();
.getBlobSidecarOldSchema();
return getCachedBlobsBundle(block.getSlot())
.thenApply(
blobsBundle ->
Expand All @@ -394,70 +381,46 @@ public Function<BeaconBlock, SafeFuture<List<BlobSidecarOld>>> createBlobSidecar
};
}

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

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

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

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

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

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

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

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

protected ExecutionPayloadResult cachedExecutionPayloadResult = null;

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

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

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

private BuilderPayload getBuilderPayload(final Spec spec) {
Expand Down
Loading

0 comments on commit 09741ba

Please sign in to comment.