Skip to content

Commit

Permalink
make engine get blobs versioned
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Sep 30, 2024
1 parent c01fee7 commit db389fa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public SafeFuture<Response<List<ClientVersionV1>>> getClientVersionV1(

@Override
public SafeFuture<Response<List<BlobAndProofV1>>> getBlobsV1(
List<VersionedHash> blobVersionedHashes) {
final List<VersionedHash> blobVersionedHashes) {
final Request<?, GetBlobsVersionV1Web3jResponse> web3jRequest =
new Request<>(
"engine_getBlobsVersionV1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.ethereum.executionlayer;

import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import tech.pegasys.teku.ethereum.executionclient.methods.EngineApiMethod;
Expand All @@ -24,6 +25,9 @@ public interface EngineJsonRpcMethodsResolver {
<T> EngineJsonRpcMethod<T> getMethod(
EngineApiMethod method, Supplier<SpecMilestone> milestoneSupplier, Class<T> resultType);

<T> EngineJsonRpcMethod<List<T>> getMethodList(
EngineApiMethod method, Supplier<SpecMilestone> milestoneSupplier, Class<T> resultType);

/**
* Get CL capabilities required for the <a
* href="https://github.com/ethereum/execution-apis/blob/main/src/engine/common.md#engine_exchangecapabilities">engine_exchangeCapabilities</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.execution.BlobAndProof;
import tech.pegasys.teku.spec.datastructures.execution.ClientVersion;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
Expand All @@ -37,8 +36,6 @@
import tech.pegasys.teku.spec.executionlayer.PayloadBuildingAttributes;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
import tech.pegasys.teku.spec.logic.versions.deneb.types.VersionedHash;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;

public class ExecutionClientHandlerImpl implements ExecutionClientHandler {

Expand Down Expand Up @@ -132,17 +129,13 @@ public SafeFuture<List<ClientVersion>> engineGetClientVersion(final ClientVersio
@Override
public SafeFuture<List<BlobAndProof>> engineGetBlobs(
final List<VersionedHash> blobVersionedHashes, final UInt64 slot) {
// TODO Make it versioned
final SchemaDefinitions schemaDefinitions = spec.atSlot(slot).getSchemaDefinitions();
final BlobSchema blobSchema =
SchemaDefinitionsDeneb.required(schemaDefinitions).getBlobSchema();
return executionEngineClient
.getBlobsV1(blobVersionedHashes)
.thenApply(ResponseUnwrapper::unwrapExecutionClientResponseOrThrow)
.thenApply(
blobAndProofV1s ->
blobAndProofV1s.stream()
.map(blobAndProofV1 -> blobAndProofV1.asInternalBlobsAndProofs(blobSchema))
.toList());
final JsonRpcRequestParams params =
new JsonRpcRequestParams.Builder().add(blobVersionedHashes).add(slot).build();
return engineMethodsResolver
.getMethodList(
EngineApiMethod.ENGINE_GET_BLOBS,
() -> spec.atSlot(slot).getMilestone(),
BlobAndProof.class)
.execute(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
Expand Down Expand Up @@ -108,6 +109,7 @@ private Map<EngineApiMethod, EngineJsonRpcMethod<?>> denebSupportedMethods() {
methods.put(ENGINE_NEW_PAYLOAD, new EngineNewPayloadV3(executionEngineClient));
methods.put(ENGINE_GET_PAYLOAD, new EngineGetPayloadV3(executionEngineClient, spec));
methods.put(ENGINE_FORK_CHOICE_UPDATED, new EngineForkChoiceUpdatedV3(executionEngineClient));
methods.put(ENGINE_GET_BLOBS, new EngineGetBlobsV1(executionEngineClient, spec));

return methods;
}
Expand Down Expand Up @@ -141,6 +143,24 @@ public <T> EngineJsonRpcMethod<T> getMethod(
return foundMethod;
}

@Override
@SuppressWarnings({"unchecked", "unused"})
public <T> EngineJsonRpcMethod<List<T>> getMethodList(
final EngineApiMethod method,
final Supplier<SpecMilestone> milestoneSupplier,
final Class<T> resultType) {
final SpecMilestone milestone = milestoneSupplier.get();
final Map<EngineApiMethod, EngineJsonRpcMethod<?>> milestoneMethods =
methodsByMilestone.getOrDefault(milestone, Collections.emptyMap());
final EngineJsonRpcMethod<List<T>> foundMethod =
(EngineJsonRpcMethod<List<T>>) milestoneMethods.get(method);
if (foundMethod == null) {
throw new IllegalArgumentException(
"Can't find method with name " + method.getName() + " for milestone " + milestone);
}
return foundMethod;
}

@Override
public Set<String> getCapabilities() {
return methodsByMilestone.values().stream()
Expand Down

0 comments on commit db389fa

Please sign in to comment.