5098 branch 12 update invalid block index and number (#7440)

* 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: Update with usage of RpcErrorType.INVALID_BLOCK_COUNT_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: Include parameter index in INVALID_BLOCK_COUNT_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: Update INVALID_BLOCK_HASH_PARAMS locations

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

* 5098: Fix broken unit test

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

* 5098: apply spotless

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

* 5098: Update RpcErrorType.INVALID_BLOCK_INDEX

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

* 5098: Update RpcErrorType.INVALID_BLOCK_NUMBER

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

* 5098: apply spotless

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 test

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

* 5098: Apply spotless

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>

* 5098: Remove TODO by wrapping unexpected exception and rethrowing

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/7454/head
Matilda-Clerke 3 months ago committed by GitHub
parent 50f8add052
commit c61cf0b5af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSignerMetricsTest.java
  2. 21
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/jsonrpc/AbstractGetSignerMetricsMethod.java
  3. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/jsonrpc/methods/IbftGetSignerMetricsTest.java
  4. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java
  5. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractBlockParameterOrBlockHashMethod.java
  6. 21
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCache.java
  7. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRepairCache.java
  8. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java
  9. 24
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetLogs.java
  10. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndex.java
  11. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndex.java
  12. 13
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java
  13. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminLogsRemoveCacheTest.java
  14. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java
  15. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java
  16. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java
  17. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_illegalRangeLessThan.json
  18. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_illegalRangeLessThan.json
  19. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_illegalRangeLessThan.json
  20. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_illegalRangeLessThan.json
  21. 10
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java

@ -75,14 +75,14 @@ public class CliqueGetSignerMetricsTest {
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

@ -18,6 +18,7 @@ import org.hyperledger.besu.consensus.common.BlockInterface;
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.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
@ -66,17 +67,27 @@ public abstract class AbstractGetSignerMetricsMethod {
*/
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Optional<BlockParameter> startBlockParameter =
requestContext.getOptionalParameter(0, BlockParameter.class);
final Optional<BlockParameter> endBlockParameter =
requestContext.getOptionalParameter(1, BlockParameter.class);
final Optional<BlockParameter> 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<BlockParameter> 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<Address, SignerMetricResult> proposersMap = new HashMap<>();

@ -75,14 +75,14 @@ public class IbftGetSignerMetricsTest {
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

@ -75,14 +75,14 @@ public class QbftGetSignerMetricsTest {
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

@ -106,7 +106,7 @@ public abstract class AbstractBlockParameterOrBlockHashMethod implements JsonRpc
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);

@ -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.JsonRpcResponse;
@ -42,10 +43,20 @@ public class AdminLogsRemoveCache implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Optional<BlockParameter> startBlockParameter =
requestContext.getOptionalParameter(0, BlockParameter.class);
final Optional<BlockParameter> stopBlockParameter =
requestContext.getOptionalParameter(1, BlockParameter.class);
final Optional<BlockParameter> 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<BlockParameter> 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 +92,7 @@ public class AdminLogsRemoveCache implements JsonRpcMethod {
if (stopBlock < startBlock) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
}
final TransactionLogBloomCacher transactionLogBloomCacher =

@ -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.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 +40,13 @@ public class AdminLogsRepairCache implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Optional<Long> blockNumber = requestContext.getOptionalParameter(0, Long.class);
final Optional<Long> 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()) {

@ -113,7 +113,7 @@ public class EthFeeHistory implements JsonRpcMethod {
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));

@ -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.FilterParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
@ -78,16 +79,22 @@ public class EthGetLogs implements JsonRpcMethod {
.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);
@ -107,12 +114,13 @@ public class EthGetLogs implements JsonRpcMethod {
.addArgument(requestContext.getRequest())
.setCause(ex.get())
.log();
if (ex.get() instanceof IllegalArgumentException) {
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 {
throw new RuntimeException(ex.get());
}
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
}
return new JsonRpcSuccessResponse(

@ -53,7 +53,13 @@ public class EthGetUncleByBlockHashAndIndex implements JsonRpcMethod {
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);
}

@ -48,7 +48,13 @@ public class EthGetUncleByBlockNumberAndIndex extends AbstractBlockParameterMeth
@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)

@ -58,8 +58,15 @@ public class EngineGetPayloadBodiesByRangeV1 extends ExecutionEngineJsonRpcMetho
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 +84,7 @@ public class EngineGetPayloadBodiesByRangeV1 extends ExecutionEngineJsonRpcMetho
.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()) {

@ -152,7 +152,8 @@ public class AdminLogsRemoveCacheTest {
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));

@ -233,7 +233,7 @@ public class EthFeeHistoryTest {
assertThat(
((JsonRpcErrorResponse) feeHistoryRequest("0x2", "11", new double[] {100.0}))
.getErrorType())
.isEqualTo(RpcErrorType.INVALID_PARAMS);
.isEqualTo(RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
}
@Test

@ -90,7 +90,7 @@ public class EthGetUncleByBlockHashAndIndexTest {
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 class EthGetUncleByBlockHashAndIndexTest {
assertThat(thrown)
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Invalid json rpc parameter at index 1");
.hasMessageContaining("Invalid block index parameter (index 1)");
}
@Test

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

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

@ -13,7 +13,7 @@
"id": 13,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block number params"
}
},
"statusCode": 200

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

@ -14,7 +14,7 @@
"id": 337,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block number params"
}
},
"statusCode": 200

@ -15,9 +15,11 @@
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.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 +38,13 @@ public class TestRewindToBlock implements JsonRpcMethod {
@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));

Loading…
Cancel
Save