Skip to content

Commit

Permalink
feat: hildr proposer and hildr batcher add dockerfile and docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed May 10, 2024
1 parent 4e40faf commit a8bbc4c
Show file tree
Hide file tree
Showing 24 changed files with 418 additions and 41 deletions.
28 changes: 26 additions & 2 deletions docker/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@ L1_WS_RPC_URL=wss://eth-mainnet.g.alchemy.com/v2/<API_KEY>
# The beacon chain RPC endpoint
L1_BEACON_RPC_URL=

# The L1 signer private key
L1_SIGNER=

# The batch inbox contract address deployed on l1
BATCH_INBOX_ADDRESS=

# JWT secret for the engine API
JWT_SECRET=bf549f5188556ce0951048ef467ec93067bc4ea21acebe46ef675cd4e8e015ff

# Hildr's external rpc service port
RPC_PORT=9545
# Execution client chain ID
L2_CHAIN_ID=

# Execution client signer private key
L2_SIGNER=

# Deployed l2 output oracle contract address
L2OO_ADDRESS=

# Deployed l2 dispute game factory contract address
L2DGF_ADDRESS=

# Execution client: can be either `op-geth` or `op-erigon`
EXECUTION_CLIENT=op-geth
Expand All @@ -28,6 +43,15 @@ EXECUTION_CLIENT_RPC_PORT=8545
# The execution client WebSocket port.
EXECUTION_CLIENT_WS_PORT=8546

# The Roll up client.
ROLLUP_CLIENT=hildr-node

# The Roll up client RPC port.
ROLLUP_RPC_PORT=11545

# Hildr's external rpc service port
ROLLUP_RPC_PORT=9545

# Sync mode: can be either `full` or `checkpoint`
SYNC_MODE=full

Expand Down
14 changes: 14 additions & 0 deletions docker/batcher.dock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ghcr.io/graalvm/graalvm-community:21 as builder

WORKDIR /root/hildr
COPY . .
RUN ./gradlew clean hildr-batcher:buildJarForDocker

FROM ghcr.io/graalvm/graalvm-community:21

WORKDIR /usr/local/bin
COPY --from=builder /root/hildr/hildr-batcher/build/docker/hildr-batcher.jar .
ENV HILDR_BATCHER_JAR /usr/local/bin/hildr-batcher.jar
ENV HILDR_BATCHER_MAIN_CLASS io.optimism.batcher.HildrBatcher

ENTRYPOINT ["java", "--enable-preview", "-cp" , "/usr/local/bin/hildr-batcher.jar", "io.optimism.batcher.HildrBatcher"]
44 changes: 42 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
- .env
ports:
- "9200:9200"
- "${RPC_PORT}:${RPC_PORT}"
- "${ROLLUP_RPC_PORT}:${ROLLUP_RPC_PORT}"
volumes:
- ./:/scripts
- data:/data
Expand All @@ -49,13 +49,53 @@ services:
- .env
ports:
- "9200:9200"
- "${RPC_PORT}:${RPC_PORT}"
- "${ROLLUP_RPC_PORT}:${ROLLUP_RPC_PORT}"
volumes:
- ./:/scripts
- data:/data
- ${OP_ROLLUP_JSON_FILEPATH:-.}:/rollup.json
<<: *logging

hildr-batcher:
container_name: hildr-batcher
build:
dockerfile: ./docker/batcher.dock
context: ../
profiles:
- hildr-batcher
restart: unless-stopped
stop_grace_period: 3m
entrypoint: /scripts/start-hildr-batcher-java.sh
depends_on:
- op-geth
env_file:
- .env
ports:
- "9201:9201"
volumes:
- ./:/scripts
<<: *logging

hildr-proposer:
container_name: hildr-proposer
build:
dockerfile: ./docker/proposer.dock
context: ../
profiles:
- hildr-proposer
restart: unless-stopped
stop_grace_period: 3m
entrypoint: /scripts/start-hildr-batcher-java.sh
depends_on:
- op-geth
env_file:
- .env
ports:
- "9203:9203"
volumes:
- ./:/scripts
<<: *logging

