Skip to content

Commit

Permalink
improve retrieval of blobs and proofs from reference test
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Oct 20, 2023
1 parent 90281dd commit bbb84f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -309,27 +310,28 @@ private void applyBlock(
final SignedBeaconBlock block =
TestDataUtils.loadSsz(
testDefinition, blockName + SSZ_SNAPPY_EXTENSION, spec::deserializeSignedBeaconBlock);
getOptionally(step, "blobs")
.ifPresent(
blobsName -> {
final List<Blob> blobs =
TestDataUtils.loadSsz(
testDefinition,
blobsName + SSZ_SNAPPY_EXTENSION,
sszBytes -> spec.deserializeBlobsInBlock(sszBytes, block.getSlot()))
.asList();
@SuppressWarnings("unchecked")
final List<KZGProof> proofs =
((List<String>) get(step, "proofs"))
.stream().map(KZGProof::fromHexString).toList();
LOG.info(
"Preparing {} blobs with proofs {} for block {}",
blobs.size(),
proofs,
block.getRoot());
blobSidecarManager.prepareBlobsAndProofsForBlock(block, blobs, proofs);
});

final List<Blob> blobs =
getOptionally(step, "blobs")
.map(
blobsName ->
TestDataUtils.loadSsz(
testDefinition,
blobsName + SSZ_SNAPPY_EXTENSION,
sszBytes -> spec.deserializeBlobsInBlock(sszBytes, block.getSlot()))
.asList())
.orElse(Collections.emptyList());
@SuppressWarnings("unchecked")
final List<KZGProof> proofs =
getOptionally(step, "proofs")
.map(
proofsArray ->
((List<String>) proofsArray).stream().map(KZGProof::fromHexString).toList())
.orElse(Collections.emptyList());
if (block.getMessage().getBody().toVersionDeneb().isPresent()) {
LOG.info(
"Preparing {} blobs with proofs {} for block {}", blobs.size(), proofs, block.getRoot());
blobSidecarManager.prepareBlobsAndProofsForBlock(block, blobs, proofs);
}
LOG.info(
"Importing block {} at slot {} with parent {}",
block.getRoot(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class StubBlobSidecarManager implements BlobSidecarManager {
this.spec = spec;
}

/** Manually provide blobs and proofs for a block * */
/** Prepare the blobs and proofs for a block provided by the reference test * */
public void prepareBlobsAndProofsForBlock(
final SignedBeaconBlock block, final List<Blob> blobs, final List<KZGProof> proofs) {
blobsAndProofsByBlockRoot.put(block.getRoot(), new BlobsAndProofs(blobs, proofs));
Expand Down Expand Up @@ -80,8 +80,8 @@ public boolean isAvailabilityRequiredAtSlot(final UInt64 slot) {

/**
* Creates an implementation of {@link BlobSidecarsAvailabilityChecker} which uses the simplified
* {@link MiscHelpers#isDataAvailable(List, List, List)} method with the already provided blobs
* and proofs by the reference test
* {@link MiscHelpers#isDataAvailable(List, List, List)} method with the blobs and proofs that the
* reference test has provided
*/
@Override
public BlobSidecarsAvailabilityChecker createAvailabilityChecker(final SignedBeaconBlock block) {
Expand All @@ -93,7 +93,7 @@ public boolean initiateDataAvailabilityCheck() {

@Override
public SafeFuture<BlobSidecarsAndValidationResult> getAvailabilityCheckResult() {
final BlobsAndProofs blobsAndProofs = blobsAndProofsByBlockRoot.get(block.getRoot());
final BlobsAndProofs blobsAndProofs = blobsAndProofsByBlockRoot.remove(block.getRoot());
if (blobsAndProofs == null) {
return SafeFuture.completedFuture(BlobSidecarsAndValidationResult.NOT_REQUIRED);
}
Expand Down

0 comments on commit bbb84f7

Please sign in to comment.