Skip to content

Commit

Permalink
feat: support sepolia and devnet
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed Oct 24, 2023
1 parent 69418e4 commit d689c93
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 41 deletions.
21 changes: 20 additions & 1 deletion docker/.env.default
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# L1 network option: can be either `optimism-goerli` or `base-goerli`
# L1 network option: can be either `optimism`, `optimism-goerli`, `optimism-sepolia` or `base-goerli`
NETWORK=optimism

# The HTTP RPC endpoint of an L1 node
Expand All @@ -16,9 +16,28 @@ RPC_PORT=9545
# Execution client: can be either `op-geth` or `op-erigon`
EXECUTION_CLIENT=op-geth

# The exeuction client Auth RPC port.
EXECUTION_CLIENT_AUTH_RPC_PORT=8551

# The execution client RPC port.
EXECUTION_CLIENT_RPC_PORT=8545

# The execution client WebSocket port.
EXECUTION_CLIENT_WS_PORT=8546

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

# Only for `custom` or `devnet` network.
# Specify the path to the `rollup.json` file generated by `op-node`.
# For the devnet configuration, this file should be located in the `.devnet` folder within the Optimism directory.
# OP_ROLLUP_JSON_FILEPATH=

# Only for `custom` or `devnet` network.
# Specify the path to the `genesis-l2.json` file generated by `op-node`.
# For the devnet configuration, this file should be located in the `.devnet` folder within the Optimism directory.
# OP_GENESIS_JSON_FILEPATH=

# If the OP-Challenger should be run as a service alongside Magi
# (comment out the next line if you don't want to run this service)
#RUN_OP_CHALLENGER=run-op-challenger
Expand Down
14 changes: 8 additions & 6 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
volumes:
- ./:/scripts
- data:/data
- ${OP_ROLLUP_JSON_FILEPATH:-.}:/rollup.json
<<: *logging

op-geth:
Expand All @@ -42,12 +43,13 @@ services:
env_file:
- .env
ports:
- 8551:8551
- 8545:8545
- 8546:8546
- ${EXECUTION_CLIENT_AUTH_RPC_PORT}:8551
- ${EXECUTION_CLIENT_RPC_PORT}:8545
- ${EXECUTION_CLIENT_WS_PORT}:8546
volumes:
- ./:/scripts
- data:/data
- ${OP_GENESIS_JSON_FILEPATH:-.}:/genesis-l2.json
<<: *logging

op-erigon:
Expand All @@ -61,9 +63,9 @@ services:
env_file:
- .env
ports:
- 8551:8551
- 8545:8545
- 8546:8546
- ${EXECUTION_CLIENT_AUTH_RPC_PORT}:8551
- ${EXECUTION_CLIENT_RPC_PORT}:8545
- ${EXECUTION_CLIENT_WS_PORT}:8546
volumes:
- ./:/scripts
- data:/data
Expand Down
12 changes: 12 additions & 0 deletions docker/start-hildr-node.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/sh
set -e
DEVNET=""

if [ $NETWORK = "custom" ] || [ $NETWORK = "devnet" ]
then
NETWORK="./rollup.json"
if [ "$NETWORK" = "devnet" ]
then
DEVNET="--devnet"
fi
fi

if [ $SYNC_MODE = "full" ]
then
Expand All @@ -10,6 +20,7 @@ then
--l2-rpc-url http://${EXECUTION_CLIENT}:8545 \
--l2-engine-url http://${EXECUTION_CLIENT}:8551 \
--rpc-port $RPC_PORT \
$DEVNET \
--sync-mode $SYNC_MODE
elif [ $SYNC_MODE = "checkpoint"]
then
Expand All @@ -20,6 +31,7 @@ then
--l2-rpc-url http://${EXECUTION_CLIENT}:8545 \
--l2-engine-url http://${EXECUTION_CLIENT}:8551 \
--rpc-port $RPC_PORT \
$DEVNET \
--sync-mode $SYNC_MODE \
--checkpoint-sync-url $CHECKPOINT_SYNC_URL \
--checkpoint-hash $CHECKPOINT_HASH
Expand Down
2 changes: 1 addition & 1 deletion docker/start-op-erigon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

echo $JWT_SECRET > jwtsecret.txt

erigon \
exec erigon \
--datadir=$DATADIR \
--private.api.addr=localhost:9090 \
--http.addr=0.0.0.0 \
Expand Down
35 changes: 29 additions & 6 deletions docker/start-op-geth.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/sh
set -e

apk add zstd
apk add jq

DATADIR=/data/geth

