Skip to content

Commit d7c3a7f

Browse files
committed
Exclude empty requests and prepend request type byte in engine_getPayloadV4
Fixes ethereum/execution-apis#599 change to EIP-7685 Signed-off-by: Simon Dudley <[email protected]>
1 parent 770ee68 commit d7c3a7f

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public EngineGetPayloadResultV4 payloadTransactionCompleteV4(final PayloadWrappe
167167
rqs ->
168168
rqs.stream()
169169
.sorted(Comparator.comparing(Request::getType))
170-
.map(r -> r.getData().toHexString())
170+
.filter(r -> !r.getData().isEmpty())
171+
.map(Request::getEncodedRequest)
172+
.map(Bytes::toHexString)
171173
.toList());
172174

173175
final BlobsBundleV1 blobsBundleV1 =

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4Test.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ header, new BlockBody(List.of(blobTx), emptyList(), Optional.of(emptyList()))),
147147
final List<String> requestsWithoutRequestId =
148148
requests.stream()
149149
.sorted(Comparator.comparing(Request::getType))
150-
.map(r -> r.getData().toHexString())
150+
.map(Request::getEncodedRequest)
151+
.map(Bytes::toHexString)
151152
.toList();
152153
Optional.of(resp)
153154
.map(JsonRpcSuccessResponse.class::cast)
@@ -172,6 +173,53 @@ header, new BlockBody(List.of(blobTx), emptyList(), Optional.of(emptyList()))),
172173
verify(engineCallListener, times(1)).executionEngineCalled();
173174
}
174175

176+
@Test
177+
public void shouldExcludeEmptyRequestsInRequestsList() {
178+
179+
BlockHeader header =
180+
new BlockHeaderTestFixture().timestamp(pragueHardfork.milestone() + 1).buildHeader();
181+
PayloadIdentifier payloadIdentifier =
182+
PayloadIdentifier.forPayloadParams(
183+
Hash.ZERO,
184+
pragueHardfork.milestone(),
185+
Bytes32.random(),
186+
Address.fromHexString("0x42"),
187+
Optional.empty(),
188+
Optional.empty());
189+
190+
BlockWithReceipts block =
191+
new BlockWithReceipts(
192+
new Block(header, new BlockBody(emptyList(), emptyList(), Optional.of(emptyList()))),
193+
emptyList());
194+
final List<Request> unorderedRequests =
195+
List.of(
196+
new Request(RequestType.CONSOLIDATION, Bytes.of(1)),
197+
new Request(RequestType.DEPOSIT, Bytes.of(1)),
198+
new Request(RequestType.WITHDRAWAL, Bytes.EMPTY));
199+
PayloadWrapper payload =
200+
new PayloadWrapper(payloadIdentifier, block, Optional.of(unorderedRequests));
201+
202+
when(mergeContext.retrievePayloadById(payloadIdentifier)).thenReturn(Optional.of(payload));
203+
204+
final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), payloadIdentifier);
205+
assertThat(resp).isInstanceOf(JsonRpcSuccessResponse.class);
206+
207+
final List<String> expectedRequests =
208+
List.of(
209+
Bytes.concatenate(Bytes.of(RequestType.DEPOSIT.getSerializedType()), Bytes.of(1))
210+
.toHexString(),
211+
Bytes.concatenate(Bytes.of(RequestType.CONSOLIDATION.getSerializedType()), Bytes.of(1))
212+
.toHexString());
213+
Optional.of(resp)
214+
.map(JsonRpcSuccessResponse.class::cast)
215+
.ifPresent(
216+
r -> {
217+
assertThat(r.getResult()).isInstanceOf(EngineGetPayloadResultV4.class);
218+
final EngineGetPayloadResultV4 res = (EngineGetPayloadResultV4) r.getResult();
219+
assertThat(res.getExecutionRequests()).isEqualTo(expectedRequests);
220+
});
221+
}
222+
175223
@Test
176224
public void shouldReturnUnsupportedFork() {
177225
final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), mockPid);

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Request.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ public RequestType getType() {
2929
public Bytes getData() {
3030
return data();
3131
}
32+
33+
/**
34+
* Gets the serialized form of the concatenated type and data.
35+
*
36+
* @return the serialized request as a byte.
37+
*/
38+
public Bytes getEncodedRequest() {
39+
return Bytes.concatenate(Bytes.of(getType().getSerializedType()), getData());
40+
}
3241
}

0 commit comments

Comments
 (0)