Skip to content
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
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 debian:bullseye-slim
FROM debian:bullseye-slim

RUN apt update && \
apt install --no-install-recommends -q --assume-yes curl=7* libjemalloc-dev=5.* && \
Expand Down
34 changes: 34 additions & 0 deletions docker/binary.dock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM debian:bullseye-slim

RUN apt update && \
apt install --no-install-recommends -q --assume-yes curl=7* libjemalloc-dev=5.* && \
apt clean

RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then \
curl -kL -o jdk-19.tar.gz https://github.com/adoptium/temurin19-binaries/releases/download/jdk-19.0.2%2B7/OpenJDK19U-jre_aarch64_linux_hotspot_19.0.2_7.tar.gz ; \
elif [ "$(uname -s)" = "Darwin" ] && [ "$(uname -m)" = "arm64" ]; then \
curl -kL -o jdk-19.tar.gz https://github.com/adoptium/temurin19-binaries/releases/download/jdk-19.0.2%2B7/OpenJDK19U-jre_aarch64_linux_hotspot_19.0.2_7.tar.gz ; \
elif [ "$ARCH" = "x86_64" ]; then \
curl -kL -o jdk-19.tar.gz https://github.com/adoptium/temurin19-binaries/releases/download/jdk-19.0.2%2B7/OpenJDK19U-jre_x64_linux_hotspot_19.0.2_7.tar.gz ; \
else \
echo "Unsupported platform: $ARCH"; exit 1; \
fi

RUN tar -xzf jdk-19.tar.gz && \
rm jdk-19.tar.gz && \
mv jdk-19.0.2+7-jre /usr/bin/ && \
update-alternatives --install "/usr/bin/java" "java" "/usr/bin/jdk-19.0.2+7-jre/bin/java" 1

ENV JAVA_HOME /usr/bin/jdk-19.0.2+7-jre
RUN export JAVA_HOME
RUN export PATH=$JAVA_HOME/bin:$PATH

WORKDIR /usr/local/bin
COPY . .

RUN chmod 0755 hildr-node && export PATH=/usr/local/bin:$PATH




28 changes: 28 additions & 0 deletions docker/start-hildr-node-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
set -e

if [ $SYNC_MODE = "full" ]
then
exec java -cp $HILDR_JAR $HILDR_MAIN_CLASS \
--network $NETWORK \
--jwt-secret $JWT_SECRET \
--l1-rpc-url $L1_RPC_URL \
--l2-rpc-url http://${EXECUTION_CLIENT}:8545 \
--l2-engine-url http://${EXECUTION_CLIENT}:8551 \
--rpc-port $RPC_PORT \
--sync-mode $SYNC_MODE
elif [ $SYNC_MODE = "checkpoint"]
then
exec java -cp $HILDR_JAR $HILDR_MAIN_CLASS \
--network $NETWORK \
--jwt-secret $JWT_SECRET \
--l1-rpc-url $L1_RPC_URL \
--l2-rpc-url http://${EXECUTION_CLIENT}:8545 \
--l2-engine-url http://${EXECUTION_CLIENT}:8551 \
--rpc-port $RPC_PORT \
--sync-mode $SYNC_MODE \
--checkpoint-sync-url $CHECKPOINT_SYNC_URL \
--checkpoint-hash $CHECKPOINT_HASH
else
echo "Sync mode not recognized. Available options are full and checkpoint"
fi
4 changes: 2 additions & 2 deletions docker/start-hildr-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

