From e41cf313c4991911ded7bfb8283443e50a11bbbf Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 08:54:08 +1000 Subject: [PATCH 01/13] 5098: Add RpcErrorTypes Signed-off-by: Matilda Clerke --- .../execution/TracedJsonRpcProcessor.java | 66 +++++++++++++++++ .../internal/response/RpcErrorType.java | 70 +++++++++++++++++++ 2 files changed, 136 insertions(+) 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 c40c8f8c1f6..375e824c10f 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 @@ -57,6 +57,72 @@ public JsonRpcResponse process( this.rpcErrorsCounter.labels(method.getName(), errorResponse.getErrorType().name()).inc(); switch (errorResponse.getErrorType()) { case INVALID_PARAMS: + case INVALID_ACCOUNTS_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_PARAMETER: + case INVALID_ENGINE_PAYLOAD_PARAMETER: + case INVALID_ENGINE_PREPARE_PAYLOAD_PARAMETER: + 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_PARAMETER: + case INVALID_SEALER_ID_PARAMS: + case INVALID_STORAGE_KEYS_PARAMS: + case INVALID_SUBSCRIPTION_PARAMS: + case INVALID_TARGET_GAS_LIMIT_PARAMS: + case INVALID_TIMESTAMP_PARAMETER: + 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"); break; case UNAUTHORIZED: 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 1b1ee48c0af..fe659dba803 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 @@ -26,7 +26,77 @@ public enum RpcErrorType implements RpcMethodError { PARSE_ERROR(-32700, "Parse error"), INVALID_REQUEST(-32600, "Invalid Request"), METHOD_NOT_FOUND(-32601, "Method not found"), + INVALID_PARAMS(-32602, "Invalid params"), + INVALID_ACCOUNTS_PARAMS(-32602, "Invalid accounts params"), + INVALID_ADDRESS_HASH_PARAMS(-32602, "Invalid address hash params"), + INVALID_ADDRESS_PARAMS(-32602, "Invalid address params"), + INVALID_AUTH_PARAMS(-32602, "Invalid auth params"), + INVALID_BLOB_COUNT(-32602, "Invalid blob count (blob transactions must have at least one blob)"), + INVALID_BLOB_GAS_USED_PARAMS(-32602, "Invalid blob gas used param (missing or invalid)"), + INVALID_BLOCK_PARAMS(-32602, "Invalid block, unable to parse RLP"), + INVALID_BLOCK_COUNT_PARAMS(-32602, "Invalid block count params"), + INVALID_BLOCK_HASH_PARAMS(-32602, "Invalid block hash params"), + INVALID_BLOCK_INDEX_PARAMS(-32602, "Invalid block index params"), + INVALID_BLOCK_NUMBER_PARAMS(-32602, "Invalid block number params"), + INVALID_CALL_PARAMS(-32602, "Invalid call params"), + INVALID_CONSOLIDATION_REQUEST_PARAMS(-32602, "Invalid consolidation request params"), + INVALID_CREATE_PRIVACY_GROUP_PARAMS(-32602, "Invalid create privacy group params"), + INVALID_DATA_PARAMS(-32602, "Invalid data params"), + INVALID_DEPOSIT_REQUEST_PARAMS(-32602, "Invalid deposit request"), + INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS( + -32602, "Invalid engine exchange transition configuration params"), + INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS(-32602, "Invalid engine forkchoice updated params"), + INVALID_ENGINE_PAYLOAD_ATTRIBUTES_PARAMETER(-32602, "Invalid engine payload attributes params"), + INVALID_ENGINE_PAYLOAD_PARAMETER(-32602, "Invalid engine payload params"), + INVALID_ENGINE_PREPARE_PAYLOAD_PARAMETER(-32602, "Invalid engine prepare payload parameter"), + INVALID_ENODE_PARAMS(-32602, "Invalid enode params"), + INVALID_EXCESS_BLOB_GAS_PARAMS(-32602, "Invalid excess blob gas params (missing or invalid)"), + INVALID_EXTRA_DATA_PARAMS(-32602, "Invalid extra data params"), + INVALID_FILTER_PARAMS(-32602, "Invalid filter params"), + INVALID_GAS_PRICE_PARAMS(-32602, "Invalid gas price params"), + INVALID_HASH_RATE_PARAMS(-32602, "Invalid hash rate params"), + INVALID_ID_PARAMS(-32602, "Invalid ID params"), + INVALID_IS_TRANSACTION_COMPLETE_PARAMS(-32602, "Invalid is transaction complete params"), + INVALID_LOG_FILTER_PARAMS(-32602, "Invalid log filter params"), + INVALID_LOG_LEVEL_PARAMS(-32602, "Invalid log level params (missing or incorrect)"), + INVALID_MAX_RESULTS_PARAMS(-32602, "Invalid max results params"), + INVALID_METHOD_PARAMS(-32602, "Invalid method params"), + INVALID_MIN_GAS_PRICE_PARAMS(-32602, "Invalid min gas price params"), + INVALID_MIN_PRIORITY_FEE_PARAMS(-32602, "Invalid min priority fee params"), + INVALID_MIX_HASH_PARAMS(-32602, "Invalid mix hash params"), + INVALID_NONCE_PARAMS(-32602, "Invalid nonce params"), + INVALID_PARENT_BEACON_BLOCK_ROOT_PARAMS( + -32602, "Invalid parent beacon block root (missing or incorrect)"), + INVALID_PARAM_COUNT(-32602, "Invalid number of params"), + INVALID_PAYLOAD_ID_PARAMS(-32602, "Invalid payload id params"), + INVALID_PENDING_TRANSACTIONS_PARAMS(-32602, "Invalid pending transactions params"), + INVAlID_PLUGIN_NAME_PARAMS(-32602, "Invalid plug in name params"), + INVALID_POSITION_PARAMS(-32602, "Invalid position params"), + INVALID_POW_HASH_PARAMS(-32602, "Invalid pow hash params"), + INVALID_PRIVACY_GROUP_PARAMS(-32602, "Invalid privacy group params"), + INVALID_PRIVATE_FROM_PARAMS(-32602, "Invalid private from params"), + INVALID_PRIVATE_FOR_PARAMS(-32602, "Invalid private for params"), + INVALID_REMOTE_CAPABILITIES_PARAMS(-32602, "Invalid remote capabilities params"), + INVALID_REWARD_PERCENTILES_PARAMETER(-32602, "Invalid reward percentiles params"), + INVALID_SEALER_ID_PARAMS(-32602, "Invalid sealer ID params"), + INVALID_STORAGE_KEYS_PARAMS(-32602, "Invalid storage keys params"), + INVALID_SUBSCRIPTION_PARAMS(-32602, "Invalid subscription params"), + INVALID_TARGET_GAS_LIMIT_PARAMS(-32602, "Invalid target gas limit params"), + INVALID_TIMESTAMP_PARAMETER(-32602, "Invalid timestamp params"), + INVALID_TRACE_CALL_MANY_PARAMS(-32602, "Invalid trace call many params"), + INVALID_TRACE_NUMBERS_PARAMS(-32602, "Invalid trace numbers params"), + INVALID_TRACE_TYPE_PARAMS(-32602, "Invalid trace type params"), + INVALID_TRANSACTION_PARAMS(-32602, "Invalid transaction params (missing or incorrect)"), + INVALID_TRANSACTION_HASH_PARAMS(-32602, "Invalid transaction hash params"), + INVALID_TRANSACTION_ID_PARAMS(-32602, "Invalid transaction id params"), + INVALID_TRANSACTION_INDEX_PARAMS(-32602, "Invalid transaction index params"), + INVALID_TRANSACTION_LIMIT_PARAMS(-32602, "Invalid transaction limit params"), + INVALID_TRANSACTION_TRACE_PARAMS(-32602, "Invalid transaction trace params"), + INVALID_VERSIONED_HASH_PARAMS(-32602, "Invalid versioned hash params"), + INVALID_VOTE_TYPE_PARAMS(-32602, "Invalid vote type params"), + INVALID_WITHDRAWALS_PARAMS(-32602, "Invalid withdrawals"), + INTERNAL_ERROR(-32603, "Internal error"), TIMEOUT_ERROR(-32603, "Timeout expired"), From 147d58028f9ad17365745e19fa41fb2030849209 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 09:02:38 +1000 Subject: [PATCH 02/13] 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless Signed-off-by: Matilda Clerke --- .../exception/InvalidJsonRpcParameters.java | 10 +++++++++ .../InvalidJsonRpcRequestException.java | 22 +++++++++++++++++++ .../internal/response/RpcErrorType.java | 4 ++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java index 65fe455bd5c..6cf037190d4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java @@ -14,13 +14,23 @@ */ 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 InvalidJsonRpcParameters(final String s) { super(s); } + public InvalidJsonRpcParameters(String message, RpcErrorType rpcErrorType) { + super(message, rpcErrorType); + } + public InvalidJsonRpcParameters(final String message, final Throwable cause) { super(message, cause); } + + public InvalidJsonRpcParameters(String message, RpcErrorType rpcErrorType, Throwable cause) { + super(message, rpcErrorType, cause); + } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcRequestException.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcRequestException.java index 5353439e0b0..7dcda5939c8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcRequestException.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcRequestException.java @@ -14,12 +14,34 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; + public class InvalidJsonRpcRequestException extends IllegalArgumentException { + + private final RpcErrorType rpcErrorType; + public InvalidJsonRpcRequestException(final String 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) { 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; } } 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 fe659dba803..9bbe58b3076 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 @@ -45,7 +45,7 @@ public enum RpcErrorType implements RpcMethodError { INVALID_DATA_PARAMS(-32602, "Invalid data params"), INVALID_DEPOSIT_REQUEST_PARAMS(-32602, "Invalid deposit request"), INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS( - -32602, "Invalid engine exchange transition configuration params"), + -32602, "Invalid engine exchange transition configuration params"), INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS(-32602, "Invalid engine forkchoice updated params"), INVALID_ENGINE_PAYLOAD_ATTRIBUTES_PARAMETER(-32602, "Invalid engine payload attributes params"), INVALID_ENGINE_PAYLOAD_PARAMETER(-32602, "Invalid engine payload params"), @@ -67,7 +67,7 @@ public enum RpcErrorType implements RpcMethodError { INVALID_MIX_HASH_PARAMS(-32602, "Invalid mix hash params"), INVALID_NONCE_PARAMS(-32602, "Invalid nonce params"), INVALID_PARENT_BEACON_BLOCK_ROOT_PARAMS( - -32602, "Invalid parent beacon block root (missing or incorrect)"), + -32602, "Invalid parent beacon block root (missing or incorrect)"), INVALID_PARAM_COUNT(-32602, "Invalid number of params"), INVALID_PAYLOAD_ID_PARAMS(-32602, "Invalid payload id params"), INVALID_PENDING_TRANSACTIONS_PARAMS(-32602, "Invalid pending transactions params"), From 8da4815530978bdabab304f5ba163895d50d4a04 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 11:08:30 +1000 Subject: [PATCH 03/13] 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless Signed-off-by: Matilda Clerke --- .../jsonrpc/internal/exception/InvalidJsonRpcParameters.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java index 6cf037190d4..ea28ca7c4a2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/exception/InvalidJsonRpcParameters.java @@ -22,7 +22,7 @@ public InvalidJsonRpcParameters(final String s) { super(s); } - public InvalidJsonRpcParameters(String message, RpcErrorType rpcErrorType) { + public InvalidJsonRpcParameters(final String message, final RpcErrorType rpcErrorType) { super(message, rpcErrorType); } @@ -30,7 +30,8 @@ public InvalidJsonRpcParameters(final String message, final Throwable cause) { super(message, cause); } - public InvalidJsonRpcParameters(String message, RpcErrorType rpcErrorType, Throwable cause) { + public InvalidJsonRpcParameters( + final String message, final RpcErrorType rpcErrorType, final Throwable cause) { super(message, rpcErrorType, cause); } } From 8ca34d76a5a2c75a1127f5b31faa3462428504ac Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 13:48:44 +1000 Subject: [PATCH 04/13] 5098: Add JsonRpcParameterException for later use Signed-off-by: Matilda Clerke --- .../internal/parameters/JsonRpcParameter.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java index 6e10b7a2316..da919a1830b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java @@ -40,6 +40,7 @@ public class JsonRpcParameter { * @param The type of parameter. * @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 required(final Object[] params, final int index, final Class paramClass) { return optional(params, index, paramClass) .orElseThrow( @@ -58,6 +59,7 @@ public T required(final Object[] params, final int index, final Class par * @param The type of parameter. * @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") public Optional optional( final Object[] params, final int index, final Class paramClass) { @@ -87,6 +89,7 @@ public Optional optional( return Optional.of(param); } + //TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to handle it to supply appropriate context public Optional> optionalList( final Object[] params, final int index, final Class listClass) { if (params == null || params.length <= index || params[index] == null) { @@ -108,4 +111,14 @@ public Optional> optionalList( } 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); + } + } } From 5b5631a0381184619e32555081ae5fa7ab2f79e9 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 14:50:48 +1000 Subject: [PATCH 05/13] 5098: Update locations for RpcErrorType.INVALID_ACCOUNTS_PARAMS Signed-off-by: Matilda Clerke --- .../permissioning/PermAddAccountsToAllowlist.java | 10 +++++++++- .../PermRemoveAccountsFromAllowlist.java | 11 ++++++++++- .../permissioning/PermAddAccountsToAllowlistTest.java | 3 +-- .../PermRemoveAccountsFromAllowlistTest.java | 3 +-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java index 21898c79ede..9b21db59c21 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java @@ -16,7 +16,9 @@ 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.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -44,7 +46,13 @@ public String getName() { @Override @SuppressWarnings("unchecked") public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final List accountsList = requestContext.getRequiredParameter(0, List.class); + final List accountsList; + try { + accountsList = requestContext.getRequiredParameter(0, List.class); + } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNTS_PARAMS, e); + } if (allowlistController.isPresent()) { final AllowlistOperationResult addResult = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java index aefd69141d5..688bec0e9ad 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java @@ -16,7 +16,9 @@ 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.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -44,7 +46,14 @@ public String getName() { @Override @SuppressWarnings("unchecked") public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final List accountsList = requestContext.getRequiredParameter(0, List.class); + final List accountsList; + try { + accountsList = requestContext.getRequiredParameter(0, List.class); + } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNTS_PARAMS, e); + } + if (allowlistController.isPresent()) { final AllowlistOperationResult removeResult = allowlistController.get().removeAccounts(accountsList); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java index 0892cc5c647..a37db420a14 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java @@ -124,9 +124,8 @@ public void whenEmptyParamOnRequestShouldThrowInvalidJsonRpcException() { final Throwable thrown = catchThrowable(() -> method.response(request)); assertThat(thrown) - .hasNoCause() .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid accounts list parameter"); } private JsonRpcRequestContext request(final List accounts) { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlistTest.java index a70ac9e4b3a..2e8218752e6 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlistTest.java @@ -125,9 +125,8 @@ public void whenEmptyParamOnRequestShouldThrowInvalidJsonRpcException() { final Throwable thrown = catchThrowable(() -> method.response(request)); assertThat(thrown) - .hasNoCause() .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid accounts list parameter"); } private JsonRpcRequestContext request(final List accounts) { From 950117bc43b9da6c59f71bd69b6a453acf04ca30 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 15:10:06 +1000 Subject: [PATCH 06/13] 5098: Address review comments, apply spotless Signed-off-by: Matilda Clerke --- .../execution/TracedJsonRpcProcessor.java | 12 +- .../internal/parameters/JsonRpcParameter.java | 9 +- .../internal/response/RpcErrorType.java | 149 ++++++++++-------- .../plugin/services/rpc/RpcMethodError.java | 2 + 4 files changed, 95 insertions(+), 77 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 375e824c10f..d52ac9253d5 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 @@ -57,7 +57,7 @@ public JsonRpcResponse process( this.rpcErrorsCounter.labels(method.getName(), errorResponse.getErrorType().name()).inc(); switch (errorResponse.getErrorType()) { case INVALID_PARAMS: - case INVALID_ACCOUNTS_PARAMS: + case INVALID_ACCOUNT_PARAMS: case INVALID_ADDRESS_HASH_PARAMS: case INVALID_ADDRESS_PARAMS: case INVALID_AUTH_PARAMS: @@ -75,9 +75,9 @@ 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_PARAMETER: - case INVALID_ENGINE_PAYLOAD_PARAMETER: - case INVALID_ENGINE_PREPARE_PAYLOAD_PARAMETER: + 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: @@ -105,12 +105,12 @@ public JsonRpcResponse process( case INVALID_PRIVATE_FROM_PARAMS: case INVALID_PRIVATE_FOR_PARAMS: case INVALID_REMOTE_CAPABILITIES_PARAMS: - case INVALID_REWARD_PERCENTILES_PARAMETER: + 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_PARAMETER: + case INVALID_TIMESTAMP_PARAMS: case INVALID_TRACE_CALL_MANY_PARAMS: case INVALID_TRACE_NUMBERS_PARAMS: case INVALID_TRACE_TYPE_PARAMS: diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java index da919a1830b..a8b5fb7dc8a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonRpcParameter.java @@ -40,7 +40,8 @@ public class JsonRpcParameter { * @param The type of parameter. * @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 + // TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to + // handle it to supply appropriate context public T required(final Object[] params, final int index, final Class paramClass) { return optional(params, index, paramClass) .orElseThrow( @@ -59,7 +60,8 @@ public T required(final Object[] params, final int index, final Class par * @param The type of parameter. * @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 + // TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to + // handle it to supply appropriate context @SuppressWarnings("unchecked") public Optional optional( final Object[] params, final int index, final Class paramClass) { @@ -89,7 +91,8 @@ public Optional optional( return Optional.of(param); } - //TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to handle it to supply appropriate context + // TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to + // handle it to supply appropriate context public Optional> optionalList( final Object[] params, final int index, final Class listClass) { if (params == null || params.length <= index || params[index] == null) { 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 9bbe58b3076..309fe498627 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 @@ -27,75 +27,89 @@ public enum RpcErrorType implements RpcMethodError { INVALID_REQUEST(-32600, "Invalid Request"), METHOD_NOT_FOUND(-32601, "Method not found"), - INVALID_PARAMS(-32602, "Invalid params"), - INVALID_ACCOUNTS_PARAMS(-32602, "Invalid accounts params"), - INVALID_ADDRESS_HASH_PARAMS(-32602, "Invalid address hash params"), - INVALID_ADDRESS_PARAMS(-32602, "Invalid address params"), - INVALID_AUTH_PARAMS(-32602, "Invalid auth params"), - INVALID_BLOB_COUNT(-32602, "Invalid blob count (blob transactions must have at least one blob)"), - INVALID_BLOB_GAS_USED_PARAMS(-32602, "Invalid blob gas used param (missing or invalid)"), - INVALID_BLOCK_PARAMS(-32602, "Invalid block, unable to parse RLP"), - INVALID_BLOCK_COUNT_PARAMS(-32602, "Invalid block count params"), - INVALID_BLOCK_HASH_PARAMS(-32602, "Invalid block hash params"), - INVALID_BLOCK_INDEX_PARAMS(-32602, "Invalid block index params"), - INVALID_BLOCK_NUMBER_PARAMS(-32602, "Invalid block number params"), - INVALID_CALL_PARAMS(-32602, "Invalid call params"), - INVALID_CONSOLIDATION_REQUEST_PARAMS(-32602, "Invalid consolidation request params"), - INVALID_CREATE_PRIVACY_GROUP_PARAMS(-32602, "Invalid create privacy group params"), - INVALID_DATA_PARAMS(-32602, "Invalid data params"), - INVALID_DEPOSIT_REQUEST_PARAMS(-32602, "Invalid deposit request"), + 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( - -32602, "Invalid engine exchange transition configuration params"), - INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS(-32602, "Invalid engine forkchoice updated params"), - INVALID_ENGINE_PAYLOAD_ATTRIBUTES_PARAMETER(-32602, "Invalid engine payload attributes params"), - INVALID_ENGINE_PAYLOAD_PARAMETER(-32602, "Invalid engine payload params"), - INVALID_ENGINE_PREPARE_PAYLOAD_PARAMETER(-32602, "Invalid engine prepare payload parameter"), - INVALID_ENODE_PARAMS(-32602, "Invalid enode params"), - INVALID_EXCESS_BLOB_GAS_PARAMS(-32602, "Invalid excess blob gas params (missing or invalid)"), - INVALID_EXTRA_DATA_PARAMS(-32602, "Invalid extra data params"), - INVALID_FILTER_PARAMS(-32602, "Invalid filter params"), - INVALID_GAS_PRICE_PARAMS(-32602, "Invalid gas price params"), - INVALID_HASH_RATE_PARAMS(-32602, "Invalid hash rate params"), - INVALID_ID_PARAMS(-32602, "Invalid ID params"), - INVALID_IS_TRANSACTION_COMPLETE_PARAMS(-32602, "Invalid is transaction complete params"), - INVALID_LOG_FILTER_PARAMS(-32602, "Invalid log filter params"), - INVALID_LOG_LEVEL_PARAMS(-32602, "Invalid log level params (missing or incorrect)"), - INVALID_MAX_RESULTS_PARAMS(-32602, "Invalid max results params"), - INVALID_METHOD_PARAMS(-32602, "Invalid method params"), - INVALID_MIN_GAS_PRICE_PARAMS(-32602, "Invalid min gas price params"), - INVALID_MIN_PRIORITY_FEE_PARAMS(-32602, "Invalid min priority fee params"), - INVALID_MIX_HASH_PARAMS(-32602, "Invalid mix hash params"), - INVALID_NONCE_PARAMS(-32602, "Invalid nonce 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( - -32602, "Invalid parent beacon block root (missing or incorrect)"), - INVALID_PARAM_COUNT(-32602, "Invalid number of params"), - INVALID_PAYLOAD_ID_PARAMS(-32602, "Invalid payload id params"), - INVALID_PENDING_TRANSACTIONS_PARAMS(-32602, "Invalid pending transactions params"), - INVAlID_PLUGIN_NAME_PARAMS(-32602, "Invalid plug in name params"), - INVALID_POSITION_PARAMS(-32602, "Invalid position params"), - INVALID_POW_HASH_PARAMS(-32602, "Invalid pow hash params"), - INVALID_PRIVACY_GROUP_PARAMS(-32602, "Invalid privacy group params"), - INVALID_PRIVATE_FROM_PARAMS(-32602, "Invalid private from params"), - INVALID_PRIVATE_FOR_PARAMS(-32602, "Invalid private for params"), - INVALID_REMOTE_CAPABILITIES_PARAMS(-32602, "Invalid remote capabilities params"), - INVALID_REWARD_PERCENTILES_PARAMETER(-32602, "Invalid reward percentiles params"), - INVALID_SEALER_ID_PARAMS(-32602, "Invalid sealer ID params"), - INVALID_STORAGE_KEYS_PARAMS(-32602, "Invalid storage keys params"), - INVALID_SUBSCRIPTION_PARAMS(-32602, "Invalid subscription params"), - INVALID_TARGET_GAS_LIMIT_PARAMS(-32602, "Invalid target gas limit params"), - INVALID_TIMESTAMP_PARAMETER(-32602, "Invalid timestamp params"), - INVALID_TRACE_CALL_MANY_PARAMS(-32602, "Invalid trace call many params"), - INVALID_TRACE_NUMBERS_PARAMS(-32602, "Invalid trace numbers params"), - INVALID_TRACE_TYPE_PARAMS(-32602, "Invalid trace type params"), - INVALID_TRANSACTION_PARAMS(-32602, "Invalid transaction params (missing or incorrect)"), - INVALID_TRANSACTION_HASH_PARAMS(-32602, "Invalid transaction hash params"), - INVALID_TRANSACTION_ID_PARAMS(-32602, "Invalid transaction id params"), - INVALID_TRANSACTION_INDEX_PARAMS(-32602, "Invalid transaction index params"), - INVALID_TRANSACTION_LIMIT_PARAMS(-32602, "Invalid transaction limit params"), - INVALID_TRANSACTION_TRACE_PARAMS(-32602, "Invalid transaction trace params"), - INVALID_VERSIONED_HASH_PARAMS(-32602, "Invalid versioned hash params"), - INVALID_VOTE_TYPE_PARAMS(-32602, "Invalid vote type params"), - INVALID_WITHDRAWALS_PARAMS(-32602, "Invalid withdrawals"), + 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"), TIMEOUT_ERROR(-32603, "Timeout expired"), @@ -301,7 +315,6 @@ public enum RpcErrorType implements RpcMethodError { UNKNOWN(-32603, "Unknown internal error"), INVALID_BLOBS(-32603, "blobs failed kzg validation"); - private final int code; private final String message; private final Function> dataDecoder; diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java index b8d6791ecec..26f11df5e81 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java @@ -23,6 +23,8 @@ */ public interface RpcMethodError { + static final int INVALID_PARAMS_ERROR_CODE = -32602; + /** * Retrieves the error code associated with the RPC error. * From 7fc2c2bc383b43c029d6d8e68cc76c8409729188 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 15:14:44 +1000 Subject: [PATCH 07/13] 5098: Update with changes from branch 1 Signed-off-by: Matilda Clerke --- .../methods/permissioning/PermAddAccountsToAllowlist.java | 2 +- .../methods/permissioning/PermRemoveAccountsFromAllowlist.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java index 9b21db59c21..d2ad041a6db 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java @@ -51,7 +51,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { accountsList = requestContext.getRequiredParameter(0, List.class); } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNTS_PARAMS, e); + "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); } if (allowlistController.isPresent()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java index 688bec0e9ad..bc22830c0d7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java @@ -51,7 +51,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { accountsList = requestContext.getRequiredParameter(0, List.class); } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNTS_PARAMS, e); + "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); } if (allowlistController.isPresent()) { From 5acb2d7d882dae47bb79df98394b1e4fdbede163 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 15:33:55 +1000 Subject: [PATCH 08/13] 5098: apply spotless Signed-off-by: Matilda Clerke --- .../methods/permissioning/PermAddAccountsToAllowlist.java | 5 ++--- .../permissioning/PermRemoveAccountsFromAllowlist.java | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java index d2ad041a6db..407edcd8fe4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java @@ -18,7 +18,6 @@ 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.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -49,9 +48,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final List accountsList; try { accountsList = requestContext.getRequiredParameter(0, List.class); - } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); + "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); } if (allowlistController.isPresent()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java index bc22830c0d7..bd0176dbd3f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java @@ -18,7 +18,6 @@ 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.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -49,9 +48,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final List accountsList; try { accountsList = requestContext.getRequiredParameter(0, List.class); - } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); + "Invalid accounts list parameter", RpcErrorType.INVALID_ACCOUNT_PARAMS, e); } if (allowlistController.isPresent()) { From 0d4a9b32fca49a8582515221a8458b5911393971 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 16:12:45 +1000 Subject: [PATCH 09/13] 5098: Update plugin-api gradle hash Signed-off-by: Matilda Clerke --- plugin-api/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 0d593b1105f..8895b8ecb6e 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -70,7 +70,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'oPsVhFhdIkzHqD+jjwRX7dbgeNeKbpCmPjiBWDdMV7o=' + knownHash = 'u2Tr4YiyhfOKhAp+5foXYpKdc0o9PPG7e0X0DV7gNCk=' } check.dependsOn('checkAPIChanges') From 9ba006b7dbf0166a1652fd4f18aed8b6541bae9c Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 16:41:48 +1000 Subject: [PATCH 10/13] 5098: Add comment on INVALID_PARAMS_ERROR_CODE Signed-off-by: Matilda Clerke --- plugin-api/build.gradle | 2 +- .../hyperledger/besu/plugin/services/rpc/RpcMethodError.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 8895b8ecb6e..37ab56011ed 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -70,7 +70,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'u2Tr4YiyhfOKhAp+5foXYpKdc0o9PPG7e0X0DV7gNCk=' + knownHash = 'N6ap3z6ZYo4F5CKm0LHvNdwxVZA6J1cpC5lM3nVV8Ek=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java index 26f11df5e81..f8ad79acaf7 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java @@ -23,6 +23,9 @@ */ public interface RpcMethodError { + /** + * The error code for all invalid params + */ static final int INVALID_PARAMS_ERROR_CODE = -32602; /** From 531c530cedf7dc614f323a859a71727fdaee20a4 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 16:45:50 +1000 Subject: [PATCH 11/13] 5098: Apply spotless on latest changes Signed-off-by: Matilda Clerke --- plugin-api/build.gradle | 2 +- .../hyperledger/besu/plugin/services/rpc/RpcMethodError.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 37ab56011ed..c7203e2f883 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -70,7 +70,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'N6ap3z6ZYo4F5CKm0LHvNdwxVZA6J1cpC5lM3nVV8Ek=' + knownHash = 'o0IuPVpCvE3YUzuZgVf4NP74q1ECpkbAkeC6u/Nr8yU=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java index f8ad79acaf7..efba770701f 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java @@ -23,9 +23,7 @@ */ public interface RpcMethodError { - /** - * The error code for all invalid params - */ + /** The error code for all invalid params */ static final int INVALID_PARAMS_ERROR_CODE = -32602; /** From 728ab2c47ce08d773099ecca61f661493773c406 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 09:50:35 +1000 Subject: [PATCH 12/13] 5098: Fix broken unit test Signed-off-by: Matilda Clerke --- .../permissioning/PermRemoveAccountsFromWhitelistTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java index 934329052dc..582ef1d32ac 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java @@ -126,9 +126,8 @@ public void whenEmptyParamOnRequestShouldThrowInvalidJsonRpcException() { final Throwable thrown = catchThrowable(() -> method.response(request)); assertThat(thrown) - .hasNoCause() .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid accounts list parameter"); } private JsonRpcRequestContext request(final List accounts) { From 0fb6919814e7e80fb67e4bb210361900eee2a9f5 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 10:28:26 +1000 Subject: [PATCH 13/13] 5098: Fix broken unit test Signed-off-by: Matilda Clerke --- .../methods/permissioning/PermAddAccountsToWhitelistTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java index 0dd4fb73d46..d07beb934f2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java @@ -125,9 +125,8 @@ public void whenEmptyParamOnRequestShouldThrowInvalidJsonRpcException() { final Throwable thrown = catchThrowable(() -> method.response(request)); assertThat(thrown) - .hasNoCause() .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid accounts list parameter"); } private JsonRpcRequestContext request(final List accounts) {