Skip to content

Commit

Permalink
5098 branch 16 update invalid enode and excess blob gas params (#7457)
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: Update RpcErrorType.INVALID_CALL_PARAMS

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

* 5098: Update RpcErrorType.INVALID_CONSOLIDATION_REQUEST_PARAMS

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

* 5098: Update RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS

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

* 5098: Fix broken test

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

* 5098: Update RpcErrorType.INVALID_DATA_PARAMS

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

* 5098: Update RpcErrorType.INVALID_DEPOSIT_REQUEST_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_FORKCHOICE_UPDATED_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_PAYLOAD_ATTRIBUTES_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_PAYLOAD_PARAMS

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

* 5098: Update RpcErrorType.INVALID_ENGINE_PREPARE_PAYLOAD_PARAMS

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

* 5098: Apply spotless

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

* 5098: Update RpcErrorType.INVALID_ENODE_PARAMS

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

* 5098: Update RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS

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

* 5098: Apply spotless

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 15, 2024
1 parent b4869e7 commit 137515d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.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.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
Expand Down Expand Up @@ -45,9 +44,6 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
try {
final String enodeString = requestContext.getRequiredParameter(0, String.class);
return performOperation(requestContext.getRequest().getId(), enodeString);
} catch (final InvalidJsonRpcParameters e) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
} catch (final IllegalArgumentException e) {
if (e.getMessage()
.endsWith(
Expand All @@ -69,6 +65,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
} catch (final P2PDisabledException e) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.P2P_DISABLED);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_ENODE_PARAMS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ protected ValidationResult<RpcErrorType> validateBlobs(
if (maybeParentHeader.isPresent()) {
if (!validateExcessBlobGas(header, maybeParentHeader.get(), protocolSpec)) {
return ValidationResult.invalid(
RpcErrorType.INVALID_PARAMS,
RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS,
"Payload excessBlobGas does not match calculated excessBlobGas");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected ValidationResult<RpcErrorType> validateParameters(
}
if (payloadParameter.getExcessBlobGas() != null) {
return ValidationResult.invalid(
RpcErrorType.INVALID_PARAMS, "non-null ExcessBlobGas pre-cancun");
RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS, "Missing excess blob gas field");
}
return ValidationResult.valid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ protected ValidationResult<RpcErrorType> validateParameters(
return ValidationResult.invalid(
RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field");
} else if (payloadParameter.getExcessBlobGas() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing blob gas fields");
return ValidationResult.invalid(
RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS, "Missing excess blob gas field");
} else if (maybeVersionedHashParam == null || maybeVersionedHashParam.isEmpty()) {
return ValidationResult.invalid(
RpcErrorType.INVALID_PARAMS, "Missing versioned hashes field");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected ValidationResult<RpcErrorType> validateParameters(
RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field");
} else if (payloadParameter.getExcessBlobGas() == null) {
return ValidationResult.invalid(
RpcErrorType.INVALID_PARAMS, "non-null ExcessBlobGas pre-cancun");
RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS, "Missing excess blob gas field");
} else if (maybeVersionedHashParam == null || maybeVersionedHashParam.isEmpty()) {
return ValidationResult.invalid(
RpcErrorType.INVALID_PARAMS, "Missing versioned hashes field");
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.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.StringListParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
Expand Down Expand Up @@ -46,8 +47,13 @@ public String getName() {

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final StringListParameter enodeListParam =
requestContext.getRequiredParameter(0, StringListParameter.class);
final StringListParameter enodeListParam;
try {
enodeListParam = requestContext.getRequiredParameter(0, StringListParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid enode list parameter (index 0)", RpcErrorType.INVALID_ENODE_PARAMS, e);
}

try {
if (nodeAllowlistPermissioningController.isPresent()) {
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.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.StringListParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
Expand Down Expand Up @@ -46,8 +47,13 @@ public String getName() {

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final StringListParameter enodeListParam =
requestContext.getRequiredParameter(0, StringListParameter.class);
final StringListParameter enodeListParam;
try {
enodeListParam = requestContext.getRequiredParameter(0, StringListParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid enode list parameter (index 0)", RpcErrorType.INVALID_ENODE_PARAMS, e);
}
try {
if (nodeAllowlistPermissioningController.isPresent()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void shouldValidateExcessBlobGasCorrectly() {

final JsonRpcError jsonRpcError = fromErrorResp(resp);
assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode());
assertThat(jsonRpcError.getData()).isEqualTo("non-null ExcessBlobGas pre-cancun");
assertThat(jsonRpcError.getData()).isEqualTo("Missing excess blob gas field");
verify(engineCallListener, times(1)).executionEngineCalled();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void shouldValidateExcessBlobGasCorrectly() {

final JsonRpcError jsonRpcError = fromErrorResp(resp);
assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode());
assertThat(jsonRpcError.getData()).isEqualTo("Missing blob gas fields");
assertThat(jsonRpcError.getData()).isEqualTo("Missing excess blob gas field");
verify(engineCallListener, times(1)).executionEngineCalled();
}

Expand Down

0 comments on commit 137515d

Please sign in to comment.