Skip to content

Commit

Permalink
Merge branch 'main' into zkbesu
Browse files Browse the repository at this point in the history
# Conflicts:
#	besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
#	besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java
#	plugin-api/build.gradle
  • Loading branch information
fab-10 committed Feb 26, 2024
2 parents 66bb56e + 3538c55 commit 29ad708
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 11 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"jsonrpc" : "2.0",
"id" : 67,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"code" : -38003,
"message" : "Invalid payload attributes"
}
},
"statusCode" : 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ protected Optional<JsonRpcErrorResponse> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ protected ValidationResult<RpcErrorType> validateParameter(
final EngineForkchoiceUpdatedParameter fcuParameter,
final Optional<EnginePayloadAttributesParameter> 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();
Expand Down Expand Up @@ -93,11 +93,18 @@ protected Optional<JsonRpcErrorResponse> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29ad708

Please sign in to comment.