From f8baf760fcaab5810894b45378690e45240089bf Mon Sep 17 00:00:00 2001 From: Barnabas Busa Date: Fri, 9 Aug 2024 13:21:09 +0200 Subject: [PATCH 1/5] feat: add op-besu --- .github/tests/op-besu.yaml | 4 + README.md | 2 + src/el/op-besu/op_besu_launcher.star | 229 +++++++++++++++++++++++++++ src/el_cl_launcher.star | 10 ++ src/package_io/input_parser.star | 1 + 5 files changed, 246 insertions(+) create mode 100644 .github/tests/op-besu.yaml create mode 100644 src/el/op-besu/op_besu_launcher.star diff --git a/.github/tests/op-besu.yaml b/.github/tests/op-besu.yaml new file mode 100644 index 00000000..da0d16c5 --- /dev/null +++ b/.github/tests/op-besu.yaml @@ -0,0 +1,4 @@ +optimism_package: + participants: + - el_type: op-besu + cl_type: op-node diff --git a/README.md b/README.md index 7b9b2cf3..308b26a2 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ optimism_package: # op-reth # op-erigon # op-nethermind + # op-besu - el_type: geth # The Docker image that should be used for the EL client; leave blank to use the default for the client type @@ -59,6 +60,7 @@ optimism_package: # - op-reth: parithoshj/op-reth:latest # - op-erigon: testinprod/op-erigon:latest # - op-nethermind: nethermindeth/nethermind:op-c482d56 + # - op-besu: ghcr.io/optimism-java/op-besu:latest el_image: "" # CL(Consensus Layer) Specific flags diff --git a/src/el/op-besu/op_besu_launcher.star b/src/el/op-besu/op_besu_launcher.star new file mode 100644 index 00000000..71a9646c --- /dev/null +++ b/src/el/op-besu/op_besu_launcher.star @@ -0,0 +1,229 @@ +shared_utils = import_module( + "github.com/ethpandaops/ethereum-package/src/shared_utils/shared_utils.star" +) + +el_context = import_module( + "github.com/ethpandaops/ethereum-package/src/el/el_context.star" +) +el_admin_node_info = import_module( + "github.com/ethpandaops/ethereum-package/src/el/el_admin_node_info.star" +) + +node_metrics = import_module( + "github.com/ethpandaops/ethereum-package/src/node_metrics_info.star" +) +constants = import_module( + "github.com/ethpandaops/ethereum-package/src/package_io/constants.star" +) + +RPC_PORT_NUM = 8545 +WS_PORT_NUM = 8546 +DISCOVERY_PORT_NUM = 30303 +ENGINE_RPC_PORT_NUM = 8551 +METRICS_PORT_NUM = 9001 + +# The min/max CPU/memory that the execution node can use +EXECUTION_MIN_CPU = 300 +EXECUTION_MIN_MEMORY = 512 + +# Port IDs +RPC_PORT_ID = "rpc" +WS_PORT_ID = "ws" +TCP_DISCOVERY_PORT_ID = "tcp-discovery" +UDP_DISCOVERY_PORT_ID = "udp-discovery" +ENGINE_RPC_PORT_ID = "engine-rpc" +ENGINE_WS_PORT_ID = "engineWs" +METRICS_PORT_ID = "metrics" + +# TODO(old) Scale this dynamically based on CPUs available and Geth nodes mining +NUM_MINING_THREADS = 1 + +METRICS_PATH = "/debug/metrics/prometheus" + +# The dirpath of the execution data directory on the client container +EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER = "/data/besu/execution-data" + + +def get_used_ports(discovery_port=DISCOVERY_PORT_NUM): + used_ports = { + RPC_PORT_ID: shared_utils.new_port_spec( + RPC_PORT_NUM, + shared_utils.TCP_PROTOCOL, + shared_utils.HTTP_APPLICATION_PROTOCOL, + ), + WS_PORT_ID: shared_utils.new_port_spec(WS_PORT_NUM, shared_utils.TCP_PROTOCOL), + TCP_DISCOVERY_PORT_ID: shared_utils.new_port_spec( + discovery_port, shared_utils.TCP_PROTOCOL + ), + UDP_DISCOVERY_PORT_ID: shared_utils.new_port_spec( + discovery_port, shared_utils.UDP_PROTOCOL + ), + ENGINE_RPC_PORT_ID: shared_utils.new_port_spec( + ENGINE_RPC_PORT_NUM, + shared_utils.TCP_PROTOCOL, + ), + METRICS_PORT_ID: shared_utils.new_port_spec( + METRICS_PORT_NUM, shared_utils.TCP_PROTOCOL + ), + } + return used_ports + + +ENTRYPOINT_ARGS = ["sh", "-c"] + +VERBOSITY_LEVELS = { + constants.GLOBAL_LOG_LEVEL.error: "1", + constants.GLOBAL_LOG_LEVEL.warn: "2", + constants.GLOBAL_LOG_LEVEL.info: "3", + constants.GLOBAL_LOG_LEVEL.debug: "4", + constants.GLOBAL_LOG_LEVEL.trace: "5", +} + +BUILDER_IMAGE_STR = "builder" +SUAVE_ENABLED_GETH_IMAGE_STR = "suave" + + +def launch( + plan, + launcher, + service_name, + image, + existing_el_clients, + sequencer_enabled, + sequencer_context, +): + network_name = shared_utils.get_network_name(launcher.network) + + config = get_config( + plan, + launcher.el_cl_genesis_data, + launcher.jwt_file, + launcher.network, + launcher.network_id, + image, + service_name, + existing_el_clients, + sequencer_enabled, + sequencer_context, + ) + + service = plan.add_service(service_name, config) + + enode, enr = el_admin_node_info.get_enode_enr_for_node( + plan, service_name, RPC_PORT_ID + ) + + metrics_url = "{0}:{1}".format(service.ip_address, METRICS_PORT_NUM) + besu_metrics_info = node_metrics.new_node_metrics_info( + service_name, METRICS_PATH, metrics_url + ) + + http_url = "http://{0}:{1}".format(service.ip_address, RPC_PORT_NUM) + + return el_context.new_el_context( + "op-besu", + enr, + enode, + service.ip_address, + RPC_PORT_NUM, + WS_PORT_NUM, + ENGINE_RPC_PORT_NUM, + http_url, + service_name, + [besu_metrics_info], + ) + + +def get_config( + plan, + el_cl_genesis_data, + jwt_file, + network, + network_id, + image, + service_name, + existing_el_clients, + sequencer_enabled, + sequencer_context, +): + discovery_port = DISCOVERY_PORT_NUM + used_ports = get_used_ports(discovery_port) + + cmd = [ + "besu", + "--genesis-file=" + + constants.GENESIS_CONFIG_MOUNT_PATH_ON_CONTAINER + + "/genesis.json", + "--network-id={0}".format(network_id), + # "--logging=" + log_level, + "--data-path=" + EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER, + "--host-allowlist=*", + "--rpc-http-enabled=true", + "--rpc-http-host=0.0.0.0", + "--rpc-http-port={0}".format(RPC_PORT_NUM), + "--rpc-http-api=ADMIN,CLIQUE,ETH,NET,DEBUG,TXPOOL,ENGINE,TRACE,WEB3", + "--rpc-http-cors-origins=*", + "--rpc-http-max-active-connections=300", + "--rpc-ws-enabled=true", + "--rpc-ws-host=0.0.0.0", + "--rpc-ws-port={0}".format(WS_PORT_NUM), + "--rpc-ws-api=ADMIN,CLIQUE,ETH,NET,DEBUG,TXPOOL,ENGINE,TRACE,WEB3", + "--p2p-enabled=true", + "--p2p-host=" + constants.PRIVATE_IP_ADDRESS_PLACEHOLDER, + "--p2p-port={0}".format(discovery_port), + "--engine-rpc-enabled=true", + "--engine-jwt-secret=" + constants.JWT_MOUNT_PATH_ON_CONTAINER, + "--engine-host-allowlist=*", + "--engine-rpc-port={0}".format(ENGINE_RPC_PORT_NUM), + "--sync-mode=FULL", + "--metrics-enabled=true", + "--metrics-host=0.0.0.0", + "--metrics-port={0}".format(METRICS_PORT_NUM), + "--bonsai-limit-trie-logs-enabled=false", + ] + + if not sequencer_enabled: + cmd.append( + "--rollup.sequencerhttp={0}".format(sequencer_context.beacon_http_url) + ) + + if len(existing_el_clients) > 0: + cmd.append( + "--bootnodes=" + + ",".join( + [ + ctx.enode + for ctx in existing_el_clients[: constants.MAX_ENODE_ENTRIES] + ] + ) + ) + + cmd_str = " ".join(cmd) + + files = { + constants.GENESIS_DATA_MOUNTPOINT_ON_CLIENTS: el_cl_genesis_data, + constants.JWT_MOUNTPOINT_ON_CLIENTS: jwt_file, + } + + return ServiceConfig( + image=image, + ports=used_ports, + cmd=[cmd_str], + files=files, + entrypoint=ENTRYPOINT_ARGS, + private_ip_address_placeholder=constants.PRIVATE_IP_ADDRESS_PLACEHOLDER, + ) + + +def new_op_besu_launcher( + el_cl_genesis_data, + jwt_file, + network, + network_id, +): + return struct( + el_cl_genesis_data=el_cl_genesis_data, + jwt_file=jwt_file, + network=network, + network_id=network_id, + ) diff --git a/src/el_cl_launcher.star b/src/el_cl_launcher.star index d04f13e3..88ede090 100644 --- a/src/el_cl_launcher.star +++ b/src/el_cl_launcher.star @@ -9,6 +9,7 @@ op_geth = import_module("./el/op-geth/op_geth_launcher.star") op_reth = import_module("./el/op-reth/op_reth_launcher.star") op_erigon = import_module("./el/op-erigon/op_erigon_launcher.star") op_nethermind = import_module("./el/op-nethermind/op_nethermind_launcher.star") +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") @@ -62,6 +63,15 @@ def launch( ), "launch_method": op_nethermind.launch, }, + "op-besu": { + "launcher": op_besu.new_op_besu_launcher( + el_cl_data, + jwt_file, + network_params.network, + network_params.network_id, + ), + "launch_method": op_besu.launch, + }, } cl_launchers = { diff --git a/src/package_io/input_parser.star b/src/package_io/input_parser.star index c8a062f9..afd258c3 100644 --- a/src/package_io/input_parser.star +++ b/src/package_io/input_parser.star @@ -9,6 +9,7 @@ DEFAULT_EL_IMAGES = { "op-reth": "parithoshj/op-reth:latest", "op-erigon": "testinprod/op-erigon:latest", "op-nethermind": "nethermindeth/nethermind:op-c482d56", + "op-besu": "ghcr.io/optimism-java/op-besu:latest", } DEFAULT_CL_IMAGES = { From bd89045cac15a580018ddf34163e92ef1ee829c7 Mon Sep 17 00:00:00 2001 From: Barnabas Busa Date: Sat, 17 Aug 2024 14:57:21 +0200 Subject: [PATCH 2/5] Update op_besu_launcher.star --- src/el/op-besu/op_besu_launcher.star | 1 + 1 file changed, 1 insertion(+) diff --git a/src/el/op-besu/op_besu_launcher.star b/src/el/op-besu/op_besu_launcher.star index 71a9646c..24eaeca3 100644 --- a/src/el/op-besu/op_besu_launcher.star +++ b/src/el/op-besu/op_besu_launcher.star @@ -180,6 +180,7 @@ def get_config( "--metrics-host=0.0.0.0", "--metrics-port={0}".format(METRICS_PORT_NUM), "--bonsai-limit-trie-logs-enabled=false", + "--version-compatibility-protection=false", ] if not sequencer_enabled: From 14d2f4d2f50d0d33e3e09e98598ad6a3a8afeb2a Mon Sep 17 00:00:00 2001 From: Barnabas Busa Date: Thu, 22 Aug 2024 13:46:08 +0200 Subject: [PATCH 3/5] add besu --- network_params.yaml | 1 + src/el/op-besu/op_besu_launcher.star | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/network_params.yaml b/network_params.yaml index 8f88ec82..90c67b8c 100644 --- a/network_params.yaml +++ b/network_params.yaml @@ -4,5 +4,6 @@ optimism_package: - el_type: op-reth - el_type: op-erigon - el_type: op-nethermind + - el_type: op-besu additional_services: - blockscout diff --git a/src/el/op-besu/op_besu_launcher.star b/src/el/op-besu/op_besu_launcher.star index 24eaeca3..69c0e6dc 100644 --- a/src/el/op-besu/op_besu_launcher.star +++ b/src/el/op-besu/op_besu_launcher.star @@ -183,10 +183,10 @@ def get_config( "--version-compatibility-protection=false", ] - if not sequencer_enabled: - cmd.append( - "--rollup.sequencerhttp={0}".format(sequencer_context.beacon_http_url) - ) + # if not sequencer_enabled: + # cmd.append( + # "--rollup.sequencerhttp={0}".format(sequencer_context.beacon_http_url) + # ) if len(existing_el_clients) > 0: cmd.append( From 10bb5b9cc36badc8fa21d52e043d1170214e211b Mon Sep 17 00:00:00 2001 From: Barnabas Busa Date: Mon, 26 Aug 2024 13:51:39 +0200 Subject: [PATCH 4/5] fix besu --- src/el/op-besu/op_besu_launcher.star | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/el/op-besu/op_besu_launcher.star b/src/el/op-besu/op_besu_launcher.star index 69c0e6dc..d1109cb9 100644 --- a/src/el/op-besu/op_besu_launcher.star +++ b/src/el/op-besu/op_besu_launcher.star @@ -109,7 +109,7 @@ def launch( service = plan.add_service(service_name, config) - enode, enr = el_admin_node_info.get_enode_enr_for_node( + enode = el_admin_node_info.get_enode_for_node( plan, service_name, RPC_PORT_ID ) @@ -122,7 +122,7 @@ def launch( return el_context.new_el_context( "op-besu", - enr, + "", # besu has no ENR enode, service.ip_address, RPC_PORT_NUM, @@ -213,6 +213,7 @@ def get_config( files=files, entrypoint=ENTRYPOINT_ARGS, private_ip_address_placeholder=constants.PRIVATE_IP_ADDRESS_PLACEHOLDER, + user=User(uid=0, gid=0), ) From 1995e097a4dbd155ee04c1d0a06be94f24ad648b Mon Sep 17 00:00:00 2001 From: Barnabas Busa Date: Mon, 26 Aug 2024 13:53:13 +0200 Subject: [PATCH 5/5] fix linter --- src/el/op-besu/op_besu_launcher.star | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/el/op-besu/op_besu_launcher.star b/src/el/op-besu/op_besu_launcher.star index d1109cb9..f51f57b2 100644 --- a/src/el/op-besu/op_besu_launcher.star +++ b/src/el/op-besu/op_besu_launcher.star @@ -109,9 +109,7 @@ def launch( service = plan.add_service(service_name, config) - enode = el_admin_node_info.get_enode_for_node( - plan, service_name, RPC_PORT_ID - ) + enode = el_admin_node_info.get_enode_for_node(plan, service_name, RPC_PORT_ID) metrics_url = "{0}:{1}".format(service.ip_address, METRICS_PORT_NUM) besu_metrics_info = node_metrics.new_node_metrics_info( @@ -122,7 +120,7 @@ def launch( return el_context.new_el_context( "op-besu", - "", # besu has no ENR + "", # besu has no ENR enode, service.ip_address, RPC_PORT_NUM,