if [ $SYNC_MODE = "full" ]
then
exec java -cp $HILDR_JAR $HILDR_MAIN_CLASS \
exec hildr-node \
--network $NETWORK \
--jwt-secret $JWT_SECRET \
--l1-rpc-url $L1_RPC_URL \
Expand All @@ -13,7 +13,7 @@ then
--sync-mode $SYNC_MODE
elif [ $SYNC_MODE = "checkpoint"]
then
exec java -cp $HILDR_JAR $HILDR_MAIN_CLASS \
exec hildr-node \
--network $NETWORK \
--jwt-secret $JWT_SECRET \
--l1-rpc-url $L1_RPC_URL \
Expand Down
36 changes: 30 additions & 6 deletions hildr-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ spotless {
// make sure every file has the following copyright header.
// optionally, Spotless can set copyright years by digging
// through git history (see "license" section below)
licenseHeaderFile project(":").file("config/spotless/java.license")
// licenseHeaderFile project(":").file("config/spotless/java.license")
importOrder()

removeUnusedImports()
Expand Down Expand Up @@ -268,7 +268,7 @@ task buildBinary {
exec {
workingDir buildBinaryDir
executable "sh"
args "-c", "native-image -jar ${project.name}.jar --initialize-at-build-time=ch.qos.logback,org.slf4j,io.opentelemetry ${project.name}"
args "-c", "native-image -jar ${project.name}.jar --static --initialize-at-build-time=ch.qos.logback,org.slf4j,io.opentelemetry,java.io ${project.name}"
standardOutput out
}
}
Expand All @@ -281,10 +281,6 @@ task buildDocker {
def out = new ByteArrayOutputStream()
doFirst {
new File(buildImageDir).mkdirs()
copy {
from "../docker/start-hildr-node.sh"
into buildImageDir
}
copy {
from "../docker/Dockerfile"
into buildImageDir
Expand All @@ -305,3 +301,31 @@ task buildDocker {
}
println(out.toString())
}

task buildNativeDocker {
dependsOn buildBinary
def buildImageDir = "build/docker"
def out = new ByteArrayOutputStream()
doFirst {
new File(buildImageDir).mkdirs()
copy {
from "../docker/binary.dock"
into buildImageDir
}
copy {
from "build/binary/"
into buildImageDir
include "${project.name}"
}
}
doLast {
exec {
workingDir buildImageDir
executable "sh"
args "-c", "docker build --platform=linux/amd64 -f binary.dock -t optimism-java/${project.name}:latest ."
standardOutput out
}
}
println(out.toString())

}
2 changes: 1 addition & 1 deletion hildr-node/src/main/java/io/optimism/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void run() {
var checkpointHash = this.checkpointHash;
var config = this.toConfig();

Tracer tracer = Logging.INSTANCE.getTracer();
Tracer tracer = Logging.INSTANCE.getTracer("hildr-cli");
InnerMetrics.start(9200);

Runner runner = Runner.create(config).setSyncMode(syncMode).setCheckpointHash(checkpointHash);
Expand Down
13 changes: 3 additions & 10 deletions hildr-node/src/main/java/io/optimism/l1/InnerWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.optimism.derive.stages.Attributes.UserDeposited;
import io.optimism.driver.L1AttributesDepositedTxNotFoundException;
import io.optimism.l1.BlockUpdate.FinalityUpdate;
import io.optimism.rpc.provider.Web3jProvider;
import java.math.BigInteger;
import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -36,7 +37,6 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import okhttp3.OkHttpClient;
import org.jctools.queues.MessagePassingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -55,7 +55,6 @@
import org.web3j.protocol.core.methods.response.EthLog;
import org.web3j.protocol.core.methods.response.EthLog.LogObject;
import org.web3j.protocol.core.methods.response.EthLog.LogResult;
import org.web3j.protocol.http.HttpService;
import org.web3j.tuples.generated.Tuple2;
import org.web3j.utils.Numeric;

Expand Down Expand Up @@ -143,7 +142,7 @@ public InnerWatcher(
BigInteger l2StartBlock,
ExecutorService executor) {
this.executor = executor;
this.provider = createClient(config.l1RpcUrl());
this.provider = Web3jProvider.createClient(config.l1RpcUrl());
this.config = config;

if (l2StartBlock.equals(config.chainConfig().l2Genesis().number())) {
Expand All @@ -162,7 +161,7 @@ public InnerWatcher(
}

private void getMetadataFromL2(BigInteger l2StartBlock) {
Web3j l2Client = createClient(config.l2RpcUrl());
Web3j l2Client = Web3jProvider.createClient(config.l2RpcUrl());
EthBlock block;
try {
block = this.getBlock(l2Client, l2StartBlock.subtract(BigInteger.ONE));
Expand Down Expand Up @@ -460,12 +459,6 @@ private List<Attributes.UserDeposited> getDeposits(BigInteger blockNum)
return remv;
}

private Web3j createClient(String url) {
OkHttpClient okHttpClient =
new OkHttpClient.Builder().addInterceptor(new RetryRateLimitInterceptor()).build();
return Web3j.build(new HttpService(url, okHttpClient));
}

@Override
protected void run() {
while (isRunning()) {
Expand Down
54 changes: 54 additions & 0 deletions hildr-node/src/main/java/io/optimism/rpc/RpcMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023 281165273grape@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package io.optimism.rpc;

import java.util.HashSet;

/**
* method handler of rpc.
*
* @author thinkAfCod
* @since 2023.06
*/
public enum RpcMethod {

/** optimism_outputAtBlock api. */
OP_OUTPUT_AT_BLOCK("optimism_outputAtBlock");

private final String rpcMethodName;

private static final HashSet<String> allMethodNames;

static {
allMethodNames = new HashSet<>();
for (RpcMethod m : RpcMethod.values()) {
allMethodNames.add(m.getRpcMethodName());
}
}

RpcMethod(String rpcMethodName) {
this.rpcMethodName = rpcMethodName;
}

public String getRpcMethodName() {
return rpcMethodName;
}

public static boolean rpcMethodExists(final String rpcMethodName) {
return allMethodNames.contains(rpcMethodName);
}
}
Loading