Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia committed Aug 24, 2023
1 parent e79c370 commit d018c26
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)

final ValidationResult<RpcErrorType> forkValidationResult =
validateForkSupported(blockParam.getTimestamp());
ValidationResult<RpcErrorType> forkValidationResult =
validateParamsAndForkSupported(newPayloadParams);
if (!forkValidationResult.isValid()) {
return new JsonRpcErrorResponse(reqId, forkValidationResult);
}

final ValidationResult<RpcErrorType> parameterValidationResult =
validateParameters(blockParam, maybeVersionedHashParam, maybeParentBeaconBlockRootParam);
validateParameters(blockParam, maybeVersionedHashParam, maybeParentBeaconBlockRoot);
if (!parameterValidationResult.isValid()) {
return new JsonRpcErrorResponse(reqId, parameterValidationResult);
}
Expand Down Expand Up @@ -412,8 +410,10 @@ protected EngineStatus getInvalidBlockHashStatus() {
return INVALID;
}

protected ValidationResult<RpcErrorType> validateParamsAndForkSupported(
final EngineNewPayloadRequestParameter params) {
protected ValidationResult<RpcErrorType> validateParameters(
final EnginePayloadParameter parameter,
final Optional<List<String>> maybeVersionedHashParam,
final Optional<Bytes32> maybeBeaconBlockRootParam) {
return ValidationResult.valid();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineNewPayloadRequestParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;

import java.util.List;
import java.util.Optional;

import io.vertx.core.Vertx;
import org.apache.tuweni.bytes.Bytes32;

public class EngineNewPayloadV3 extends AbstractEngineNewPayload {

Expand All @@ -53,13 +55,8 @@ public String getName() {
protected ValidationResult<RpcErrorType> validateParameters(
final EnginePayloadParameter payloadParameter,
final Optional<List<String>> maybeVersionedHashParam,
final Optional<String> maybeBeaconBlockRootParam) {
final Optional<Bytes32> maybeBeaconBlockRootParam) {
if (payloadParameter.getBlobGasUsed() == null || payloadParameter.getExcessBlobGas() == null) {
protected ValidationResult<RpcErrorType> validateParamsAndForkSupported(
final EngineNewPayloadRequestParameter params) {

if (params.getPayload().getBlobGasUsed() == null
|| params.getPayload().getExcessBlobGas() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing blob gas fields");
} else if (maybeVersionedHashParam == null) {
return ValidationResult.invalid(
Expand All @@ -86,9 +83,5 @@ protected ValidationResult<RpcErrorType> validateForkSupported(final long blockT
return ValidationResult.invalid(
RpcErrorType.UNSUPPORTED_FORK, "Configuration error, no schedule for Cancun fork set");
}
if (params.getPayload().getTimestamp() < cancunTimestamp) {
return ValidationResult.invalid(RpcErrorType.UNSUPPORTED_FORK, "Fork not supported");
}
return ValidationResult.valid();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

import java.util.Collections;
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.BlockProcessingOutputs;
Expand Down Expand Up @@ -55,13 +54,13 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic;
import org.mockito.MockedStatic.Verification;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test {

private static final String DEFAULT_PARENT_BEACON_ROOT = "0x0000000000000000000000000000000000000000000000000000000000000000";
private static final String DEFAULT_PARENT_BEACON_ROOT =
"0x0000000000000000000000000000000000000000000000000000000000000000";

public EngineNewPayloadV3Test() {}

Expand Down Expand Up @@ -103,9 +102,7 @@ public void shouldInvalidVersionedHash_whenShortVersionedHash() {
"2.0",
RpcMethod.ENGINE_NEW_PAYLOAD_V3.getMethodName(),
new Object[] {
payload,
List.of(shortHash.toHexString()),
DEFAULT_PARENT_BEACON_ROOT
payload, List.of(shortHash.toHexString()), DEFAULT_PARENT_BEACON_ROOT
})));
final EnginePayloadStatusResult res = fromSuccessResp(badParam);
assertThat(res.getStatusAsString()).isEqualTo(INVALID.name());
Expand All @@ -114,33 +111,33 @@ public void shouldInvalidVersionedHash_whenShortVersionedHash() {

@Test
public void shouldReturnInvalid_missing_TransactionVersionedHash() {
Bytes shortHash = Bytes.fromHexString("0x0100000000000000000000000000000000000000000000000000000000000000");
Bytes shortHash =
Bytes.fromHexString("0x0100000000000000000000000000000000000000000000000000000000000000");
BlockHeader mockHeader =
setupValidPayload(
new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))),
Optional.empty(),
Optional.empty());


Transaction blobTransaction = mock(Transaction.class);

try (MockedStatic<TransactionDecoder> utilities = mockStatic(TransactionDecoder.class)) {
utilities.when(() -> TransactionDecoder.decodeOpaqueBytes(any(Bytes.class)))
utilities
.when(() -> TransactionDecoder.decodeOpaqueBytes(any(Bytes.class)))
.thenReturn(blobTransaction);

lenient()
.when(blockchain.getBlockHeader(mockHeader.getParentHash()))
.thenReturn(Optional.of(mock(BlockHeader.class)));

var resp = resp(mockEnginePayload(mockHeader, List.of("0xblob")) ,
List.of(shortHash.toHexString()));
var resp =
resp(mockEnginePayload(mockHeader, List.of("0xblob")), List.of(shortHash.toHexString()));
EnginePayloadStatusResult res = fromSuccessResp(resp);
assertThat(res.getStatusAsString()).isEqualTo(INVALID.name());
assertThat(res.getError()).isEqualTo("Invalid versionedHash");
}
}


@Test
public void shouldReturnInvalidParameterWhenVersionedHashesIsNull() {
EnginePayloadParameter payload = mock(EnginePayloadParameter.class);
Expand All @@ -150,11 +147,7 @@ public void shouldReturnInvalidParameterWhenVersionedHashesIsNull() {
new JsonRpcRequest(
"2.0",
RpcMethod.ENGINE_NEW_PAYLOAD_V3.getMethodName(),
new Object[] {
payload,
null,
DEFAULT_PARENT_BEACON_ROOT
})));
new Object[] {payload, null, DEFAULT_PARENT_BEACON_ROOT})));
JsonRpcError res = fromErrorResp(badParam);
assertThat(res.getCode()).isEqualTo(RpcErrorType.INVALID_PARAMS.getCode());
assertThat(res.getData()).isEqualTo("Missing required json rpc parameter at index 1");
Expand Down Expand Up @@ -189,7 +182,9 @@ public void shouldValidVersionedHash_whenListIsEmpty() {
method.validateParameters(
payload,
Optional.of(List.of()),
Optional.of("0x0000000000000000000000000000000000000000000000000000000000000000"));
Optional.of(
Bytes32.fromHexString(
"0x0000000000000000000000000000000000000000000000000000000000000000")));
assertThat(res.isValid()).isTrue();
}

Expand Down

0 comments on commit d018c26

Please sign in to comment.