Skip to content

Commit

Permalink
5098 branch 12 update invalid block index and number (#7440)
Browse files Browse the repository at this point in the history
* 5098: Add RpcErrorTypes

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Add JsonRpcParameterException for later use

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update locations for RpcErrorType.INVALID_ACCOUNTS_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Address review comments, apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with changes from branch 1

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_HASH_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update plugin-api gradle hash

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Add comment on INVALID_PARAMS_ERROR_CODE

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Apply spotless on latest changes

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken unit test

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken unit test

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with usage of RpcErrorType.INVALID_AUTH_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with usage of RpcErrorType.INVALID_BLOB_COUNT

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with usage of RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update with usage of RpcErrorType.INVALID_BLOCK_COUNT_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken integration test

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Add index to exception messages

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: apoply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update BaseJsonRpcProcessor to utilise RpcErrorType from InvalidJsonRpcParameters

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Include parameter index in INVALID_AUTH_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Include parameter index in INVALID_BLOCK_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Include parameter index in INVALID_BLOCK_COUNT_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken integration test

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Rename INVALID_AUTH_PARAMS to INVALID_PROPOSAL_PARAMS

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update INVALID_BLOCK_HASH_PARAMS locations

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken unit test

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update RpcErrorType.INVALID_BLOCK_INDEX

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Update RpcErrorType.INVALID_BLOCK_NUMBER

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken tests

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken test

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Apply spotless

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken tests

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken tests

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken tests

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Fix broken tests

Signed-off-by: Matilda Clerke <[email protected]>

* 5098: Remove TODO by wrapping unexpected exception and rethrowing

Signed-off-by: Matilda Clerke <[email protected]>

---------

Signed-off-by: Matilda Clerke <[email protected]>
Signed-off-by: Matilda-Clerke <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
  • Loading branch information
Matilda-Clerke and macfarla authored Aug 13, 2024
1 parent 50f8add commit c61cf0b
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand Down Expand Up @@ -66,17 +67,27 @@ protected 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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.BlockParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
Expand All @@ -42,10 +43,20 @@ public String getName() {

@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()) {
Expand Down Expand Up @@ -81,7 +92,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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +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.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;

Expand All @@ -38,7 +40,13 @@ public String getName() {

@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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,16 +79,22 @@ 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);
Expand All @@ -107,12 +114,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
.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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ 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();
Expand All @@ -77,7 +84,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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_PARAMS);
new JsonRpcErrorResponse(
request.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);

when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.of(block));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"id": 28,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block number params"
}
},
"statusCode": 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"id": 13,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block number params"
}
},
"statusCode": 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"id": 28,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block number params"
}
},
"statusCode": 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"id": 337,
"error": {
"code": -32602,
"message": "Invalid params"
"message": "Invalid block number params"
}
},
"statusCode": 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,7 +38,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));
Expand Down

0 comments on commit c61cf0b

Please sign in to comment.