if [ $NETWORK = "optimism" ]
Expand All @@ -9,8 +12,8 @@ then
if [ ! -d $DATADIR ]
then
mkdir $DATADIR
wget -c "https://storage.googleapis.com/oplabs-mainnet-data/mainnet-bedrock.tar" -P $DATADIR
tar -xvf $DATADIR/mainnet-bedrock.tar -C $DATADIR
wget "https://datadirs.optimism.io/mainnet-bedrock.tar.zst" -P $DATADIR
zstd -cd $DATADIR/mainnet-bedrock.tar.zst | tar xvf - -C $DATADIR
fi
elif [ $NETWORK = "base" ]
then
Expand All @@ -19,30 +22,48 @@ then
then
mkdir $DATADIR
wget "https://raw.githubusercontent.com/base-org/node/main/mainnet/genesis-l2.json" -O ./genesis-l2.json
exec geth init --datadir=$DATADIR ./genesis-l2.json
geth init --datadir=$DATADIR ./genesis-l2.json
fi
elif [ $NETWORK = "optimism-goerli" ]
then
CHAIN_ID=420
if [ ! -d $DATADIR ]
then
mkdir $DATADIR
wget "https://storage.googleapis.com/oplabs-goerli-data/goerli-bedrock.tar" -P $DATADIR
tar -xvf $DATADIR/goerli-bedrock.tar -C $DATADIR
wget "https://datadirs.optimism.io/goerli-bedrock.tar.zst" -P $DATADIR
zstd -cd $DATADIR/goerli-bedrock.tar.zst | tar xvf - -C $DATADIR
fi
elif [ "$NETWORK" = "optimism-sepolia" ]
then
CHAIN_ID=11155420
if [ ! -d "$DATADIR" ]
then
wget "https://storage.googleapis.com/oplabs-network-data/Sepolia/genesis.json" -O ./genesis-l2.json
geth init --datadir=$DATADIR ./genesis-l2.json
fi
elif [ $NETWORK = "base-goerli" ]
then
CHAIN_ID=84531
if [ ! -d $DATADIR ]
then
wget "https://raw.githubusercontent.com/base-org/node/main/goerli/genesis-l2.json" -O ./genesis-l2.json
exec geth init --datadir=$DATADIR ./genesis-l2.json
geth init --datadir=$DATADIR ./genesis-l2.json
fi
elif [ $NETWORK = "custom" ] || [ $NETWORK = "devnet" ]
then
CHAIN_ID=$(jq '.config.chainId' ./genesis-l2.json)

if [ ! -d $DATADIR ]
then
mkdir $DATADIR
geth init --datadir=$DATADIR ./genesis-l2.json
fi
else
echo "Network not recognized. Available options are optimism-goerli and base-goerli"
exit 1
fi


echo $JWT_SECRET > jwtsecret.txt

echo "chain id"
Expand All @@ -65,3 +86,5 @@ exec geth \
--authrpc.port=8551 \
--authrpc.jwtsecret=/jwtsecret.txt \
--rollup.disabletxpoolgossip=true \
--snapshot=false
$@
41 changes: 39 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 @@ -24,8 +24,12 @@
import io.optimism.telemetry.InnerMetrics;
import io.optimism.utilities.telemetry.Logging;
import io.optimism.utilities.telemetry.TracerTaskWrapper;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
Expand Down Expand Up @@ -70,6 +74,11 @@ public class Cli implements Runnable {
description = "Engine API JWT Secret. This is used to authenticate with the engine API")
String jwtSecret;

@Option(
names = "--jwt-file",
description = "Path to a JWT secret to use for authenticated RPC endpoints")
String jwtFile;

@Option(
names = {"--verbose", "-v"},
description = "")
Expand All @@ -91,6 +100,9 @@ public class Cli implements Runnable {
description = "A trusted L2 RPC URL to use for fast/checkpoint syncing")
String checkpointSyncUrl;

@Option(names = "--devnet", description = "Dev net flag")
private Boolean devnet;

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

