Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Teku to Java 21 #8462

Merged
merged 13 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ orbs:
executors:
small_executor:
docker:
- image: cimg/openjdk:17.0.7
- image: cimg/openjdk:21.0.2
auth: &docker-auth
# Don't panic, throw away account to avoid Docker rate limits when downloading.
# Second reason we're doing this is so that forked PRs from external contributors works ie env vars aren't visible to forked PRs from within contexts
Expand All @@ -27,7 +27,7 @@ executors:

medium_executor:
docker:
- image: cimg/openjdk:17.0.7
- image: cimg/openjdk:21.0.2
auth:
<<: *docker-auth
resource_class: medium
Expand All @@ -39,7 +39,7 @@ executors:

medium_plus_executor:
docker:
- image: cimg/openjdk:17.0.7
- image: cimg/openjdk:21.0.2
auth:
<<: *docker-auth
resource_class: "medium+"
Expand All @@ -50,7 +50,7 @@ executors:

large_executor:
docker:
- image: cimg/openjdk:17.0.7
- image: cimg/openjdk:21.0.2
auth:
<<: *docker-auth
resource_class: large
Expand Down Expand Up @@ -83,6 +83,21 @@ executors:
<<: *docker-auth

commands:
install_java_21:
description: "Install Java 21"
steps:
- run:
name: "Install Java 21"
command: |
sudo apt update
sudo apt install -y openjdk-21-jdk
if [ "$(uname -m)" = "aarch64" ]; then
ARCH="arm64"
else
ARCH="amd64"
fi
sudo update-alternatives --set java /usr/lib/jvm/java-21-openjdk-$ARCH/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-21-openjdk-$ARCH/bin/javac
prepare:
description: "Prepare"
steps:
Expand Down Expand Up @@ -331,6 +346,7 @@ jobs:
parallelism: 5
executor: machine_executor_amd64
steps:
- install_java_21
- prepare
- attach_workspace:
at: ~/project
Expand Down Expand Up @@ -449,6 +465,7 @@ jobs:
publishDockerArm64:
executor: machine_executor_arm64
steps:
- install_java_21
- prepare
- attach_workspace:
at: ~/project
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 17
java-version: 21

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
### Breaking Changes

- Updated counter metrics to incorporate the suffix `_total`. If you are using a custom dashboard to monitor Teku metrics, you might need to update the metrics manually when breaking changes are introduced. For more information, see [Update metrics](../../how-to/monitor/update-metrics.md).
- Java 21+ is required to be installed to run Teku. Refer to https://docs.teku.consensys.io/get-started/install for the updated instructions.

### Additions and Improvements
- Added a state pruner that can limit the number of finalized states stored when running an archive node.

- Updated bootnodes for Sepolia network.
- Implemented [GetBlockAttestationV2](https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getBlockAttestationsV2) (adding support for Electra attestations)

- Updated a number of parameters to reduce issues when using `p2p-subscribe-all-subnets-enabled`. If you have adjusted queue sizes manually when using all-subnets, please refer to details below. Manual settings will still override these defaults.
- When `p2p-subscribe-all-subnets-enabled`, `p2p-peer-lower-bound` now defaults to 60 (previously 64), and `p2p-peer-upper-bound` now defaults to 80 (previously 100).
- When `p2p-subscribe-all-subnets-enabled`, (`Xnetwork-async-p2p-max-queue`, `Xnetwork-async-beaconchain-max-queue`, `Xp2p-batch-verify-signatures-queue-capacity`) now default to 40_000 (previously 10_000)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ Release notifications are available via:

### Install Prerequisites

* Java 17+
* Java 21+

