Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add magi #40

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/tests/magi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
optimism_package:
chains:
- participants:
- el_type: op-geth
cl_type: op-node
- el_type: op-geth
cl_type: magi
- el_type: op-reth
cl_type: magi
- el_type: op-erigon
cl_type: magi
2 changes: 2 additions & 0 deletions .github/tests/op-erigon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ optimism_package:
- participants:
- el_type: op-erigon
cl_type: op-node
- el_type: op-erigon
cl_type: magi
2 changes: 2 additions & 0 deletions .github/tests/op-geth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ optimism_package:
- participants:
- el_type: op-geth
cl_type: op-node
- el_type: op-geth
cl_type: magi
2 changes: 2 additions & 0 deletions .github/tests/op-reth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ optimism_package:
- participants:
- el_type: op-reth
cl_type: op-node
- el_type: op-reth
cl_type: magi
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ optimism_package:
# Valid values are:
# op-node
# hildr
# magi
cl_type: op-node

# The Docker image that should be used for the CL client; leave blank to use the default for the client type
# Defaults by client:
# - op-node: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-node:develop
# - hildr: ghcr.io/optimism-java/hildr:latest
# - magi: a16zcrypto/magi:latest
cl_image: ""

# Count of nodes to spin up for this participant
Expand Down
195 changes: 195 additions & 0 deletions src/cl/magi/magi_launcher.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
shared_utils = import_module(
"github.com/ethpandaops/ethereum-package/src/shared_utils/shared_utils.star"
)

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

cl_node_ready_conditions = import_module(
"github.com/ethpandaops/ethereum-package/src/cl/cl_node_ready_conditions.star"
)
constants = import_module(
"github.com/ethpandaops/ethereum-package/src/package_io/constants.star"
)

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

# The Docker container runs as the "magi" user so we can't write to root
BEACON_DATA_DIRPATH_ON_SERVICE_CONTAINER = "/data/magi/magi-beacon-data"
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"

# Port nums
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, wait=None
),
BEACON_UDP_DISCOVERY_PORT_ID: shared_utils.new_port_spec(
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,
),
}
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,
sequencer_enabled,
):
# 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,
image,
service_name,
el_context,
existing_cl_clients,
l1_config_env_vars,
# beacon_node_identity_recipe,
sequencer_enabled,
)

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
)

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

return cl_context.new_cl_context(
client_name="magi",
enr="", # beacon_node_enr,
ip_addr=beacon_service.ip_address,
http_port=beacon_http_port.number,
beacon_http_url=beacon_http_url,
beacon_service_name=service_name,
)


def get_beacon_config(
plan,
launcher,
image,
service_name,
el_context,
existing_cl_clients,
l1_config_env_vars,
# beacon_node_identity_recipe,
sequencer_enabled,
):
EXECUTION_ENGINE_ENDPOINT = "http://{0}:{1}".format(
el_context.ip_addr,
el_context.engine_rpc_port_num,
)
EXECUTION_RPC_ENDPOINT = "http://{0}:{1}".format(
el_context.ip_addr,
el_context.rpc_port_num,
)

used_ports = get_used_ports(BEACON_DISCOVERY_PORT_NUM)

cmd = [
"magi",
"--devnet",
"--jwt-file=" + constants.JWT_MOUNT_PATH_ON_CONTAINER,
"--l1-beacon-url={0}".format(l1_config_env_vars["CL_RPC_URL"]),
"--l1-rpc-url={0}".format(l1_config_env_vars["L1_RPC_URL"]),
"--l2-engine-url={0}".format(EXECUTION_ENGINE_ENDPOINT),
"--l2-rpc-url={0}".format(EXECUTION_RPC_ENDPOINT),
"--rpc-addr=0.0.0.0",
"--rpc-port={0}".format(BEACON_HTTP_PORT_NUM),
"--sync-mode=full",
"--network=optimism",
]

# if sequencer_enabled:
# cmd.append("--p2p.sequencer.key=" + gs_sequencer_private_key)
# cmd.append("--sequencer.enabled")
# cmd.append("--sequencer.l1-confs=5")

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

files = {
constants.GENESIS_DATA_MOUNTPOINT_ON_CLIENTS: launcher.deployment_output,
constants.JWT_MOUNTPOINT_ON_CLIENTS: launcher.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=ReadyCondition(
# recipe=beacon_node_identity_recipe,
# field="code",
# assertion="==",
# target_value=200,
# timeout="1m",
# ),
)


def new_magi_launcher(deployment_output, jwt_file, network_params):
return struct(
deployment_output=deployment_output,
jwt_file=jwt_file,
network_params=network_params,
)
7 changes: 7 additions & 0 deletions src/el_cl_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ op_besu = import_module("./el/op-besu/op_besu_launcher.star")
# CL
op_node = import_module("./cl/op-node/op_node_launcher.star")
hildr = import_module("./cl/hildr/hildr_launcher.star")
magi = import_module("./cl/magi/magi_launcher.star")


def launch(
Expand Down Expand Up @@ -86,6 +87,12 @@ def launch(
),
"launch_method": hildr.launch,
},
"magi": {
"launcher": magi.new_magi_launcher(
deployment_output, jwt_file, network_params
),
"launch_method": magi.launch,
},
}

all_cl_contexts = []
Expand Down
1 change: 1 addition & 0 deletions src/package_io/input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DEFAULT_EL_IMAGES = {
DEFAULT_CL_IMAGES = {
"op-node": "us-docker.pkg.dev/oplabs-tools-artifacts/images/op-node:develop",
"hildr": "ghcr.io/optimism-java/hildr:latest",
"magi": "a16zcrypto/magi:master",
}

DEFAULT_BATCHER_IMAGES = {
Expand Down