Skip to content

Commit

Permalink
Exclude empty requests and prepend request type byte in engine_getPay…
Browse files Browse the repository at this point in the history
…loadV4

Fixes ethereum/execution-apis#599 change to EIP-7685

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
  • Loading branch information
siladu committed Dec 18, 2024
1 parent 770ee68 commit d7c3a7f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public EngineGetPayloadResultV4 payloadTransactionCompleteV4(final PayloadWrappe
rqs ->
rqs.stream()
.sorted(Comparator.comparing(Request::getType))
.map(r -> r.getData().toHexString())
.filter(r -> !r.getData().isEmpty())
.map(Request::getEncodedRequest)
.map(Bytes::toHexString)
.toList());

final BlobsBundleV1 blobsBundleV1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ header, new BlockBody(List.of(blobTx), emptyList(), Optional.of(emptyList()))),
final List<String> requestsWithoutRequestId =
requests.stream()
.sorted(Comparator.comparing(Request::getType))
.map(r -> r.getData().toHexString())
.map(Request::getEncodedRequest)
.map(Bytes::toHexString)
.toList();
Optional.of(resp)
.map(JsonRpcSuccessResponse.class::cast)
Expand All @@ -172,6 +173,53 @@ header, new BlockBody(List.of(blobTx), emptyList(), Optional.of(emptyList()))),
verify(engineCallListener, times(1)).executionEngineCalled();
}

@Test
public void shouldExcludeEmptyRequestsInRequestsList() {

BlockHeader header =
new BlockHeaderTestFixture().timestamp(pragueHardfork.milestone() + 1).buildHeader();
PayloadIdentifier payloadIdentifier =
PayloadIdentifier.forPayloadParams(
Hash.ZERO,
pragueHardfork.milestone(),
Bytes32.random(),
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty());

BlockWithReceipts block =
new BlockWithReceipts(
new Block(header, new BlockBody(emptyList(), emptyList(), Optional.of(emptyList()))),
emptyList());
final List<Request> unorderedRequests =
List.of(
new Request(RequestType.CONSOLIDATION, Bytes.of(1)),
new Request(RequestType.DEPOSIT, Bytes.of(1)),
new Request(RequestType.WITHDRAWAL, Bytes.EMPTY));
PayloadWrapper payload =
new PayloadWrapper(payloadIdentifier, block, Optional.of(unorderedRequests));

when(mergeContext.retrievePayloadById(payloadIdentifier)).thenReturn(Optional.of(payload));

final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), payloadIdentifier);
assertThat(resp).isInstanceOf(JsonRpcSuccessResponse.class);

final List<String> expectedRequests =
List.of(
Bytes.concatenate(Bytes.of(RequestType.DEPOSIT.getSerializedType()), Bytes.of(1))
.toHexString(),
Bytes.concatenate(Bytes.of(RequestType.CONSOLIDATION.getSerializedType()), Bytes.of(1))
.toHexString());
Optional.of(resp)
.map(JsonRpcSuccessResponse.class::cast)
.ifPresent(
r -> {
assertThat(r.getResult()).isInstanceOf(EngineGetPayloadResultV4.class);
final EngineGetPayloadResultV4 res = (EngineGetPayloadResultV4) r.getResult();
assertThat(res.getExecutionRequests()).isEqualTo(expectedRequests);
});
}

@Test
public void shouldReturnUnsupportedFork() {
final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), mockPid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public RequestType getType() {
public Bytes getData() {
return data();
}

/**
* Gets the serialized form of the concatenated type and data.
*
* @return the serialized request as a byte.
*/
public Bytes getEncodedRequest() {
return Bytes.concatenate(Bytes.of(getType().getSerializedType()), getData());
}
}

0 comments on commit d7c3a7f

Please sign in to comment.