Skip to content

Commit

Permalink
5098 branch 15 update remaining invalid engine params (#7443)
Browse files Browse the repository at this point in the history
Signed-off-by: Matilda Clerke <[email protected]>
  • Loading branch information
Matilda-Clerke authored Aug 14, 2024
1 parent ac9f8bb commit a3b6fd5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<EnginePayloadAttributesParameter> 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<EnginePayloadAttributesParameter> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<String>> maybeVersionedHashParam =
requestContext.getOptionalList(1, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit a3b6fd5

Please sign in to comment.