diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java index 66bb879569a..2639525d8b0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java @@ -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 = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4Test.java index 744600ddca9..4a241ce3867 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4Test.java @@ -147,7 +147,8 @@ header, new BlockBody(List.of(blobTx), emptyList(), Optional.of(emptyList()))), final List 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) @@ -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 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 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); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Request.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Request.java index 7d485336ad8..bdfcbd55cff 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Request.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Request.java @@ -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()); + } }