Skip to content

Commit

Permalink
feat: add op_node
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasbusa committed Jun 5, 2024
1 parent 1032c95 commit 05b45c2
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 62 deletions.
45 changes: 28 additions & 17 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ participant_network = import_module("./src/participant_network.star")


def get_l1_stuff(all_l1_participants, l1_network_params):
first_l1_el_node = all_l1_participants[0].el_context.rpc_http_url
first_l1_cl_node = all_l1_participants[0].cl_context.beacon_http_url
l1_chain_id = l1_network_params.network_id
l1_block_time = l1_network_params.seconds_per_slot
return first_l1_el_node, first_l1_cl_node, l1_chain_id, l1_block_time
env_vars = {}
env_vars["L1_RPC_KIND"] = "any"
env_vars["WEB3_RPC_URL"] = str(all_l1_participants[0].el_context.rpc_http_url)
env_vars["L1_RPC_URL"] = str(all_l1_participants[0].el_context.rpc_http_url)
env_vars["CL_RPC_URL"] = str(all_l1_participants[0].cl_context.beacon_http_url)
env_vars["L1_CHAIN_ID"] = str(l1_network_params.network_id)
env_vars["L1_BLOCK_TIME"] = str(l1_network_params.seconds_per_slot)
env_vars["DEPLOYMENT_OUTFILE"] = (
"/workspace/optimism/packages/contracts-bedrock/deployments/"
+ str(l1_network_params.network_id)
+ "/kurtosis.json"
)
env_vars["STATE_DUMP_PATH"] = (
"/workspace/optimism/packages/contracts-bedrock/deployments/"
+ str(l1_network_params.network_id)
+ "/state-dump.json"
)

return env_vars


def run(plan, args={}):
Expand Down Expand Up @@ -42,25 +56,20 @@ def run(plan, args={}):
plan.print("Parsing the L2 input args")
optimism_args = args["optimism_package"]

first_l1_el_node, first_l1_cl_node, l1_chain_id, l1_block_time = get_l1_stuff(
all_l1_participants, l1_network_params
)
l1_config_env_vars = get_l1_stuff(all_l1_participants, l1_network_params)

args_with_right_defaults = input_parser.input_parser(plan, optimism_args)
network_params = args_with_right_defaults.network_params

l2_block_time = network_params.seconds_per_slot
l2_chain_id = network_params.network_id
l2_config_env_vars = {}
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 = contract_deployer.launch_contract_deployer(
el_cl_data, gs_sequencer_private_key = contract_deployer.launch_contract_deployer(
plan,
first_l1_el_node,
first_l1_cl_node,
priv_key,
l1_chain_id,
l2_chain_id,
l1_block_time,
l2_block_time,
l1_config_env_vars,
l2_config_env_vars,
)

# Deploy the L2
Expand All @@ -77,6 +86,8 @@ def run(plan, args={}):
jwt_file,
network_params,
el_cl_data,
gs_sequencer_private_key,
l1_config_env_vars,
)

plan.print(all_participants)
74 changes: 74 additions & 0 deletions src/cl/cl_launcher.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
constants = import_module(
"github.com/kurtosis-tech/ethereum-package/src/package_io/constants.star"
)
shared_utils = import_module(
"github.com/kurtosis-tech/ethereum-package/src/shared_utils/shared_utils.star"
)

cl_context_BOOTNODE = None

op_node = import_module("./op-node/op_node_launcher.star")


def launch(
plan,
jwt_file,
network_params,
el_cl_data,
participants,
num_participants,
all_el_contexts,
l1_config_env_vars,
gs_sequencer_private_key,
):
plan.print("Launching CL network")

cl_launchers = {
"op-node": {
"launcher": op_node.new_op_node_launcher(
el_cl_data, jwt_file, network_params
),
"launch_method": op_node.launch,
},
}
all_cl_contexts = []

for index, participant in enumerate(participants):
cl_type = participant.cl_type
el_type = participant.el_type

if cl_type not in cl_launchers:
fail(
"Unsupported launcher '{0}', need one of '{1}'".format(
cl_type, ",".join(cl_launchers.keys())
)
)

cl_launcher, launch_method = (
cl_launchers[cl_type]["launcher"],
cl_launchers[cl_type]["launch_method"],
)

index_str = shared_utils.zfill_custom(index + 1, len(str(len(participants))))

cl_service_name = "op-cl-{0}-{1}-{2}".format(index_str, cl_type, el_type)

el_context = all_el_contexts[index]

cl_context = None

full_name = "{0}-{1}-{2}".format(index_str, el_type, cl_type)

cl_context = launch_method(
plan,
cl_launcher,
cl_service_name,
participant.cl_image,
el_context,
all_cl_contexts,
l1_config_env_vars,
gs_sequencer_private_key,
)

all_cl_contexts.append(cl_context)
return (all_cl_contexts,)
202 changes: 202 additions & 0 deletions src/cl/op-node/op_node_launcher.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
shared_utils = import_module(
"github.com/kurtosis-tech/ethereum-package/src/shared_utils/shared_utils.star"
)

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

cl_node_ready_conditions = import_module(
"github.com/kurtosis-tech/ethereum-package/src/cl/cl_node_ready_conditions.star"
)
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"
# 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


def get_used_ports(discovery_port):
used_ports = {
BEACON_TCP_DISCOVERY_PORT_ID: shared_utils.new_port_spec(
discovery_port, shared_utils.TCP_PROTOCOL
),
BEACON_UDP_DISCOVERY_PORT_ID: shared_utils.new_port_spec(
discovery_port, shared_utils.UDP_PROTOCOL
),
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


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_sequencer_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_sequencer_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
)

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,
multiaddr=beacon_multiaddr,
peer_id=beacon_peer_id,
)


def get_beacon_config(
plan,
el_cl_genesis_data,
jwt_file,
image,
service_name,
el_context,
existing_cl_clients,
l1_config_env_vars,
gs_sequencer_private_key,
):
EXECUTION_ENGINE_ENDPOINT = el_context.rpc_http_url

discovery_port = BEACON_DISCOVERY_PORT_NUM
used_ports = get_used_ports(discovery_port)

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",
]

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,
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
),
)


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,
)
Loading

0 comments on commit 05b45c2

Please sign in to comment.