Skip to content

Commit 9dbcb09

Browse files
Gabriel-Trintinaliajflo
authored andcommitted
Revert "EngineNewPayload - respond with error if params invalid (besu-eth#8729)" (besu-eth#9108)
This reverts commit 7a3ca6b. Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
1 parent 114bb95 commit 9dbcb09

File tree

6 files changed

+24
-174
lines changed

6 files changed

+24
-174
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565

6666
### Bug fixes
6767
- Fix bug with `eth_estimateGas` on QBFT - use zero address when doing simulation against `pending` block [#9031](https://github.com/hyperledger/besu/pull/9031)
68-
- Fix bug with handling of invalid requests for `engine_newPayloadV4` [#8729](https://github.com/hyperledger/besu/pull/8729)
6968

7069
## 25.7.0
7170
### Breaking Changes

acceptance-tests/tests/src/test/resources/jsonrpc/engine/prague/test-cases/17_prague_newPayloadV4_invalid_duplicate_requests.json

Lines changed: 0 additions & 63 deletions
This file was deleted.

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
173173
try {
174174
maybeVersionedHashes = extractVersionedHashes(maybeVersionedHashParam);
175175
} catch (RuntimeException ex) {
176-
return respondWithError(
176+
return respondWithInvalid(
177177
reqId,
178178
blockParam,
179179
mergeCoordinator.getLatestValidAncestor(blockParam.getParentHash()).orElse(null),
@@ -203,7 +203,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
203203
try {
204204
maybeRequests = extractRequests(maybeRequestsParam);
205205
} catch (RequestType.InvalidRequestTypeException ex) {
206-
return respondWithError(
206+
return respondWithInvalid(
207207
reqId,
208208
blockParam,
209209
mergeCoordinator.getLatestValidAncestor(blockParam.getParentHash()).orElse(null),
@@ -285,15 +285,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
285285
"Computed block hash %s does not match block hash parameter %s",
286286
newBlockHeader.getBlockHash(), blockParam.getBlockHash());
287287
LOG.debug(errorMessage);
288-
// If the block is invalid, we want to return INVALID
289-
// from the spec:
290-
// https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md#engine_newpayloadv4
291-
// Given the executionRequests, client software MUST compute the execution requests commitment
292-
// and incorporate it into the blockHash validation process.
293-
// That is, if the computed commitment does not match the corresponding commitment in the
294-
// execution layer block header,
295-
// the call MUST return {status: INVALID, latestValidHash: null, validationError: errorMessage
296-
// | null}.
297288
return respondWithInvalid(reqId, blockParam, null, getInvalidBlockHashStatus(), errorMessage);
298289
}
299290

@@ -308,7 +299,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
308299
maybeVersionedHashes,
309300
protocolSchedule.get().getByBlockHeader(newBlockHeader));
310301
if (!blobValidationResult.isValid()) {
311-
return respondWithError(
302+
return respondWithInvalid(
312303
reqId,
313304
blockParam,
314305
mergeCoordinator.getLatestValidAncestor(blockParam.getParentHash()).orElse(null),
@@ -335,7 +326,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
335326
if (maybeParentHeader.isPresent()
336327
&& (Long.compareUnsigned(maybeParentHeader.get().getTimestamp(), blockParam.getTimestamp())
337328
>= 0)) {
338-
return respondWithError(
329+
return respondWithInvalid(
339330
reqId,
340331
blockParam,
341332
mergeCoordinator.getLatestValidAncestor(blockParam.getParentHash()).orElse(null),
@@ -382,7 +373,8 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
382373
Throwable causedBy = executionResult.causedBy().get();
383374
if (causedBy instanceof StorageException || causedBy instanceof MerkleTrieException) {
384375
RpcErrorType error = RpcErrorType.INTERNAL_ERROR;
385-
return new JsonRpcErrorResponse(reqId, error);
376+
JsonRpcErrorResponse response = new JsonRpcErrorResponse(reqId, error);
377+
return response;
386378
}
387379
}
388380
LOG.debug("New payload is invalid: {}", executionResult.errorMessage.get());
@@ -464,7 +456,7 @@ JsonRpcResponse respondWith(
464456
JsonRpcResponse respondWithInvalid(
465457
final Object requestId,
466458
final EnginePayloadParameter param,
467-
final Hash latestValidHash, // this should be null for invalid
459+
final Hash latestValidHash,
468460
final EngineStatus invalidStatus,
469461
final String validationError) {
470462
if (!INVALID.equals(invalidStatus) && !INVALID_BLOCK_HASH.equals(invalidStatus)) {
@@ -493,36 +485,6 @@ JsonRpcResponse respondWithInvalid(
493485
invalidStatus, latestValidHash, Optional.of(validationError)));
494486
}
495487

496-
JsonRpcResponse respondWithError(
497-
final Object requestId,
498-
final EnginePayloadParameter param,
499-
final Hash latestValidHash,
500-
final EngineStatus invalidStatus,
501-
final String validationError) {
502-
if (!INVALID.equals(invalidStatus) && !INVALID_BLOCK_HASH.equals(invalidStatus)) {
503-
throw new IllegalArgumentException(
504-
"Don't call respondWithError() with non-invalid status of " + invalidStatus.toString());
505-
}
506-
final String invalidBlockLogMessage =
507-
String.format(
508-
"Invalid new payload: number: %s, hash: %s, parentHash: %s, latestValidHash: %s, status: %s, validationError: %s",
509-
param.getBlockNumber(),
510-
param.getBlockHash(),
511-
param.getParentHash(),
512-
latestValidHash == null ? null : latestValidHash.toHexString(),
513-
invalidStatus.name(),
514-
validationError);
515-
// always log invalid at DEBUG
516-
LOG.debug(invalidBlockLogMessage);
517-
// periodically log at WARN
518-
if (lastInvalidWarn + ENGINE_API_LOGGING_THRESHOLD < System.currentTimeMillis()) {
519-
lastInvalidWarn = System.currentTimeMillis();
520-
LOG.warn(invalidBlockLogMessage);
521-
}
522-
// return ErrorResponse
523-
return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_ENGINE_PARAMS);
524-
}
525-
526488
protected EngineStatus getInvalidBlockHashStatus() {
527489
return INVALID;
528490
}

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public enum RpcErrorType implements RpcMethodError {
6161
INVALID_EXCESS_BLOB_GAS_PARAMS(
6262
INVALID_PARAMS_ERROR_CODE, "Invalid excess blob gas params (missing or invalid)"),
6363
INVALID_EXECUTION_REQUESTS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid execution requests params"),
64-
INVALID_ENGINE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid engine params"),
6564
INVALID_EXTRA_DATA_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid extra data params"),
6665
INVALID_FILTER_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid filter params"),
6766
INVALID_HASH_RATE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid hash rate params"),

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717
import static java.util.Collections.emptyList;
1818
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.hyperledger.besu.ethereum.api.graphql.internal.response.GraphQLError.INVALID_PARAMS;
2019
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID;
2120
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineTestSupport.fromErrorResp;
22-
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_ENGINE_PARAMS;
21+
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_PARAMS;
2322
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.UNSUPPORTED_FORK;
2423
import static org.mockito.Mockito.lenient;
2524
import static org.mockito.Mockito.mock;
@@ -176,12 +175,9 @@ public void shouldInvalidVersionedHash_whenShortVersionedHash() {
176175
List.of(shortHash.toHexString()),
177176
"0x0000000000000000000000000000000000000000000000000000000000000000"
178177
})));
179-
180-
// Should return an error response with INVALID_EXECUTION_REQUESTS_PARAMS
181-
final JsonRpcError jsonRpcError = fromErrorResp(badParam);
182-
assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode());
183-
assertThat(jsonRpcError.getMessage()).isEqualTo(INVALID_ENGINE_PARAMS.getMessage());
184-
verify(engineCallListener, times(1)).executionEngineCalled();
178+
final EnginePayloadStatusResult res = fromSuccessResp(badParam);
179+
assertThat(res.getStatusAsString()).isEqualTo(INVALID.name());
180+
assertThat(res.getError()).isEqualTo("Invalid versionedHash");
185181
}
186182

187183
@Test
@@ -230,16 +226,19 @@ protected BlockHeader createBlockHeader(final Optional<List<Withdrawal>> maybeWi
230226
when(blockchain.getBlockHeader(parentBlockHeader.getBlockHash()))
231227
.thenReturn(Optional.of(parentBlockHeader));
232228
when(protocolContext.getBlockchain()).thenReturn(blockchain);
233-
return new BlockHeaderTestFixture()
234-
.baseFeePerGas(Wei.ONE)
235-
.parentHash(parentBlockHeader.getParentHash())
236-
.number(parentBlockHeader.getNumber() + 1)
237-
.timestamp(parentBlockHeader.getTimestamp() + 12)
238-
.withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null))
239-
.excessBlobGas(BlobGas.ZERO)
240-
.blobGasUsed(0L)
241-
.parentBeaconBlockRoot(maybeParentBeaconBlockRoot)
242-
.buildHeader();
229+
BlockHeader mockHeader =
230+
new BlockHeaderTestFixture()
231+
.baseFeePerGas(Wei.ONE)
232+
.parentHash(parentBlockHeader.getParentHash())
233+
.number(parentBlockHeader.getNumber() + 1)
234+
.timestamp(parentBlockHeader.getTimestamp() + 12)
235+
.withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null))
236+
.excessBlobGas(BlobGas.ZERO)
237+
.blobGasUsed(0L)
238+
.parentBeaconBlockRoot(
239+
maybeParentBeaconBlockRoot.isPresent() ? maybeParentBeaconBlockRoot : null)
240+
.buildHeader();
241+
return mockHeader;
243242
}
244243

245244
@Override

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ protected Set<ScheduledProtocolSpec.Hardfork> supportedHardforks() {
7878
new Request(RequestType.WITHDRAWAL, Bytes.of(1)),
7979
new Request(RequestType.CONSOLIDATION, Bytes.of(1)));
8080

81-
private static final List<Request> INVALID_REQUESTS_DUPLICATES =
82-
List.of(
83-
new Request(RequestType.CONSOLIDATION, Bytes.of(1)),
84-
new Request(RequestType.CONSOLIDATION, Bytes.of(1)));
85-
8681
@BeforeEach
8782
@Override
8883
public void before() {
@@ -135,27 +130,6 @@ public void shouldReturnInvalidIfRequestsIsNull_WhenRequestsAllowed() {
135130
verify(engineCallListener, times(1)).executionEngineCalled();
136131
}
137132

138-
@Test
139-
public void shouldReturnInvalidIfRequestsInvalidWithDuplicates() {
140-
BlockHeader mockHeader =
141-
setupValidPayload(
142-
new BlockProcessingResult(
143-
Optional.of(
144-
new BlockProcessingOutputs(
145-
null, List.of(), Optional.of(INVALID_REQUESTS_DUPLICATES)))),
146-
Optional.empty());
147-
when(blockchain.getBlockHeader(mockHeader.getParentHash()))
148-
.thenReturn(Optional.of(mock(BlockHeader.class)));
149-
when(mergeCoordinator.getLatestValidAncestor(mockHeader))
150-
.thenReturn(Optional.of(mockHeader.getHash()));
151-
var resp = respWithInvalidDuplicateRequests(mockEnginePayload(mockHeader, emptyList()));
152-
153-
assertThat(fromErrorResp(resp).getCode()).isEqualTo(INVALID_PARAMS.getCode());
154-
assertThat(fromErrorResp(resp).getMessage())
155-
.isEqualTo(INVALID_EXECUTION_REQUESTS_PARAMS.getMessage());
156-
verify(engineCallListener, times(1)).executionEngineCalled();
157-
}
158-
159133
@Test
160134
public void shouldReturnValidIfRequestsIsNotNull_WhenRequestsAllowed() {
161135
BlockHeader mockHeader =
@@ -290,26 +264,6 @@ protected JsonRpcResponse respWithInvalidRequests(final EnginePayloadParameter p
290264
new JsonRpcRequestContext(new JsonRpcRequest("2.0", this.method.getName(), params)));
291265
}
292266

293-
protected JsonRpcResponse respWithInvalidDuplicateRequests(final EnginePayloadParameter payload) {
294-
final List<String> requestsWithoutRequestId =
295-
INVALID_REQUESTS_DUPLICATES.stream() // don't sort them
296-
.map(
297-
r ->
298-
Bytes.concatenate(Bytes.of(r.getType().getSerializedType()), r.getData())
299-
.toHexString())
300-
.toList();
301-
Object[] params =
302-
maybeParentBeaconBlockRoot
303-
.map(
304-
bytes32 ->
305-
new Object[] {
306-
payload, emptyList(), bytes32.toHexString(), requestsWithoutRequestId
307-
})
308-
.orElseGet(() -> new Object[] {payload});
309-
return method.response(
310-
new JsonRpcRequestContext(new JsonRpcRequest("2.0", this.method.getName(), params)));
311-
}
312-
313267
private void mockProhibitedRequestsValidator() {
314268
var validator = new ProhibitedRequestValidator();
315269
when(protocolSpec.getRequestsValidator()).thenReturn(validator);

0 commit comments

Comments
 (0)