op-geth:
image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:v1.101304.2
container_name: op-geth
Expand Down
14 changes: 14 additions & 0 deletions docker/proposer.dock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ghcr.io/graalvm/graalvm-community:21 as builder

WORKDIR /root/hildr
COPY . .
RUN ./gradlew clean hildr-batcher:buildJarForDocker

FROM ghcr.io/graalvm/graalvm-community:21

WORKDIR /usr/local/bin
COPY --from=builder /root/hildr/hildr-batcher/build/docker/hildr-proposer.jar .
ENV HILDR_PROPOSER_JAR /usr/local/bin/hildr-proposer.jar
ENV HILDR_PROPOSER_MAIN_CLASS io.optimism.proposer.HildrProposer

ENTRYPOINT ["java", "--enable-preview", "-cp" , "/usr/local/bin/hildr-proposer.jar", "io.optimism.proposer.HildrProposer"]
11 changes: 11 additions & 0 deletions docker/start-hildr-batcher-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e

exec java --enable-preview \
-cp $HILDR_BATCHER_JAR $HILDR_BATCHER_MAIN_CLASS \
--l1-rpc-url $L1_RPC_URL \
--l1-signer $L1_SIGNER \
--batch-inbox-address $BATCH_INBOX_ADDRESS \
--l2-rpc-url http://${EXECUTION_CLIENT}:${EXECUTION_CLIENT_RPC_PORT} \
--rollup-rpc-url http://${ROLLUP_CLIENT}:${ROLLUP_RPC_PORT} \
--log-level $LOG_LEVEL
13 changes: 13 additions & 0 deletions docker/start-hildr-proposer-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
set -e

exec java --enable-preview \
-cp $HILDR_PROPOSER_JAR $HILDR_PROPOSER_MAIN_CLASS \
--l1-rpc-url $L1_RPC_URL \
--l2-rpc-url http://${EXECUTION_CLIENT}:${EXECUTION_CLIENT_RPC_PORT} \
--l2-chain-id $L2_CHAIN_ID \
--l2-signer $L2_SIGNER \
--l2oo-address $L2OO_ADDRESS \
--l2dgf-address $L2DGF_ADDRESS \
--rollup-rpc-url http://${ROLLUP_CLIENT}:${ROLLUP_RPC_PORT} \
--log-level $LOG_LEVEL
15 changes: 15 additions & 0 deletions hildr-batcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ shadowJar {
archiveFileName = "${project.name}-${project.version}.jar"
}

task buildJarForDocker {
dependsOn jar
def buildImageDir = "build/docker"
def out = new ByteArrayOutputStream()
doFirst {
new File(buildImageDir).mkdirs()
copy {
from "build/libs/${project.name}-${project.version}.jar"
into buildImageDir
rename "${project.name}-${project.version}.jar", "${project.name}.jar"
}
}
println(out.toString())
}

nativeCompile {
enabled = false
}
22 changes: 16 additions & 6 deletions hildr-batcher/src/main/java/io/optimism/batcher/cli/Cli.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.optimism.batcher.cli;

