From a3b6fd54022334acb01f643fed3ba8d86a90e303 Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Wed, 14 Aug 2024 14:34:45 +1000 Subject: [PATCH] 5098 branch 15 update remaining invalid engine params (#7443) Signed-off-by: Matilda Clerke --- .../execution/TracedJsonRpcProcessor.java | 4 +-- .../AbstractEngineForkchoiceUpdated.java | 24 ++++++++++--- .../engine/AbstractEngineNewPayload.java | 12 +++++-- .../engine/EnginePreparePayloadDebug.java | 36 ++++++++++++------- .../internal/response/RpcErrorType.java | 4 +-- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java index 822c6ac895b..f1a799cf638 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java @@ -74,8 +74,8 @@ public JsonRpcResponse process( case INVALID_DEPOSIT_REQUEST_PARAMS: case INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS: case INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS: - case INVALID_ENGINE_PAYLOAD_ATTRIBUTES_PARAMS: - case INVALID_ENGINE_PAYLOAD_PARAMS: + case INVALID_ENGINE_FORKCHOICE_UPDATED_PAYLOAD_ATTRIBUTES: + case INVALID_ENGINE_NEW_PAYLOAD_PARAMS: case INVALID_ENGINE_PREPARE_PAYLOAD_PARAMS: case INVALID_ENODE_PARAMS: case INVALID_EXCESS_BLOB_GAS_PARAMS: diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java index eec79e9a7cd..f958b584447 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineForkchoiceUpdatedParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadAttributesParameter; @@ -80,10 +81,25 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) final Object requestId = requestContext.getRequest().getId(); - final EngineForkchoiceUpdatedParameter forkChoice = - requestContext.getRequiredParameter(0, EngineForkchoiceUpdatedParameter.class); - final Optional maybePayloadAttributes = - requestContext.getOptionalParameter(1, EnginePayloadAttributesParameter.class); + final EngineForkchoiceUpdatedParameter forkChoice; + try { + forkChoice = requestContext.getRequiredParameter(0, EngineForkchoiceUpdatedParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid engine forkchoice updated parameter (index 0)", + RpcErrorType.INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS, + e); + } + final Optional maybePayloadAttributes; + try { + maybePayloadAttributes = + requestContext.getOptionalParameter(1, EnginePayloadAttributesParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid engine payload attributes parameter (index 1)", + RpcErrorType.INVALID_ENGINE_FORKCHOICE_UPDATED_PAYLOAD_ATTRIBUTES, + e); + } LOG.debug("Forkchoice parameters {}", forkChoice); mergeContext diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java index 246a2777c8a..5d0d379d810 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java @@ -35,6 +35,7 @@ import org.hyperledger.besu.ethereum.BlockProcessingResult; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcRequestException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.ConsolidationRequestParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositRequestParameter; @@ -107,8 +108,15 @@ public AbstractEngineNewPayload( public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) { engineCallListener.executionEngineCalled(); - final EnginePayloadParameter blockParam = - requestContext.getRequiredParameter(0, EnginePayloadParameter.class); + final EnginePayloadParameter blockParam; + try { + blockParam = requestContext.getRequiredParameter(0, EnginePayloadParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcRequestException( + "Invalid engine payload parameter (index 0)", + RpcErrorType.INVALID_ENGINE_NEW_PAYLOAD_PARAMS, + e); + } final Optional> maybeVersionedHashParam = requestContext.getOptionalList(1, String.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java index 26f8e99edd7..e55cfb1506e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EnginePreparePayloadDebug.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePreparePayloadParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter; @@ -58,17 +59,25 @@ public String getName() { @Override public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) { - final EnginePreparePayloadParameter enginePreparePayloadParameter = - requestContext - .getOptionalParameter(0, EnginePreparePayloadParameter.class) - .orElse( - new EnginePreparePayloadParameter( - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty(), - Optional.empty())); + final EnginePreparePayloadParameter enginePreparePayloadParameter; + try { + enginePreparePayloadParameter = + requestContext + .getOptionalParameter(0, EnginePreparePayloadParameter.class) + .orElse( + new EnginePreparePayloadParameter( + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty(), + Optional.empty())); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid engine prepare payload parameter (index 0)", + RpcErrorType.INVALID_ENGINE_PREPARE_PAYLOAD_PARAMS, + e); + } final var requestId = requestContext.getRequest().getId(); @@ -81,7 +90,10 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) payloadIdentifier -> new JsonRpcSuccessResponse( requestId, new EnginePreparePayloadResult(VALID, payloadIdentifier))) - .orElseGet(() -> new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS)); + .orElseGet( + () -> + new JsonRpcErrorResponse( + requestId, RpcErrorType.INVALID_ENGINE_PREPARE_PAYLOAD_PARAMS)); } @VisibleForTesting diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java index d46dc900c57..d16c258879c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java @@ -52,9 +52,9 @@ public enum RpcErrorType implements RpcMethodError { INVALID_PARAMS_ERROR_CODE, "Invalid engine exchange transition configuration params"), INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS( INVALID_PARAMS_ERROR_CODE, "Invalid engine forkchoice updated params"), - INVALID_ENGINE_PAYLOAD_ATTRIBUTES_PARAMS( + INVALID_ENGINE_FORKCHOICE_UPDATED_PAYLOAD_ATTRIBUTES( INVALID_PARAMS_ERROR_CODE, "Invalid engine payload attributes parameter"), - INVALID_ENGINE_PAYLOAD_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid engine payload parameter"), + INVALID_ENGINE_NEW_PAYLOAD_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid engine payload parameter"), INVALID_ENGINE_PREPARE_PAYLOAD_PARAMS( INVALID_PARAMS_ERROR_CODE, "Invalid engine prepare payload parameter"), INVALID_ENODE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid enode params"),