Skip to content

Commit

Permalink
[4844] [Hive] Fix fcuV3 parameter return (hyperledger#5940)
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Justin Florentine <[email protected]>
  • Loading branch information
Gabriel-Trintinalia authored and jflo committed Nov 10, 2023
1 parent 7303ecf commit bc66a96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public AbstractEngineForkchoiceUpdated(
}

protected ValidationResult<RpcErrorType> validateParameter(
final EngineForkchoiceUpdatedParameter forkchoiceUpdatedParameter) {
final EngineForkchoiceUpdatedParameter forkchoiceUpdatedParameter,
final Optional<EnginePayloadAttributesParameter> maybePayloadAttributes) {
return ValidationResult.valid();
}

Expand All @@ -85,21 +86,21 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
requestContext.getOptionalParameter(1, EnginePayloadAttributesParameter.class);

LOG.debug("Forkchoice parameters {}", forkChoice);
ValidationResult<RpcErrorType> parameterValidationResult =
validateParameter(forkChoice, maybePayloadAttributes);
if (!parameterValidationResult.isValid()) {
return new JsonRpcErrorResponse(requestId, parameterValidationResult);
}

if (maybePayloadAttributes.isPresent()) {
final EnginePayloadAttributesParameter payloadAttributes = maybePayloadAttributes.get();
ValidationResult<RpcErrorType> forkValidationResult =
validateForkSupported(payloadAttributes.getTimestamp());
if (!forkValidationResult.isValid()) {
return new JsonRpcSuccessResponse(requestId, forkValidationResult);
return new JsonRpcErrorResponse(requestId, forkValidationResult);
}
}

ValidationResult<RpcErrorType> parameterValidationResult = validateParameter(forkChoice);
if (!parameterValidationResult.isValid()) {
return new JsonRpcSuccessResponse(requestId, parameterValidationResult);
}

mergeContext
.get()
.fireNewUnverifiedForkchoiceEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +78,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) {
ValidationResult<RpcErrorType> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,14 +49,21 @@ public String getName() {

@Override
protected ValidationResult<RpcErrorType> validateParameter(
final EngineForkchoiceUpdatedParameter fcuParameter) {
final EngineForkchoiceUpdatedParameter fcuParameter,
final Optional<EnginePayloadAttributesParameter> maybePayloadAttributes) {
if (fcuParameter.getHeadBlockHash() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing head block hash");
} else if (fcuParameter.getSafeBlockHash() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing safe block hash");
} 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();
}

Expand Down

0 comments on commit bc66a96

Please sign in to comment.