5098 branch 8 update invalid block params (#7409)

* 5098: Add RpcErrorTypes

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

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

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

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

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

* 5098: Add JsonRpcParameterException for later use

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

* 5098: Update locations for RpcErrorType.INVALID_ACCOUNTS_PARAMS

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

* 5098: Address review comments, apply spotless

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

* 5098: Update with changes from branch 1

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

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_HASH_PARAMS

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

* 5098: apply spotless

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

* 5098: apply spotless

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

* 5098: Update plugin-api gradle hash

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

* 5098: Add comment on INVALID_PARAMS_ERROR_CODE

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

* 5098: Apply spotless on latest changes

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

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_PARAMS

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

* 5098: Fix broken unit test

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

* 5098: Fix broken unit test

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

* 5098: Update with usage of RpcErrorType.INVALID_AUTH_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOB_COUNT

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

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

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

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

* 5098: Fix broken integration test

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

* 5098: Add index to exception messages

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

* 5098: apoply spotless

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

* 5098: Update BaseJsonRpcProcessor to utilise RpcErrorType from InvalidJsonRpcParameters

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

* 5098: Include parameter index in INVALID_AUTH_PARAMS

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

* 5098: Include parameter index in INVALID_BLOCK_PARAMS

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

* 5098: Fix broken integration test

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

* 5098: Rename INVALID_AUTH_PARAMS to INVALID_PROPOSAL_PARAMS

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

* 5098: apply spotless

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

* 5098: Fix broken unit test

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

* 5098: Fix broken tests

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

* 5098: Fix broken tests

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

* 5098: Fix broken tests

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

* 5098: Fix broken tests

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

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda-Clerke <matilda.clerke@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7452/head
Matilda-Clerke 3 months ago committed by GitHub
parent 067be8cccc
commit bca34cb61f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java
  2. 9
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetValidatorsByBlockNumber.java
  3. 9
      consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumber.java
  4. 8
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java
  5. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java
  6. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java
  7. 20
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminGenerateLogBloomCache.java
  8. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountAt.java
  9. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java
  10. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawBlock.java
  11. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawHeader.java
  12. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java
  13. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java
  14. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java
  15. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java
  16. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockByNumber.java
  17. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java
  18. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java
  19. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java
  20. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBalance.java
  21. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java
  22. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceipts.java
  23. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockTransactionCountByNumber.java
  24. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java
  25. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumber.java
  26. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java
  27. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetStorageAt.java
  28. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByBlockNumberAndIndex.java
  29. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionCount.java
  30. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java
  31. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java
  32. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java
  33. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java
  34. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java
  35. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java
  36. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java
  37. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java
  38. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java
  39. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java
  40. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java
  41. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumberTest.java
  42. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java
  43. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java
  44. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_callParamsMissing_block_8.json
  45. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidBlockhash.json
  46. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidBlockHash.json
  47. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidParams.json
  48. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_blockNumber.json
  49. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockReceipts_invalidParams_tag.json
  50. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByNumber_invalidParams.json
  51. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidBlockHash.json
  52. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidParams.json
  53. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidBlockHash.json
  54. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidParams.json
  55. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidBlockHash.json
  56. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidParams.json
  57. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_invalidParams.json
  58. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockHash.json
  59. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockNumber.json
  60. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_missingArgument.json
  61. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/replay-trace-transaction/flat/trace_replayBlockTransactions_invalidBlockParam.json
  62. 9
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java

@ -17,6 +17,7 @@ package org.hyperledger.besu.consensus.clique.jsonrpc.methods;
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.response.JsonRpcErrorResponse;
@ -67,8 +68,13 @@ public class CliqueGetSigners implements JsonRpcMethod {
}
private Optional<BlockHeader> determineBlockHeader(final JsonRpcRequestContext request) {
final Optional<BlockParameter> blockParameter =
request.getOptionalParameter(0, BlockParameter.class);
final Optional<BlockParameter> blockParameter;
try {
blockParameter = request.getOptionalParameter(0, BlockParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"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);
return blockchainQueries.blockByNumber(blockNumber).map(BlockWithMetadata::getHeader);

@ -17,9 +17,11 @@ package org.hyperledger.besu.consensus.ibft.jsonrpc.methods;
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.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -50,7 +52,12 @@ public class IbftGetValidatorsByBlockNumber extends AbstractBlockParameterMethod
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -18,9 +18,11 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
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.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -50,7 +52,12 @@ public class QbftGetValidatorsByBlockNumber extends AbstractBlockParameterMethod
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -410,7 +410,7 @@ public class EthGetBlockByNumberIntegrationTest {
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 class EthGetBlockByNumberIntegrationTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Invalid json rpc parameter at index 0");
.hasMessageContaining("Invalid block parameter");
}
/**
@ -437,7 +437,6 @@ public class EthGetBlockByNumberIntegrationTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasNoCause()
.hasMessage("Missing required json rpc parameter at index 1");
}
@ -453,8 +452,7 @@ public class EthGetBlockByNumberIntegrationTest {
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) {

@ -19,10 +19,12 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErr
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.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 +58,12 @@ public class DebugReplayBlock extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -17,9 +17,11 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.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 +64,13 @@ public abstract class AbstractTraceByBlock extends AbstractBlockParameterMethod
@Override
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
final Optional<BlockParameter> maybeBlockParameter =
request.getOptionalParameter(2, BlockParameter.class);
final Optional<BlockParameter> maybeBlockParameter;
try {
maybeBlockParameter = request.getOptionalParameter(2, BlockParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
if (maybeBlockParameter.isPresent()) {
return maybeBlockParameter.get();

@ -16,9 +16,11 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.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 +40,13 @@ public class AdminGenerateLogBloomCache implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Optional<BlockParameter> startBlockParam =
requestContext.getOptionalParameter(0, BlockParameter.class);
final Optional<BlockParameter> startBlockParam;
try {
startBlockParam = 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_PARAMS, e);
}
final long startBlock;
if (startBlockParam.isEmpty() || startBlockParam.get().isEarliest()) {
startBlock = 0;
@ -50,8 +57,13 @@ public class AdminGenerateLogBloomCache implements JsonRpcMethod {
startBlock = Long.MAX_VALUE;
}
final Optional<BlockParameter> stopBlockParam =
requestContext.getOptionalParameter(1, BlockParameter.class);
final Optional<BlockParameter> stopBlockParam;
try {
stopBlockParam = 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_PARAMS, e);
}
final long stopBlock;
if (stopBlockParam.isEmpty()) {
if (startBlockParam.isEmpty()) {

@ -67,7 +67,12 @@ public class DebugAccountAt extends AbstractBlockParameterOrBlockHashMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -58,8 +58,16 @@ public class DebugAccountRange implements JsonRpcMethod {
@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 (index 0)",
RpcErrorType.INVALID_BLOCK_PARAMS,
e);
}
final String addressHash;
try {
addressHash = requestContext.getRequiredParameter(2, String.class);

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
@ -37,7 +38,12 @@ public class DebugGetRawBlock extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
@ -37,7 +38,12 @@ public class DebugGetRawHeader extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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 org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.rlp.RLP;
@ -40,7 +42,12 @@ public class DebugGetRawReceipts extends AbstractBlockParameterOrBlockHashMethod
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -20,9 +20,11 @@ import org.hyperledger.besu.datatypes.Hash;
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.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 +45,12 @@ public class DebugSetHead extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -69,8 +69,14 @@ public class DebugStorageRangeAt implements JsonRpcMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
final int transactionIndex = requestContext.getRequiredParameter(1, Integer.class);
final Address accountAddress;
try {

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.TransactionTraceParams;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer;
@ -69,9 +70,12 @@ public class DebugTraceBlock implements JsonRpcMethod {
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_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid block params (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
final TraceOptions traceOptions =
requestContext

@ -17,11 +17,13 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.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 +49,12 @@ public class DebugTraceBlockByNumber extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -18,11 +18,13 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErr
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.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 +63,13 @@ public class DebugTraceCall extends AbstractTraceCall {
@Override
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
final Optional<BlockParameter> maybeBlockParameter =
request.getOptionalParameter(1, BlockParameter.class);
final Optional<BlockParameter> maybeBlockParameter;
try {
maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
return maybeBlockParameter.orElse(BlockParameter.LATEST);
}

@ -22,6 +22,7 @@ import org.hyperledger.besu.datatypes.Wei;
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.response.JsonRpcError;
@ -57,7 +58,12 @@ public class EthCall extends AbstractBlockParameterOrBlockHashMethod {
@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 (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -22,6 +22,7 @@ import org.hyperledger.besu.datatypes.Wei;
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.UnsignedIntParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
@ -91,7 +92,13 @@ public class EthFeeHistory implements JsonRpcMethod {
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 (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
final Optional<List<Double>> maybeRewardPercentiles =
request.getOptionalParameter(2, Double[].class).map(Arrays::asList);

@ -43,7 +43,12 @@ public class EthGetBalance extends AbstractBlockParameterOrBlockHashMethod {
@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 (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.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 +64,12 @@ public class EthGetBlockByNumber extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.BlockReceiptsResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptRootResult;
@ -53,7 +55,12 @@ public class EthGetBlockReceipts extends AbstractBlockParameterOrBlockHashMethod
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -16,7 +16,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
@ -33,7 +35,12 @@ public class EthGetBlockTransactionCountByNumber extends AbstractBlockParameterM
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -45,7 +45,12 @@ public class EthGetCode extends AbstractBlockParameterOrBlockHashMethod {
@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 (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.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 +42,12 @@ public class EthGetMinerDataByBlockNumber extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -49,7 +49,12 @@ public class EthGetProof extends AbstractBlockParameterOrBlockHashMethod {
@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 (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -39,7 +39,12 @@ public class EthGetStorageAt extends AbstractBlockParameterOrBlockHashMethod {
@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 (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -16,8 +16,10 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.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 +39,12 @@ public class EthGetTransactionByBlockNumberAndIndex extends AbstractBlockParamet
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -52,7 +52,12 @@ public class EthGetTransactionCount extends AbstractBlockParameterOrBlockHashMet
@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 (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -16,8 +16,10 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.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 +37,12 @@ public class EthGetUncleByBlockNumberAndIndex extends AbstractBlockParameterMeth
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -86,7 +86,7 @@ public class EthSendRawTransaction implements JsonRpcMethod {
} 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(

@ -18,10 +18,12 @@ import static org.hyperledger.besu.services.pipeline.PipelineBuilder.createPipel
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.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 +70,12 @@ public class TraceBlock extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErr
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.TraceCallManyParameter;
@ -63,8 +64,13 @@ public class TraceCallMany extends TraceCall implements JsonRpcMethod {
@Override
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
final Optional<BlockParameter> maybeBlockParameter =
request.getOptionalParameter(1, BlockParameter.class);
final Optional<BlockParameter> maybeBlockParameter;
try {
maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
return maybeBlockParameter.orElse(BlockParameter.LATEST);
}

@ -18,11 +18,13 @@ import static org.hyperledger.besu.services.pipeline.PipelineBuilder.createPipel
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.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 +72,12 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -53,7 +53,12 @@ public class PrivCall extends AbstractBlockParameterMethod {
@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 (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -20,6 +20,7 @@ import org.hyperledger.besu.enclave.EnclaveClientException;
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.privacy.methods.PrivacyIdProvider;
@ -60,7 +61,12 @@ public class PrivDebugGetStateRoot extends AbstractBlockParameterMethod {
@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 (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -48,7 +48,12 @@ public class PrivGetCode extends AbstractBlockParameterMethod {
@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 (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
}
@Override

@ -980,7 +980,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
// 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());
}

@ -129,8 +129,7 @@ public class EthGetBlockByNumberTest {
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 (index 0)");
verifyNoMoreInteractions(blockchainQueries);
}

@ -100,7 +100,7 @@ public class EthGetBlockReceiptsTest {
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 (index 0)");
verifyNoMoreInteractions(blockchainQueries);
}

@ -103,7 +103,7 @@ public class EthGetMinerDataByBlockNumberTest {
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 (index 0)");
verifyNoMoreInteractions(blockchainQueries);
}
@ -114,7 +114,7 @@ public class EthGetMinerDataByBlockNumberTest {
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);
}

@ -129,7 +129,7 @@ class EthGetProofTest {
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

@ -79,7 +79,7 @@ public class EthGetUncleByBlockNumberAndIndexTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Missing required json rpc parameter at index 0");
.hasMessage("Invalid block parameter (index 0)");
}
@Test

@ -12,7 +12,7 @@
"id": 4,
"error":{
"code":-32602,
"message":"Invalid params"
"message":"Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -17,7 +17,7 @@
"id": 3,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -13,7 +13,7 @@
"id": 28,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id": 32,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -12,7 +12,7 @@
"id": 300,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -12,7 +12,7 @@
"id": 301,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id": 248,
"error": {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -13,7 +13,7 @@
"id": 0,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id": 255,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -14,7 +14,7 @@
"id": 28,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id": 28,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -14,7 +14,7 @@
"id": 341,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id": 342,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id": 486,
"error": {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -13,7 +13,7 @@
"id": 487,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -13,7 +13,7 @@
"id": 487,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id": 489,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -13,7 +13,7 @@
"id": 415,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block, unable to parse RLP"
}
},
"statusCode": 200

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.retesteth.methods;
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.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
@ -52,7 +53,13 @@ public class TestImportRawBlock implements JsonRpcMethod {
@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 (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
final ProtocolContext protocolContext = this.context.getProtocolContext();
final Block block;

Loading…
Cancel
Save