Skip to content

Commit

Permalink
Consolidate L2Config and L2ExecutionConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
cygaar authored and norswap committed Sep 1, 2023
1 parent 6c6376b commit 94e6a00
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 54 deletions.
35 changes: 35 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import libroll as lib
from paths import OPPaths

# Summary on default port mapping:
Expand Down Expand Up @@ -79,6 +80,30 @@ def __init__(self):
execution engine. Must be supplied.
"""

# ==========================================================================================
# L2 Execution Engine Configuration

self.data_dir = L2_EXECUTION_DATA_DIR
"""Geth data directory for op-geth node."""

self.chaindata_dir = f"{self.data_dir}/geth/chaindata"
"""Directory storing chain data."""

self.chain_id = 42069
"""Chain ID of the local L2."""

# For the following values, allow environment override for now, to follow the original.
# In due time, remove that as we provide our own way to customize.

self.verbosity = 3
"""Geth verbosity level (from 0 to 5, see geth --help)."""

self.rpc_port = 9545
"""Port to use for the http-based JSON-RPC server."""

self.ws_port = 9546
"""Port to use for the WebSocket-based JSON_RPC server."""

# ==========================================================================================
# Node Configuration

Expand Down Expand Up @@ -419,6 +444,11 @@ def use_devnet_config(self, paths: OPPaths):

self.jwt_secret_path = paths.jwt_test_secret_path

# === L2 Execution Engine ===

genesis = lib.read_json_file(paths.l2_genesis_path)
self.chain_id = genesis["config"]["chainId"]

# === Node ===

self.sequencer_l1_confs = 0
Expand All @@ -442,3 +472,8 @@ def use_devnet_config(self, paths: OPPaths):
self.sub_safety_margin = 4

####################################################################################################

L2_EXECUTION_DATA_DIR = "db/L2-execution"
"""Directory to store the op-geth blockchain data."""

####################################################################################################
70 changes: 16 additions & 54 deletions l2_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@
import sys

import libroll as lib
from config import L2Config
from config import L2_EXECUTION_DATA_DIR, L2Config
from paths import OPPaths
from processes import PROCESS_MGR

####################################################################################################

L2_EXECUTION_DATA_DIR = "db/L2-execution"
"""Directory to store the op-geth blockchain data."""


####################################################################################################

def deploy_l2_execution(paths: OPPaths):
Expand Down Expand Up @@ -57,67 +51,35 @@ def generate_l2_execution_genesis(paths: OPPaths):

####################################################################################################


class L2ExecutionConfig:
def __init__(self, geth_data_dir: str, paths: OPPaths):
self.data_dir = geth_data_dir
"""Geth data directory for op-geth node."""

self.chaindata_dir = f"{self.data_dir}/geth/chaindata"
"""Directory storing chain data."""

genesis = lib.read_json_file(paths.l2_genesis_path)
self.chain_id = genesis["config"]["chainId"]

self.jwt_secret_path = paths.jwt_test_secret_path
"""Path for Jason Web Token secret, used for op-geth rpc auth."""

# For the following values, allow environment override for now, to follow the original.
# In due time, remove that as we provide our own way to customize.

self.verbosity = os.environ.get("GETH_VERBOSITY", 3)
"""Geth verbosity level (from 0 to 5, see geth --help)."""

self.rpc_port = os.environ.get("RPC_PORT", 9545)
"""Port to use for the http-based JSON-RPC server."""

self.ws_port = os.environ.get("WS_PORT", 9546)
"""Port to use for the WebSocket-based JSON_RPC server."""


####################################################################################################

def start_l2_execution_node(paths: OPPaths):
def start_l2_execution_node(config: L2Config, paths: OPPaths):
"""
Spin the op-geth node, then wait for it to be ready.
"""

cfg = L2ExecutionConfig(L2_EXECUTION_DATA_DIR, paths)

# Make sure the port isn't occupied yet.
# Necessary on MacOS that easily allows two processes to bind to the same port.
running = True
try:
lib.wait("127.0.0.1", cfg.rpc_port, retries=1)
lib.wait("127.0.0.1", config.rpc_port, retries=1)
except Exception:
running = False
if running:
raise Exception(
"Couldn't start op-geth node: server already running at localhost:9545")

# Create geth db if it doesn't exist.
os.makedirs(L2_EXECUTION_DATA_DIR, exist_ok=True)
os.makedirs(config.data_dir, exist_ok=True)

if not os.path.exists(cfg.chaindata_dir):
if not os.path.exists(config.chaindata_dir):
log_file = "logs/init_l2_genesis.log"
print(f"Directory {cfg.chaindata_dir} missing, importing genesis in op-geth node."
print(f"Directory {config.chaindata_dir} missing, importing genesis in op-geth node."
f"Logging to {log_file}")
lib.run(
"initializing genesis",
["op-geth",
f"--verbosity={cfg.verbosity}",
f"--verbosity={config.verbosity}",
"init",
f"--datadir={cfg.data_dir}",
f"--datadir={config.data_dir}",
paths.l2_genesis_path])

log_file_path = "logs/l2_engine.log"
Expand All @@ -131,10 +93,10 @@ def start_l2_execution_node(paths: OPPaths):
[
"op-geth",

f"--datadir={cfg.data_dir}",
f"--verbosity={cfg.verbosity}",
f"--datadir={config.data_dir}",
f"--verbosity={config.verbosity}",

f"--networkid={cfg.chain_id}",
f"--networkid={config.chain_id}",
"--syncmode=full", # doesn't matter, it's only us
"--gcmode=archive",

Expand All @@ -149,13 +111,13 @@ def start_l2_execution_node(paths: OPPaths):
"--http.corsdomain=*",
"--http.vhosts=*",
"--http.addr=0.0.0.0",
f"--http.port={cfg.rpc_port}",
f"--http.port={config.rpc_port}",
"--http.api=web3,debug,eth,txpool,net,engine",

# WebSocket JSON-RPC server config
"--ws",
"--ws.addr=0.0.0.0",
f"--ws.port={cfg.ws_port}",
f"--ws.port={config.ws_port}",
"--ws.origins=*",
"--ws.api=debug,eth,txpool,net,engine",

Expand All @@ -166,7 +128,7 @@ def start_l2_execution_node(paths: OPPaths):
"--authrpc.addr=0.0.0.0",
"--authrpc.port=9551",
"--authrpc.vhosts=*",
f"--authrpc.jwtsecret={cfg.jwt_secret_path}",
f"--authrpc.jwtsecret={config.jwt_secret_path}",

# Configuration for the metrics server (we currently don't use this)
"--metrics",
Expand All @@ -177,7 +139,7 @@ def start_l2_execution_node(paths: OPPaths):
"--rollup.disabletxpoolgossip=true",
], forward="fd", stdout=log_file, stderr=subprocess.STDOUT)

lib.wait_for_rpc_server("127.0.0.1", cfg.rpc_port)
lib.wait_for_rpc_server("127.0.0.1", config.rpc_port)


####################################################################################################
Expand Down Expand Up @@ -220,7 +182,7 @@ def deploy_l2(paths: OPPaths):
"L2OutputOracleProxy address not found in addresses.json. "
"Try redeploying the L1 contracts.")

start_l2_execution_node(paths)
start_l2_execution_node(config, paths)
start_l2_node(config, paths, sequencer=True)
start_l2_proposer(config, deployments)
start_l2_batcher(config)
Expand Down

0 comments on commit 94e6a00

Please sign in to comment.