Use Invalid payload attributes error code (#6582)

* invalid payload error code

* use non-zero timestamp

* use invalidPayloadAttributes error for V2 if non-null beacon root pre cancun

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/6605/head
Sally MacFarlane 8 months ago committed by GitHub
parent 7836e09d4e
commit 094fbb9453
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json
  2. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java
  3. 17
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java
  4. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java
  5. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java

@ -20,8 +20,8 @@
"jsonrpc" : "2.0",
"id" : 67,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"code" : -38003,
"message" : "Invalid payload attributes"
}
},
"statusCode" : 200

@ -56,14 +56,21 @@ public class EngineForkchoiceUpdatedV2 extends AbstractEngineForkchoiceUpdated {
|| 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;
}
}

@ -56,16 +56,16 @@ public class EngineForkchoiceUpdatedV3 extends AbstractEngineForkchoiceUpdated {
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();
@ -93,11 +93,18 @@ public class EngineForkchoiceUpdatedV3 extends AbstractEngineForkchoiceUpdated {
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;
}
}

@ -454,7 +454,7 @@ public abstract class AbstractEngineForkchoiceUpdatedTest {
@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);

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;
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 class EngineForkchoiceUpdatedV2Test extends AbstractEngineForkchoiceUpdat
protected String getMethodName() {
return RpcMethod.ENGINE_FORKCHOICE_UPDATED_V2.getMethodName();
}
@Override
protected RpcErrorType expectedInvalidPayloadError() {
return RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES;
}
}

Loading…
Cancel
Save