|
| 1 | +shared_utils = import_module("../shared_utils/shared_utils.star") |
| 2 | +constants = import_module("../package_io/constants.star") |
| 3 | +SERVICE_NAME = "forky" |
| 4 | + |
| 5 | +HTTP_PORT_ID = "http" |
| 6 | +HTTP_PORT_NUMBER = 8080 |
| 7 | + |
| 8 | +FORKY_CONFIG_FILENAME = "forky-config.yaml" |
| 9 | + |
| 10 | +FORKY_CONFIG_MOUNT_DIRPATH_ON_SERVICE = "/config" |
| 11 | + |
| 12 | +VALIDATOR_RANGES_MOUNT_DIRPATH_ON_SERVICE = "/validator-ranges" |
| 13 | +VALIDATOR_RANGES_ARTIFACT_NAME = "validator-ranges" |
| 14 | + |
| 15 | +# The min/max CPU/memory that forky can use |
| 16 | +MIN_CPU = 100 |
| 17 | +MAX_CPU = 1000 |
| 18 | +MIN_MEMORY = 128 |
| 19 | +MAX_MEMORY = 2048 |
| 20 | + |
| 21 | +USED_PORTS = { |
| 22 | + HTTP_PORT_ID: shared_utils.new_port_spec( |
| 23 | + HTTP_PORT_NUMBER, |
| 24 | + shared_utils.TCP_PROTOCOL, |
| 25 | + shared_utils.HTTP_APPLICATION_PROTOCOL, |
| 26 | + ) |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +def launch_forky( |
| 31 | + plan, |
| 32 | + config_template, |
| 33 | + participant_contexts, |
| 34 | + participant_configs, |
| 35 | + el_cl_data_files_artifact_uuid, |
| 36 | + network_params, |
| 37 | + global_node_selectors, |
| 38 | + final_genesis_timestamp, |
| 39 | +): |
| 40 | + all_cl_client_info = [] |
| 41 | + all_el_client_info = [] |
| 42 | + for index, participant in enumerate(participant_contexts): |
| 43 | + full_name, cl_client, el_client, _ = shared_utils.get_client_names( |
| 44 | + participant, index, participant_contexts, participant_configs |
| 45 | + ) |
| 46 | + all_cl_client_info.append( |
| 47 | + new_cl_client_info( |
| 48 | + cl_client.beacon_http_url, |
| 49 | + full_name, |
| 50 | + ) |
| 51 | + ) |
| 52 | + all_el_client_info.append( |
| 53 | + new_el_client_info( |
| 54 | + "http://{0}:{1}".format( |
| 55 | + el_client.ip_addr, |
| 56 | + el_client.rpc_port_num, |
| 57 | + ), |
| 58 | + full_name, |
| 59 | + ) |
| 60 | + ) |
| 61 | + |
| 62 | + template_data = new_config_template_data( |
| 63 | + network_params.network, |
| 64 | + network_params.seconds_per_slot, |
| 65 | + final_genesis_timestamp, |
| 66 | + network_params.preset, |
| 67 | + HTTP_PORT_NUMBER, |
| 68 | + all_cl_client_info, |
| 69 | + all_el_client_info, |
| 70 | + ) |
| 71 | + |
| 72 | + template_and_data = shared_utils.new_template_and_data( |
| 73 | + config_template, template_data |
| 74 | + ) |
| 75 | + template_and_data_by_rel_dest_filepath = {} |
| 76 | + template_and_data_by_rel_dest_filepath[FORKY_CONFIG_FILENAME] = template_and_data |
| 77 | + |
| 78 | + config_files_artifact_name = plan.render_templates( |
| 79 | + template_and_data_by_rel_dest_filepath, "forky-config" |
| 80 | + ) |
| 81 | + el_cl_data_files_artifact_uuid = el_cl_data_files_artifact_uuid |
| 82 | + config = get_config( |
| 83 | + config_files_artifact_name, |
| 84 | + el_cl_data_files_artifact_uuid, |
| 85 | + network_params, |
| 86 | + global_node_selectors, |
| 87 | + ) |
| 88 | + |
| 89 | + plan.add_service(SERVICE_NAME, config) |
| 90 | + |
| 91 | + |
| 92 | +def get_config( |
| 93 | + config_files_artifact_name, |
| 94 | + el_cl_data_files_artifact_uuid, |
| 95 | + network_params, |
| 96 | + node_selectors, |
| 97 | +): |
| 98 | + config_file_path = shared_utils.path_join( |
| 99 | + FORKY_CONFIG_MOUNT_DIRPATH_ON_SERVICE, |
| 100 | + FORKY_CONFIG_FILENAME, |
| 101 | + ) |
| 102 | + |
| 103 | + IMAGE_NAME = "ethpandaops/forky:latest" |
| 104 | + |
| 105 | + return ServiceConfig( |
| 106 | + image=IMAGE_NAME, |
| 107 | + ports=USED_PORTS, |
| 108 | + files={ |
| 109 | + FORKY_CONFIG_MOUNT_DIRPATH_ON_SERVICE: config_files_artifact_name, |
| 110 | + VALIDATOR_RANGES_MOUNT_DIRPATH_ON_SERVICE: VALIDATOR_RANGES_ARTIFACT_NAME, |
| 111 | + constants.GENESIS_DATA_MOUNTPOINT_ON_CLIENTS: el_cl_data_files_artifact_uuid, |
| 112 | + }, |
| 113 | + cmd=["--config", config_file_path], |
| 114 | + min_cpu=MIN_CPU, |
| 115 | + max_cpu=MAX_CPU, |
| 116 | + min_memory=MIN_MEMORY, |
| 117 | + max_memory=MAX_MEMORY, |
| 118 | + node_selectors=node_selectors, |
| 119 | + ) |
| 120 | + |
| 121 | + |
| 122 | +def new_config_template_data( |
| 123 | + network, |
| 124 | + seconds_per_slot, |
| 125 | + final_genesis_timestamp, |
| 126 | + preset, |
| 127 | + listen_port_num, |
| 128 | + cl_client_info, |
| 129 | + el_client_info, |
| 130 | +): |
| 131 | + return { |
| 132 | + "Network": network, |
| 133 | + "SecondsPerSlot": seconds_per_slot, |
| 134 | + "FinalGenesisTimestamp": final_genesis_timestamp, |
| 135 | + "Preset": preset, |
| 136 | + "ListenPortNum": listen_port_num, |
| 137 | + "CLClientInfo": cl_client_info, |
| 138 | + "ELClientInfo": el_client_info, |
| 139 | + "PublicNetwork": True if network in constants.PUBLIC_NETWORKS else False, |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | +def new_cl_client_info(beacon_http_url, full_name): |
| 144 | + return { |
| 145 | + "Beacon_HTTP_URL": beacon_http_url, |
| 146 | + "FullName": full_name, |
| 147 | + } |
| 148 | + |
| 149 | + |
| 150 | +def new_el_client_info(execution_http_url, full_name): |
| 151 | + return { |
| 152 | + "Execution_HTTP_URL": execution_http_url, |
| 153 | + "FullName": full_name, |
| 154 | + } |
0 commit comments