|
| 1 | +shared_utils = import_module("../shared_utils/shared_utils.star") |
| 2 | +constants = import_module("../package_io/constants.star") |
| 3 | + |
| 4 | +IMAGE_NAME = "ethpandaops/tracoor:0.0.18" |
| 5 | +SERVICE_NAME = "tracoor" |
| 6 | + |
| 7 | +HTTP_PORT_ID = "http" |
| 8 | +HTTP_PORT_NUMBER = 7007 |
| 9 | + |
| 10 | +TRACOOR_CONFIG_FILENAME = "tracoor-config.yaml" |
| 11 | + |
| 12 | +TRACOOR_CONFIG_MOUNT_DIRPATH_ON_SERVICE = "/config" |
| 13 | + |
| 14 | +# The min/max CPU/memory that tracoor can use |
| 15 | +MIN_CPU = 100 |
| 16 | +MAX_CPU = 1000 |
| 17 | +MIN_MEMORY = 128 |
| 18 | +MAX_MEMORY = 2048 |
| 19 | + |
| 20 | +USED_PORTS = { |
| 21 | + HTTP_PORT_ID: shared_utils.new_port_spec( |
| 22 | + HTTP_PORT_NUMBER, |
| 23 | + shared_utils.TCP_PROTOCOL, |
| 24 | + shared_utils.HTTP_APPLICATION_PROTOCOL, |
| 25 | + ) |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +def launch_tracoor( |
| 30 | + plan, |
| 31 | + config_template, |
| 32 | + participant_contexts, |
| 33 | + participant_configs, |
| 34 | + el_cl_data_files_artifact_uuid, |
| 35 | + network_params, |
| 36 | + global_node_selectors, |
| 37 | + final_genesis_timestamp, |
| 38 | +): |
| 39 | + all_client_info = [] |
| 40 | + for index, participant in enumerate(participant_contexts): |
| 41 | + full_name, cl_client, el_client, _ = shared_utils.get_client_names( |
| 42 | + participant, index, participant_contexts, participant_configs |
| 43 | + ) |
| 44 | + |
| 45 | + beacon = new_cl_client_info(cl_client.beacon_http_url, full_name) |
| 46 | + execution = new_el_client_info( |
| 47 | + "http://{0}:{1}".format( |
| 48 | + el_client.ip_addr, |
| 49 | + el_client.rpc_port_num, |
| 50 | + ), |
| 51 | + full_name, |
| 52 | + ) |
| 53 | + |
| 54 | + client_info = { |
| 55 | + "Beacon": beacon, |
| 56 | + "Execution": execution, |
| 57 | + "Network": network_params.network, |
| 58 | + } |
| 59 | + all_client_info.append(client_info) |
| 60 | + plan.print(network_params.network) |
| 61 | + template_data = new_config_template_data( |
| 62 | + HTTP_PORT_NUMBER, |
| 63 | + all_client_info, |
| 64 | + ) |
| 65 | + |
| 66 | + template_and_data = shared_utils.new_template_and_data( |
| 67 | + config_template, template_data |
| 68 | + ) |
| 69 | + template_and_data_by_rel_dest_filepath = {} |
| 70 | + template_and_data_by_rel_dest_filepath[TRACOOR_CONFIG_FILENAME] = template_and_data |
| 71 | + |
| 72 | + config_files_artifact_name = plan.render_templates( |
| 73 | + template_and_data_by_rel_dest_filepath, "tracoor-config" |
| 74 | + ) |
| 75 | + el_cl_data_files_artifact_uuid = el_cl_data_files_artifact_uuid |
| 76 | + config = get_config( |
| 77 | + config_files_artifact_name, |
| 78 | + el_cl_data_files_artifact_uuid, |
| 79 | + network_params, |
| 80 | + global_node_selectors, |
| 81 | + ) |
| 82 | + |
| 83 | + plan.add_service(SERVICE_NAME, config) |
| 84 | + |
| 85 | + |
| 86 | +def get_config( |
| 87 | + config_files_artifact_name, |
| 88 | + el_cl_data_files_artifact_uuid, |
| 89 | + network_params, |
| 90 | + node_selectors, |
| 91 | +): |
| 92 | + config_file_path = shared_utils.path_join( |
| 93 | + TRACOOR_CONFIG_MOUNT_DIRPATH_ON_SERVICE, |
| 94 | + TRACOOR_CONFIG_FILENAME, |
| 95 | + ) |
| 96 | + |
| 97 | + return ServiceConfig( |
| 98 | + image=IMAGE_NAME, |
| 99 | + ports=USED_PORTS, |
| 100 | + files={ |
| 101 | + TRACOOR_CONFIG_MOUNT_DIRPATH_ON_SERVICE: config_files_artifact_name, |
| 102 | + }, |
| 103 | + cmd=[ |
| 104 | + "single", |
| 105 | + "--single-config={0}".format(config_file_path), |
| 106 | + ], |
| 107 | + min_cpu=MIN_CPU, |
| 108 | + max_cpu=MAX_CPU, |
| 109 | + min_memory=MIN_MEMORY, |
| 110 | + max_memory=MAX_MEMORY, |
| 111 | + node_selectors=node_selectors, |
| 112 | + ) |
| 113 | + |
| 114 | + |
| 115 | +def new_config_template_data( |
| 116 | + listen_port_num, |
| 117 | + client_info, |
| 118 | +): |
| 119 | + return { |
| 120 | + "ListenPortNum": listen_port_num, |
| 121 | + "ParticipantClientInfo": client_info, |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | +def new_cl_client_info(beacon_http_url, full_name): |
| 126 | + return { |
| 127 | + "Beacon_HTTP_URL": beacon_http_url, |
| 128 | + "FullName": full_name, |
| 129 | + } |
| 130 | + |
| 131 | + |
| 132 | +def new_el_client_info(execution_http_url, full_name): |
| 133 | + return { |
| 134 | + "Execution_HTTP_URL": execution_http_url, |
| 135 | + "FullName": full_name, |
| 136 | + } |
0 commit comments