diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a9a2a4eadb..6122cd3bbb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 24.2.1-SNAPSHOT + +### Breaking Changes + +### Deprecations + +### Additions and Improvements +- Extend `Blockchain` service [#6592](https://github.com/hyperledger/besu/pull/6592) + +### Bug fixes + ## 24.2.0-SNAPSHOT ### Breaking Changes diff --git a/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json b/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json index ac5947c79be..23ddea33af0 100644 --- a/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json +++ b/acceptance-tests/tests/src/test/resources/jsonrpc/engine/shanghai/test-cases/05_shanghai_prepare_payload_invalid_null_withdrawals.json @@ -20,8 +20,8 @@ "jsonrpc" : "2.0", "id" : 67, "error" : { - "code" : -32602, - "message" : "Invalid params" + "code" : -38003, + "message" : "Invalid payload attributes" } }, "statusCode" : 200 diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java index b6406a3e662..77ca45df043 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2.java @@ -56,14 +56,21 @@ protected Optional isPayloadAttributesValid( || payloadAttributes.getParentBeaconBlockRoot().isEmpty()) { return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.UNSUPPORTED_FORK)); } else { - return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS)); + return Optional.of( + new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES)); } } else if (payloadAttributes.getParentBeaconBlockRoot() != null) { LOG.error( "Parent beacon block root hash present in payload attributes before cancun hardfork"); - return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS)); + return Optional.of( + new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES)); } else { return Optional.empty(); } } + + @Override + protected RpcErrorType getInvalidPayloadError() { + return RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES; + } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java index c070d220854..51672d7280e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java @@ -56,16 +56,16 @@ protected ValidationResult validateParameter( final EngineForkchoiceUpdatedParameter fcuParameter, final Optional maybePayloadAttributes) { if (fcuParameter.getHeadBlockHash() == null) { - return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing head block hash"); + return ValidationResult.invalid(getInvalidPayloadError(), "Missing head block hash"); } else if (fcuParameter.getSafeBlockHash() == null) { - return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing safe block hash"); + return ValidationResult.invalid(getInvalidPayloadError(), "Missing safe block hash"); } else if (fcuParameter.getFinalizedBlockHash() == null) { - return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing finalized block hash"); + return ValidationResult.invalid(getInvalidPayloadError(), "Missing finalized block hash"); } if (maybePayloadAttributes.isPresent()) { if (maybePayloadAttributes.get().getParentBeaconBlockRoot() == null) { return ValidationResult.invalid( - RpcErrorType.INVALID_PARAMS, "Missing parent beacon block root hash"); + getInvalidPayloadError(), "Missing parent beacon block root hash"); } } return ValidationResult.valid(); @@ -93,11 +93,18 @@ protected Optional isPayloadAttributesValid( if (payloadAttributes.getParentBeaconBlockRoot() == null) { LOG.error( "Parent beacon block root hash not present in payload attributes after cancun hardfork"); - return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS)); + return Optional.of(new JsonRpcErrorResponse(requestId, getInvalidPayloadError())); + } else if (payloadAttributes.getTimestamp().longValue() == 0) { + return Optional.of(new JsonRpcErrorResponse(requestId, getInvalidPayloadError())); } else if (payloadAttributes.getTimestamp() < cancun.get().milestone()) { return Optional.of(new JsonRpcErrorResponse(requestId, RpcErrorType.UNSUPPORTED_FORK)); } else { return Optional.empty(); } } + + @Override + protected RpcErrorType getInvalidPayloadError() { + return RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES; + } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java index 249a12d9f0b..931d2259875 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java @@ -454,7 +454,7 @@ public void shouldIgnoreUpdateToOldHeadAndNotPreparePayload() { @Test public void shouldReturnInvalidIfPayloadTimestampNotGreaterThanHead() { - BlockHeader mockParent = blockHeaderBuilder.number(9L).buildHeader(); + BlockHeader mockParent = blockHeaderBuilder.timestamp(99).number(9L).buildHeader(); BlockHeader mockHeader = blockHeaderBuilder.number(10L).parentHash(mockParent.getHash()).buildHeader(); setupValidForkchoiceUpdate(mockHeader); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java index 77249934113..4cb17eab4f7 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -42,4 +43,9 @@ public void shouldReturnExpectedMethodName() { protected String getMethodName() { return RpcMethod.ENGINE_FORKCHOICE_UPDATED_V2.getMethodName(); } + + @Override + protected RpcErrorType expectedInvalidPayloadError() { + return RpcErrorType.INVALID_PAYLOAD_ATTRIBUTES; + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java index 0723fda97a0..afa07cbf84b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java @@ -67,7 +67,14 @@ public void writeToDirectory(final Path dataDir) throws IOException { } private static File getDefaultMetadataFile(final Path dataDir) { - return dataDir.resolve(METADATA_FILENAME).toFile(); + File metaDataFile = dataDir.resolve(METADATA_FILENAME).toFile(); + + // Create the data dir here if it doesn't exist yet + if (!metaDataFile.getParentFile().exists()) { + LOG.info("Data directory {} does not exist - creating it", dataDir); + metaDataFile.getParentFile().mkdirs(); + } + return metaDataFile; } private static VersionMetadata resolveVersionMetadata(final File metadataFile) diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/VersionMetadataTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/VersionMetadataTest.java index a506be214a9..0cebcd4bda8 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/VersionMetadataTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/VersionMetadataTest.java @@ -49,6 +49,17 @@ void metaFileShouldContain() throws Exception { assertThat(versionMetadata.getBesuVersion()).isEqualTo("23.10.3"); } + @Test + void dataDirShouldBeCreatedIfNotPresent() throws Exception { + Files.deleteIfExists(temporaryFolder); + assertThat(Files.exists(temporaryFolder)).isFalse(); + + final VersionMetadata versionMetadata = VersionMetadata.lookUpFrom(temporaryFolder); + assertThat(versionMetadata).isNotNull(); + + assertThat(Files.exists(temporaryFolder)).isTrue(); + } + @Test void compatibilityCheckShouldThrowExceptionIfEnabled() throws Exception { // The version file says the last version to start was 23.10.3