5098 branch 14 update invalid data deposit and engine exchange (#7442)

* 5098: Add RpcErrorTypes

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda-Clerke <matilda.clerke@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7455/head
Matilda-Clerke 3 months ago committed by GitHub
parent b8c062cdcb
commit 1a9154586f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java
  2. 3
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java
  3. 16
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java
  4. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3Test.java

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.crypto.Hash;
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.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
@ -41,11 +42,17 @@ public class Web3Sha3 implements JsonRpcMethod {
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
}
final String data = requestContext.getRequiredParameter(0, String.class);
final String data;
try {
data = requestContext.getRequiredParameter(0, String.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid data parameter (index 0)", RpcErrorType.INVALID_DATA_PARAMS, e);
}
if (!data.isEmpty() && !data.startsWith("0x")) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS);
}
try {
@ -54,7 +61,7 @@ public class Web3Sha3 implements JsonRpcMethod {
requestContext.getRequest().getId(), Hash.keccak256(byteData).toString());
} catch (final IllegalArgumentException err) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS);
}
}
}

@ -169,8 +169,7 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet
if (!getDepositRequestValidator(
protocolSchedule.get(), blockParam.getTimestamp(), blockParam.getBlockNumber())
.validateParameter(maybeDepositRequests)) {
return new JsonRpcErrorResponse(
reqId, new JsonRpcError(INVALID_PARAMS, "Invalid deposit request"));
return new JsonRpcErrorResponse(reqId, RpcErrorType.INVALID_DEPOSIT_REQUEST_PARAMS);
}
final Optional<List<Request>> maybeWithdrawalRequests =

@ -20,10 +20,12 @@ import org.hyperledger.besu.consensus.merge.MergeContext;
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.EngineExchangeTransitionConfigurationParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineExchangeTransitionConfigurationResult;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Difficulty;
@ -65,9 +67,17 @@ public class EngineExchangeTransitionConfiguration extends ExecutionEngineJsonRp
public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) {
engineCallListener.executionEngineCalled();
final EngineExchangeTransitionConfigurationParameter remoteTransitionConfiguration =
requestContext.getRequiredParameter(
0, EngineExchangeTransitionConfigurationParameter.class);
final EngineExchangeTransitionConfigurationParameter remoteTransitionConfiguration;
try {
remoteTransitionConfiguration =
requestContext.getRequiredParameter(
0, EngineExchangeTransitionConfigurationParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid engine exchange transition configuration parameters (index 0)",
RpcErrorType.INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS,
e);
}
final Object reqId = requestContext.getRequest().getId();
LOG.atTrace()

@ -70,7 +70,7 @@ public class Web3Sha3Test {
new JsonRpcRequest("2", "web3_sha3", new Object[] {"0x68656c6c6f20776f726c6"}));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS);
final JsonRpcResponse actual = method.response(request);
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
@ -83,7 +83,7 @@ public class Web3Sha3Test {
new JsonRpcRequest("2", "web3_sha3", new Object[] {"0x68656c6c6fThisIsNotHex"}));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS);
final JsonRpcResponse actual = method.response(request);
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
@ -96,7 +96,7 @@ public class Web3Sha3Test {
new JsonRpcRequest("2", "web3_sha3", new Object[] {"68656c6c6f20776f726c64"}));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS);
final JsonRpcResponse actual = method.response(request);
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
@ -109,7 +109,7 @@ public class Web3Sha3Test {
new JsonRpcRequest("2", "web3_sha3", new Object[] {"68656c6c6fThisIsNotHex"}));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS);
final JsonRpcResponse actual = method.response(request);
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);

Loading…
Cancel
Save