import ch.qos.logback.classic.Level;
import io.micrometer.tracing.Tracer;
import io.optimism.batcher.BatcherSubmitter;
import io.optimism.batcher.config.Config;
import io.optimism.batcher.exception.BatcherExecutionException;
import io.optimism.batcher.telemetry.BatcherMetricsServer;
import io.optimism.batcher.telemetry.BatcherPrometheusMetrics;
import io.optimism.cli.typeconverter.LogLevelConverter;
import io.optimism.utilities.telemetry.Logging;
import io.optimism.utilities.telemetry.TracerTaskWrapper;
import org.slf4j.Logger;
Expand Down Expand Up @@ -43,7 +45,7 @@ public class Cli implements Runnable {
@Option(names = "--sub-safety-margin", required = true, description = "")
Long subSafetyMargin;

@Option(names = "--pull-interval", required = true, description = "")
@Option(names = "--poll-interval", required = true, description = "")
Long pollInterval;

@Option(names = "--max-l1-tx-size", required = true, description = "")
Expand All @@ -61,18 +63,26 @@ public class Cli implements Runnable {
@Option(names = "--enable-metrics", description = "If not contains this option, will not open metrics server")
boolean enableMetrics;

@Option(
names = "--metrics-port",
defaultValue = "9200",
required = true,
description = "The port of metrics server ")
@Option(names = "--metrics-port", defaultValue = "9200", description = "The port of metrics server ")
Integer metricsPort;

@Option(
names = "--log-level",
defaultValue = "DEBUG",
converter = LogLevelConverter.class,
description = "Log level")
Level logLevel;

/** the Cli constructor. */
public Cli() {}

@Override
public void run() {
var logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (logger instanceof ch.qos.logback.classic.Logger) {
var logbackLogger = (ch.qos.logback.classic.Logger) logger;
logbackLogger.setLevel(logLevel);
}
TracerTaskWrapper.setTracerSupplier(Logging.INSTANCE::getTracer);

// listen close signal
Expand Down
15 changes: 13 additions & 2 deletions hildr-node/src/main/java/io/optimism/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public class Cli implements Runnable {
@Option(names = "--devnet", description = "Dev net flag")
Boolean devnet;

@Option(
names = "--sequencer-enable",
defaultValue = "false",
description =
"Enable sequencing of new L2 blocks. A separate batch submitter has to be deployed to publish the data for verifiers.")
Boolean sequencerEnable;

@Option(
names = "--log-level",
defaultValue = "DEBUG",
Expand All @@ -118,8 +125,11 @@ public Cli() {}

@Override
public void run() {
var logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.setLevel(logLevel);
var logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (logger instanceof ch.qos.logback.classic.Logger) {
var logbackLogger = (ch.qos.logback.classic.Logger) logger;
logbackLogger.setLevel(logLevel);
}
TracerTaskWrapper.setTracerSupplier(Logging.INSTANCE::getTracer);
if (Boolean.TRUE.equals(metricsEnable)) {
var metricsPort = this.metricsPort;
Expand Down Expand Up @@ -211,6 +221,7 @@ private Config.CliConfig from(Cli cli) {
cli.checkpointSyncUrl,
cli.rpcPort,
cli.syncMode,
cli.sequencerEnable,
cli.devnet);
}
}

This file was deleted.

7 changes: 6 additions & 1 deletion hildr-node/src/main/java/io/optimism/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* @param checkpointSyncUrl The checkpoint sync url.
* @param rpcPort The rpc port.
* @param devnet The flag of devnet.
* @param sequencerEnable The flag of sequencerEnable.
* @param syncMode The sync mode
* @param chainConfig The chain config.
* @author grapebaba
Expand All @@ -59,6 +60,7 @@ public record Config(
String checkpointSyncUrl,
Integer rpcPort,
Boolean devnet,
Boolean sequencerEnable,
SyncMode syncMode,
ChainConfig chainConfig) {

Expand Down Expand Up @@ -144,7 +146,8 @@ private static MapConfigSource getMapConfigSource() {
* @param jwtSecret L2 engine API jwt secret.
* @param checkpointSyncUrl The checkpoint sync url.
* @param rpcPort The rpc port.
* @param syncMode The sync mode.
* @param syncMode The sync mode.
* @param sequencerEnable The sequencer enable flag.
* @param devnet The devnet flag.
*/
public record CliConfig(
Expand All @@ -158,6 +161,7 @@ public record CliConfig(
String checkpointSyncUrl,
Integer rpcPort,
SyncMode syncMode,
Boolean sequencerEnable,
Boolean devnet) {

/**
Expand Down Expand Up @@ -197,6 +201,7 @@ public Map<String, String> toConfigMap() {
if (syncMode != null) {
map.put("config.syncMode", syncMode.toString());
}
map.put("config.sequencerEnable", String.valueOf(sequencerEnable != null && sequencerEnable));
map.put("config.devnet", String.valueOf(devnet != null && devnet));
return map;
}
Expand Down
Loading

0 comments on commit a8bbc4c

Please sign in to comment.