5098 Branch 1: Groundwork for coming changes (#7398)

* 5098: Add RpcErrorTypes

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

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

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

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

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

* 5098: Add JsonRpcParameterException for later use

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

* 5098: Address review comments, apply spotless

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

* 5098: Update plugin-api gradle hash

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

* 5098: Add comment on INVALID_PARAMS_ERROR_CODE

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

* 5098: Apply spotless on latest changes

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

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
pull/7412/head
Matilda-Clerke 4 months ago committed by GitHub
parent 9592b64310
commit 9fe374a62b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 66
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java
  2. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java
  3. 22
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcRequestException.java
  4. 16
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java
  5. 87
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java
  6. 2
      plugin-api/build.gradle
  7. 3
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java

@ -57,6 +57,72 @@ public class TracedJsonRpcProcessor implements JsonRpcProcessor {
this.rpcErrorsCounter.labels(method.getName(), errorResponse.getErrorType().name()).inc(); this.rpcErrorsCounter.labels(method.getName(), errorResponse.getErrorType().name()).inc();
switch (errorResponse.getErrorType()) { switch (errorResponse.getErrorType()) {
case INVALID_PARAMS: case INVALID_PARAMS:
case INVALID_ACCOUNT_PARAMS:
case INVALID_ADDRESS_HASH_PARAMS:
case INVALID_ADDRESS_PARAMS:
case INVALID_AUTH_PARAMS:
case INVALID_BLOB_COUNT:
case INVALID_BLOB_GAS_USED_PARAMS:
case INVALID_BLOCK_PARAMS:
case INVALID_BLOCK_COUNT_PARAMS:
case INVALID_BLOCK_HASH_PARAMS:
case INVALID_BLOCK_INDEX_PARAMS:
case INVALID_BLOCK_NUMBER_PARAMS:
case INVALID_CALL_PARAMS:
case INVALID_CONSOLIDATION_REQUEST_PARAMS:
case INVALID_CREATE_PRIVACY_GROUP_PARAMS:
case INVALID_DATA_PARAMS:
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_PREPARE_PAYLOAD_PARAMS:
case INVALID_ENODE_PARAMS:
case INVALID_EXCESS_BLOB_GAS_PARAMS:
case INVALID_EXTRA_DATA_PARAMS:
case INVALID_FILTER_PARAMS:
case INVALID_GAS_PRICE_PARAMS:
case INVALID_HASH_RATE_PARAMS:
case INVALID_ID_PARAMS:
case INVALID_IS_TRANSACTION_COMPLETE_PARAMS:
case INVALID_LOG_FILTER_PARAMS:
case INVALID_LOG_LEVEL_PARAMS:
case INVALID_MAX_RESULTS_PARAMS:
case INVALID_METHOD_PARAMS:
case INVALID_MIN_GAS_PRICE_PARAMS:
case INVALID_MIN_PRIORITY_FEE_PARAMS:
case INVALID_MIX_HASH_PARAMS:
case INVALID_NONCE_PARAMS:
case INVALID_PARENT_BEACON_BLOCK_ROOT_PARAMS:
case INVALID_PARAM_COUNT:
case INVALID_PAYLOAD_ID_PARAMS:
case INVALID_PENDING_TRANSACTIONS_PARAMS:
case INVAlID_PLUGIN_NAME_PARAMS:
case INVALID_POSITION_PARAMS:
case INVALID_POW_HASH_PARAMS:
case INVALID_PRIVACY_GROUP_PARAMS:
case INVALID_PRIVATE_FROM_PARAMS:
case INVALID_PRIVATE_FOR_PARAMS:
case INVALID_REMOTE_CAPABILITIES_PARAMS:
case INVALID_REWARD_PERCENTILES_PARAMS:
case INVALID_SEALER_ID_PARAMS:
case INVALID_STORAGE_KEYS_PARAMS:
case INVALID_SUBSCRIPTION_PARAMS:
case INVALID_TARGET_GAS_LIMIT_PARAMS:
case INVALID_TIMESTAMP_PARAMS:
case INVALID_TRACE_CALL_MANY_PARAMS:
case INVALID_TRACE_NUMBERS_PARAMS:
case INVALID_TRACE_TYPE_PARAMS:
case INVALID_TRANSACTION_PARAMS:
case INVALID_TRANSACTION_HASH_PARAMS:
case INVALID_TRANSACTION_ID_PARAMS:
case INVALID_TRANSACTION_INDEX_PARAMS:
case INVALID_TRANSACTION_LIMIT_PARAMS:
case INVALID_TRANSACTION_TRACE_PARAMS:
case INVALID_VERSIONED_HASH_PARAMS:
case INVALID_VOTE_TYPE_PARAMS:
case INVALID_WITHDRAWALS_PARAMS:
metricSpan.setStatus(StatusCode.ERROR, "Invalid Params"); metricSpan.setStatus(StatusCode.ERROR, "Invalid Params");
break; break;
case UNAUTHORIZED: case UNAUTHORIZED:

@ -14,13 +14,24 @@
*/ */
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception; package org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
public class InvalidJsonRpcParameters extends InvalidJsonRpcRequestException { public class InvalidJsonRpcParameters extends InvalidJsonRpcRequestException {
public InvalidJsonRpcParameters(final String s) { public InvalidJsonRpcParameters(final String s) {
super(s); super(s);
} }
public InvalidJsonRpcParameters(final String message, final RpcErrorType rpcErrorType) {
super(message, rpcErrorType);
}
public InvalidJsonRpcParameters(final String message, final Throwable cause) { public InvalidJsonRpcParameters(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }
public InvalidJsonRpcParameters(
final String message, final RpcErrorType rpcErrorType, final Throwable cause) {
super(message, rpcErrorType, cause);
}
} }

@ -14,12 +14,34 @@
*/ */
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception; package org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
public class InvalidJsonRpcRequestException extends IllegalArgumentException { public class InvalidJsonRpcRequestException extends IllegalArgumentException {
private final RpcErrorType rpcErrorType;
public InvalidJsonRpcRequestException(final String message) { public InvalidJsonRpcRequestException(final String message) {
super(message); super(message);
rpcErrorType = RpcErrorType.INVALID_PARAMS;
}
public InvalidJsonRpcRequestException(final String message, final RpcErrorType rpcErrorType) {
super(message);
this.rpcErrorType = rpcErrorType;
} }
public InvalidJsonRpcRequestException(final String message, final Throwable cause) { public InvalidJsonRpcRequestException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
rpcErrorType = RpcErrorType.INVALID_PARAMS;
}
public InvalidJsonRpcRequestException(
final String message, final RpcErrorType rpcErrorType, final Throwable cause) {
super(message, cause);
this.rpcErrorType = rpcErrorType;
}
public RpcErrorType getRpcErrorType() {
return rpcErrorType;
} }
} }

@ -40,6 +40,8 @@ public class JsonRpcParameter {
* @param <T> The type of parameter. * @param <T> The type of parameter.
* @return Returns the parameter cast as T if available, otherwise throws exception. * @return Returns the parameter cast as T if available, otherwise throws exception.
*/ */
// TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to
// handle it to supply appropriate context
public <T> T required(final Object[] params, final int index, final Class<T> paramClass) { public <T> T required(final Object[] params, final int index, final Class<T> paramClass) {
return optional(params, index, paramClass) return optional(params, index, paramClass)
.orElseThrow( .orElseThrow(
@ -58,6 +60,8 @@ public class JsonRpcParameter {
* @param <T> The type of parameter. * @param <T> The type of parameter.
* @return Returns the parameter cast as T if available. * @return Returns the parameter cast as T if available.
*/ */
// TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to
// handle it to supply appropriate context
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> Optional<T> optional( public <T> Optional<T> optional(
final Object[] params, final int index, final Class<T> paramClass) { final Object[] params, final int index, final Class<T> paramClass) {
@ -87,6 +91,8 @@ public class JsonRpcParameter {
return Optional.of(param); return Optional.of(param);
} }
// TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to
// handle it to supply appropriate context
public <T> Optional<List<T>> optionalList( public <T> Optional<List<T>> optionalList(
final Object[] params, final int index, final Class<T> listClass) { final Object[] params, final int index, final Class<T> listClass) {
if (params == null || params.length <= index || params[index] == null) { if (params == null || params.length <= index || params[index] == null) {
@ -108,4 +114,14 @@ public class JsonRpcParameter {
} }
return Optional.empty(); return Optional.empty();
} }
public static class JsonRpcParameterException extends Exception {
public JsonRpcParameterException(final String message) {
super(message);
}
public JsonRpcParameterException(final String message, final Throwable cause) {
super(message, cause);
}
}
} }

@ -26,7 +26,91 @@ public enum RpcErrorType implements RpcMethodError {
PARSE_ERROR(-32700, "Parse error"), PARSE_ERROR(-32700, "Parse error"),
INVALID_REQUEST(-32600, "Invalid Request"), INVALID_REQUEST(-32600, "Invalid Request"),
METHOD_NOT_FOUND(-32601, "Method not found"), METHOD_NOT_FOUND(-32601, "Method not found"),
INVALID_PARAMS(-32602, "Invalid params"),
INVALID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid params"),
INVALID_ACCOUNT_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid account params"),
INVALID_ADDRESS_HASH_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid address hash params"),
INVALID_ADDRESS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid address params"),
INVALID_AUTH_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid auth params"),
INVALID_BLOB_COUNT(
INVALID_PARAMS_ERROR_CODE,
"Invalid blob count (blob transactions must have at least one blob)"),
INVALID_BLOB_GAS_USED_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid blob gas used param (missing or invalid)"),
INVALID_BLOCK_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid block, unable to parse RLP"),
INVALID_BLOCK_COUNT_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid block count params"),
INVALID_BLOCK_HASH_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid block hash params"),
INVALID_BLOCK_INDEX_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid block index params"),
INVALID_BLOCK_NUMBER_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid block number params"),
INVALID_CALL_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid call params"),
INVALID_CONSOLIDATION_REQUEST_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid consolidation request params"),
INVALID_CREATE_PRIVACY_GROUP_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid create privacy group params"),
INVALID_DATA_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid data params"),
INVALID_DEPOSIT_REQUEST_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid deposit request"),
INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS(
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_PARAMS_ERROR_CODE, "Invalid engine payload attributes parameter"),
INVALID_ENGINE_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"),
INVALID_EXCESS_BLOB_GAS_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid excess blob gas params (missing or invalid)"),
INVALID_EXTRA_DATA_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid extra data params"),
INVALID_FILTER_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid filter params"),
INVALID_GAS_PRICE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid gas price params"),
INVALID_HASH_RATE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid hash rate params"),
INVALID_ID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid ID params"),
INVALID_IS_TRANSACTION_COMPLETE_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid is transaction complete params"),
INVALID_LOG_FILTER_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid log filter params"),
INVALID_LOG_LEVEL_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid log level params (missing or incorrect)"),
INVALID_MAX_RESULTS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid max results params"),
INVALID_METHOD_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid method params"),
INVALID_MIN_GAS_PRICE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid min gas price params"),
INVALID_MIN_PRIORITY_FEE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid min priority fee params"),
INVALID_MIX_HASH_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid mix hash params"),
INVALID_NONCE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid nonce params"),
INVALID_PARENT_BEACON_BLOCK_ROOT_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid parent beacon block root (missing or incorrect)"),
INVALID_PARAM_COUNT(INVALID_PARAMS_ERROR_CODE, "Invalid number of params"),
INVALID_PAYLOAD_ID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid payload id params"),
INVALID_PENDING_TRANSACTIONS_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid pending transactions params"),
INVAlID_PLUGIN_NAME_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid plug in name params"),
INVALID_POSITION_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid position params"),
INVALID_POW_HASH_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid pow hash params"),
INVALID_PRIVACY_GROUP_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid privacy group params"),
INVALID_PRIVATE_FROM_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid private from params"),
INVALID_PRIVATE_FOR_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid private for params"),
INVALID_REMOTE_CAPABILITIES_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid remote capabilities params"),
INVALID_REWARD_PERCENTILES_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid reward percentiles params"),
INVALID_SEALER_ID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid sealer ID params"),
INVALID_STORAGE_KEYS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid storage keys params"),
INVALID_SUBSCRIPTION_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid subscription params"),
INVALID_TARGET_GAS_LIMIT_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid target gas limit params"),
INVALID_TIMESTAMP_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid timestamp parameter"),
INVALID_TRACE_CALL_MANY_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid trace call many params"),
INVALID_TRACE_NUMBERS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid trace numbers params"),
INVALID_TRACE_TYPE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid trace type params"),
INVALID_TRANSACTION_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid transaction params (missing or incorrect)"),
INVALID_TRANSACTION_HASH_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid transaction hash params"),
INVALID_TRANSACTION_ID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid transaction id params"),
INVALID_TRANSACTION_INDEX_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid transaction index params"),
INVALID_TRANSACTION_LIMIT_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid transaction limit params"),
INVALID_TRANSACTION_TRACE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid transaction trace params"),
INVALID_VERSIONED_HASH_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid versioned hash params"),
INVALID_VOTE_TYPE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid vote type params"),
INVALID_WITHDRAWALS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid withdrawals"),
INTERNAL_ERROR(-32603, "Internal error"), INTERNAL_ERROR(-32603, "Internal error"),
TIMEOUT_ERROR(-32603, "Timeout expired"), TIMEOUT_ERROR(-32603, "Timeout expired"),
@ -231,7 +315,6 @@ public enum RpcErrorType implements RpcMethodError {
UNKNOWN(-32603, "Unknown internal error"), UNKNOWN(-32603, "Unknown internal error"),
INVALID_BLOBS(-32603, "blobs failed kzg validation"); INVALID_BLOBS(-32603, "blobs failed kzg validation");
private final int code; private final int code;
private final String message; private final String message;
private final Function<String, Optional<String>> dataDecoder; private final Function<String, Optional<String>> dataDecoder;

@ -70,7 +70,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) { tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought" description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files files = sourceSets.main.allJava.files
knownHash = 'oPsVhFhdIkzHqD+jjwRX7dbgeNeKbpCmPjiBWDdMV7o=' knownHash = 'o0IuPVpCvE3YUzuZgVf4NP74q1ECpkbAkeC6u/Nr8yU='
} }
check.dependsOn('checkAPIChanges') check.dependsOn('checkAPIChanges')

@ -23,6 +23,9 @@ import java.util.Optional;
*/ */
public interface RpcMethodError { public interface RpcMethodError {
/** The error code for all invalid params */
static final int INVALID_PARAMS_ERROR_CODE = -32602;
/** /**
* Retrieves the error code associated with the RPC error. * Retrieves the error code associated with the RPC error.
* *

Loading…
Cancel
Save