From e41cf313c4991911ded7bfb8283443e50a11bbbf Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 08:54:08 +1000 Subject: [PATCH 01/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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/56] 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 a54a5aa90837b43ac417c5280d483b2a265899cc Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 15:27:46 +1000 Subject: [PATCH 08/56] 5098: Update code to use RpcErrorType.INVALID_ADDRESS_HASH_PARAMS Signed-off-by: Matilda Clerke --- .../jsonrpc/internal/methods/DebugAccountRange.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java index 4ca5cb0685f..f48e839e044 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java @@ -17,9 +17,12 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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.DebugAccountRangeAtResult; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -58,7 +61,13 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final BlockParameterOrBlockHash blockParameterOrBlockHash = requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); - final String addressHash = requestContext.getRequiredParameter(2, String.class); + final String addressHash; + try { + addressHash = requestContext.getRequiredParameter(2, String.class); + } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address hash parameter", RpcErrorType.INVALID_ADDRESS_HASH_PARAMS, e); + } final int maxResults = requestContext.getRequiredParameter(3, Integer.TYPE); final Optional blockHashOptional = hashFromParameter(blockParameterOrBlockHash); From 5acb2d7d882dae47bb79df98394b1e4fdbede163 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 15:33:55 +1000 Subject: [PATCH 09/56] 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 afb8860e8f881887adf355168797e8a953c0e82e Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 15:47:51 +1000 Subject: [PATCH 10/56] 5098: apply spotless Signed-off-by: Matilda Clerke --- .../api/jsonrpc/internal/methods/DebugAccountRange.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java index f48e839e044..47fe7738b9d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java @@ -19,7 +19,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -64,9 +63,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final String addressHash; try { addressHash = requestContext.getRequiredParameter(2, String.class); - } catch (Exception e) { //TODO:replace with JsonRpcParameter.JsonRpcParameterException + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address hash parameter", RpcErrorType.INVALID_ADDRESS_HASH_PARAMS, e); + "Invalid address hash parameter", RpcErrorType.INVALID_ADDRESS_HASH_PARAMS, e); } final int maxResults = requestContext.getRequiredParameter(3, Integer.TYPE); From 0d4a9b32fca49a8582515221a8458b5911393971 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 30 Jul 2024 16:12:45 +1000 Subject: [PATCH 11/56] 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 12/56] 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 13/56] 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 6fc67ee258ca858727c20d588a1b57a25f2f3908 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 09:32:04 +1000 Subject: [PATCH 14/56] 5098: Update code to use RpcErrorType.INVALID_ADDRESS_PARAMS Signed-off-by: Matilda Clerke --- .../clique/jsonrpc/methods/Discard.java | 10 +++++++++- .../clique/jsonrpc/methods/Propose.java | 9 ++++++++- .../clique/jsonrpc/methods/DiscardTest.java | 2 +- .../methods/IbftDiscardValidatorVote.java | 10 +++++++++- .../methods/IbftProposeValidatorVote.java | 10 +++++++++- .../methods/IbftDiscardValidatorVoteTest.java | 4 ++-- .../methods/IbftProposeValidatorVoteTest.java | 4 ++-- .../methods/QbftDiscardValidatorVote.java | 9 ++++++++- .../methods/QbftProposeValidatorVote.java | 9 ++++++++- .../methods/QbftDiscardValidatorVoteTest.java | 4 ++-- .../methods/QbftProposeValidatorVoteTest.java | 4 ++-- .../internal/methods/DebugAccountAt.java | 9 ++++++++- .../internal/methods/DebugStorageRangeAt.java | 10 +++++++++- .../internal/methods/EthGetBalance.java | 10 +++++++++- .../jsonrpc/internal/methods/EthGetCode.java | 10 +++++++++- .../jsonrpc/internal/methods/EthGetProof.java | 9 ++++++++- .../internal/methods/EthGetStorageAt.java | 10 +++++++++- .../methods/EthGetTransactionCount.java | 18 ++++++++++++++++-- .../methods/miner/MinerSetCoinbase.java | 4 ++++ .../methods/priv/PrivFindPrivacyGroup.java | 10 +++++++++- .../privacy/methods/priv/PrivGetCode.java | 10 +++++++++- .../priv/PrivGetEeaTransactionCount.java | 9 ++++++++- .../methods/priv/PrivGetTransactionCount.java | 9 ++++++++- .../privx/PrivxFindFlexiblePrivacyGroup.java | 10 +++++++++- .../internal/methods/EthGetProofTest.java | 2 +- .../methods/miner/MinerSetCoinbaseTest.java | 2 +- 26 files changed, 177 insertions(+), 30 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java index 4fb3af6cd46..9354d506d4b 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java @@ -20,9 +20,11 @@ import org.hyperledger.besu.datatypes.Address; 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.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; /** The Discard Json RPC method. */ public class Discard implements JsonRpcMethod { @@ -46,7 +48,13 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { checkState( validatorProvider.getVoteProviderAtHead().isPresent(), "Clique requires a vote provider"); - final Address address = requestContext.getRequiredParameter(0, Address.class); + final Address address; + try { + address = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } validatorProvider.getVoteProviderAtHead().get().discardVote(address); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java index 0e278dee953..9ad5c9c0837 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.datatypes.Address; 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.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -49,7 +50,13 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { checkState( validatorProvider.getVoteProviderAtHead().isPresent(), "Clique requires a vote provider"); - final Address address = requestContext.getRequiredParameter(0, Address.class); + final Address address; + try { + address = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final Boolean auth = requestContext.getRequiredParameter(1, Boolean.class); if (address.equals(CliqueBlockInterface.NO_VOTE_SUBJECT)) { return new JsonRpcErrorResponse( diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java index 038f97e1e74..497677dec76 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java @@ -121,7 +121,7 @@ public void discardWithoutAddress() { final Discard discard = new Discard(validatorProvider); assertThatThrownBy(() -> discard.response(requestWithParams())) - .hasMessage("Missing required json rpc parameter at index 0") + .hasMessage("Invalid address parameter") .isInstanceOf(InvalidJsonRpcParameters.class); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java index 2fdc60c1298..2a12fc34fda 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java @@ -20,9 +20,11 @@ import org.hyperledger.besu.datatypes.Address; 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.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +52,13 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { checkState( validatorProvider.getVoteProviderAtHead().isPresent(), "Ibft requires a vote provider"); - final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class); + final Address validatorAddress; + try { + validatorAddress = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid validator address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } LOG.trace("Received RPC rpcName={} address={}", getName(), validatorAddress); validatorProvider.getVoteProviderAtHead().get().discardVote(validatorAddress); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java index fe89961410e..3e5039e5ccf 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java @@ -21,9 +21,11 @@ import org.hyperledger.besu.datatypes.Address; 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.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +53,13 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { checkState( validatorProvider.getVoteProviderAtHead().isPresent(), "Ibft requires a vote provider"); - final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class); + final Address validatorAddress; + try { + validatorAddress = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final Boolean add = requestContext.getRequiredParameter(1, Boolean.class); LOG.trace( "Received RPC rpcName={} voteType={} address={}", diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java index da0a35ab2fe..7b2408f1838 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java @@ -56,14 +56,14 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid validator address parameter"); } @Test public void exceptionWhenInvalidAddressParameterSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid validator address parameter"); } @Test diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java index d667bb173b4..5e4c254037a 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java @@ -56,7 +56,7 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid address parameter"); } @Test @@ -70,7 +70,7 @@ public void exceptionWhenNoAuthSupplied() { public void exceptionWhenNoAddressSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("true"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid address parameter"); } @Test diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java index 7e9a3b973fd..80becc6f0bc 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Address; 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.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -49,7 +50,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { if (validatorProvider.getVoteProviderAtHead().isPresent()) { - final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class); + final Address validatorAddress; + try { + validatorAddress = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid validator address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } LOG.trace("Received RPC rpcName={} address={}", getName(), validatorAddress); validatorProvider.getVoteProviderAtHead().get().discardVote(validatorAddress); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java index 160ca144d69..0a47766c7be 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.datatypes.Address; 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.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -50,7 +51,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { if (validatorProvider.getVoteProviderAtHead().isPresent()) { - final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class); + final Address validatorAddress; + try { + validatorAddress = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid validator address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final Boolean add = requestContext.getRequiredParameter(1, Boolean.class); LOG.trace( "Received RPC rpcName={} voteType={} address={}", diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java index 0716fd42d20..8c83b91bc94 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java @@ -58,14 +58,14 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid validator address parameter"); } @Test public void exceptionWhenInvalidAddressParameterSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid validator address parameter"); } @Test diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java index fa3f89036eb..e44c9d66dec 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java @@ -58,7 +58,7 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid validator address parameter"); } @Test @@ -72,7 +72,7 @@ public void exceptionWhenNoAuthSupplied() { public void exceptionWhenNoAddressSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("true"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid validator address parameter"); } @Test diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java index f4a56f05eb5..e7c045fffa7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -73,7 +74,13 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( protected Object resultByBlockHash( final JsonRpcRequestContext requestContext, final Hash blockHash) { final Integer txIndex = requestContext.getRequiredParameter(1, Integer.class); - final Address address = requestContext.getRequiredParameter(2, Address.class); + final Address address; + try { + address = requestContext.getRequiredParameter(2, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } Optional> block = blockchainQueries.get().blockByHash(blockHash); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java index 0ea50b41aca..4b93c2af385 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java @@ -18,12 +18,14 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer.TraceableState; 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.DebugStorageRangeAtResult; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -70,7 +72,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final BlockParameterOrBlockHash blockParameterOrBlockHash = requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); final int transactionIndex = requestContext.getRequiredParameter(1, Integer.class); - final Address accountAddress = requestContext.getRequiredParameter(2, Address.class); + final Address accountAddress; + try { + accountAddress = requestContext.getRequiredParameter(2, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid account address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final Hash startKey = Hash.fromHexStringLenient(requestContext.getRequiredParameter(3, String.class)); final int limit = requestContext.getRequiredParameter(4, Integer.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java index 8b658d27530..5572b536d09 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java @@ -18,7 +18,9 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -46,7 +48,13 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( @Override protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { - final Address address = request.getRequiredParameter(0, Address.class); + final Address address; + try { + address = request.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } return blockchainQueries .get() .accountBalance(address, blockHash) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java index 2417b422fa2..ab69e46c46d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java @@ -18,7 +18,9 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import java.util.function.Supplier; @@ -48,7 +50,13 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( @Override protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { - final Address address = request.getRequiredParameter(0, Address.class); + final Address address; + try { + address = request.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } return getBlockchainQueries().getCode(address, blockHash).map(Bytes::toString).orElse(null); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java index 96602e23a97..ee7e2585fdb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -55,7 +56,13 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( protected Object resultByBlockHash( final JsonRpcRequestContext requestContext, final Hash blockHash) { - final Address address = requestContext.getRequiredParameter(0, Address.class); + final Address address; + try { + address = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final List storageKeys = getStorageKeys(requestContext); final Blockchain blockchain = getBlockchainQueries().getBlockchain(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java index e2741233f61..efe87be6de6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java @@ -18,8 +18,10 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UInt256Parameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.apache.tuweni.units.bigints.UInt256; @@ -42,7 +44,13 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( @Override protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { - final Address address = request.getRequiredParameter(0, Address.class); + final Address address; + try { + address = request.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final UInt256 position = request.getRequiredParameter(1, UInt256Parameter.class).getValue(); return blockchainQueries .get() diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java index 053588e89a4..ca4601bdd62 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java @@ -18,7 +18,9 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -55,7 +57,13 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( @Override protected Object pendingResult(final JsonRpcRequestContext request) { - final Address address = request.getRequiredParameter(0, Address.class); + final Address address; + try { + address = request.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final long pendingNonce = transactionPoolSupplier.get().getNextNonceForSender(address).orElse(0); final long latestNonce = @@ -72,7 +80,13 @@ protected Object pendingResult(final JsonRpcRequestContext request) { @Override protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { - final Address address = request.getRequiredParameter(0, Address.class); + final Address address; + try { + address = request.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final long transactionCount = getBlockchainQueries().getTransactionCount(address, blockHash); return Quantity.create(transactionCount); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java index eda085d77c4..9866b2a6b33 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.datatypes.Address; 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.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -46,6 +47,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } catch (final UnsupportedOperationException ex) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVALID_REQUEST); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java index c09e21dc2a2..6f917b09169 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java @@ -19,11 +19,13 @@ import org.hyperledger.besu.enclave.types.PrivacyGroup; 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.privacy.methods.PrivacyIdProvider; 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; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.privacy.MultiTenancyValidationException; import org.hyperledger.besu.ethereum.privacy.PrivacyController; @@ -55,7 +57,13 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { LOG.trace("Executing {}", RpcMethod.PRIV_FIND_PRIVACY_GROUP.getMethodName()); - final String[] addresses = requestContext.getRequiredParameter(0, String[].class); + final String[] addresses; + try { + addresses = requestContext.getRequiredParameter(0, String[].class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameters", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } LOG.trace("Finding a privacy group with members {}", Arrays.toString(addresses)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index b7cafd8cabe..2ba5386b09e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -17,9 +17,11 @@ import org.hyperledger.besu.datatypes.Address; 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.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.privacy.PrivacyController; @@ -53,7 +55,13 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { protected String resultByBlockNumber( final JsonRpcRequestContext request, final long blockNumber) { final String privacyGroupId = request.getRequiredParameter(0, String.class); - final Address address = request.getRequiredParameter(1, Address.class); + final Address address; + try { + address = request.getRequiredParameter(1, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final String privacyUserId = privacyIdProvider.getPrivacyUserId(request.getUser()); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java index 3ec2d87b6aa..2f18ae6d5ff 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.datatypes.Address; 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.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -65,7 +66,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); } - final Address address = requestContext.getRequiredParameter(0, Address.class); + final Address address; + try { + address = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final String privateFrom = requestContext.getRequiredParameter(1, String.class); final String[] privateFor = requestContext.getRequiredParameter(2, String[].class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java index 31cac2b8b3d..3e5e2fa01cd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.datatypes.Address; 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.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -56,7 +57,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); } - final Address address = requestContext.getRequiredParameter(0, Address.class); + final Address address; + try { + address = requestContext.getRequiredParameter(0, Address.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } final String privacyGroupId = requestContext.getRequiredParameter(1, String.class); try { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java index 0275626addd..6d52d11aba0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java @@ -19,11 +19,13 @@ import org.hyperledger.besu.enclave.types.PrivacyGroup; 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.privacy.methods.PrivacyIdProvider; 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; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.privacy.MultiTenancyValidationException; import org.hyperledger.besu.ethereum.privacy.PrivacyController; @@ -54,7 +56,13 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { LOG.trace("Executing {}", RpcMethod.PRIVX_FIND_PRIVACY_GROUP.getMethodName()); - final String[] addresses = requestContext.getRequiredParameter(0, String[].class); + final String[] addresses; + try { + addresses = requestContext.getRequiredParameter(0, String[].class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid address parameters", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + } LOG.trace("Finding a privacy group with members {}", Arrays.toString(addresses)); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java index 2106b86744d..7f0d5657300 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java @@ -111,7 +111,7 @@ void errorWhenNoAddressAccountSupplied() { Assertions.assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Missing required json rpc parameter at index 0"); + .hasMessageContaining("Invalid address parameter"); } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java index a50a9576b08..b34ff91080c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java @@ -62,7 +62,7 @@ public void shouldFailWhenMissingAddress() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid address parameter"); } @Test From 728ab2c47ce08d773099ecca61f661493773c406 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 09:50:35 +1000 Subject: [PATCH 15/56] 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 16/56] 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) { From 9f53648ba67beae93adca461fa23b2b0549eb7d3 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 12:42:38 +1000 Subject: [PATCH 17/56] 5098: Update with usage of RpcErrorType.INVALID_AUTH_PARAMS Signed-off-by: Matilda Clerke --- .../besu/consensus/clique/jsonrpc/methods/Propose.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java index 9ad5c9c0837..9b69b6cbbf4 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java @@ -57,7 +57,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { throw new InvalidJsonRpcParameters( "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } - final Boolean auth = requestContext.getRequiredParameter(1, Boolean.class); + final Boolean auth; + try { + auth = requestContext.getRequiredParameter(1, Boolean.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid auth parameter", RpcErrorType.INVALID_AUTH_PARAMS, e); + } if (address.equals(CliqueBlockInterface.NO_VOTE_SUBJECT)) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVALID_REQUEST); From 3cfe6ddac8712060e47ea29249ea87fdcb46d37d Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 13:35:25 +1000 Subject: [PATCH 18/56] 5098: Update with usage of RpcErrorType.INVALID_BLOB_COUNT Signed-off-by: Matilda Clerke --- .../internal/methods/engine/AbstractEngineNewPayload.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 543c965c804..68adb2ab69c 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 @@ -466,7 +466,7 @@ protected ValidationResult validateBlobs( // blob transactions must have at least one blob if (versionedHashes.isEmpty()) { return ValidationResult.invalid( - RpcErrorType.INVALID_PARAMS, "There must be at least one blob"); + RpcErrorType.INVALID_BLOB_COUNT, "There must be at least one blob"); } transactionVersionedHashes.addAll(versionedHashes.get()); } @@ -505,7 +505,7 @@ protected ValidationResult validateBlobs( if (protocolSpec.getGasCalculator().blobGasCost(transactionVersionedHashes.size()) > protocolSpec.getGasLimitCalculator().currentBlobGasLimit()) { return ValidationResult.invalid( - RpcErrorType.INVALID_PARAMS, + RpcErrorType.INVALID_BLOB_COUNT, String.format("Invalid Blob Count: %d", transactionVersionedHashes.size())); } return ValidationResult.valid(); From 74148430c221358a77d0331a2079a68e97e0167b Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 14:25:09 +1000 Subject: [PATCH 19/56] 5098: Update with usage of RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS Signed-off-by: Matilda Clerke --- .../internal/methods/engine/AbstractEngineNewPayload.java | 2 +- .../internal/methods/engine/EngineNewPayloadV2.java | 2 +- .../internal/methods/engine/EngineNewPayloadV3.java | 5 ++++- .../internal/methods/engine/EngineNewPayloadV4.java | 8 ++++++-- .../internal/methods/engine/EngineNewPayloadV2Test.java | 5 +++-- .../internal/methods/engine/EngineNewPayloadV3Test.java | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) 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 68adb2ab69c..c548507710d 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 @@ -497,7 +497,7 @@ protected ValidationResult validateBlobs( if (header.getBlobGasUsed().isPresent() && maybeVersionedHashes.isPresent()) { if (!validateBlobGasUsed(header, maybeVersionedHashes.get(), protocolSpec)) { return ValidationResult.invalid( - RpcErrorType.INVALID_PARAMS, + RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Payload BlobGasUsed does not match calculated BlobGasUsed"); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java index 08a6b6b3d0a..640d8dc6036 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java @@ -56,7 +56,7 @@ protected ValidationResult validateParameters( final Optional maybeBeaconBlockRootParam) { if (payloadParameter.getBlobGasUsed() != null) { return ValidationResult.invalid( - RpcErrorType.INVALID_PARAMS, "non-null BlobGasUsed pre-cancun"); + RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field"); } if (payloadParameter.getExcessBlobGas() != null) { return ValidationResult.invalid( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java index 8f7a32899ee..1ca232b7737 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java @@ -55,7 +55,10 @@ protected ValidationResult validateParameters( final EnginePayloadParameter payloadParameter, final Optional> maybeVersionedHashParam, final Optional maybeBeaconBlockRootParam) { - if (payloadParameter.getBlobGasUsed() == null || payloadParameter.getExcessBlobGas() == null) { + if (payloadParameter.getBlobGasUsed() == null) { + return ValidationResult.invalid( + RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field"); + } else if (payloadParameter.getExcessBlobGas() == null) { return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing blob gas fields"); } else if (maybeVersionedHashParam == null || maybeVersionedHashParam.isEmpty()) { return ValidationResult.invalid( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java index 93060821f80..8b073a95552 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java @@ -55,8 +55,12 @@ protected ValidationResult validateParameters( final EnginePayloadParameter payloadParameter, final Optional> maybeVersionedHashParam, final Optional maybeBeaconBlockRootParam) { - if (payloadParameter.getBlobGasUsed() == null || payloadParameter.getExcessBlobGas() == null) { - return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing blob gas fields"); + if (payloadParameter.getBlobGasUsed() == null) { + return ValidationResult.invalid( + RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field"); + } else if (payloadParameter.getExcessBlobGas() == null) { + return ValidationResult.invalid( + RpcErrorType.INVALID_PARAMS, "non-null ExcessBlobGas pre-cancun"); } else if (maybeVersionedHashParam == null || maybeVersionedHashParam.isEmpty()) { return ValidationResult.invalid( RpcErrorType.INVALID_PARAMS, "Missing versioned hashes field"); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java index 412dc6f8927..afee556eda2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameterTestFixture.WITHDRAWAL_PARAM_1; +import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_PARAMS; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; @@ -149,8 +150,8 @@ public void shouldValidateBlobGasUsedCorrectly() { var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null, null, null)); final JsonRpcError jsonRpcError = fromErrorResp(resp); - assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); - assertThat(jsonRpcError.getData()).isEqualTo("non-null BlobGasUsed pre-cancun"); + assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_BLOB_GAS_USED_PARAMS.getCode()); + assertThat(jsonRpcError.getData()).isEqualTo("Missing blob gas used field"); verify(engineCallListener, times(1)).executionEngineCalled(); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java index c19bb8fbcbd..82025888176 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java @@ -198,7 +198,7 @@ public void shouldValidateBlobGasUsedCorrectly() { final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); - assertThat(jsonRpcError.getData()).isEqualTo("Missing blob gas fields"); + assertThat(jsonRpcError.getData()).isEqualTo("Missing blob gas used field"); verify(engineCallListener, times(1)).executionEngineCalled(); } From c3e8d229cff4495ac5a5cf64296dad32cc83e00c Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 16:04:10 +1000 Subject: [PATCH 20/56] 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS Signed-off-by: Matilda Clerke --- .../jsonrpc/methods/CliqueGetSigners.java | 11 ++++++++-- .../IbftGetValidatorsByBlockNumber.java | 10 ++++++++- .../QbftGetValidatorsByBlockNumber.java | 10 ++++++++- .../jsonrpc/internal/DebugReplayBlock.java | 10 ++++++++- .../methods/AbstractTraceByBlock.java | 12 +++++++++-- .../methods/AdminGenerateLogBloomCache.java | 21 +++++++++++++++---- .../internal/methods/DebugAccountAt.java | 8 ++++++- .../internal/methods/DebugAccountRange.java | 11 ++++++++-- .../internal/methods/DebugGetRawBlock.java | 9 +++++++- .../internal/methods/DebugGetRawHeader.java | 9 +++++++- .../internal/methods/DebugGetRawReceipts.java | 10 ++++++++- .../internal/methods/DebugSetHead.java | 10 ++++++++- .../internal/methods/DebugStorageRangeAt.java | 11 ++++++++-- .../internal/methods/DebugTraceBlock.java | 7 ++++++- .../methods/DebugTraceBlockByNumber.java | 10 ++++++++- .../internal/methods/DebugTraceCall.java | 12 +++++++++-- .../api/jsonrpc/internal/methods/EthCall.java | 9 +++++++- .../internal/methods/EthFeeHistory.java | 10 ++++++++- .../internal/methods/EthGetBalance.java | 8 ++++++- .../internal/methods/EthGetBlockByNumber.java | 10 ++++++++- .../internal/methods/EthGetBlockReceipts.java | 10 ++++++++- .../EthGetBlockTransactionCountByNumber.java | 10 ++++++++- .../jsonrpc/internal/methods/EthGetCode.java | 8 ++++++- .../methods/EthGetMinerDataByBlockNumber.java | 10 ++++++++- .../jsonrpc/internal/methods/EthGetProof.java | 8 ++++++- .../internal/methods/EthGetStorageAt.java | 8 ++++++- ...thGetTransactionByBlockNumberAndIndex.java | 10 ++++++++- .../methods/EthGetTransactionCount.java | 8 ++++++- .../EthGetUncleByBlockNumberAndIndex.java | 10 ++++++++- .../methods/EthSendRawTransaction.java | 2 +- .../jsonrpc/internal/methods/TraceBlock.java | 10 ++++++++- .../internal/methods/TraceCallMany.java | 11 ++++++++-- .../methods/TraceReplayBlockTransactions.java | 10 ++++++++- .../privacy/methods/priv/PrivCall.java | 8 ++++++- .../methods/priv/PrivDebugGetStateRoot.java | 9 +++++++- .../privacy/methods/priv/PrivGetCode.java | 8 ++++++- .../api/jsonrpc/JsonRpcHttpServiceTest.java | 2 +- .../methods/EthGetBlockByNumberTest.java | 3 +-- .../methods/EthGetBlockReceiptsTest.java | 2 +- .../EthGetMinerDataByBlockNumberTest.java | 4 ++-- .../internal/methods/EthGetProofTest.java | 2 +- .../EthGetUncleByBlockNumberAndIndexTest.java | 2 +- .../retesteth/methods/TestImportRawBlock.java | 10 ++++++++- 43 files changed, 319 insertions(+), 54 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java index 9f7b2d9f9d5..0127781476d 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java @@ -17,8 +17,10 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; 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.BlockParameter; +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; @@ -67,8 +69,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } private Optional determineBlockHeader(final JsonRpcRequestContext request) { - final Optional blockParameter = - request.getOptionalParameter(0, BlockParameter.class); + final Optional blockParameter; + try { + blockParameter = request.getOptionalParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } final long latest = blockchainQueries.headBlockNumber(); final long blockNumber = blockParameter.map(b -> b.getNumber().orElse(latest)).orElse(latest); return blockchainQueries.blockByNumber(blockNumber).map(BlockWithMetadata::getHeader); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java index 5e36ca2070c..60b76dc4160 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java @@ -17,9 +17,12 @@ import org.hyperledger.besu.consensus.common.BlockInterface; 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.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -50,7 +53,12 @@ public IbftGetValidatorsByBlockNumber( @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java index 804ecc6b5a0..2b08f0caf51 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java @@ -18,9 +18,12 @@ import org.hyperledger.besu.datatypes.Address; 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.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -50,7 +53,12 @@ public QbftGetValidatorsByBlockNumber( @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java index e55a8c4785c..c96b9c1fe72 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java @@ -19,10 +19,13 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +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.JsonRpcSuccessResponse; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; @@ -56,7 +59,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java index 4fd98cd4fed..e89f647ac90 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java @@ -17,9 +17,12 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType; 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TraceCallResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff.StateDiffGenerator; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff.StateDiffTrace; @@ -62,8 +65,13 @@ protected AbstractTraceByBlock( @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - final Optional maybeBlockParameter = - request.getOptionalParameter(2, BlockParameter.class); + final Optional maybeBlockParameter; + try { + maybeBlockParameter = request.getOptionalParameter(2, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } if (maybeBlockParameter.isPresent()) { return maybeBlockParameter.get(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java index fd197110b68..f23c691fdd4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java @@ -16,9 +16,12 @@ 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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.query.BlockchainQueries; import java.util.Optional; @@ -38,8 +41,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional startBlockParam = - requestContext.getOptionalParameter(0, BlockParameter.class); + final Optional startBlockParam; + try { + startBlockParam = requestContext.getOptionalParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid start block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } final long startBlock; if (startBlockParam.isEmpty() || startBlockParam.get().isEarliest()) { startBlock = 0; @@ -50,8 +58,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { startBlock = Long.MAX_VALUE; } - final Optional stopBlockParam = - requestContext.getOptionalParameter(1, BlockParameter.class); + final Optional stopBlockParam; + try { + stopBlockParam = requestContext.getOptionalParameter(1, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid stop block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } final long stopBlock; if (stopBlockParam.isEmpty()) { if (startBlockParam.isEmpty()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java index e7c045fffa7..1f00f2e280f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java @@ -20,6 +20,7 @@ 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; @@ -67,7 +68,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext requestContext) { - return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + try { + return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java index 47fe7738b9d..e11f92c530e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java @@ -19,6 +19,7 @@ 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -58,8 +59,14 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final BlockParameterOrBlockHash blockParameterOrBlockHash = - requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + final BlockParameterOrBlockHash blockParameterOrBlockHash; + try { + blockParameterOrBlockHash = + requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } final String addressHash; try { addressHash = requestContext.getRequiredParameter(2, String.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java index cec275e5a62..eb69704f6a8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.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.parameters.BlockParameter; +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.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -37,7 +39,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java index 05ef0eb53db..d126e103710 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.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.parameters.BlockParameter; +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.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -37,7 +39,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java index 7965480c6fb..d482bf5ac64 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java @@ -17,7 +17,10 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.rlp.RLP; @@ -40,7 +43,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java index 7d26eaca25e..d531930dac7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java @@ -20,9 +20,12 @@ 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.parameters.BlockParameter; +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.JsonRpcSuccessResponse; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import java.util.Optional; @@ -43,7 +46,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java index 4b93c2af385..a1bd9b9bf79 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java @@ -20,6 +20,7 @@ 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer.TraceableState; @@ -69,8 +70,14 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final BlockParameterOrBlockHash blockParameterOrBlockHash = - requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + final BlockParameterOrBlockHash blockParameterOrBlockHash; + try { + blockParameterOrBlockHash = + requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } final int transactionIndex = requestContext.getRequiredParameter(1, Integer.class); final Address accountAddress; try { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java index 3a1dee65608..ac782bafd0a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java @@ -16,6 +16,8 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -71,7 +73,10 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } catch (final RLPException e) { LOG.debug("Failed to parse block RLP", e); return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block params", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final TraceOptions traceOptions = requestContext diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java index 32d0e02f90c..b5a53ca9d3a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java @@ -17,11 +17,14 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.debug.TraceOptions; @@ -47,7 +50,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java index 0243398833e..d892a7d20d0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java @@ -18,11 +18,14 @@ 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.debug.TraceOptions; @@ -61,8 +64,13 @@ protected TraceOptions getTraceOptions(final JsonRpcRequestContext requestContex @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - final Optional maybeBlockParameter = - request.getOptionalParameter(1, BlockParameter.class); + final Optional maybeBlockParameter; + try { + maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } return maybeBlockParameter.orElse(BlockParameter.LATEST); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index c645bab453f..92eb849aff3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -22,8 +22,10 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter; 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.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -57,7 +59,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 6bea493d312..fae387f9067 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -22,7 +22,9 @@ import org.hyperledger.besu.ethereum.api.ApiConfiguration; 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -91,7 +93,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) { if (isInvalidBlockCount(blockCount)) { return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS); } - final BlockParameter highestBlock = request.getRequiredParameter(1, BlockParameter.class); + final BlockParameter highestBlock; + try { + highestBlock = request.getRequiredParameter(1, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid highest block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } final Optional> maybeRewardPercentiles = request.getOptionalParameter(2, Double[].class).map(Arrays::asList); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java index 5572b536d09..55c59b013dd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java @@ -20,6 +20,7 @@ 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -43,7 +44,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java index c1bdcc37dd2..14306ec371b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java @@ -17,7 +17,10 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -62,7 +65,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java index 54a37332860..469e880833a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java @@ -17,7 +17,10 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockReceiptsResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptRootResult; @@ -53,7 +56,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java index b6819c7510d..a8ba018881d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java @@ -16,7 +16,10 @@ 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -33,7 +36,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java index ab69e46c46d..b11b3b91125 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java @@ -20,6 +20,7 @@ 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -45,7 +46,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java index 83ca008890d..8fe3c471a4d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java @@ -17,7 +17,10 @@ import org.hyperledger.besu.datatypes.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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -40,7 +43,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java index ee7e2585fdb..c66edfd030a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java @@ -20,6 +20,7 @@ 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.parameters.BlockParameterOrBlockHash; +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,7 +50,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java index efe87be6de6..dc562876ef4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java @@ -20,6 +20,7 @@ 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UInt256Parameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -39,7 +40,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java index ab08127ca79..8e865e604f1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java @@ -16,8 +16,11 @@ 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionCompleteResult; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; @@ -37,7 +40,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java index ca4601bdd62..ac11e14dd60 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java @@ -20,6 +20,7 @@ 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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -52,7 +53,12 @@ public String getName() { @Override protected BlockParameterOrBlockHash blockParameterOrBlockHash( final JsonRpcRequestContext request) { - return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + try { + return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java index 2687982b8e3..7a1575e1291 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java @@ -16,8 +16,11 @@ 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.UncleBlockResult; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -35,7 +38,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java index 5fbfc80a988..8e43718df11 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java @@ -86,7 +86,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } catch (final RLPException e) { LOG.debug("RLPException: {} caused by {}", e.getMessage(), e.getCause()); return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); } catch (final InvalidJsonRpcRequestException i) { LOG.debug("InvalidJsonRpcRequestException: {} caused by {}", i.getMessage(), i.getCause()); return new JsonRpcErrorResponse( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java index cd78d837dfa..47e8803dfab 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java @@ -18,10 +18,13 @@ 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.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTraceGenerator; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.RewardTraceGenerator; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -68,7 +71,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 3e3b0c9343c..2510190e2a4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -19,8 +19,10 @@ 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.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceCallManyParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; @@ -63,8 +65,13 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - final Optional maybeBlockParameter = - request.getOptionalParameter(1, BlockParameter.class); + final Optional maybeBlockParameter; + try { + maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } return maybeBlockParameter.orElse(BlockParameter.LATEST); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java index 058fbd47960..a17ab700b9c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java @@ -18,11 +18,14 @@ 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.TraceBlock.ChainUpdater; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TraceReplayResult; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper; @@ -70,7 +73,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(0, BlockParameter.class); + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index 31469530b09..d08ecfd8989 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -53,7 +54,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(2, BlockParameter.class); + try { + return request.getRequiredParameter(2, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java index 6ccc9630f96..d0adce7cd4d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java @@ -20,8 +20,10 @@ import org.hyperledger.besu.enclave.types.PrivacyGroup; 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.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -60,7 +62,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(1, BlockParameter.class); + try { + return request.getRequiredParameter(1, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index 2ba5386b09e..4f51d8bfcad 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -48,7 +49,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - return request.getRequiredParameter(2, BlockParameter.class); + try { + return request.getRequiredParameter(2, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java index 7c3157d2231..96b9b9f7793 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java @@ -980,7 +980,7 @@ public void getBlockByNumberForInvalidBlockParameter() throws Exception { // Check general format of result final String respBody = resp.body().string(); final JsonObject json = new JsonObject(respBody); - final RpcErrorType expectedError = RpcErrorType.INVALID_PARAMS; + final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_PARAMS; testHelper.assertValidJsonRpcError( json, id, expectedError.getCode(), expectedError.getMessage()); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java index b12cdbe22fd..587288d6b79 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java @@ -129,8 +129,7 @@ public void exceptionWhenNoBoolSupplied() { public void exceptionWhenNumberParamInvalid() { assertThatThrownBy(() -> method.response(requestWithParams("invalid", "true"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage( - "Invalid json rpc parameter at index 0. Supplied value was: 'invalid' of type: 'java.lang.String' - expected type: 'org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter'"); + .hasMessage("Invalid block parameter"); verifyNoMoreInteractions(blockchainQueries); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java index 5e8ad1455d8..d2dbc648a17 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java @@ -100,7 +100,7 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid block or block hash parameters"); verifyNoMoreInteractions(blockchainQueries); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumberTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumberTest.java index ca65fcf42ab..e91d067bb1f 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumberTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumberTest.java @@ -103,7 +103,7 @@ public void exceptionWhenNoNumberSuppliedTest() { JsonRpcRequestContext requestContext = new JsonRpcRequestContext(request); assertThatThrownBy(() -> method.response(requestContext)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid block parameter"); verifyNoMoreInteractions(blockchainQueries); } @@ -114,7 +114,7 @@ public void exceptionWhenNumberParamInvalidTest() { JsonRpcRequestContext requestContext = new JsonRpcRequestContext(request); assertThatThrownBy(() -> method.response(requestContext)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid block parameter"); verifyNoMoreInteractions(blockchainQueries); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java index 7f0d5657300..81bb41e2092 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java @@ -129,7 +129,7 @@ void errorWhenNoBlockNumberSupplied() { Assertions.assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Missing required json rpc parameter at index 2"); + .hasMessageContaining("Invalid block or block hash parameter"); } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java index 59b20d58466..cfcb127036f 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java @@ -79,7 +79,7 @@ public void shouldReturnErrorWhenMissingBlockNumberParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid block parameter"); } @Test diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java index 0652b92cdbf..5d5d22c3f66 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java @@ -16,7 +16,9 @@ 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.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; @@ -52,7 +54,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final String input = requestContext.getRequiredParameter(0, String.class); + final String input; + try { + input = requestContext.getRequiredParameter(0, String.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } final ProtocolContext protocolContext = this.context.getProtocolContext(); final Block block; From 75dff8fda25d6f15aaee3c1da27f56ffc801374f Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 16:11:53 +1000 Subject: [PATCH 21/56] 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS Signed-off-by: Matilda Clerke --- .../consensus/clique/jsonrpc/methods/CliqueGetSigners.java | 3 +-- .../ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java | 3 +-- .../besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java | 3 +-- .../api/jsonrpc/internal/methods/AbstractTraceByBlock.java | 3 +-- .../jsonrpc/internal/methods/AdminGenerateLogBloomCache.java | 5 ++--- .../api/jsonrpc/internal/methods/DebugAccountAt.java | 3 +-- .../api/jsonrpc/internal/methods/DebugAccountRange.java | 5 ++--- .../api/jsonrpc/internal/methods/DebugGetRawBlock.java | 3 +-- .../api/jsonrpc/internal/methods/DebugGetRawHeader.java | 3 +-- .../api/jsonrpc/internal/methods/DebugGetRawReceipts.java | 3 +-- .../ethereum/api/jsonrpc/internal/methods/DebugSetHead.java | 3 +-- .../api/jsonrpc/internal/methods/DebugStorageRangeAt.java | 5 ++--- .../api/jsonrpc/internal/methods/DebugTraceBlock.java | 5 ++--- .../jsonrpc/internal/methods/DebugTraceBlockByNumber.java | 3 +-- .../api/jsonrpc/internal/methods/DebugTraceCall.java | 3 +-- .../besu/ethereum/api/jsonrpc/internal/methods/EthCall.java | 3 +-- .../ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java | 3 +-- .../ethereum/api/jsonrpc/internal/methods/EthGetBalance.java | 3 +-- .../api/jsonrpc/internal/methods/EthGetBlockByNumber.java | 3 +-- .../api/jsonrpc/internal/methods/EthGetBlockReceipts.java | 3 +-- .../methods/EthGetBlockTransactionCountByNumber.java | 3 +-- .../ethereum/api/jsonrpc/internal/methods/EthGetCode.java | 3 +-- .../internal/methods/EthGetMinerDataByBlockNumber.java | 3 +-- .../ethereum/api/jsonrpc/internal/methods/EthGetProof.java | 3 +-- .../api/jsonrpc/internal/methods/EthGetStorageAt.java | 3 +-- .../methods/EthGetTransactionByBlockNumberAndIndex.java | 3 +-- .../api/jsonrpc/internal/methods/EthGetTransactionCount.java | 3 +-- .../internal/methods/EthGetUncleByBlockNumberAndIndex.java | 3 +-- .../api/jsonrpc/internal/methods/EthSendRawTransaction.java | 2 +- .../api/jsonrpc/internal/privacy/methods/priv/PrivCall.java | 3 +-- .../internal/privacy/methods/priv/PrivDebugGetStateRoot.java | 3 +-- 31 files changed, 35 insertions(+), 65 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java index 0127781476d..0762deac2ee 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java @@ -20,7 +20,6 @@ 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.BlockParameter; -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; @@ -74,7 +73,7 @@ private Optional determineBlockHeader(final JsonRpcRequestContext r blockParameter = request.getOptionalParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final long latest = blockchainQueries.headBlockNumber(); final long blockNumber = blockParameter.map(b -> b.getNumber().orElse(latest)).orElse(latest); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java index 60b76dc4160..c7f70764d75 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -57,7 +56,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java index c96b9c1fe72..9e4cc668137 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; -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.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -63,7 +62,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java index e89f647ac90..91bc305ba4a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java @@ -19,7 +19,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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -70,7 +69,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { maybeBlockParameter = request.getOptionalParameter(2, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } if (maybeBlockParameter.isPresent()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java index f23c691fdd4..e6c262e3fd6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -46,7 +45,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { startBlockParam = requestContext.getOptionalParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid start block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid start block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final long startBlock; if (startBlockParam.isEmpty() || startBlockParam.get().isEarliest()) { @@ -63,7 +62,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { stopBlockParam = requestContext.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid stop block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid stop block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final long stopBlock; if (stopBlockParam.isEmpty()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java index 1f00f2e280f..bd164e600e9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java @@ -20,7 +20,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; @@ -72,7 +71,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java index e11f92c530e..12a81c7b252 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java @@ -19,7 +19,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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; @@ -62,10 +61,10 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final BlockParameterOrBlockHash blockParameterOrBlockHash; try { blockParameterOrBlockHash = - requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final String addressHash; try { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java index eb69704f6a8..ad71960ba5c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.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.parameters.BlockParameter; -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.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -43,7 +42,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java index d126e103710..ee7e89c3c60 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.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.parameters.BlockParameter; -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.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -43,7 +42,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java index d482bf5ac64..90dcd79eb6f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java @@ -19,7 +19,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -47,7 +46,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java index d531930dac7..37bdabb6b43 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java @@ -22,7 +22,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.parameters.BlockParameter; -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.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -50,7 +49,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java index a1bd9b9bf79..c46692547e7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java @@ -20,7 +20,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer.TraceableState; @@ -73,10 +72,10 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final BlockParameterOrBlockHash blockParameterOrBlockHash; try { blockParameterOrBlockHash = - requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); + requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final int transactionIndex = requestContext.getRequiredParameter(1, Integer.class); final Address accountAddress; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java index ac782bafd0a..6a193379167 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java @@ -17,7 +17,6 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -73,10 +72,10 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } catch (final RLPException e) { LOG.debug("Failed to parse block RLP", e); return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block params", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block params", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final TraceOptions traceOptions = requestContext diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java index b5a53ca9d3a..6838053d9f9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java @@ -19,7 +19,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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -54,7 +53,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java index d892a7d20d0..264611de2e0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java @@ -20,7 +20,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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; @@ -69,7 +68,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } return maybeBlockParameter.orElse(BlockParameter.LATEST); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 92eb849aff3..1c794b0c2ff 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -63,7 +62,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index fae387f9067..0887ba6e437 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -24,7 +24,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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -98,7 +97,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) { highestBlock = request.getRequiredParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid highest block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid highest block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final Optional> maybeRewardPercentiles = request.getOptionalParameter(2, Double[].class).map(Arrays::asList); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java index 55c59b013dd..c2e7c27eb8a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java @@ -20,7 +20,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -48,7 +47,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java index 14306ec371b..44e8fe62fe4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java @@ -19,7 +19,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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; @@ -69,7 +68,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java index 469e880833a..70cd39709ac 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java @@ -19,7 +19,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockReceiptsResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptResult; @@ -60,7 +59,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java index a8ba018881d..4714932cc1a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -40,7 +39,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java index b11b3b91125..4f15d616c95 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java @@ -20,7 +20,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -50,7 +49,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java index 8fe3c471a4d..c6ff6dbb04a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java @@ -19,7 +19,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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; @@ -47,7 +46,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java index c66edfd030a..bbc6c505de8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java @@ -20,7 +20,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.parameters.BlockParameterOrBlockHash; -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; @@ -54,7 +53,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java index dc562876ef4..ffa6ddc15ec 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java @@ -20,7 +20,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UInt256Parameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -44,7 +43,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java index 8e865e604f1..da6e76179f2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionCompleteResult; @@ -44,7 +43,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java index ac11e14dd60..f1b5050bdce 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java @@ -20,7 +20,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.parameters.BlockParameterOrBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -57,7 +56,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java index 7a1575e1291..07ec0f6786c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; @@ -42,7 +41,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java index 8e43718df11..e79c0b60b7d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java @@ -86,7 +86,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } catch (final RLPException e) { LOG.debug("RLPException: {} caused by {}", e.getMessage(), e.getCause()); return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); } catch (final InvalidJsonRpcRequestException i) { LOG.debug("InvalidJsonRpcRequestException: {} caused by {}", i.getMessage(), i.getCause()); return new JsonRpcErrorResponse( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index d08ecfd8989..7f26f55b355 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -58,7 +57,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(2, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java index d0adce7cd4d..0b2be26115a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java @@ -23,7 +23,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -66,7 +65,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } From dd6c10b090ef17ba32866a9982b25c84a58c970c Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 16:12:06 +1000 Subject: [PATCH 22/56] 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS Signed-off-by: Matilda Clerke --- .../methods/QbftGetValidatorsByBlockNumber.java | 3 +-- .../api/jsonrpc/internal/methods/TraceBlock.java | 13 ++++++------- .../api/jsonrpc/internal/methods/TraceCallMany.java | 3 +-- .../methods/TraceReplayBlockTransactions.java | 13 ++++++------- .../internal/privacy/methods/priv/PrivGetCode.java | 3 +-- .../retesteth/methods/TestImportRawBlock.java | 3 +-- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java index 2b08f0caf51..5ba54214b71 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -57,7 +56,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java index 47e8803dfab..6ac9a349571 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -71,12 +70,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - try { - return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException - throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); - } + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 2510190e2a4..54acfe859ee 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceCallManyParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; @@ -70,7 +69,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } return maybeBlockParameter.orElse(BlockParameter.LATEST); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java index a17ab700b9c..f2de42eb819 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceBlock.ChainUpdater; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; @@ -73,12 +72,12 @@ public String getName() { @Override protected BlockParameter blockParameter(final JsonRpcRequestContext request) { - try { - return request.getRequiredParameter(0, BlockParameter.class); - } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException - throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); - } + try { + return request.getRequiredParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + } } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index 4f51d8bfcad..b76af2896d2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -20,7 +20,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -53,7 +52,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(2, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java index 5d5d22c3f66..fe6eae51a0d 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.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; @@ -59,7 +58,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { input = requestContext.getRequiredParameter(0, String.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final ProtocolContext protocolContext = this.context.getProtocolContext(); From 7d41fac36423d58fe76007ea23acef8267f327ec Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 16:24:53 +1000 Subject: [PATCH 23/56] 5098: Update with usage of RpcErrorType.INVALID_BLOCK_COUNT_PARAMS Signed-off-by: Matilda Clerke --- .../api/jsonrpc/internal/methods/EthFeeHistory.java | 10 ++++++++-- .../engine/EngineGetPayloadBodiesByRangeV1.java | 9 ++++++++- .../jsonrpc/internal/methods/EthFeeHistoryTest.java | 4 ++-- .../ethereum/retesteth/methods/TestMineBlocks.java | 10 +++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 0887ba6e437..b6abb43c14a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -88,9 +88,15 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext request) { final Object requestId = request.getRequest().getId(); - final int blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue(); + final int blockCount; + try { + blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue(); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block count parameter", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); + } if (isInvalidBlockCount(blockCount)) { - return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS); + return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_BLOCK_COUNT_PARAMS); } final BlockParameter highestBlock; try { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java index 5fdd1657f67..16e9e3aaf5e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java @@ -17,6 +17,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.UnsignedLongParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -59,7 +60,13 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { final long startBlockNumber = request.getRequiredParameter(0, UnsignedLongParameter.class).getValue(); - final long count = request.getRequiredParameter(1, UnsignedLongParameter.class).getValue(); + final long count; + try { + count = request.getRequiredParameter(1, UnsignedLongParameter.class).getValue(); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block count params", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); + } final Object reqId = request.getRequest().getId(); LOG.atTrace() diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java index a0821abf2de..0ed7e133822 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java @@ -241,11 +241,11 @@ public void blockCountBounds() { assertThat( ((JsonRpcErrorResponse) feeHistoryRequest("0x0", "latest", new double[] {100.0})) .getErrorType()) - .isEqualTo(RpcErrorType.INVALID_PARAMS); + .isEqualTo(RpcErrorType.INVALID_BLOCK_COUNT_PARAMS); assertThat( ((JsonRpcErrorResponse) feeHistoryRequest("0x401", "latest", new double[] {100.0})) .getErrorType()) - .isEqualTo(RpcErrorType.INVALID_PARAMS); + .isEqualTo(RpcErrorType.INVALID_BLOCK_COUNT_PARAMS); } @Test diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java index 3060b326bb8..acf82a4a996 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java @@ -16,9 +16,11 @@ 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.JsonRpcMethod; 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.blockcreation.PoWBlockCreator; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; @@ -44,7 +46,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - long blocksToMine = requestContext.getRequiredParameter(0, Long.class); + long blocksToMine = 0; + try { + blocksToMine = requestContext.getRequiredParameter(0, Long.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid blocks to mine", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); + } while (blocksToMine-- > 0) { if (!mineNewBlock()) { return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), false); From e316045f445825b0732efcf2fa3c6ed1afbf488f Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 31 Jul 2024 16:28:20 +1000 Subject: [PATCH 24/56] 5098: Fix broken integration test Signed-off-by: Matilda Clerke --- .../fork/frontier/EthGetBlockByNumberIntegrationTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java index a7c3aa254ea..36b77812269 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java @@ -410,7 +410,7 @@ public void missingTagParameterBlockHashes() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid block parameter"); } /** The Tag | Quantity is the first parameter, either a String or a number */ @@ -422,7 +422,7 @@ public void missingTagParameterBlockTransactions() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid block parameter"); } /** @@ -437,8 +437,7 @@ public void missingHashesOrTransactionParameter() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasNoCause() - .hasMessage("Missing required json rpc parameter at index 1"); + .hasMessage("Invalid block parameter"); } /** From bd6b7d353af7f09c5005e62d5560f453e0795e94 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 1 Aug 2024 09:17:03 +1000 Subject: [PATCH 25/56] 5098: Add index to exception messages Signed-off-by: Matilda Clerke --- .../besu/consensus/clique/jsonrpc/methods/Discard.java | 2 +- .../besu/consensus/clique/jsonrpc/methods/Propose.java | 2 +- .../besu/consensus/clique/jsonrpc/methods/DiscardTest.java | 2 +- .../ibft/jsonrpc/methods/IbftDiscardValidatorVote.java | 2 +- .../ibft/jsonrpc/methods/IbftProposeValidatorVote.java | 2 +- .../ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java | 4 ++-- .../ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java | 4 ++-- .../qbft/jsonrpc/methods/QbftDiscardValidatorVote.java | 2 +- .../qbft/jsonrpc/methods/QbftProposeValidatorVote.java | 2 +- .../qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java | 4 ++-- .../qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java | 2 +- .../api/jsonrpc/internal/methods/DebugStorageRangeAt.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/EthGetBalance.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/EthGetCode.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/EthGetProof.java | 2 +- .../api/jsonrpc/internal/methods/EthGetStorageAt.java | 2 +- .../api/jsonrpc/internal/methods/EthGetTransactionCount.java | 4 ++-- .../api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java | 2 +- .../internal/privacy/methods/priv/PrivFindPrivacyGroup.java | 2 +- .../jsonrpc/internal/privacy/methods/priv/PrivGetCode.java | 2 +- .../privacy/methods/priv/PrivGetEeaTransactionCount.java | 2 +- .../privacy/methods/priv/PrivGetTransactionCount.java | 2 +- .../privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java | 2 +- .../api/jsonrpc/internal/methods/EthGetProofTest.java | 2 +- .../jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java | 2 +- 26 files changed, 30 insertions(+), 30 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java index 9354d506d4b..467164e8c02 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Discard.java @@ -53,7 +53,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { address = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } validatorProvider.getVoteProviderAtHead().get().discardVote(address); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java index 9ad5c9c0837..f2b81d56e3e 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java @@ -55,7 +55,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { address = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final Boolean auth = requestContext.getRequiredParameter(1, Boolean.class); if (address.equals(CliqueBlockInterface.NO_VOTE_SUBJECT)) { diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java index 497677dec76..80220a3f04a 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/DiscardTest.java @@ -121,7 +121,7 @@ public void discardWithoutAddress() { final Discard discard = new Discard(validatorProvider); assertThatThrownBy(() -> discard.response(requestWithParams())) - .hasMessage("Invalid address parameter") + .hasMessage("Invalid address parameter (index 0)") .isInstanceOf(InvalidJsonRpcParameters.class); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java index 2a12fc34fda..7e6c0010888 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVote.java @@ -57,7 +57,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { validatorAddress = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid validator address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } LOG.trace("Received RPC rpcName={} address={}", getName(), validatorAddress); validatorProvider.getVoteProviderAtHead().get().discardVote(validatorAddress); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java index 3e5039e5ccf..a29187b5138 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVote.java @@ -58,7 +58,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { validatorAddress = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final Boolean add = requestContext.getRequiredParameter(1, Boolean.class); LOG.trace( diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java index 7b2408f1838..7a25ab67b85 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftDiscardValidatorVoteTest.java @@ -56,14 +56,14 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid validator address parameter"); + .hasMessage("Invalid validator address parameter (index 0)"); } @Test public void exceptionWhenInvalidAddressParameterSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid validator address parameter"); + .hasMessageContaining("Invalid validator address parameter (index 0)"); } @Test diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java index 5e4c254037a..d0df723d54f 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftProposeValidatorVoteTest.java @@ -56,7 +56,7 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid address parameter"); + .hasMessage("Invalid address parameter (index 0)"); } @Test @@ -70,7 +70,7 @@ public void exceptionWhenNoAuthSupplied() { public void exceptionWhenNoAddressSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("true"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid address parameter"); + .hasMessageContaining("Invalid address parameter (index 0)"); } @Test diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java index 80becc6f0bc..580c8d7f9bf 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java @@ -55,7 +55,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { validatorAddress = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid validator address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } LOG.trace("Received RPC rpcName={} address={}", getName(), validatorAddress); validatorProvider.getVoteProviderAtHead().get().discardVote(validatorAddress); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java index 0a47766c7be..f7231ccabce 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java @@ -56,7 +56,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { validatorAddress = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid validator address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final Boolean add = requestContext.getRequiredParameter(1, Boolean.class); LOG.trace( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java index 8c83b91bc94..c8ce4195695 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java @@ -58,14 +58,14 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid validator address parameter"); + .hasMessage("Invalid validator address parameter (index 0)"); } @Test public void exceptionWhenInvalidAddressParameterSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid validator address parameter"); + .hasMessageContaining("Invalid validator address parameter (index 0)"); } @Test diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java index e44c9d66dec..62f7dc61691 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java @@ -58,7 +58,7 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid validator address parameter"); + .hasMessage("Invalid validator address parameter (index 0)"); } @Test diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java index e7c045fffa7..8fafd5ec3da 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java @@ -79,7 +79,7 @@ protected Object resultByBlockHash( address = requestContext.getRequiredParameter(2, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 2)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } Optional> block = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java index 4b93c2af385..72110852b76 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java @@ -77,7 +77,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { accountAddress = requestContext.getRequiredParameter(2, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid account address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid account address parameter (index 2)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final Hash startKey = Hash.fromHexStringLenient(requestContext.getRequiredParameter(3, String.class)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java index 5572b536d09..449de64261a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java @@ -53,7 +53,7 @@ protected String resultByBlockHash(final JsonRpcRequestContext request, final Ha address = request.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } return blockchainQueries .get() diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java index ab69e46c46d..9002b6d89ce 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java @@ -55,7 +55,7 @@ protected String resultByBlockHash(final JsonRpcRequestContext request, final Ha address = request.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } return getBlockchainQueries().getCode(address, blockHash).map(Bytes::toString).orElse(null); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java index ee7e2585fdb..67a07924080 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java @@ -61,7 +61,7 @@ protected Object resultByBlockHash( address = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final List storageKeys = getStorageKeys(requestContext); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java index efe87be6de6..efec2ee1d6f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java @@ -49,7 +49,7 @@ protected String resultByBlockHash(final JsonRpcRequestContext request, final Ha address = request.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final UInt256 position = request.getRequiredParameter(1, UInt256Parameter.class).getValue(); return blockchainQueries diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java index ca4601bdd62..a03d90ea293 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java @@ -62,7 +62,7 @@ protected Object pendingResult(final JsonRpcRequestContext request) { address = request.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final long pendingNonce = transactionPoolSupplier.get().getNextNonceForSender(address).orElse(0); @@ -85,7 +85,7 @@ protected String resultByBlockHash(final JsonRpcRequestContext request, final Ha address = request.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final long transactionCount = getBlockchainQueries().getTransactionCount(address, blockHash); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java index 9866b2a6b33..d6676a60740 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbase.java @@ -49,7 +49,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequest().getId(), RpcErrorType.INVALID_REQUEST); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java index 6f917b09169..8f0e8290842 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java @@ -62,7 +62,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { addresses = requestContext.getRequiredParameter(0, String[].class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameters", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameters (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } LOG.trace("Finding a privacy group with members {}", Arrays.toString(addresses)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index 2ba5386b09e..56318da37eb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -60,7 +60,7 @@ protected String resultByBlockNumber( address = request.getRequiredParameter(1, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 1)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final String privacyUserId = privacyIdProvider.getPrivacyUserId(request.getUser()); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java index 2f18ae6d5ff..cd107b2e713 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java @@ -71,7 +71,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { address = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final String privateFrom = requestContext.getRequiredParameter(1, String.class); final String[] privateFor = requestContext.getRequiredParameter(2, String[].class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java index 3e5e2fa01cd..c796d35d5f4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java @@ -62,7 +62,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { address = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } final String privacyGroupId = requestContext.getRequiredParameter(1, String.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java index 6d52d11aba0..e6cf056989d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java @@ -61,7 +61,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { addresses = requestContext.getRequiredParameter(0, String[].class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid address parameters", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid address parameters (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); } LOG.trace("Finding a privacy group with members {}", Arrays.toString(addresses)); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java index 7f0d5657300..344ee39d80f 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java @@ -111,7 +111,7 @@ void errorWhenNoAddressAccountSupplied() { Assertions.assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid address parameter"); + .hasMessageContaining("Invalid address parameter (index 0)"); } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java index b34ff91080c..20abf9e9c1d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetCoinbaseTest.java @@ -62,7 +62,7 @@ public void shouldFailWhenMissingAddress() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid address parameter"); + .hasMessage("Invalid address parameter (index 0)"); } @Test From eda22ac74dd74f46ccd09b0baacbeec2e8b108cc Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 1 Aug 2024 09:26:16 +1000 Subject: [PATCH 26/56] 5098: apoply spotless Signed-off-by: Matilda Clerke --- .../qbft/jsonrpc/methods/QbftDiscardValidatorVote.java | 4 +++- .../qbft/jsonrpc/methods/QbftProposeValidatorVote.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java index 580c8d7f9bf..98856caaa61 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVote.java @@ -55,7 +55,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { validatorAddress = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid validator address parameter (index 0)", + RpcErrorType.INVALID_ADDRESS_PARAMS, + e); } LOG.trace("Received RPC rpcName={} address={}", getName(), validatorAddress); validatorProvider.getVoteProviderAtHead().get().discardVote(validatorAddress); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java index f7231ccabce..9eefbb8d13a 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVote.java @@ -56,7 +56,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { validatorAddress = requestContext.getRequiredParameter(0, Address.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e); + "Invalid validator address parameter (index 0)", + RpcErrorType.INVALID_ADDRESS_PARAMS, + e); } final Boolean add = requestContext.getRequiredParameter(1, Boolean.class); LOG.trace( From 6ce053b9b137446002c8c64155ffc39e5fe2b84f Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 1 Aug 2024 13:41:52 +1000 Subject: [PATCH 27/56] 5098: Update BaseJsonRpcProcessor to utilise RpcErrorType from InvalidJsonRpcParameters Signed-off-by: Matilda Clerke --- .../api/jsonrpc/execution/BaseJsonRpcProcessor.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/BaseJsonRpcProcessor.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/BaseJsonRpcProcessor.java index 3d823886484..db6481b46aa 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/BaseJsonRpcProcessor.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/BaseJsonRpcProcessor.java @@ -43,8 +43,12 @@ public JsonRpcResponse process( try { return method.response(request); } catch (final InvalidJsonRpcParameters e) { - LOG.debug("Invalid Params for method: {}", method.getName(), e); - return new JsonRpcErrorResponse(id, RpcErrorType.INVALID_PARAMS); + LOG.debug( + "Invalid Params for method: {}, error: {}", + method.getName(), + e.getRpcErrorType().getMessage(), + e); + return new JsonRpcErrorResponse(id, e.getRpcErrorType()); } catch (final MultiTenancyValidationException e) { return new JsonRpcUnauthorizedResponse(id, RpcErrorType.UNAUTHORIZED); } catch (final RuntimeException e) { From d441737f77b8875534cd0ff2ff20ab349ca7f64d Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 1 Aug 2024 13:56:36 +1000 Subject: [PATCH 28/56] 5098: Include parameter index in INVALID_AUTH_PARAMS Signed-off-by: Matilda Clerke --- .../besu/consensus/clique/jsonrpc/methods/Propose.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java index fcb4ff187d1..bc6d44c1fbb 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java @@ -62,7 +62,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { auth = requestContext.getRequiredParameter(1, Boolean.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid auth parameter", RpcErrorType.INVALID_AUTH_PARAMS, e); + "Invalid auth parameter (index 1)", RpcErrorType.INVALID_AUTH_PARAMS, e); } if (address.equals(CliqueBlockInterface.NO_VOTE_SUBJECT)) { return new JsonRpcErrorResponse( From 93594a94952d64aaee101ce4bbdf40b6f9a2095a Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 1 Aug 2024 14:12:44 +1000 Subject: [PATCH 29/56] 5098: Include parameter index in INVALID_BLOCK_PARAMS Signed-off-by: Matilda Clerke --- .../consensus/clique/jsonrpc/methods/CliqueGetSigners.java | 2 +- .../ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java | 2 +- .../qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java | 2 +- .../besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java | 2 +- .../api/jsonrpc/internal/methods/AbstractTraceByBlock.java | 2 +- .../jsonrpc/internal/methods/AdminGenerateLogBloomCache.java | 4 ++-- .../ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java | 2 +- .../api/jsonrpc/internal/methods/DebugAccountRange.java | 2 +- .../api/jsonrpc/internal/methods/DebugGetRawBlock.java | 2 +- .../api/jsonrpc/internal/methods/DebugGetRawHeader.java | 2 +- .../api/jsonrpc/internal/methods/DebugGetRawReceipts.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/DebugSetHead.java | 2 +- .../api/jsonrpc/internal/methods/DebugStorageRangeAt.java | 2 +- .../api/jsonrpc/internal/methods/DebugTraceBlock.java | 4 ++-- .../api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java | 2 +- .../besu/ethereum/api/jsonrpc/internal/methods/EthCall.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/EthGetBalance.java | 2 +- .../api/jsonrpc/internal/methods/EthGetBlockByNumber.java | 2 +- .../api/jsonrpc/internal/methods/EthGetBlockReceipts.java | 2 +- .../internal/methods/EthGetBlockTransactionCountByNumber.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/EthGetCode.java | 2 +- .../internal/methods/EthGetMinerDataByBlockNumber.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/EthGetProof.java | 2 +- .../api/jsonrpc/internal/methods/EthGetStorageAt.java | 2 +- .../methods/EthGetTransactionByBlockNumberAndIndex.java | 2 +- .../api/jsonrpc/internal/methods/EthGetTransactionCount.java | 2 +- .../internal/methods/EthGetUncleByBlockNumberAndIndex.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/TraceBlock.java | 2 +- .../ethereum/api/jsonrpc/internal/methods/TraceCallMany.java | 2 +- .../internal/methods/TraceReplayBlockTransactions.java | 2 +- .../api/jsonrpc/internal/privacy/methods/priv/PrivCall.java | 2 +- .../internal/privacy/methods/priv/PrivDebugGetStateRoot.java | 2 +- .../jsonrpc/internal/privacy/methods/priv/PrivGetCode.java | 2 +- .../besu/ethereum/retesteth/methods/TestImportRawBlock.java | 2 +- 36 files changed, 38 insertions(+), 38 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java index 0762deac2ee..813c296098c 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java @@ -73,7 +73,7 @@ private Optional determineBlockHeader(final JsonRpcRequestContext r blockParameter = request.getOptionalParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final long latest = blockchainQueries.headBlockNumber(); final long blockNumber = blockParameter.map(b -> b.getNumber().orElse(latest)).orElse(latest); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java index c7f70764d75..7992f0918c4 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java @@ -56,7 +56,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java index 5ba54214b71..7a64a7ab22a 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java @@ -56,7 +56,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java index 9e4cc668137..6dbf9f586fe 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java @@ -62,7 +62,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java index 91bc305ba4a..a5965211757 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java @@ -69,7 +69,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { maybeBlockParameter = request.getOptionalParameter(2, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } if (maybeBlockParameter.isPresent()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java index e6c262e3fd6..437f7f5821a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java @@ -45,7 +45,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { startBlockParam = requestContext.getOptionalParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid start block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final long startBlock; if (startBlockParam.isEmpty() || startBlockParam.get().isEarliest()) { @@ -62,7 +62,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { stopBlockParam = requestContext.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid stop block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final long stopBlock; if (stopBlockParam.isEmpty()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java index a417bc121fd..550a25982d2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java @@ -71,7 +71,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java index 12a81c7b252..9ab9d68de8e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java @@ -64,7 +64,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final String addressHash; try { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java index ad71960ba5c..28d886bd81e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java @@ -42,7 +42,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java index ee7e89c3c60..e2f2c89e1aa 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java @@ -42,7 +42,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java index 90dcd79eb6f..cddba5086e8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java @@ -46,7 +46,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java index 37bdabb6b43..a3b423675fd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java @@ -49,7 +49,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java index efd994a822f..9f0f2f0b1e3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java @@ -75,7 +75,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final int transactionIndex = requestContext.getRequiredParameter(1, Integer.class); final Address accountAddress; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java index 6a193379167..44cbf153dee 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java @@ -70,12 +70,12 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { block = Block.readFrom(RLP.input(Bytes.fromHexString(input)), this.blockHeaderFunctions); } catch (final RLPException e) { - LOG.debug("Failed to parse block RLP", e); + LOG.debug("Failed to parse block RLP (index 0)", e); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block params", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block params (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final TraceOptions traceOptions = requestContext diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java index 6838053d9f9..dce3ab1ebf1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java @@ -53,7 +53,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java index 264611de2e0..9de8108e679 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java @@ -68,7 +68,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } return maybeBlockParameter.orElse(BlockParameter.LATEST); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 1c794b0c2ff..a08b17dfc63 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -62,7 +62,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameters (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 0887ba6e437..26e414acda9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -97,7 +97,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) { highestBlock = request.getRequiredParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid highest block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid highest block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final Optional> maybeRewardPercentiles = request.getOptionalParameter(2, Double[].class).map(Arrays::asList); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java index b2594c70c26..e863626c967 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java @@ -47,7 +47,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java index 44e8fe62fe4..19ad9a51ad2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java @@ -68,7 +68,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java index 70cd39709ac..d9592db8c11 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java @@ -59,7 +59,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameters (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java index 4714932cc1a..2a068a61740 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java @@ -39,7 +39,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameters", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameters (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java index 57d208d252a..8a9881a0125 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java @@ -49,7 +49,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java index c6ff6dbb04a..c2df7126864 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java @@ -46,7 +46,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java index 98cb163e48c..a20cd62f290 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java @@ -53,7 +53,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java index cdbc06607d3..7b84365b561 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java @@ -43,7 +43,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(2, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java index da6e76179f2..6a419d35c54 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java @@ -43,7 +43,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java index f54929b9580..a9916099eac 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java @@ -56,7 +56,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( return request.getRequiredParameter(1, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block or block hash parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java index 07ec0f6786c..d2ac0b26af8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java @@ -41,7 +41,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java index 6ac9a349571..5ec46e08cc4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java @@ -74,7 +74,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 54acfe859ee..8dabd29a3ee 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -69,7 +69,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } return maybeBlockParameter.orElse(BlockParameter.LATEST); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java index f2de42eb819..50e580cd86d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java @@ -76,7 +76,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index 7f26f55b355..8fe48474a83 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -57,7 +57,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(2, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java index 0b2be26115a..b6ea645dc3e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java @@ -65,7 +65,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index 71cba24d4bb..0010b8e0525 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -52,7 +52,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { return request.getRequiredParameter(2, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java index fe6eae51a0d..516dc2f55f1 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java @@ -58,7 +58,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { input = requestContext.getRequiredParameter(0, String.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } final ProtocolContext protocolContext = this.context.getProtocolContext(); From f2fb791dde17771de0659c35cfef4f907fb8f5ae Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 1 Aug 2024 14:15:50 +1000 Subject: [PATCH 30/56] 5098: Include parameter index in INVALID_BLOCK_COUNT_PARAMS Signed-off-by: Matilda Clerke --- .../ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java | 2 +- .../methods/engine/EngineGetPayloadBodiesByRangeV1.java | 2 +- .../besu/ethereum/retesteth/methods/TestMineBlocks.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 7e908c4c9d5..5b688249f62 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -93,7 +93,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) { blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue(); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block count parameter", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); + "Invalid block count parameter (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); } if (isInvalidBlockCount(blockCount)) { return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_BLOCK_COUNT_PARAMS); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java index 16e9e3aaf5e..88431dd89bd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java @@ -65,7 +65,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { count = request.getRequiredParameter(1, UnsignedLongParameter.class).getValue(); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block count params", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); + "Invalid block count params (index 1)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); } final Object reqId = request.getRequest().getId(); diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java index acf82a4a996..7907cee3f78 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java @@ -51,7 +51,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { blocksToMine = requestContext.getRequiredParameter(0, Long.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid blocks to mine", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); + "Invalid blocks to mine (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); } while (blocksToMine-- > 0) { if (!mineNewBlock()) { From 005640e231e8f3be12186b15c1df00fa34ee85a0 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Fri, 2 Aug 2024 13:14:36 +1000 Subject: [PATCH 31/56] 5098: Fix broken integration test Signed-off-by: Matilda Clerke --- .../fork/frontier/EthGetBlockByNumberIntegrationTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java index 36b77812269..9f76609fd79 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java @@ -437,7 +437,7 @@ public void missingHashesOrTransactionParameter() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid block parameter"); + .hasMessage("Missing required json rpc parameter at index 1"); } /** @@ -452,8 +452,7 @@ public void missingAllParameters() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasNoCause() - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid block parameter (index 0)"); } private JsonRpcRequestContext requestWithParams(final Object... params) { From 792f328a249fcd7bb490ad7424ee952f3fdf7a5d Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Fri, 2 Aug 2024 13:48:19 +1000 Subject: [PATCH 32/56] 5098: Rename INVALID_AUTH_PARAMS to INVALID_PROPOSAL_PARAMS Signed-off-by: Matilda Clerke --- .../besu/consensus/clique/jsonrpc/methods/Propose.java | 2 +- .../ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java | 2 +- .../ethereum/api/jsonrpc/internal/response/RpcErrorType.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java index bc6d44c1fbb..6e198a84fe2 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/Propose.java @@ -62,7 +62,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { auth = requestContext.getRequiredParameter(1, Boolean.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid auth parameter (index 1)", RpcErrorType.INVALID_AUTH_PARAMS, e); + "Invalid auth parameter (index 1)", RpcErrorType.INVALID_PROPOSAL_PARAMS, e); } if (address.equals(CliqueBlockInterface.NO_VOTE_SUBJECT)) { return new JsonRpcErrorResponse( 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 eba3827bfaf..822c6ac895b 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 @@ -60,7 +60,6 @@ public JsonRpcResponse process( 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: @@ -104,6 +103,7 @@ public JsonRpcResponse process( case INVALID_PRIVACY_GROUP_PARAMS: case INVALID_PRIVATE_FROM_PARAMS: case INVALID_PRIVATE_FOR_PARAMS: + case INVALID_PROPOSAL_PARAMS: case INVALID_REMOTE_CAPABILITIES_PARAMS: case INVALID_REWARD_PERCENTILES_PARAMS: case INVALID_SEALER_ID_PARAMS: 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 309fe498627..d46dc900c57 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 @@ -31,7 +31,6 @@ public enum RpcErrorType implements RpcMethodError { 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)"), @@ -89,6 +88,7 @@ public enum RpcErrorType implements RpcMethodError { 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_PROPOSAL_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid proposal 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"), From ff2db15fdf5dbac0d25f9b5aa3ff8701fdd6afa7 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Fri, 2 Aug 2024 14:26:13 +1000 Subject: [PATCH 33/56] 5098: apply spotless Signed-off-by: Matilda Clerke --- .../api/jsonrpc/internal/methods/DebugAccountRange.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java index 9ab9d68de8e..9a2da2c5f49 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java @@ -64,7 +64,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block parameter or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block parameter or block hash parameter (index 0)", + RpcErrorType.INVALID_BLOCK_PARAMS, + e); } final String addressHash; try { From 74616be3409e65edc631c25b077a63fe9df27338 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Fri, 2 Aug 2024 15:27:10 +1000 Subject: [PATCH 34/56] 5098: Update INVALID_BLOCK_HASH_PARAMS locations Signed-off-by: Matilda Clerke --- .../jsonrpc/methods/CliqueGetSignersAtHash.java | 10 +++++++++- .../jsonrpc/methods/CliqueGetSignersAtHashTest.java | 2 +- .../jsonrpc/methods/IbftGetValidatorsByBlockHash.java | 11 ++++++++++- .../jsonrpc/methods/QbftGetValidatorsByBlockHash.java | 11 ++++++++++- .../AbstractBlockParameterOrBlockHashMethod.java | 2 +- .../methods/DebugStandardTraceBadBlockToFile.java | 10 +++++++++- .../methods/DebugStandardTraceBlockToFile.java | 10 +++++++++- .../internal/methods/DebugTraceBlockByHash.java | 11 ++++++++++- .../jsonrpc/internal/methods/EthGetBlockByHash.java | 11 ++++++++++- .../methods/EthGetBlockTransactionCountByHash.java | 11 ++++++++++- .../internal/methods/EthGetMinerDataByBlockHash.java | 11 ++++++++++- .../methods/EthGetUncleByBlockHashAndIndex.java | 11 ++++++++++- .../internal/methods/EthGetUncleCountByBlockHash.java | 11 ++++++++++- .../engine/EngineGetPayloadBodiesByHashV1.java | 10 +++++++++- .../ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java | 10 +++++----- .../internal/methods/EthGetBlockByHashTest.java | 3 +-- .../methods/EthGetMinerDataByBlockHashTest.java | 4 ++-- .../methods/EthGetUncleByBlockHashAndIndexTest.java | 4 ++-- 18 files changed, 128 insertions(+), 25 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java index 8dd7ac5c23a..85e654cc73e 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java @@ -18,7 +18,9 @@ import org.hyperledger.besu.datatypes.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.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; @@ -67,7 +69,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } private Optional determineBlockHeader(final JsonRpcRequestContext request) { - final Hash hash = request.getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = request.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } return blockchainQueries.blockByHash(hash).map(BlockWithMetadata::getHeader); } } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java index ee5dc0f023c..3699ccf6eed 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHashTest.java @@ -101,7 +101,7 @@ public void failsWhenNoParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid block hash parameter (index 0)"); } @Test diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java index a14eb49e876..38e60dd2dc5 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java @@ -18,9 +18,12 @@ import org.hyperledger.besu.datatypes.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.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -61,7 +64,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } private Object blockResult(final JsonRpcRequestContext request) { - final Hash hash = request.getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = request.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } LOG.trace("Received RPC rpcName={} blockHash={}", getName(), hash); final Optional blockHeader = blockchain.getBlockHeader(hash); return blockHeader diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java index 4726e81bd33..3d9080d84ba 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java @@ -19,9 +19,12 @@ import org.hyperledger.besu.datatypes.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.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -62,7 +65,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } private Object blockResult(final JsonRpcRequestContext request) { - final Hash hash = request.getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = request.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } LOG.trace("Received RPC rpcName={} blockHash={}", getName(), hash); final Optional blockHeader = blockchain.getBlockHeader(hash); return blockHeader diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java index 8110bf6c2c4..be6ecfa82e6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java @@ -123,7 +123,7 @@ protected Object handleParamTypes(final JsonRpcRequestContext requestContext) { Optional blockHash = blockParameterOrBlockHash.getHash(); if (blockHash.isEmpty()) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_HASH_PARAMS); } // return error if block hash does not find a block diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java index 25c59e47636..8ef45b8cc38 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java @@ -18,6 +18,8 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -52,7 +54,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class); + final Hash blockHash; + try { + blockHash = requestContext.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } final Optional transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java index 306f4c449ed..a138d0dd792 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java @@ -19,6 +19,8 @@ import org.hyperledger.besu.datatypes.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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; @@ -59,7 +61,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class); + final Hash blockHash; + try { + blockHash = requestContext.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } final Optional transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java index c1caaef2b9e..b0f14f50441 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java @@ -17,12 +17,15 @@ import org.hyperledger.besu.datatypes.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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; 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.DebugTraceTransactionResult; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.debug.TraceOptions; @@ -50,7 +53,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class); + final Hash blockHash; + try { + blockHash = requestContext.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } final TraceOptions traceOptions = requestContext .getOptionalParameter(1, TransactionTraceParams.class) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java index 04cad96291e..7368e362236 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java @@ -17,8 +17,11 @@ import org.hyperledger.besu.datatypes.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.parameters.JsonRpcParameter; 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.BlockResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -59,7 +62,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } private BlockResult blockResult(final JsonRpcRequestContext request) { - final Hash hash = request.getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = request.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } if (isCompleteTransactions(request)) { return transactionComplete(hash); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java index a9654555953..59fe09e9c5c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java @@ -17,8 +17,11 @@ import org.hyperledger.besu.datatypes.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.parameters.JsonRpcParameter; 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.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -37,7 +40,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash hash = requestContext.getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = requestContext.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block header hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } final Integer count = blockchain.getTransactionCount(hash); if (count == -1) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java index 0e868d89870..0f5632246dc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java @@ -18,8 +18,11 @@ import org.hyperledger.besu.datatypes.Wei; 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.parameters.JsonRpcParameter; 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.ImmutableMinerDataResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableUncleRewardResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult; @@ -60,7 +63,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash hash = requestContext.getRequest().getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = requestContext.getRequest().getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } BlockWithMetadata block = blockchain.get().blockByHash(hash).orElse(null); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java index 311da6b45f4..fe493bd9161 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java @@ -17,9 +17,12 @@ import org.hyperledger.besu.datatypes.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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; 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.BlockResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.UncleBlockResult; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -44,7 +47,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } private BlockResult blockResult(final JsonRpcRequestContext requestContext) { - final Hash hash = requestContext.getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = requestContext.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } final int index = requestContext.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); return blockchain.getOmmer(hash, index).map(UncleBlockResult::build).orElse(null); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java index c8efa19f309..789ad98709b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java @@ -17,8 +17,11 @@ import org.hyperledger.besu.datatypes.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.parameters.JsonRpcParameter; 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.Quantity; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -37,7 +40,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash hash = requestContext.getRequiredParameter(0, Hash.class); + final Hash hash; + try { + hash = requestContext.getRequiredParameter(0, Hash.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } final String result = blockchain.getOmmerCount(hash).map(Quantity::create).orElse(null); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java index b5644502464..580006069b6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java @@ -18,7 +18,9 @@ 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.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; @@ -60,7 +62,13 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { final Object reqId = request.getRequest().getId(); - final Hash[] blockHashes = request.getRequiredParameter(0, Hash[].class); + final Hash[] blockHashes; + try { + blockHashes = request.getRequiredParameter(0, Hash[].class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block hash parameters (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + } LOG.atTrace() .setMessage("{} parameters: blockHashes {}") diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java index 96b9b9f7793..05284af6b87 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java @@ -760,7 +760,7 @@ public void getBlockByHashWithMissingHashParameter() throws Exception { assertThat(resp.code()).isEqualTo(200); // Check general format of result final JsonObject json = new JsonObject(resp.body().string()); - final RpcErrorType expectedError = RpcErrorType.INVALID_PARAMS; + final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_HASH_PARAMS; testHelper.assertValidJsonRpcError( json, id, expectedError.getCode(), expectedError.getMessage()); } @@ -807,7 +807,7 @@ public void getBlockByHashWithInvalidHashParameterWithOddLength() throws Excepti assertThat(resp.code()).isEqualTo(200); // Check general format of result final JsonObject json = new JsonObject(resp.body().string()); - final RpcErrorType expectedError = RpcErrorType.INVALID_PARAMS; + final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_HASH_PARAMS; testHelper.assertValidJsonRpcError( json, id, expectedError.getCode(), expectedError.getMessage()); } @@ -830,7 +830,7 @@ public void getBlockByHashWithInvalidHashParameterThatIsTooShort() throws Except assertThat(resp.code()).isEqualTo(200); // Check general format of result final JsonObject json = new JsonObject(resp.body().string()); - final RpcErrorType expectedError = RpcErrorType.INVALID_PARAMS; + final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_HASH_PARAMS; testHelper.assertValidJsonRpcError( json, id, expectedError.getCode(), expectedError.getMessage()); } @@ -874,7 +874,7 @@ public void getBlockByHashWithAllParametersMissing() throws Exception { assertThat(resp.code()).isEqualTo(200); // Check general format of result final JsonObject json = new JsonObject(resp.body().string()); - final RpcErrorType expectedError = RpcErrorType.INVALID_PARAMS; + final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_HASH_PARAMS; testHelper.assertValidJsonRpcError( json, id, expectedError.getCode(), expectedError.getMessage()); } @@ -894,7 +894,7 @@ public void getBlockByHashWithNoParameters() throws Exception { assertThat(resp.code()).isEqualTo(200); // Check general format of result final JsonObject json = new JsonObject(resp.body().string()); - final RpcErrorType expectedError = RpcErrorType.INVALID_PARAMS; + final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_HASH_PARAMS; testHelper.assertValidJsonRpcError( json, id, expectedError.getCode(), expectedError.getMessage()); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHashTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHashTest.java index 1747030ba60..28043b2e092 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHashTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHashTest.java @@ -77,8 +77,7 @@ public void exceptionWhenNoBoolSupplied() { public void exceptionWhenHashParamInvalid() { assertThatThrownBy(() -> method.response(requestWithParams("hash", "true"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage( - "Invalid json rpc parameter at index 0. Supplied value was: 'hash' of type: 'java.lang.String' - expected type: 'org.hyperledger.besu.datatypes.Hash'"); + .hasMessage("Invalid block hash parameter (index 0)"); verifyNoMoreInteractions(blockchainQueries); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHashTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHashTest.java index 08737d0546c..9d93dde85ae 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHashTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHashTest.java @@ -109,7 +109,7 @@ public void exceptionWhenNoHashSuppliedTest() { JsonRpcRequestContext requestContext = new JsonRpcRequestContext(request); assertThatThrownBy(() -> method.response(requestContext)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid block hash parameter (index 0)"); verifyNoMoreInteractions(blockchainQueries); } @@ -120,7 +120,7 @@ public void exceptionWhenHashParamInvalidTest() { JsonRpcRequestContext requestContext = new JsonRpcRequestContext(request); assertThatThrownBy(() -> method.response(requestContext)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid block hash parameter (index 0)"); verifyNoMoreInteractions(blockchainQueries); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java index 07f8364615c..fff08f81fbd 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java @@ -79,7 +79,7 @@ public void shouldReturnErrorWhenMissingBlockHashParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); + .hasMessage("Invalid block hash parameter (index 0)"); } @Test @@ -101,7 +101,7 @@ public void shouldReturnErrorWhenInvalidBlockHashParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid block hash parameter (index 0)"); } @Test From e2d2f4c0538e8ffadad66800211442dc08965fa9 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 09:48:50 +1000 Subject: [PATCH 35/56] 5098: Fix broken unit test Signed-off-by: Matilda Clerke --- .../api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java index d2dbc648a17..545b43a6e70 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java @@ -100,7 +100,7 @@ public void returnsCorrectMethodName() { public void exceptionWhenNoParamsSupplied() { assertThatThrownBy(() -> method.response(requestWithParams())) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid block or block hash parameters"); + .hasMessage("Invalid block or block hash parameters (index 0)"); verifyNoMoreInteractions(blockchainQueries); } From 7378dcf493cb087f25d8b1591325392fe1c52e07 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 09:59:02 +1000 Subject: [PATCH 36/56] 5098: apply spotless Signed-off-by: Matilda Clerke --- .../clique/jsonrpc/methods/CliqueGetSignersAtHash.java | 3 +-- .../ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java | 3 +-- .../qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java | 3 +-- .../internal/methods/DebugStandardTraceBadBlockToFile.java | 3 +-- .../internal/methods/DebugStandardTraceBlockToFile.java | 3 +-- .../api/jsonrpc/internal/methods/DebugTraceBlockByHash.java | 3 +-- .../api/jsonrpc/internal/methods/EthGetBlockByHash.java | 3 +-- .../internal/methods/EthGetBlockTransactionCountByHash.java | 5 +++-- .../jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java | 3 +-- .../internal/methods/EthGetUncleByBlockHashAndIndex.java | 3 +-- .../internal/methods/EthGetUncleCountByBlockHash.java | 3 +-- .../methods/engine/EngineGetPayloadBodiesByHashV1.java | 3 +-- 12 files changed, 14 insertions(+), 24 deletions(-) diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java index 85e654cc73e..c683b9d4855 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignersAtHash.java @@ -20,7 +20,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; @@ -74,7 +73,7 @@ private Optional determineBlockHeader(final JsonRpcRequestContext r hash = request.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } return blockchainQueries.blockByHash(hash).map(BlockWithMetadata::getHeader); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java index 38e60dd2dc5..3c3346cd436 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockHash.java @@ -20,7 +20,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.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -69,7 +68,7 @@ private Object blockResult(final JsonRpcRequestContext request) { hash = request.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } LOG.trace("Received RPC rpcName={} blockHash={}", getName(), hash); final Optional blockHeader = blockchain.getBlockHeader(hash); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java index 3d9080d84ba..e991f7f355d 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHash.java @@ -21,7 +21,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.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -70,7 +69,7 @@ private Object blockResult(final JsonRpcRequestContext request) { hash = request.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } LOG.trace("Received RPC rpcName={} blockHash={}", getName(), hash); final Optional blockHeader = blockchain.getBlockHeader(hash); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java index 8ef45b8cc38..7587e40c75a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java @@ -19,7 +19,6 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -59,7 +58,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { blockHash = requestContext.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final Optional transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java index a138d0dd792..601eabeab14 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFile.java @@ -20,7 +20,6 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; @@ -66,7 +65,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { blockHash = requestContext.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final Optional transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java index b0f14f50441..b1216885f1a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByHash.java @@ -18,7 +18,6 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; @@ -58,7 +57,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { blockHash = requestContext.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final TraceOptions traceOptions = requestContext diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java index 7368e362236..d5f1bba01c9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByHash.java @@ -18,7 +18,6 @@ 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.parameters.JsonRpcParameter; 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; @@ -67,7 +66,7 @@ private BlockResult blockResult(final JsonRpcRequestContext request) { hash = request.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } if (isCompleteTransactions(request)) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java index 59fe09e9c5c..e1fbd790868 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByHash.java @@ -18,7 +18,6 @@ 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.parameters.JsonRpcParameter; 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; @@ -45,7 +44,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { hash = requestContext.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block header hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block header hash parameter (index 0)", + RpcErrorType.INVALID_BLOCK_HASH_PARAMS, + e); } final Integer count = blockchain.getTransactionCount(hash); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java index 0f5632246dc..8e3d55f1eab 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java @@ -19,7 +19,6 @@ 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.parameters.JsonRpcParameter; 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; @@ -68,7 +67,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { hash = requestContext.getRequest().getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } BlockWithMetadata block = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java index fe493bd9161..93ae857a695 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java @@ -18,7 +18,6 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -52,7 +51,7 @@ private BlockResult blockResult(final JsonRpcRequestContext requestContext) { hash = requestContext.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final int index = requestContext.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java index 789ad98709b..9a5a3b225ba 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleCountByBlockHash.java @@ -18,7 +18,6 @@ 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.parameters.JsonRpcParameter; 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; @@ -45,7 +44,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { hash = requestContext.getRequiredParameter(0, Hash.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } final String result = blockchain.getOmmerCount(hash).map(Quantity::create).orElse(null); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java index 580006069b6..0e6b62d320f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByHashV1.java @@ -20,7 +20,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.ExecutionEngineJsonRpcMethod; -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; @@ -67,7 +66,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { blockHashes = request.getRequiredParameter(0, Hash[].class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block hash parameters (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); + "Invalid block hash parameters (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } LOG.atTrace() From ae1a45f0feff6c446b119043b9040ee90a3cf904 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 10:15:41 +1000 Subject: [PATCH 37/56] 5098: Update RpcErrorType.INVALID_BLOCK_INDEX Signed-off-by: Matilda Clerke --- .../internal/methods/EthGetUncleByBlockHashAndIndex.java | 9 ++++++++- .../methods/EthGetUncleByBlockNumberAndIndex.java | 9 ++++++++- .../methods/EthGetUncleByBlockHashAndIndexTest.java | 4 ++-- .../methods/EthGetUncleByBlockNumberAndIndexTest.java | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java index 93ae857a695..a3bddb8769f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java @@ -18,6 +18,7 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -53,7 +54,13 @@ private BlockResult blockResult(final JsonRpcRequestContext requestContext) { throw new InvalidJsonRpcParameters( "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e); } - final int index = requestContext.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); + final int index; + try { + index = requestContext.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block index parameter (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); + } return blockchain.getOmmer(hash, index).map(UncleBlockResult::build).orElse(null); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java index d2ac0b26af8..c11c32051ca 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java @@ -18,6 +18,7 @@ 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.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; @@ -48,7 +49,13 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) { @Override protected BlockResult resultByBlockNumber( final JsonRpcRequestContext request, final long blockNumber) { - final int index = request.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); + final int index; + try { + index = request.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block index (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); + } return getBlockchainQueries() .getOmmer(blockNumber, index) .map(UncleBlockResult::build) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java index fff08f81fbd..6b968380c67 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java @@ -90,7 +90,7 @@ public void shouldReturnErrorWhenMissingIndexParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 1"); + .hasMessage("Invalid block index parameter (index 1)"); } @Test @@ -113,7 +113,7 @@ public void shouldReturnErrorWhenInvalidIndexParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 1"); + .hasMessageContaining("Invalid block index parameter (index 1)"); } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java index cfcb127036f..746f63be75c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java @@ -79,7 +79,7 @@ public void shouldReturnErrorWhenMissingBlockNumberParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid block parameter"); + .hasMessage("Invalid block parameter (index 0)"); } @Test @@ -90,7 +90,7 @@ public void shouldReturnErrorWhenMissingIndexParam() { assertThat(thrown) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 1"); + .hasMessage("Invalid block index (index 1)"); } @Test From f5bba2f8d6f650d704e8e307ce2d448741c6e684 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 11:29:42 +1000 Subject: [PATCH 38/56] 5098: Update RpcErrorType.INVALID_BLOCK_NUMBER Signed-off-by: Matilda Clerke --- .../AbstractGetSignerMetricsMethod.java | 22 ++++++++++--- ...stractBlockParameterOrBlockHashMethod.java | 2 +- .../methods/AdminLogsRemoveCache.java | 22 ++++++++++--- .../methods/AdminLogsRepairCache.java | 11 ++++++- .../internal/methods/EthFeeHistory.java | 2 +- .../jsonrpc/internal/methods/EthGetLogs.java | 32 ++++++++++++------- .../EngineGetPayloadBodiesByRangeV1.java | 12 +++++-- .../methods/AdminLogsRemoveCacheTest.java | 2 +- .../internal/methods/EthFeeHistoryTest.java | 2 +- .../retesteth/methods/TestRewindToBlock.java | 11 ++++++- 10 files changed, 87 insertions(+), 31 deletions(-) diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java index 3566684ab14..478ed55e514 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java @@ -18,7 +18,9 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; import org.hyperledger.besu.datatypes.Address; 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.parameters.BlockParameter; +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; @@ -66,17 +68,27 @@ protected AbstractGetSignerMetricsMethod( */ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional startBlockParameter = - requestContext.getOptionalParameter(0, BlockParameter.class); - final Optional endBlockParameter = - requestContext.getOptionalParameter(1, BlockParameter.class); + final Optional startBlockParameter; + try { + startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + } + final Optional endBlockParameter; + try { + endBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid end block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + } final long fromBlockNumber = getFromBlockNumber(startBlockParameter); final long toBlockNumber = getEndBlockNumber(endBlockParameter); if (!isValidParameters(fromBlockNumber, toBlockNumber)) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); } final Map proposersMap = new HashMap<>(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java index be6ecfa82e6..ba3bcd69c63 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java @@ -106,7 +106,7 @@ protected Object handleParamTypes(final JsonRpcRequestContext requestContext) { final OptionalLong blockNumber = blockParameterOrBlockHash.getNumber(); if (blockNumber.isEmpty() || blockNumber.getAsLong() < 0) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); } else if (blockNumber.getAsLong() > getBlockchainQueries().headBlockNumber()) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.BLOCK_NOT_FOUND); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java index 01cfb02a1e8..6c74effdeb6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.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.parameters.BlockParameter; +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; @@ -42,10 +44,20 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional startBlockParameter = - requestContext.getOptionalParameter(0, BlockParameter.class); - final Optional stopBlockParameter = - requestContext.getOptionalParameter(1, BlockParameter.class); + final Optional startBlockParameter; + try { + startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + } + final Optional stopBlockParameter; + try { + stopBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + } final long startBlock; if (startBlockParameter.isEmpty() || startBlockParameter.get().isEarliest()) { @@ -81,7 +93,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { if (stopBlock < startBlock) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); } final TransactionLogBloomCacher transactionLogBloomCacher = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java index 757ac2756bb..2e471189c61 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java @@ -16,8 +16,11 @@ 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.parameters.JsonRpcParameter; 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.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.cache.TransactionLogBloomCacher; @@ -38,7 +41,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Optional blockNumber = requestContext.getOptionalParameter(0, Long.class); + final Optional blockNumber; + try { + blockNumber = requestContext.getOptionalParameter(0, Long.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + } if (blockNumber.isPresent() && blockchainQueries.getBlockchain().getBlockByNumber(blockNumber.get()).isEmpty()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 5b688249f62..ad9a3a57e9a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -112,7 +112,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) { final long chainHeadBlockNumber = chainHeadHeader.getNumber(); final long highestBlockNumber = highestBlock.getNumber().orElse(chainHeadBlockNumber); if (highestBlockNumber > chainHeadBlockNumber) { - return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS); + return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); } final long firstBlock = Math.max(0, highestBlockNumber - (blockCount - 1)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java index c4356ce1c2b..fba6bc89036 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java @@ -16,6 +16,7 @@ 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.parameters.FilterParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -78,16 +79,21 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { .getBlockNumber(blockchain) .orElseThrow( () -> - new Exception("fromBlock not found: " + filter.getFromBlock())); + new InvalidJsonRpcParameters( + "fromBlock not found: " + filter.getFromBlock(), + RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS)); toBlockNumber = filter .getToBlock() .getBlockNumber(blockchain) .orElseThrow( - () -> new Exception("toBlock not found: " + filter.getToBlock())); + () -> new InvalidJsonRpcParameters( + "toBlock not found: " + filter.getToBlock(), + RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS)); if (maxLogRange > 0 && (toBlockNumber - fromBlockNumber) > maxLogRange) { - throw new IllegalArgumentException( - "Requested range exceeds maximum range limit"); + throw new InvalidJsonRpcParameters( + "Requested range exceeds maximum range limit", + RpcErrorType.EXCEEDS_RPC_MAX_BLOCK_RANGE); } } catch (final Exception e) { ex.set(e); @@ -103,16 +109,18 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { if (ex.get() != null) { LOG.atDebug() - .setMessage("eth_getLogs request {} failed:") - .addArgument(requestContext.getRequest()) - .setCause(ex.get()) - .log(); - if (ex.get() instanceof IllegalArgumentException) { + .setMessage("eth_getLogs request {} failed:") + .addArgument(requestContext.getRequest()) + .setCause(ex.get()) + .log(); + if (ex.get() instanceof InvalidJsonRpcParameters) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.EXCEEDS_RPC_MAX_BLOCK_RANGE); + requestContext.getRequest().getId(), + ((InvalidJsonRpcParameters) ex.get()).getRpcErrorType()); + } else { + LOG.error("Unexpected exception: {}", ex.get(), ex.get()); + // TODO: wrap and throw? Something obviously went wrong } - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); } return new JsonRpcSuccessResponse( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java index 88431dd89bd..f813a1608db 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java @@ -19,6 +19,7 @@ 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.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -58,8 +59,13 @@ public String getName() { public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { engineCallListener.executionEngineCalled(); - final long startBlockNumber = - request.getRequiredParameter(0, UnsignedLongParameter.class).getValue(); + final long startBlockNumber; + try { + startBlockNumber = request.getRequiredParameter(0, UnsignedLongParameter.class).getValue(); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid start block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + } final long count; try { count = request.getRequiredParameter(1, UnsignedLongParameter.class).getValue(); @@ -77,7 +83,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { .log(); if (startBlockNumber < 1 || count < 1) { - return new JsonRpcErrorResponse(reqId, RpcErrorType.INVALID_PARAMS); + return new JsonRpcErrorResponse(reqId, RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); } if (count > getMaxRequestBlocks()) { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java index fbe27b42fb9..c5add54bf74 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java @@ -152,7 +152,7 @@ public void requestBlockRangeInvalidTest() { new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRemoveCache", new String[] {"0x20", "0x1"})); final JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS); + new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.of(block)); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java index 0ed7e133822..a04cb06c67a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java @@ -233,7 +233,7 @@ public void cantGetBlockHigherThanChainHead() { assertThat( ((JsonRpcErrorResponse) feeHistoryRequest("0x2", "11", new double[] {100.0})) .getErrorType()) - .isEqualTo(RpcErrorType.INVALID_PARAMS); + .isEqualTo(RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); } @Test diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java index a2bc59ecc23..dea09f526d0 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java @@ -15,9 +15,12 @@ package org.hyperledger.besu.ethereum.retesteth.methods; 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.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.retesteth.RetestethContext; public class TestRewindToBlock implements JsonRpcMethod { @@ -36,7 +39,13 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final long blockNumber = requestContext.getRequiredParameter(0, Long.TYPE); + final long blockNumber; + try { + blockNumber = requestContext.getRequiredParameter(0, Long.TYPE); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + } return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), context.getBlockchain().rewindToBlock(blockNumber)); From 1135c0f8ba32165302f27c6adea871bfa7638360 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 11:30:57 +1000 Subject: [PATCH 39/56] 5098: apply spotless Signed-off-by: Matilda Clerke --- .../AbstractGetSignerMetricsMethod.java | 5 ++-- .../methods/AdminLogsRemoveCache.java | 5 ++-- .../methods/AdminLogsRepairCache.java | 3 +- .../jsonrpc/internal/methods/EthGetLogs.java | 29 ++++++++++--------- .../EthGetUncleByBlockHashAndIndex.java | 3 +- .../EthGetUncleByBlockNumberAndIndex.java | 3 +- .../EngineGetPayloadBodiesByRangeV1.java | 5 ++-- .../methods/AdminLogsRemoveCacheTest.java | 3 +- .../retesteth/methods/TestRewindToBlock.java | 3 +- 9 files changed, 28 insertions(+), 31 deletions(-) diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java index 478ed55e514..7ef368fb762 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java @@ -20,7 +20,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.parameters.BlockParameter; -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; @@ -73,14 +72,14 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } final Optional endBlockParameter; try { endBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid end block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + "Invalid end block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } final long fromBlockNumber = getFromBlockNumber(startBlockParameter); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java index 6c74effdeb6..94430c526f8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.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.parameters.BlockParameter; -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,14 +48,14 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + "Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } final Optional stopBlockParameter; try { stopBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + "Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } final long startBlock; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java index 2e471189c61..7336faff0e6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java @@ -17,7 +17,6 @@ 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.parameters.JsonRpcParameter; 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; @@ -46,7 +45,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { blockNumber = requestContext.getOptionalParameter(0, Long.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } if (blockNumber.isPresent() diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java index fba6bc89036..9b23241fa97 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java @@ -79,21 +79,22 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { .getBlockNumber(blockchain) .orElseThrow( () -> - new InvalidJsonRpcParameters( - "fromBlock not found: " + filter.getFromBlock(), - RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS)); + new InvalidJsonRpcParameters( + "fromBlock not found: " + filter.getFromBlock(), + RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS)); toBlockNumber = filter .getToBlock() .getBlockNumber(blockchain) .orElseThrow( - () -> new InvalidJsonRpcParameters( - "toBlock not found: " + filter.getToBlock(), - RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS)); + () -> + new InvalidJsonRpcParameters( + "toBlock not found: " + filter.getToBlock(), + RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS)); if (maxLogRange > 0 && (toBlockNumber - fromBlockNumber) > maxLogRange) { throw new InvalidJsonRpcParameters( - "Requested range exceeds maximum range limit", - RpcErrorType.EXCEEDS_RPC_MAX_BLOCK_RANGE); + "Requested range exceeds maximum range limit", + RpcErrorType.EXCEEDS_RPC_MAX_BLOCK_RANGE); } } catch (final Exception e) { ex.set(e); @@ -109,14 +110,14 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { if (ex.get() != null) { LOG.atDebug() - .setMessage("eth_getLogs request {} failed:") - .addArgument(requestContext.getRequest()) - .setCause(ex.get()) - .log(); + .setMessage("eth_getLogs request {} failed:") + .addArgument(requestContext.getRequest()) + .setCause(ex.get()) + .log(); if (ex.get() instanceof InvalidJsonRpcParameters) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), - ((InvalidJsonRpcParameters) ex.get()).getRpcErrorType()); + requestContext.getRequest().getId(), + ((InvalidJsonRpcParameters) ex.get()).getRpcErrorType()); } else { LOG.error("Unexpected exception: {}", ex.get(), ex.get()); // TODO: wrap and throw? Something obviously went wrong diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java index a3bddb8769f..9269bf965c0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java @@ -18,7 +18,6 @@ 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.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -59,7 +58,7 @@ private BlockResult blockResult(final JsonRpcRequestContext requestContext) { index = requestContext.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block index parameter (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); + "Invalid block index parameter (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); } return blockchain.getOmmer(hash, index).map(UncleBlockResult::build).orElse(null); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java index c11c32051ca..a6c5e6d89df 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.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.parameters.BlockParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; @@ -54,7 +53,7 @@ protected BlockResult resultByBlockNumber( index = request.getRequiredParameter(1, UnsignedIntParameter.class).getValue(); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block index (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); + "Invalid block index (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); } return getBlockchainQueries() .getOmmer(blockNumber, index) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java index f813a1608db..ec5d5bf6045 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java @@ -19,7 +19,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.ExecutionEngineJsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -64,7 +63,9 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { startBlockNumber = request.getRequiredParameter(0, UnsignedLongParameter.class).getValue(); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid start block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + "Invalid start block number parameter (index 0)", + RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, + e); } final long count; try { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java index c5add54bf74..c58556114c7 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java @@ -152,7 +152,8 @@ public void requestBlockRangeInvalidTest() { new JsonRpcRequestContext( new JsonRpcRequest("2.0", "admin_logsRemoveCache", new String[] {"0x20", "0x1"})); final JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); + new JsonRpcErrorResponse( + request.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.of(block)); diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java index dea09f526d0..d5adb36a243 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java @@ -17,7 +17,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.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; @@ -44,7 +43,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { blockNumber = requestContext.getRequiredParameter(0, Long.TYPE); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); + "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); } return new JsonRpcSuccessResponse( From cce32cc06508e6aed2c3984cd73e649d86ae78ed Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 11:46:05 +1000 Subject: [PATCH 40/56] 5098: Fix broken tests Signed-off-by: Matilda Clerke --- .../api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java | 2 +- .../api/jsonrpc/eth/eth_call_callParamsMissing_block_8.json | 2 +- .../ethereum/api/jsonrpc/eth/eth_call_invalidBlockhash.json | 2 +- .../api/jsonrpc/eth/eth_getBalance_invalidBlockHash.json | 2 +- .../ethereum/api/jsonrpc/eth/eth_getBalance_invalidParams.json | 2 +- .../eth/eth_getBlockReceipts_invalidParams_blockNumber.json | 2 +- .../api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_tag.json | 2 +- .../eth/eth_getBlockTransactionCountByNumber_invalidParams.json | 2 +- .../ethereum/api/jsonrpc/eth/eth_getCode_invalidBlockHash.json | 2 +- .../ethereum/api/jsonrpc/eth/eth_getCode_invalidParams.json | 2 +- .../ethereum/api/jsonrpc/eth/eth_getProof_invalidBlockHash.json | 2 +- .../ethereum/api/jsonrpc/eth/eth_getProof_invalidParams.json | 2 +- .../api/jsonrpc/eth/eth_getStorageAt_invalidBlockHash.json | 2 +- .../api/jsonrpc/eth/eth_getStorageAt_invalidParams.json | 2 +- .../eth_getTransactionByBlockNumberAndIndex_invalidParams.json | 2 +- .../jsonrpc/eth/eth_getTransactionCount_invalidBlockHash.json | 2 +- .../jsonrpc/eth/eth_getTransactionCount_invalidBlockNumber.json | 2 +- .../jsonrpc/eth/eth_getTransactionCount_missingArgument.json | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java index 587288d6b79..e2837593800 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java @@ -129,7 +129,7 @@ public void exceptionWhenNoBoolSupplied() { public void exceptionWhenNumberParamInvalid() { assertThatThrownBy(() -> method.response(requestWithParams("invalid", "true"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Invalid block parameter"); + .hasMessage("Invalid block parameter (index 0)"); verifyNoMoreInteractions(blockchainQueries); } diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_callParamsMissing_block_8.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_callParamsMissing_block_8.json index 562e0f33265..70a9be13f5c 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_callParamsMissing_block_8.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_callParamsMissing_block_8.json @@ -12,7 +12,7 @@ "id": 4, "error":{ "code":-32602, - "message":"Invalid params" + "message":"Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidBlockhash.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidBlockhash.json index d6a714eb49b..f00531954c3 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidBlockhash.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidBlockhash.json @@ -17,7 +17,7 @@ "id": 3, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidBlockHash.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidBlockHash.json index fa6fab63065..7e56b0a5669 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidBlockHash.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidBlockHash.json @@ -13,7 +13,7 @@ "id": 28, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidParams.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidParams.json index e84f3045a33..0f07f4a3bbe 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidParams.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidParams.json @@ -10,7 +10,7 @@ "id": 32, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_blockNumber.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_blockNumber.json index 91f6a6af8f7..4dca011466b 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_blockNumber.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_blockNumber.json @@ -12,7 +12,7 @@ "id": 300, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_tag.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_tag.json index 655ff6013ae..8fc9c2d805a 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_tag.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_tag.json @@ -12,7 +12,7 @@ "id": 301, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByNumber_invalidParams.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByNumber_invalidParams.json index 7e40d417e76..1a56a83a607 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByNumber_invalidParams.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByNumber_invalidParams.json @@ -10,7 +10,7 @@ "id": 248, "error": { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidBlockHash.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidBlockHash.json index a5e1e004af8..9e715fca1da 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidBlockHash.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidBlockHash.json @@ -13,7 +13,7 @@ "id": 0, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidParams.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidParams.json index 5a65b4d17c5..929a0f3f358 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidParams.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidParams.json @@ -10,7 +10,7 @@ "id": 255, "error": { "code": -32602, - "message": "Invalid params" + "message": "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidBlockHash.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidBlockHash.json index 257380fdac1..4fb69d437c9 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidBlockHash.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidBlockHash.json @@ -14,7 +14,7 @@ "id": 28, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidParams.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidParams.json index ba169f79dea..095ebd2a910 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidParams.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidParams.json @@ -10,7 +10,7 @@ "id": 28, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidBlockHash.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidBlockHash.json index 3ab3afb25ea..e8fecda1030 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidBlockHash.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidBlockHash.json @@ -14,7 +14,7 @@ "id": 341, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidParams.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidParams.json index 99af70906a3..9ad533c0c68 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidParams.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidParams.json @@ -10,7 +10,7 @@ "id": 342, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_invalidParams.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_invalidParams.json index 8ba25d9c33b..c88d01904db 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_invalidParams.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_invalidParams.json @@ -10,7 +10,7 @@ "id": 486, "error": { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockHash.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockHash.json index 52651090e96..f98c40c0d2c 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockHash.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockHash.json @@ -13,7 +13,7 @@ "id": 487, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockNumber.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockNumber.json index 0ad4a0d3cb4..c25d81a1abb 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockNumber.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockNumber.json @@ -13,7 +13,7 @@ "id": 487, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block, unable to parse RLP" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_missingArgument.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_missingArgument.json index 75437d4db8a..75ca3aed1aa 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_missingArgument.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_missingArgument.json @@ -10,7 +10,7 @@ "id": 489, "error": { "code": -32602, - "message": "Invalid params" + "message": "Invalid block, unable to parse RLP" } }, "statusCode": 200 From bd3f5e990f535548e9b5adf480d2a23d431a3487 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 14:37:38 +1000 Subject: [PATCH 41/56] 5098: Update RpcErrorType.INVALID_CALL_PARAMS Signed-off-by: Matilda Clerke --- .../internal/methods/JsonCallParameterUtil.java | 10 +++++++++- .../internal/privacy/methods/priv/PrivCall.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java index b2df8c0676b..aba721d290d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java @@ -17,13 +17,21 @@ 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.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; public class JsonCallParameterUtil { private JsonCallParameterUtil() {} public static JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) { - final JsonCallParameter callParams = request.getRequiredParameter(0, JsonCallParameter.class); + final JsonCallParameter callParams; + try { + callParams = request.getRequiredParameter(0, JsonCallParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid call parameters (index 0)", RpcErrorType.INVALID_CALL_PARAMS); + } if (callParams.getGasPrice() != null && (callParams.getMaxFeePerGas().isPresent() diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index 8fe48474a83..90bf92ac152 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -104,9 +105,15 @@ private JsonRpcError errorResponse( } private JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) { - final JsonCallParameter callParams = request.getRequiredParameter(1, JsonCallParameter.class); + final JsonCallParameter callParams; + try { + callParams = request.getRequiredParameter(1, JsonCallParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid call parameters (index 1)", RpcErrorType.INVALID_CALL_PARAMS); + } if (callParams.getTo() == null) { - throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments"); + throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments", RpcErrorType.INVALID_CALL_PARAMS); } return callParams; } From 1f7a455299c528dc8f887bfa347d3c563d6aa784 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 14:59:59 +1000 Subject: [PATCH 42/56] 5098: Update RpcErrorType.INVALID_CONSOLIDATION_REQUEST_PARAMS Signed-off-by: Matilda Clerke --- .../internal/methods/engine/AbstractEngineNewPayload.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 c548507710d..8d7a12f2541 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 @@ -197,8 +197,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) if (!getConsolidationRequestValidator( protocolSchedule.get(), blockParam.getTimestamp(), blockParam.getBlockNumber()) .validateParameter(maybeConsolidationRequests)) { - return new JsonRpcErrorResponse( - reqId, new JsonRpcError(INVALID_PARAMS, "Invalid consolidation request")); + return new JsonRpcErrorResponse(reqId, RpcErrorType.INVALID_CONSOLIDATION_REQUEST_PARAMS); } Optional> maybeRequests = From bfe75b31cd67eb87e72c1cc6de34076839c95efe Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 15:08:19 +1000 Subject: [PATCH 43/56] 5098: Update RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS Signed-off-by: Matilda Clerke --- .../methods/priv/PrivCreatePrivacyGroup.java | 14 ++++++++++++-- .../methods/priv/PrivCreatePrivacyGroupTest.java | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java index 3527c02ad5b..42433f771b9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java @@ -18,12 +18,15 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcEnclaveErrorConverter; 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.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter; 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; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.slf4j.Logger; @@ -50,8 +53,15 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { LOG.trace("Executing {}", RpcMethod.PRIV_CREATE_PRIVACY_GROUP.getMethodName()); - final CreatePrivacyGroupParameter parameter = - requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class); + final CreatePrivacyGroupParameter parameter; + try { + parameter = requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class); + } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException + throw new InvalidJsonRpcParameters( + "Invalid create privacy group parameter (index 0)", + RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS, + e); + } LOG.trace( "Creating a privacy group with name {} and description {}", diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java index 9be3122c1e4..771c287ac3b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java @@ -231,7 +231,7 @@ public String getDescription() { catchThrowableOfType( () -> privCreatePrivacyGroup.response(request), InvalidJsonRpcParameters.class); - assertThat(response.getMessage()).contains("Invalid json rpc parameter at index 0"); + assertThat(response.getMessage()).contains("Invalid create privacy group parameter (index 0)"); } @Test @@ -249,7 +249,7 @@ public void returnsCorrectExceptionMissingParam() { catchThrowableOfType( () -> privCreatePrivacyGroup.response(request), InvalidJsonRpcParameters.class); - assertThat(response.getMessage()).isEqualTo("Missing required json rpc parameter at index 0"); + assertThat(response.getMessage()).isEqualTo("Invalid create privacy group parameter (index 0)"); } @Test From bc1e563c6d27473b97c493ec8a436692dabef3e7 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 15:17:31 +1000 Subject: [PATCH 44/56] 5098: Fix broken test Signed-off-by: Matilda Clerke --- .../eth/eth_getBlockTransactionCountByHash_invalidParams.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByHash_invalidParams.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByHash_invalidParams.json index e05ba50cc6e..07a35abf6d9 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByHash_invalidParams.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByHash_invalidParams.json @@ -10,7 +10,7 @@ "id": 209, "error": { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid block hash params" } }, "statusCode": 200 From 34a8718c089a33ad6f71333c1ef5eae6d36990f1 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 15:31:32 +1000 Subject: [PATCH 45/56] 5098: Update RpcErrorType.INVALID_DATA_PARAMS Signed-off-by: Matilda Clerke --- .../api/jsonrpc/internal/methods/Web3Sha3.java | 14 +++++++++++--- .../api/jsonrpc/internal/methods/Web3Sha3Test.java | 8 ++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java index b1d137bb6b7..1e26bff97ec 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java @@ -17,6 +17,8 @@ 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.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; @@ -41,11 +43,17 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { 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 +62,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { 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); } } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3Test.java index 83310ead028..a978e5c0c1d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3Test.java @@ -70,7 +70,7 @@ public void shouldReturnErrorOnOddLengthParam() { 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 void shouldReturnErrorOnNonHexParam() { 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 void shouldReturnErrorOnNoPrefixParam() { 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 void shouldReturnErrorOnNoPrefixNonHexParam() { 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); From 3642bebea8e9937b282795d319319e0ed7267001 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 15:34:50 +1000 Subject: [PATCH 46/56] 5098: Update RpcErrorType.INVALID_DEPOSIT_REQUEST_PARAMS Signed-off-by: Matilda Clerke --- .../internal/methods/engine/AbstractEngineNewPayload.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 8d7a12f2541..246a2777c8a 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 @@ -169,8 +169,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) 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> maybeWithdrawalRequests = From 3cf1d8c11c67a2479c79b3e05672070ef835470d Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 15:37:47 +1000 Subject: [PATCH 47/56] 5098: Update RpcErrorType.INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS Signed-off-by: Matilda Clerke --- .../EngineExchangeTransitionConfiguration.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java index fdb94df9d67..76ee4e015d3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java @@ -20,10 +20,13 @@ 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.parameters.JsonRpcParameter; 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 +68,17 @@ public String getName() { 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() From 6109c16f2da2100fd37239082f21ea105280c962 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 15:59:20 +1000 Subject: [PATCH 48/56] 5098: Apply spotless Signed-off-by: Matilda Clerke --- .../jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java | 1 - 1 file changed, 1 deletion(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java index 16d10d7ff2a..9269bf965c0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java @@ -61,7 +61,6 @@ private BlockResult blockResult(final JsonRpcRequestContext requestContext) { "Invalid block index parameter (index 1)", RpcErrorType.INVALID_BLOCK_INDEX_PARAMS, e); } - return blockchain.getOmmer(hash, index).map(UncleBlockResult::build).orElse(null); } } From 64a45be15d211d5083da36cecf068a46ff9d85c1 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 12 Aug 2024 16:16:18 +1000 Subject: [PATCH 49/56] 5098: Fix broken tests Signed-off-by: Matilda Clerke --- .../ibft/jsonrpc/methods/IbftGetSignerMetricsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetSignerMetricsTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetSignerMetricsTest.java index bb6d44aca60..4eb8fbe12bd 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetSignerMetricsTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetSignerMetricsTest.java @@ -75,14 +75,14 @@ public void returnsCorrectMethodName() { public void exceptionWhenInvalidStartBlockSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("INVALID"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid start block parameter (index 0)"); } @Test public void exceptionWhenInvalidEndBlockSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 1"); + .hasMessageContaining("Invalid end block parameter (index 1)"); } @Test From 65435df1bcabfd30944d68c7034fcdb4fcb8bd68 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 13 Aug 2024 09:28:25 +1000 Subject: [PATCH 50/56] 5098: Fix broken tests Signed-off-by: Matilda Clerke --- .../clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java index 89c48fb978b..310b3b1017d 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java @@ -75,14 +75,14 @@ public void returnsCorrectMethodName() { public void exceptionWhenInvalidStartBlockSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("INVALID"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid start block parameter (index 0)"); } @Test public void exceptionWhenInvalidEndBlockSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 1"); + .hasMessageContaining("Invalid end block parameter (index 1)"); } @Test From a37bde0250cf0d8f3b5169e9a8bf098dcbf0f614 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 13 Aug 2024 09:59:11 +1000 Subject: [PATCH 51/56] 5098: Fix broken tests Signed-off-by: Matilda Clerke --- .../api/jsonrpc/eth/eth_getBalance_illegalRangeLessThan.json | 2 +- .../api/jsonrpc/eth/eth_getCode_illegalRangeLessThan.json | 2 +- .../api/jsonrpc/eth/eth_getProof_illegalRangeLessThan.json | 2 +- .../api/jsonrpc/eth/eth_getStorageAt_illegalRangeLessThan.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_illegalRangeLessThan.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_illegalRangeLessThan.json index 146756fc552..2a59465e88f 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_illegalRangeLessThan.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_illegalRangeLessThan.json @@ -13,7 +13,7 @@ "id": 28, "error": { "code": -32602, - "message": "Invalid params" + "message": "Invalid block number params" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_illegalRangeLessThan.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_illegalRangeLessThan.json index 6a336a96667..e2011bb4d05 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_illegalRangeLessThan.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_illegalRangeLessThan.json @@ -13,7 +13,7 @@ "id": 13, "error": { "code": -32602, - "message": "Invalid params" + "message": "Invalid block number params" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_illegalRangeLessThan.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_illegalRangeLessThan.json index de1c3ccb57b..f0cf31f79dd 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_illegalRangeLessThan.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_illegalRangeLessThan.json @@ -14,7 +14,7 @@ "id": 28, "error": { "code": -32602, - "message": "Invalid params" + "message": "Invalid block number params" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_illegalRangeLessThan.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_illegalRangeLessThan.json index 67892401ce3..1f46003c8f6 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_illegalRangeLessThan.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_illegalRangeLessThan.json @@ -14,7 +14,7 @@ "id": 337, "error": { "code": -32602, - "message": "Invalid params" + "message": "Invalid block number params" } }, "statusCode": 200 From 611bf741b26edbc4d8f4d9479f36e5fb8dd94af9 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 13 Aug 2024 10:59:09 +1000 Subject: [PATCH 52/56] 5098: Fix broken tests Signed-off-by: Matilda Clerke --- .../qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java index d070ba47cc3..153a4ef55bc 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java @@ -75,14 +75,14 @@ public void returnsCorrectMethodName() { public void exceptionWhenInvalidStartBlockSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("INVALID"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 0"); + .hasMessageContaining("Invalid start block parameter (index 0)"); } @Test public void exceptionWhenInvalidEndBlockSupplied() { assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID"))) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("Invalid json rpc parameter at index 1"); + .hasMessageContaining("Invalid end block parameter (index 1)"); } @Test From 797624e24224742335f6366c8d3b0cababf5284c Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 13 Aug 2024 11:59:38 +1000 Subject: [PATCH 53/56] 5098: Remove TODO by wrapping unexpected exception and rethrowing Signed-off-by: Matilda Clerke --- .../besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java index 9b23241fa97..60f38fb7ace 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java @@ -119,8 +119,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequest().getId(), ((InvalidJsonRpcParameters) ex.get()).getRpcErrorType()); } else { - LOG.error("Unexpected exception: {}", ex.get(), ex.get()); - // TODO: wrap and throw? Something obviously went wrong + throw new RuntimeException(ex.get()); } } From f22c7cff2ad56e11cfc23aed9f010bf53d18537a Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 13 Aug 2024 15:23:54 +1000 Subject: [PATCH 54/56] 5098: Apply spotless Signed-off-by: Matilda Clerke --- .../jsonrpc/internal/methods/JsonCallParameterUtil.java | 3 +-- .../jsonrpc/internal/privacy/methods/priv/PrivCall.java | 6 +++--- .../privacy/methods/priv/PrivCreatePrivacyGroup.java | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java index aba721d290d..891d837df3c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java @@ -17,7 +17,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.parameters.JsonCallParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; public class JsonCallParameterUtil { @@ -30,7 +29,7 @@ public static JsonCallParameter validateAndGetCallParams(final JsonRpcRequestCon callParams = request.getRequiredParameter(0, JsonCallParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid call parameters (index 0)", RpcErrorType.INVALID_CALL_PARAMS); + "Invalid call parameters (index 0)", RpcErrorType.INVALID_CALL_PARAMS); } if (callParams.getGasPrice() != null diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index 90bf92ac152..0418fc24746 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -110,10 +109,11 @@ private JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext r callParams = request.getRequiredParameter(1, JsonCallParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid call parameters (index 1)", RpcErrorType.INVALID_CALL_PARAMS); + "Invalid call parameters (index 1)", RpcErrorType.INVALID_CALL_PARAMS); } if (callParams.getTo() == null) { - throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments", RpcErrorType.INVALID_CALL_PARAMS); + throw new InvalidJsonRpcParameters( + "Missing \"to\" field in call arguments", RpcErrorType.INVALID_CALL_PARAMS); } return callParams; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java index 42433f771b9..ae35506298f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java @@ -20,7 +20,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.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -58,9 +57,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { parameter = requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class); } catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException throw new InvalidJsonRpcParameters( - "Invalid create privacy group parameter (index 0)", - RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS, - e); + "Invalid create privacy group parameter (index 0)", + RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS, + e); } LOG.trace( From 292d8cd36ca4afd52e171475c558451a28802035 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 13 Aug 2024 16:09:03 +1000 Subject: [PATCH 55/56] 5098: Fix broken tests Signed-off-by: Matilda Clerke --- .../api/jsonrpc/eth/eth_call_blob_zero_versioned_hash.json | 2 +- .../eth_call_invalidWithDifferentInputAndDataAttributes.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_versioned_hash.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_versioned_hash.json index bf4cb06350a..80c21e6a1b2 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_versioned_hash.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_versioned_hash.json @@ -17,7 +17,7 @@ "response": { "jsonrpc": "2.0", "id": 4, - "error":{"code":-32602,"message":"Invalid params"} + "error":{"code":-32602,"message":"Invalid call params"} }, "statusCode": 200 } diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidWithDifferentInputAndDataAttributes.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidWithDifferentInputAndDataAttributes.json index 309e96df249..e304f0cbbd6 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidWithDifferentInputAndDataAttributes.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidWithDifferentInputAndDataAttributes.json @@ -18,7 +18,7 @@ "id": 3, "error" : { "code" : -32602, - "message" : "Invalid params" + "message" : "Invalid call params" } }, "statusCode": 200 From 5fd0307a81f2b80c81c770145832db6212ea1c36 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Tue, 13 Aug 2024 16:36:31 +1000 Subject: [PATCH 56/56] 5098: Apply spotless Signed-off-by: Matilda Clerke --- .../api/jsonrpc/internal/methods/Web3Sha3.java | 7 +++---- .../engine/EngineExchangeTransitionConfiguration.java | 11 +++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java index 1e26bff97ec..b06cd572934 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java @@ -18,7 +18,6 @@ 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.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; @@ -48,12 +47,12 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { 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); + "Invalid data parameter (index 0)", RpcErrorType.INVALID_DATA_PARAMS, e); } if (!data.isEmpty() && !data.startsWith("0x")) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS); } try { @@ -62,7 +61,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { requestContext.getRequest().getId(), Hash.keccak256(byteData).toString()); } catch (final IllegalArgumentException err) { return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS); + requestContext.getRequest().getId(), RpcErrorType.INVALID_DATA_PARAMS); } } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java index 76ee4e015d3..67b86575336 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java @@ -23,7 +23,6 @@ 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.parameters.JsonRpcParameter; 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; @@ -71,13 +70,13 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) final EngineExchangeTransitionConfigurationParameter remoteTransitionConfiguration; try { remoteTransitionConfiguration = - requestContext.getRequiredParameter( - 0, EngineExchangeTransitionConfigurationParameter.class); + 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); + "Invalid engine exchange transition configuration parameters (index 0)", + RpcErrorType.INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS, + e); } final Object reqId = requestContext.getRequest().getId();