Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import io.vertx.core.Vertx;
import org.slf4j.Logger;
Expand Down Expand Up @@ -95,15 +95,27 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
RpcErrorType.INVALID_ENGINE_GET_BLOBS_TOO_LARGE_REQUEST);
}
requestedCounter.inc(versionedHashes.length);
final List<BlobAndProofV2> result =
Stream.of(versionedHashes).map(this::getBlobAndProofOrNull).toList();
long available = result.stream().filter(java.util.Objects::nonNull).count();
availableCounter.inc(available);
if (available > 0) {
hitCounter.inc();
} else {
missCounter.inc();
List<BlobAndProofV2> result = new ArrayList<>(versionedHashes.length);
for (VersionedHash versionedHash : versionedHashes) {
BlobProofBundle blobProofBundle = transactionPool.getBlobProofBundle(versionedHash);
if (blobProofBundle == null) {
// no partial responses. this is a miss
missCounter.inc();
LOG.trace("No BlobProofBundle found for versioned hash: {}", versionedHash);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), null);
}
if (blobProofBundle.getBlobType() == BlobType.KZG_PROOF) {
// wrong blob type. this is a miss
missCounter.inc();
LOG.trace("Unsupported blob type KZG_PROOF for versioned hash: {}", versionedHash);
return new JsonRpcSuccessResponse(
requestContext.getRequest().getId(),
null); // KZG_PROOF type is not supported in this method
}
result.add(createBlobAndProofV2(blobProofBundle));
}
availableCounter.inc(versionedHashes.length);
hitCounter.inc();
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result);
}

Expand All @@ -118,19 +130,6 @@ private VersionedHash[] extractVersionedHashes(final JsonRpcRequestContext reque
}
}

private BlobAndProofV2 getBlobAndProofOrNull(final VersionedHash versionedHash) {
final BlobProofBundle bundle = transactionPool.getBlobProofBundle(versionedHash);
if (bundle == null) {
LOG.trace("No BlobProofBundle found for versioned hash: {}", versionedHash);
return null;
}
if (bundle.getBlobType() == BlobType.KZG_PROOF) {
LOG.trace("Unsupported blob type KZG_PROOF for versioned hash: {}", versionedHash);
return null;
}
return createBlobAndProofV2(bundle);
}

private BlobAndProofV2 createBlobAndProofV2(final BlobProofBundle blobProofBundle) {
return new BlobAndProofV2(
blobProofBundle.getBlob().getData().toHexString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public void shouldReturnNullForUnknownHash() {
VersionedHash unknown = new VersionedHash((byte) 1, Hash.ZERO);
JsonRpcSuccessResponse response = getSuccessResponse(buildRequestContext(unknown));
List<BlobAndProofV2> result = extractResult(response);
assertThat(result).hasSize(1);
assertThat(result.getFirst()).isNull();

assertThat(result).isNull();
}

@Test
public void shouldReturnPartialResults() {
public void shouldNotReturnPartialResults() {
BlobProofBundle bundle = createBundleAndRegisterToPool();
VersionedHash known = bundle.getVersionedHash();
VersionedHash unknown = new VersionedHash((byte) 1, Hash.ZERO);
Expand All @@ -96,10 +96,7 @@ public void shouldReturnPartialResults() {
getSuccessResponse(buildRequestContext(known, unknown, known));
List<BlobAndProofV2> result = extractResult(response);

assertThat(result).hasSize(3);
assertThat(result.get(0)).isNotNull();
assertThat(result.get(1)).isNull();
assertThat(result.get(2)).isNotNull();
assertThat(result).isNull();
}

@Test
Expand All @@ -112,8 +109,8 @@ public void shouldReturnNullForBlobProofBundleWithV1BlobType() {
JsonRpcRequestContext requestContext = buildRequestContext(versionedHash);
JsonRpcSuccessResponse response = getSuccessResponse(requestContext);
List<BlobAndProofV2> result = extractResult(response);
assertThat(result).hasSize(1);
assertThat(result.getFirst()).isNull();

assertThat(result).isNull();
}

@Test
Expand Down
Loading