Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Invalid payload attributes error code #6582

Merged
merged 14 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"jsonrpc" : "2.0",
"id" : 67,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"code" : -38003,
"message" : "Invalid payload attributes"
}
},
"statusCode" : 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ protected Optional<JsonRpcErrorResponse> isPayloadAttributesValid(
|| payloadAttributes.getParentBeaconBlockRoot().isEmpty()) {
return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.UNSUPPORTED_FORK));
} else {
return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS));
return Optional.of(
new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES));
}
} else if (payloadAttributes.getParentBeaconBlockRoot() != null) {
LOG.error(
"Parent beacon block root hash present in payload attributes before cancun hardfork");
return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS));
return Optional.of(
new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES));
} else {
return Optional.empty();
}
}

@Override
protected RpcErrorType getInvalidPayloadError() {
return RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ protected ValidationResult<RpcErrorType> validateParameter(
final EngineForkchoiceUpdatedParameter fcuParameter,
final Optional<EnginePayloadAttributesParameter> maybePayloadAttributes) {
if (fcuParameter.getHeadBlockHash() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing head block hash");
return ValidationResult.invalid(getInvalidPayloadError(), "Missing head block hash");
} else if (fcuParameter.getSafeBlockHash() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing safe block hash");
return ValidationResult.invalid(getInvalidPayloadError(), "Missing safe block hash");
} else if (fcuParameter.getFinalizedBlockHash() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing finalized block hash");
return ValidationResult.invalid(getInvalidPayloadError(), "Missing finalized block hash");
}
if (maybePayloadAttributes.isPresent()) {
if (maybePayloadAttributes.get().getParentBeaconBlockRoot() == null) {
return ValidationResult.invalid(
RpcErrorType.INVALID_PARAMS, "Missing parent beacon block root hash");
getInvalidPayloadError(), "Missing parent beacon block root hash");
}
}
return ValidationResult.valid();
Expand Down Expand Up @@ -93,11 +93,18 @@ protected Optional<JsonRpcErrorResponse> isPayloadAttributesValid(
if (payloadAttributes.getParentBeaconBlockRoot() == null) {
LOG.error(
"Parent beacon block root hash not present in payload attributes after cancun hardfork");
return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS));
return Optional.of(new JsonRpcErrorResponse(requestId, getInvalidPayloadError()));
} else if (payloadAttributes.getTimestamp().longValue() == 0) {
return Optional.of(new JsonRpcErrorResponse(requestId, getInvalidPayloadError()));
} else if (payloadAttributes.getTimestamp() < cancun.get().milestone()) {
return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.UNSUPPORTED_FORK));
} else {
return Optional.empty();
}
}

@Override
protected RpcErrorType getInvalidPayloadError() {
return RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public void shouldIgnoreUpdateToOldHeadAndNotPreparePayload() {

@Test
public void shouldReturnInvalidIfPayloadTimestampNotGreaterThanHead() {
BlockHeader mockParent = blockHeaderBuilder.number(9L).buildHeader();
BlockHeader mockParent = blockHeaderBuilder.timestamp(99).number(9L).buildHeader();
BlockHeader mockHeader =
blockHeaderBuilder.number(10L).parentHash(mockParent.getHash()).buildHeader();
setupValidForkchoiceUpdate(mockHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -42,4 +43,9 @@ public void shouldReturnExpectedMethodName() {
protected String getMethodName() {
return RpcMethod.ENGINE_FORKCHOICE_UPDATED_V2.getMethodName();
}

@Override
protected RpcErrorType expectedInvalidPayloadError() {
return RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES;
}
}
Loading