From b90dcb59d0e17f3c20ae9b6c41b67eac56414ca5 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Tue, 26 Sep 2023 10:17:40 +1000 Subject: [PATCH 1/2] Fix json return Signed-off-by: Gabriel-Trintinalia --- .../methods/engine/AbstractEngineForkchoiceUpdated.java | 4 ++-- .../internal/methods/engine/AbstractEngineGetPayload.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java index 1cde6c259a0..020b0afa10f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java @@ -91,13 +91,13 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) ValidationResult forkValidationResult = validateForkSupported(payloadAttributes.getTimestamp()); if (!forkValidationResult.isValid()) { - return new JsonRpcSuccessResponse(requestId, forkValidationResult); + return new JsonRpcErrorResponse(requestId, forkValidationResult); } } ValidationResult parameterValidationResult = validateParameter(forkChoice); if (!parameterValidationResult.isValid()) { - return new JsonRpcSuccessResponse(requestId, parameterValidationResult); + return new JsonRpcErrorResponse(requestId, parameterValidationResult); } mergeContext diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java index 5cb72d0cb82..303317316d3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java @@ -79,7 +79,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { ValidationResult forkValidationResult = validateForkSupported(proposal.getHeader().getTimestamp()); if (!forkValidationResult.isValid()) { - return new JsonRpcSuccessResponse(request.getRequest().getId(), forkValidationResult); + return new JsonRpcErrorResponse(request.getRequest().getId(), forkValidationResult); } return createResponse(request, payloadId, proposal); } From 2ef7b69afdbf73011ebfd323f6364f27af04d3f3 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Tue, 26 Sep 2023 10:49:51 +1000 Subject: [PATCH 2/2] Parameters must be validated before Fork Signed-off-by: Gabriel-Trintinalia --- .../engine/AbstractEngineForkchoiceUpdated.java | 13 +++++++------ .../methods/engine/AbstractEngineGetPayload.java | 1 - .../methods/engine/EngineForkchoiceUpdatedV3.java | 10 +++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java index 020b0afa10f..b64fca8d429 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java @@ -69,7 +69,8 @@ public AbstractEngineForkchoiceUpdated( } protected ValidationResult validateParameter( - final EngineForkchoiceUpdatedParameter forkchoiceUpdatedParameter) { + final EngineForkchoiceUpdatedParameter forkchoiceUpdatedParameter, + final Optional maybePayloadAttributes) { return ValidationResult.valid(); } @@ -85,6 +86,11 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) requestContext.getOptionalParameter(1, EnginePayloadAttributesParameter.class); LOG.debug("Forkchoice parameters {}", forkChoice); + ValidationResult parameterValidationResult = + validateParameter(forkChoice, maybePayloadAttributes); + if (!parameterValidationResult.isValid()) { + return new JsonRpcErrorResponse(requestId, parameterValidationResult); + } if (maybePayloadAttributes.isPresent()) { final EnginePayloadAttributesParameter payloadAttributes = maybePayloadAttributes.get(); @@ -95,11 +101,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) } } - ValidationResult parameterValidationResult = validateParameter(forkChoice); - if (!parameterValidationResult.isValid()) { - return new JsonRpcErrorResponse(requestId, parameterValidationResult); - } - mergeContext .get() .fireNewUnverifiedForkchoiceEvent( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java index 303317316d3..a714b25d8b4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod; 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.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.core.BlockHeader; 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 31dc738fa39..2d25e12cefd 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 @@ -18,6 +18,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineForkchoiceUpdatedParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadAttributesParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec; @@ -48,7 +49,8 @@ public String getName() { @Override protected ValidationResult validateParameter( - final EngineForkchoiceUpdatedParameter fcuParameter) { + final EngineForkchoiceUpdatedParameter fcuParameter, + final Optional maybePayloadAttributes) { if (fcuParameter.getHeadBlockHash() == null) { return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing head block hash"); } else if (fcuParameter.getSafeBlockHash() == null) { @@ -56,6 +58,12 @@ protected ValidationResult validateParameter( } else if (fcuParameter.getFinalizedBlockHash() == null) { return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing finalized block hash"); } + if (maybePayloadAttributes.isPresent()) { + if (maybePayloadAttributes.get().getParentBeaconBlockRoot() == null) { + return ValidationResult.invalid( + RpcErrorType.INVALID_PARAMS, "Missing parent beacon block root hash"); + } + } return ValidationResult.valid(); }