Skip to content

Commit

Permalink
fix op-node
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasbusa committed Jun 5, 2024
1 parent 8f373ea commit 347d0cb
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/per-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
kurtosis analytics disable
- name: Run Starlark
run: kurtosis run ${{ github.workspace }} --args-file ${{ matrix.file_name }}
run: kurtosis run ${{ github.workspace }} --args-file ${{ matrix.file_name }} --verbosity detailed

lint:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ default package for Optimism
optimism_package:
participants:
- el_type: op-geth
el_image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:latest
cl_type: op-node
cl_image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-node:develop
network_params:
network: kurtosis
network_id: "2151908"
Expand Down
8 changes: 4 additions & 4 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(plan, args={}):
l1 = ethereum_package.run(plan, ethereum_args)
all_l1_participants = l1.all_participants
l1_network_params = l1.network_params
priv_key = l1.pre_funded_accounts[
l1_priv_key = l1.pre_funded_accounts[
12
].private_key # reserved for L2 contract deployer
# Deploy L2 smart contracts
Expand All @@ -65,9 +65,9 @@ def run(plan, args={}):
l2_config_env_vars["L2_CHAIN_ID"] = str(network_params.network_id)
l2_config_env_vars["L2_BLOCK_TIME"] = str(network_params.seconds_per_slot)

el_cl_data, gs_sequencer_private_key = contract_deployer.launch_contract_deployer(
el_cl_data, gs_private_keys = contract_deployer.launch_contract_deployer(
plan,
priv_key,
l1_priv_key,
l1_config_env_vars,
l2_config_env_vars,
)
Expand All @@ -86,7 +86,7 @@ def run(plan, args={}):
jwt_file,
network_params,
el_cl_data,
gs_sequencer_private_key,
gs_private_keys,
l1_config_env_vars,
)

Expand Down
2 changes: 0 additions & 2 deletions network_params.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
optimism_package:
participants:
- el_type: op-geth
el_image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:latest
cl_type: op-node
cl_image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-node:develop
network_params:
network: kurtosis
network_id: "2151908"
Expand Down
133 changes: 133 additions & 0 deletions src/batcher/op-batcher/op_batcher_launcher.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
shared_utils = import_module(
"github.com/kurtosis-tech/ethereum-package/src/shared_utils/shared_utils.star"
)

constants = import_module(
"github.com/kurtosis-tech/ethereum-package/src/package_io/constants.star"
)


#
# ---------------------------------- Batcher client -------------------------------------
# The Docker container runs as the "op-batcher" user so we can't write to root
BATCHER_DATA_DIRPATH_ON_SERVICE_CONTAINER = "/data/op-batcher/op-batcher-beacon-data"

# Port IDs
BEACON_HTTP_PORT_ID = "http"

# Port nums
BEACON_HTTP_PORT_NUM = 8548


def get_used_ports(discovery_port):
used_ports = {
BEACON_HTTP_PORT_ID: shared_utils.new_port_spec(
BEACON_HTTP_PORT_NUM,
shared_utils.TCP_PROTOCOL,
shared_utils.HTTP_APPLICATION_PROTOCOL,
),
}
return used_ports


ENTRYPOINT_ARGS = ["sh", "-c"]

VERBOSITY_LEVELS = {
constants.GLOBAL_LOG_LEVEL.error: "ERROR",
constants.GLOBAL_LOG_LEVEL.warn: "WARN",
constants.GLOBAL_LOG_LEVEL.info: "INFO",
constants.GLOBAL_LOG_LEVEL.debug: "DEBUG",
constants.GLOBAL_LOG_LEVEL.trace: "TRACE",
}


def launch(
plan,
launcher,
service_name,
image,
el_context,
existing_cl_clients,
l1_config_env_vars,
gs_batcher_private_key,
):
beacon_service_name = "{0}".format(service_name)

network_name = shared_utils.get_network_name(launcher.network)
config = get_beacon_config(
plan,
launcher.el_cl_genesis_data,
launcher.jwt_file,
image,
service_name,
el_context,
existing_cl_clients,
l1_config_env_vars,
gs_batcher_private_key,
)

beacon_service = plan.add_service(service_name, config)

beacon_http_port = beacon_service.ports[BEACON_HTTP_PORT_ID]
beacon_http_url = "http://{0}:{1}".format(
beacon_service.ip_address, beacon_http_port.number
)

return "op_batcher"


def get_beacon_config(
plan,
el_cl_genesis_data,
jwt_file,
image,
service_name,
el_context,
cl_context,
l1_config_env_vars,
gs_batcher_private_key,
):
discovery_port = BEACON_DISCOVERY_PORT_NUM
used_ports = get_used_ports(discovery_port)

cmd = [
"--l2-eth-rpc=" + el_context.rpc_http_url,
"--rollup-rpc=" + cl_context.beacon_http_url,
"--poll-interval=1s",
"--sub-safety-margin=6",
"--num-confirmations=1",
"--safe-abort-nonce-too-low-count=3",
"--resubmission-timeout=30s",
"--rpc.addr=0.0.0.0",
"--rpc.port=" + BEACON_HTTP_PORT_NUM,
"--rpc.enable-admin",
"--max-channel-duration=1",
"--l1-eth-rpc=" + l1_config_env_vars["L1_RPC_URL"],
"--private-key=" + gs_batcher_private_key,
]

files = {
constants.GENESIS_DATA_MOUNTPOINT_ON_CLIENTS: el_cl_genesis_data,
constants.JWT_MOUNTPOINT_ON_CLIENTS: jwt_file,
}
ports = {}
ports.update(used_ports)

return ServiceConfig(
image=image,
ports=ports,
cmd=cmd,
files=files,
private_ip_address_placeholder=constants.PRIVATE_IP_ADDRESS_PLACEHOLDER,
ready_conditions=cl_node_ready_conditions.get_ready_conditions(
BEACON_HTTP_PORT_ID
),
)


def new_op_node_launcher(el_cl_genesis_data, jwt_file, network_params):
return struct(
el_cl_genesis_data=el_cl_genesis_data,
jwt_file=jwt_file,
network=network_params.network,
)
109 changes: 55 additions & 54 deletions src/cl/op-node/op_node_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,34 @@ constants = import_module(
"github.com/kurtosis-tech/ethereum-package/src/package_io/constants.star"
)

node_metrics = import_module(
"github.com/kurtosis-tech/ethereum-package/src/node_metrics_info.star"
)

# ---------------------------------- Beacon client -------------------------------------

# The Docker container runs as the "op-node" user so we can't write to root
BEACON_DATA_DIRPATH_ON_SERVICE_CONTAINER = "/data/op-node/op-node-beacon-data"
ROLLUP_CONFIG_MOUNT_PATH_ON_CONTAINER = "/network-config/rollup-config.json"
ROLLUP_CONFIG_MOUNT_PATH_ON_CONTAINER = "/network-configs/rollup.json"
# Port IDs
BEACON_TCP_DISCOVERY_PORT_ID = "tcp-discovery"
BEACON_UDP_DISCOVERY_PORT_ID = "udp-discovery"
BEACON_HTTP_PORT_ID = "http"
BEACON_METRICS_PORT_ID = "metrics"
VALIDATOR_HTTP_PORT_ID = "http-validator"

# Port nums
BEACON_DISCOVERY_PORT_NUM = 9000
BEACON_HTTP_PORT_NUM = 4000
BEACON_METRICS_PORT_NUM = 8008


BEACON_METRICS_PATH = "/metrics"

MIN_PEERS = 1
BEACON_DISCOVERY_PORT_NUM = 9003
BEACON_HTTP_PORT_NUM = 8547


def get_used_ports(discovery_port):
used_ports = {
BEACON_TCP_DISCOVERY_PORT_ID: shared_utils.new_port_spec(
discovery_port, shared_utils.TCP_PROTOCOL
discovery_port, shared_utils.TCP_PROTOCOL, wait=None
),
BEACON_UDP_DISCOVERY_PORT_ID: shared_utils.new_port_spec(
discovery_port, shared_utils.UDP_PROTOCOL
discovery_port, shared_utils.UDP_PROTOCOL, wait=None
),
BEACON_HTTP_PORT_ID: shared_utils.new_port_spec(
BEACON_HTTP_PORT_NUM,
shared_utils.TCP_PROTOCOL,
shared_utils.HTTP_APPLICATION_PROTOCOL,
),
BEACON_METRICS_PORT_ID: shared_utils.new_port_spec(
BEACON_METRICS_PORT_NUM, shared_utils.TCP_PROTOCOL
),
}
return used_ports

Expand All @@ -81,9 +66,20 @@ def launch(
l1_config_env_vars,
gs_sequencer_private_key,
):
beacon_service_name = "{0}".format(service_name)

network_name = shared_utils.get_network_name(launcher.network)

beacon_node_identity_recipe = PostHttpRequestRecipe(
endpoint="/",
content_type="application/json",
body='{"jsonrpc":"2.0","method":"opp2p_self","params":[],"id":1}',
port_id=BEACON_HTTP_PORT_ID,
extract={
"enr": ".result.ENR",
"multiaddr": ".result.addresses[0]",
"peer_id": ".result.peerID",
},
)

config = get_beacon_config(
plan,
launcher.el_cl_genesis_data,
Expand All @@ -94,6 +90,7 @@ def launch(
existing_cl_clients,
l1_config_env_vars,
gs_sequencer_private_key,
beacon_node_identity_recipe,
)

beacon_service = plan.add_service(service_name, config)
Expand All @@ -103,40 +100,22 @@ def launch(
beacon_service.ip_address, beacon_http_port.number
)

beacon_metrics_port = beacon_service.ports[BEACON_METRICS_PORT_ID]
beacon_metrics_url = "{0}:{1}".format(
beacon_service.ip_address, beacon_metrics_port.number
)

beacon_node_identity_recipe = GetHttpRequestRecipe(
endpoint="/eth/v1/node/identity",
port_id=BEACON_HTTP_PORT_ID,
extract={
"enr": ".data.enr",
"multiaddr": ".data.p2p_addresses[0]",
"peer_id": ".data.peer_id",
},
)
response = plan.request(
recipe=beacon_node_identity_recipe, service_name=service_name
)

beacon_node_enr = response["extract.enr"]
beacon_multiaddr = response["extract.multiaddr"]
beacon_peer_id = response["extract.peer_id"]

beacon_node_metrics_info = node_metrics.new_node_metrics_info(
service_name, BEACON_METRICS_PATH, beacon_metrics_url
)
nodes_metrics_info = [beacon_node_metrics_info]

return cl_context.new_cl_context(
"op-node",
beacon_node_enr,
beacon_service.ip_address,
beacon_http_port.number,
beacon_http_url,
nodes_metrics_info,
beacon_service_name,
None,
service_name,
multiaddr=beacon_multiaddr,
peer_id=beacon_peer_id,
)
Expand All @@ -152,28 +131,47 @@ def get_beacon_config(
existing_cl_clients,
l1_config_env_vars,
gs_sequencer_private_key,
beacon_node_identity_recipe,
):
EXECUTION_ENGINE_ENDPOINT = el_context.rpc_http_url
EXECUTION_ENGINE_ENDPOINT = "http://{0}:{1}".format(
el_context.ip_addr,
el_context.engine_rpc_port_num,
)

discovery_port = BEACON_DISCOVERY_PORT_NUM
used_ports = get_used_ports(discovery_port)
used_ports = get_used_ports(BEACON_DISCOVERY_PORT_NUM)

cmd = [
"--l2={0}".format(EXECUTION_ENGINE_ENDPOINT),
"--l2.jwt-secret=" + constants.JWT_MOUNT_PATH_ON_CONTAINER,
"--sequencer.enabled",
"--sequencer.l1-confs=5",
"--verifier.l1-confs=4",
"--rollup.config=" + ROLLUP_CONFIG_MOUNT_PATH_ON_CONTAINER,
"--rpc.addr=0.0.0.0",
"--rpc.port={0}".format(BEACON_HTTP_PORT_NUM),
"--p2p.disable",
"--rpc.enable-admin",
"--p2p.sequencer.key=" + gs_sequencer_private_key,
"--l1=$L1_RPC_URL",
"--l1.rpckind=$L1_RPC_KIND",
"--l1={0}".format(l1_config_env_vars["L1_RPC_URL"]),
"--l1.rpckind={0}".format(l1_config_env_vars["L1_RPC_KIND"]),
"--l1.beacon={0}".format(l1_config_env_vars["CL_RPC_URL"]),
"--p2p.listen.ip=0.0.0.0",
"--p2p.listen.tcp={0}".format(BEACON_DISCOVERY_PORT_NUM),
"--p2p.listen.udp={0}".format(BEACON_DISCOVERY_PORT_NUM),
]

if len(existing_cl_clients) == 0:
cmd.append("--sequencer.enabled")
cmd.append("--sequencer.l1-confs=5")

if len(existing_cl_clients) > 0:
cmd.append(
"--p2p.static="
+ ",".join(
[
ctx.beacon_multiaddr
for ctx in existing_cl_clients[: constants.MAX_ENR_ENTRIES]
]
)
)

files = {
constants.GENESIS_DATA_MOUNTPOINT_ON_CLIENTS: el_cl_genesis_data,
constants.JWT_MOUNTPOINT_ON_CLIENTS: jwt_file,
Expand All @@ -184,12 +182,15 @@ def get_beacon_config(
return ServiceConfig(
image=image,
ports=ports,
env_vars=l1_config_env_vars,
cmd=cmd,
files=files,
private_ip_address_placeholder=constants.PRIVATE_IP_ADDRESS_PLACEHOLDER,
ready_conditions=cl_node_ready_conditions.get_ready_conditions(
BEACON_HTTP_PORT_ID
ready_conditions=ReadyCondition(
recipe=beacon_node_identity_recipe,
field="code",
assertion="==",
target_value=200,
timeout="1m",
),
)

Expand Down
Loading

0 comments on commit 347d0cb

Please sign in to comment.