diff --git a/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json b/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json index ac5947c79be..23ddea33af0 100644 --- a/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json +++ b/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json @@ -20,8 +20,8 @@ "jsonrpc" : "2.0", "id" : 67, "error" : { - "code" : -32602, - "message" : "Invalid params" + "code" : -38003, + "message" : "Invalid payload attributes" } }, "statusCode" : 200 diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java index b6406a3e662..77ca45df043 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java @@ -56,14 +56,21 @@ protected Optional 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; + } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java index c070d220854..51672d7280e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java @@ -56,16 +56,16 @@ protected ValidationResult validateParameter( final EngineForkchoiceUpdatedParameter fcuParameter, final Optional 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(); @@ -93,11 +93,18 @@ protected Optional 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; + } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java index 249a12d9f0b..931d2259875 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java @@ -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); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java index 77249934113..4cb17eab4f7 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java @@ -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; @@ -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; + } }