mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-08 23:08:15 -05:00
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>
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user