|
| 1 | +_selectors = import_module("/src/l2/selectors.star") |
| 2 | +_net = import_module("/src/util/net.star") |
| 3 | +_registry = import_module("/src/package_io/registry.star") |
| 4 | + |
| 5 | +_CONFIG_DIRPATH_ON_SERVICE = "/etc/op-conductor-ops" |
| 6 | +_CONFIG_TEMPLATE_FILENAME = "config.toml.tmpl" |
| 7 | +_CONFIG_FILENAME = "config.toml" |
| 8 | + |
| 9 | + |
| 10 | +def launch( |
| 11 | + plan, |
| 12 | + l2_params, |
| 13 | + registry, |
| 14 | +): |
| 15 | + participants_params = _get_participants_params_with_conductors(l2_params) |
| 16 | + if not participants_params: |
| 17 | + plan.print( |
| 18 | + "No conductors found for network {}, skipping op-conductor-ops launch".format( |
| 19 | + l2_params.network_params.name |
| 20 | + ) |
| 21 | + ) |
| 22 | + |
| 23 | + return None |
| 24 | + |
| 25 | + config_artifact = _create_op_conductor_ops_config_artifact( |
| 26 | + plan=plan, |
| 27 | + network_params=l2_params.network_params, |
| 28 | + participants_params=participants_params, |
| 29 | + ) |
| 30 | + |
| 31 | + _run_op_conductor_ops_command( |
| 32 | + plan=plan, |
| 33 | + cmd="bootstrap-cluster {}".format(l2_params.network_params.name), |
| 34 | + config_artifact=config_artifact, |
| 35 | + description="Bootstrap conductors for network {} using op-conductor-ops".format( |
| 36 | + l2_params.network_params.name |
| 37 | + ), |
| 38 | + registry=registry, |
| 39 | + ) |
| 40 | + |
| 41 | + _run_op_conductor_ops_command( |
| 42 | + plan=plan, |
| 43 | + cmd="status {}".format(l2_params.network_params.name), |
| 44 | + config_artifact=config_artifact, |
| 45 | + description="Get status of conductors for network {} using op-conductor-ops".format( |
| 46 | + l2_params.network_params.name |
| 47 | + ), |
| 48 | + registry=registry, |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +def _run_op_conductor_ops_command( |
| 53 | + plan, |
| 54 | + cmd, |
| 55 | + config_artifact, |
| 56 | + description, |
| 57 | + registry, |
| 58 | +): |
| 59 | + plan.run_sh( |
| 60 | + description=description, |
| 61 | + image=registry.get(_registry.OP_CONDUCTOR_OPS), |
| 62 | + files={ |
| 63 | + _CONFIG_DIRPATH_ON_SERVICE: config_artifact, |
| 64 | + }, |
| 65 | + run="./op-conductor-ops {}".format( |
| 66 | + cmd, |
| 67 | + ), |
| 68 | + env_vars={ |
| 69 | + "CONDUCTOR_CONFIG": "{}/{}".format( |
| 70 | + _CONFIG_DIRPATH_ON_SERVICE, _CONFIG_FILENAME |
| 71 | + ), |
| 72 | + }, |
| 73 | + wait=None, |
| 74 | + ) |
| 75 | + |
| 76 | + |
| 77 | +def _get_participants_params_with_conductors(l2_params): |
| 78 | + return [ |
| 79 | + participant_params |
| 80 | + for participant_params in l2_params.participants |
| 81 | + if participant_params.conductor_params |
| 82 | + and _selectors.is_sequencer(participant_params) |
| 83 | + ] |
| 84 | + |
| 85 | + |
| 86 | +def _create_op_conductor_ops_config_artifact(plan, network_params, participants_params): |
| 87 | + config_template = read_file(_CONFIG_TEMPLATE_FILENAME) |
| 88 | + config_data = { |
| 89 | + "network_name": network_params.name, |
| 90 | + "sequencers": { |
| 91 | + participant_params.conductor_params.service_name: { |
| 92 | + "cl_rpc_url": _net.service_url( |
| 93 | + participant_params.cl.service_name, |
| 94 | + participant_params.cl.ports[_net.RPC_PORT_NAME], |
| 95 | + ), |
| 96 | + "conductor_rpc_url": _net.service_url( |
| 97 | + participant_params.conductor_params.service_name, |
| 98 | + participant_params.conductor_params.ports[_net.RPC_PORT_NAME], |
| 99 | + ), |
| 100 | + "conductor_raft_address": "{0}:{1}".format( |
| 101 | + participant_params.conductor_params.service_name, |
| 102 | + participant_params.conductor_params.ports[ |
| 103 | + _net.CONSENSUS_PORT_NAME |
| 104 | + ].number, |
| 105 | + ), |
| 106 | + } |
| 107 | + for participant_params in participants_params |
| 108 | + }, |
| 109 | + } |
| 110 | + |
| 111 | + return plan.render_templates( |
| 112 | + { |
| 113 | + _CONFIG_FILENAME: struct( |
| 114 | + template=config_template, |
| 115 | + data=config_data, |
| 116 | + ), |
| 117 | + }, |
| 118 | + name="op-conductor-ops-config-{0}".format(network_params.network_id), |
| 119 | + ) |
0 commit comments