From db389fa0fba1581ee07ebf8ece41f71b439455bd Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 30 Sep 2024 16:10:34 +0200 Subject: [PATCH] make engine get blobs versioned --- .../web3j/Web3JExecutionEngineClient.java | 2 +- .../EngineJsonRpcMethodsResolver.java | 4 ++++ .../ExecutionClientHandlerImpl.java | 23 +++++++------------ ...toneBasedEngineJsonRpcMethodsResolver.java | 20 ++++++++++++++++ 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ethereum/executionclient/src/main/java/tech/pegasys/teku/ethereum/executionclient/web3j/Web3JExecutionEngineClient.java b/ethereum/executionclient/src/main/java/tech/pegasys/teku/ethereum/executionclient/web3j/Web3JExecutionEngineClient.java index a21e0424f84..a7fae4b6f9e 100644 --- a/ethereum/executionclient/src/main/java/tech/pegasys/teku/ethereum/executionclient/web3j/Web3JExecutionEngineClient.java +++ b/ethereum/executionclient/src/main/java/tech/pegasys/teku/ethereum/executionclient/web3j/Web3JExecutionEngineClient.java @@ -257,7 +257,7 @@ public SafeFuture>> getClientVersionV1( @Override public SafeFuture>> getBlobsV1( - List blobVersionedHashes) { + final List blobVersionedHashes) { final Request web3jRequest = new Request<>( "engine_getBlobsVersionV1", diff --git a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/EngineJsonRpcMethodsResolver.java b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/EngineJsonRpcMethodsResolver.java index bcf580c3659..97b16c2acac 100644 --- a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/EngineJsonRpcMethodsResolver.java +++ b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/EngineJsonRpcMethodsResolver.java @@ -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; @@ -24,6 +25,9 @@ public interface EngineJsonRpcMethodsResolver { EngineJsonRpcMethod getMethod( EngineApiMethod method, Supplier milestoneSupplier, Class resultType); + EngineJsonRpcMethod> getMethodList( + EngineApiMethod method, Supplier milestoneSupplier, Class resultType); + /** * Get CL capabilities required for the engine_exchangeCapabilities diff --git a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionClientHandlerImpl.java b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionClientHandlerImpl.java index d46ed1f2bb6..8b12ad2df03 100644 --- a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionClientHandlerImpl.java +++ b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/ExecutionClientHandlerImpl.java @@ -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; @@ -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 { @@ -132,17 +129,13 @@ public SafeFuture> engineGetClientVersion(final ClientVersio @Override public SafeFuture> engineGetBlobs( final List 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); } } diff --git a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/MilestoneBasedEngineJsonRpcMethodsResolver.java b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/MilestoneBasedEngineJsonRpcMethodsResolver.java index ab19a273df0..e7962629b1d 100644 --- a/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/MilestoneBasedEngineJsonRpcMethodsResolver.java +++ b/ethereum/executionlayer/src/main/java/tech/pegasys/teku/ethereum/executionlayer/MilestoneBasedEngineJsonRpcMethodsResolver.java @@ -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; @@ -108,6 +109,7 @@ private Map> 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; } @@ -141,6 +143,24 @@ public EngineJsonRpcMethod getMethod( return foundMethod; } + @Override + @SuppressWarnings({"unchecked", "unused"}) + public EngineJsonRpcMethod> getMethodList( + final EngineApiMethod method, + final Supplier milestoneSupplier, + final Class resultType) { + final SpecMilestone milestone = milestoneSupplier.get(); + final Map> milestoneMethods = + methodsByMilestone.getOrDefault(milestone, Collections.emptyMap()); + final EngineJsonRpcMethod> foundMethod = + (EngineJsonRpcMethod>) 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 getCapabilities() { return methodsByMilestone.values().stream()