Note: Official builds of Teku are performed with Java 17.
Note: Official builds of Teku are performed with Java 21.
Building on a more recent version of Java is supported, but the resulting build will not work on earlier versions of Java.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public UInt64 getCount() {

@Override
public Optional<SignedBeaconBlock> getFirstBlock() {
return blocks.isEmpty() ? Optional.empty() : Optional.of(blocks.get(0));
return blocks.isEmpty() ? Optional.empty() : Optional.of(blocks.getFirst());
}

@Override
public Optional<SignedBeaconBlock> getLastBlock() {
return blocks.isEmpty() ? Optional.empty() : Optional.of(blocks.get(blocks.size() - 1));
return blocks.isEmpty() ? Optional.empty() : Optional.of(blocks.getLast());
}

@Override
Expand Down Expand Up @@ -327,8 +327,7 @@ private void onRequestComplete(
blobSidecarsByBlockRoot.putAll(newBlobSidecarsByBlockRoot);
}

if (newBlocks.isEmpty()
|| newBlocks.get(newBlocks.size() - 1).getSlot().equals(getLastSlot())) {
if (newBlocks.isEmpty() || newBlocks.getLast().getSlot().equals(getLastSlot())) {
complete = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ private SafeFuture<PeerSyncResult> executeSync(
private PeerSyncResult handleFailedRequestToPeer(
final Eth2Peer peer, final PeerStatus peerStatus, final Throwable err) {
final Throwable rootException = Throwables.getRootCause(err);
if (rootException instanceof FailedBlockImportException) {
final FailedBlockImportException importException = (FailedBlockImportException) rootException;
if (rootException instanceof FailedBlockImportException importException) {
final FailureReason reason = importException.getResult().getFailureReason();
final SignedBeaconBlock block = importException.getBlock();

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ allprojects {
jar.preserveFileTimestamps = false
}

sourceCompatibility = '17'
targetCompatibility = '17'
sourceCompatibility = '21'
targetCompatibility = '21'

repositories {
mavenLocal()
Expand Down Expand Up @@ -541,7 +541,7 @@ tasks.register("dockerDistUntar") {
}

def dockerImage = "consensys/teku"
def dockerJdkVariants = [ "jdk21", "jdk17" ]
def dockerJdkVariants = [ "jdk21" ]
def dockerBuildDir = "build/docker-teku/"

def executableAndArg = System.getProperty('os.name').toLowerCase().contains('windows') ? ["cmd", "/c"] : ["sh", "-c"]
Expand Down
63 changes: 0 additions & 63 deletions docker/jdk17/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

package tech.pegasys.teku.reference.phase0.ssz_generic;

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
Expand Down Expand Up @@ -100,9 +99,8 @@ private String format(final Object value) {
return ((SszByteList) value).sszSerialize().toHexString();
} else if (value instanceof SszBitvector) {
return ((SszBitvector) value).sszSerialize().toHexString();
} else if (value instanceof SszCollection<?>) {
final SszCollection<?> list = (SszCollection<?>) value;
return list.stream().map(this::format).collect(toList()).toString();
} else if (value instanceof final SszCollection<?> list) {
return list.stream().map(this::format).toList().toString();
} else if (value instanceof SszContainer) {
return formatSszContainer((SszContainer) value).toString();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,15 @@ private static Object extractTestStep(
}

private static ForkChoiceTestStep getStepKind(final Map<String, Object> ss) {
return ss.keySet().stream()
.map(ForkChoiceTestStep::valueOf)
.collect(Collectors.toList())
.get(0);
return ss.keySet().stream().map(ForkChoiceTestStep::valueOf).toList().get(0);
}

private static <T extends SszData> T resolvePart(
final Class<T> clazz,
final SszSchema<? extends T> type,
final File testFile,
final Object value) {
if (value instanceof String) {
String path = (String) value;
if (value instanceof String path) {
if (path.endsWith(".yaml") || path.endsWith(".ssz")) {
Path partPath = Paths.get(testFile.getParentFile().getParent(), "cache", path);
try {
Expand Down Expand Up @@ -225,9 +221,9 @@ void runForkChoiceTests(
if (!processAttestation(forkChoice, (Attestation) step)) {
attestationBuffer.add((Attestation) step);
}
} else if (step instanceof Map) {
} else if (step instanceof Map<?, ?> rawChecks) {
@SuppressWarnings("unchecked")
Map<String, Object> checks = (Map<String, Object>) step;
Map<String, Object> checks = (Map<String, Object>) rawChecks;
for (Map.Entry<String, Object> e : checks.entrySet()) {
String check = e.getKey();
switch (check) {
Expand Down
4 changes: 2 additions & 2 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ dependencyManagement {

dependency 'io.prometheus:simpleclient:0.16.0'

dependencySet(group: 'org.hyperledger.besu.internal', version: '24.5.2') {
dependencySet(group: 'org.hyperledger.besu.internal', version: '24.7.0') {
entry('metrics-core')
entry('core')
entry('config')
}
dependencySet(group: 'org.hyperledger.besu', version: '24.5.2') {
dependencySet(group: 'org.hyperledger.besu', version: '24.7.0') {
entry('besu-datatypes')
entry('evm')
entry('plugin-api')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ private static <T> T binaryTraverse(
final long gIndex, final TreeNode node, final BinaryVisitor<T> visitor) {
if (node instanceof LeafNode) {
return visitor.visitLeaf(gIndex, (LeafNode) node);
} else if (node instanceof BranchNode) {
BranchNode branchNode = (BranchNode) node;
} else if (node instanceof BranchNode branchNode) {
return visitor.visitBranch(
gIndex,
branchNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ private void assertTreeEqual(final TreeNode actual, final TreeNode expected, fin
assertThat(actual.hashTreeRoot())
.describedAs("zero branch node root at gIndex %s", gIndex)
.isEqualTo(expected.hashTreeRoot());
} else if (actual instanceof BranchNode) {
final BranchNode actualBranch = (BranchNode) actual;
} else if (actual instanceof BranchNode actualBranch) {
final BranchNode expectedBranch = (BranchNode) expected;
assertTreeEqual(
actualBranch.left(), expectedBranch.left(), GIndexUtil.gIdxLeftGIndex(gIndex));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ public <T extends SszData> Stream<T> randomDataStream(final SszSchema<T> schema)
} else {
throw new IllegalArgumentException("Unknown primitive schema: " + schema);
}
} else if (schema instanceof AbstractSszContainerSchema) {
AbstractSszContainerSchema<SszContainer> containerSchema =
(AbstractSszContainerSchema<SszContainer>) schema;
} else if (schema instanceof AbstractSszContainerSchema<?> containerSchema) {
return Stream.generate(
() -> {
List<SszData> children =
Expand Down Expand Up @@ -124,10 +122,9 @@ public <T extends SszData> Stream<T> randomDataStream(final SszSchema<T> schema)
SszCollection<SszData> ret = collectionSchema.createFromElements(children);
return (T) ret;
});
} else if (schema instanceof SszUnionSchema) {
} else if (schema instanceof SszUnionSchema<?> unionSchema) {
return Stream.generate(
() -> {
SszUnionSchema<?> unionSchema = (SszUnionSchema<?>) schema;
int selector = random.nextInt(unionSchema.getTypesCount());
return (T)
unionSchema.createFromValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ private static List<String> compareByGetters(final SszData actual, final SszData
+ ", actual: "
+ actual.getSchema());
}
if (actual instanceof SszComposite) {
SszComposite<?> c1 = (SszComposite<?>) actual;
if (actual instanceof SszComposite<?> c1) {
SszComposite<?> c2 = (SszComposite<?>) expected;
if (c1.size() != c2.size()) {
return List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.schema.SszContainerSchema;
Expand All @@ -38,7 +37,7 @@ public static IntList getVectorLengths(final SszContainerSchema<?> sszContainerS
}

public static SszBitlist not(final SszBitlist bitlist) {
List<Boolean> notList = bitlist.stream().map(b -> !b.get()).collect(Collectors.toList());
List<Boolean> notList = bitlist.stream().map(b -> !b.get()).toList();
int[] notBitIndices = IntStream.range(0, notList.size()).filter(notList::get).toArray();
return bitlist.getSchema().ofBits(bitlist.size(), notBitIndices);
}
Expand All @@ -55,8 +54,7 @@ private static void dumpBinaryTreeRec(
final String prefix,
final boolean printCommit,
final Consumer<String> linesConsumer) {
if (node instanceof LeafNode) {
LeafNode leafNode = (LeafNode) node;
if (node instanceof LeafNode leafNode) {
linesConsumer.accept(prefix + leafNode);
} else {
BranchNode branchNode = (BranchNode) node;
Expand Down