Expand Down Expand Up @@ -133,6 +145,8 @@ private Config toConfig() {
switch (network) {
case "optimism" -> Config.ChainConfig.optimism();
case "optimism-goerli" -> Config.ChainConfig.optimismGoerli();
case "optimism-sepolia" -> Config.ChainConfig.optimismSepolia();
case "base" -> Config.ChainConfig.base();
case "base-goerli" -> Config.ChainConfig.baseGoerli();
default -> {
if (network.endsWith(".json")) {
Expand All @@ -147,13 +161,36 @@ private Config toConfig() {
return Config.create(Files.exists(configPath) ? configPath : null, cliConfig, chain);
}

private String getJwtSecret() {
if (StringUtils.isNotEmpty(Cli.this.jwtSecret)) {
return Cli.this.jwtSecret;
}
return Cli.this.getJwtFromFile();
}

private String getJwtFromFile() {
final Path jwtFilePath =
StringUtils.isNotEmpty(Cli.this.jwtFile)
? Paths.get(Cli.this.jwtFile)
: Paths.get(System.getProperty("user.dir"), "jwt.hex");
if (!Files.exists(jwtFilePath)) {
throw new RuntimeException("Failed to read JWT secret from file: " + jwtFilePath);
}
try {
return Files.readString(jwtFilePath, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException("Failed to read JWT secret from file: " + jwtFilePath, e);
}
}

private Config.CliConfig from(Cli cli) {
return new Config.CliConfig(
cli.l1RpcUrl,
cli.l2RpcUrl,
cli.l2EngineUrl,
cli.jwtSecret,
Cli.this.getJwtSecret(),
cli.checkpointSyncUrl,
cli.rpcPort);
cli.rpcPort,
cli.devnet);
}
}
47 changes: 43 additions & 4 deletions hildr-node/src/main/java/io/optimism/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch
* @param jwtSecret L2 engine API jwt secret.
* @param checkpointSyncUrl The checkpoint sync url.
* @param rpcPort The rpc port.
* @param devnet The devnet flag.
*/
public record CliConfig(
String l1RpcUrl,
String l2RpcUrl,
String l2EngineUrl,
String jwtSecret,
String checkpointSyncUrl,
Integer rpcPort) {
Integer rpcPort,
Boolean devnet) {

/**
* To configMap.
Expand Down Expand Up @@ -254,6 +256,43 @@ public static ChainConfig optimism() {
"0x4200000000000000000000000000000000000016");
}

/**
* Optimism sepolia ChainConfig.
*
* @return the chain config
*/
public static ChainConfig optimismSepolia() {
return new ChainConfig(
"base-goerli",
BigInteger.valueOf(11155111L),
BigInteger.valueOf(11155420L),
new Epoch(
BigInteger.valueOf(4071408L),
"0x48f520cf4ddaf34c8336e6e490632ea3cf1e5e93b0b2bc6e917557e31845371b",
BigInteger.valueOf(1691802540L)),
new BlockInfo(
"0x102de6ffb001480cc9b8b548fd05c34cd4f46ae4aa91759393db90ea0409887d",
BigInteger.valueOf(0L),
Numeric.toHexString(new byte[32]),
BigInteger.valueOf(1691802540L)),
new SystemConfig(
"0x8F23BB38F531600e5d8FDDaAEC41F13FaB46E98c",
BigInteger.valueOf(30_000_000L),
BigInteger.valueOf(188),
BigInteger.valueOf(684000),
"0x0000000000000000000000000000000000000000"),
"0xff00000000000000000000000000000011155420",
"0x16fc5058f25648194471939df75cf27a2fdc48bc",
"0x034edd2a225f7f429a63e0f1d2084b9e0a93b538",
BigInteger.valueOf(100_000_000L),
BigInteger.valueOf(300L),
BigInteger.valueOf(3600L),
BigInteger.valueOf(600L),
BigInteger.ZERO,
BigInteger.valueOf(2L),
"0x4200000000000000000000000000000000000016");
}

/**
* Base mainnet chain config.
*
Expand Down Expand Up @@ -286,7 +325,7 @@ public static ChainConfig base() {
BigInteger.valueOf(300L),
BigInteger.valueOf(3600L),
BigInteger.valueOf(600L),
BigInteger.valueOf(Long.MAX_VALUE),
BigInteger.ZERO,
BigInteger.valueOf(2L),
"0x4200000000000000000000000000000000000016");
}
Expand Down Expand Up @@ -360,7 +399,7 @@ public static ChainConfig baseGoerli() {
BigInteger.valueOf(100L),
BigInteger.valueOf(3600L),
BigInteger.valueOf(600L),
BigInteger.valueOf(Long.MAX_VALUE),
BigInteger.valueOf(1683219600L),
BigInteger.valueOf(2L),
"0x4200000000000000000000000000000000000016");
}
Expand Down Expand Up @@ -416,7 +455,7 @@ public static ChainConfig fromExternal(ExternalChainConfig external) {
external.maxSequencerDrift,
external.regolithTime,
external.blockTime,
Numeric.toHexString(new byte[32]));
"0x4200000000000000000000000000000000000016");
}

/**
Expand Down
10 changes: 0 additions & 10 deletions hildr-node/src/main/java/io/optimism/derive/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,6 @@ public Epoch epoch(BigInteger number) {
l1Info.blockInfo().number(), l1Info.blockInfo().hash(), l1Info.blockInfo().timestamp());
}

/**
* Is full boolean.
*
* @return the boolean
*/
public boolean isFull() {
return this.currentEpochNum.compareTo(this.safeEpoch.number().add(BigInteger.valueOf(1000L)))
> 0;
}

/**
* Update l 1 info.
*
Expand Down
Loading

0 comments on commit d689c93

Please sign in to comment.