Skip to content

Commit

Permalink
feat: rework how keys are generated (#301)
Browse files Browse the repository at this point in the history
Co-authored-by: Gyanendra Mishra <anomaly.the@gmail.com>
  • Loading branch information
barnabasbusa and h4ck3rk3y committed Oct 19, 2023
1 parent 63f7ff3 commit 59f15ca
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 174 deletions.
20 changes: 15 additions & 5 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ genesis_constants = import_module(
"./src/prelaunch_data_generator/genesis_constants/genesis_constants.star"
)

validator_ranges = import_module(
"./src/prelaunch_data_generator/validator_keystores/validator_ranges_generator.star"
)

transaction_spammer = import_module(
"./src/transaction_spammer/transaction_spammer.star"
)
Expand Down Expand Up @@ -98,6 +102,17 @@ def run(plan, args={}):
all_el_client_contexts.append(participant.el_client_context)
all_cl_client_contexts.append(participant.cl_client_context)

# Generate validator ranges
validator_ranges_config_template = read_file(
static_files.VALIDATOR_RANGES_CONFIG_TEMPLATE_FILEPATH
)
ranges = validator_ranges.generate_validator_ranges(
plan,
validator_ranges_config_template,
all_cl_client_contexts,
args_with_right_defaults.participants,
)

if network_params.deneb_fork_epoch != 0:
plan.print("Launching 4788 contract deployer")
el_uri = "http://{0}:{1}".format(
Expand Down Expand Up @@ -277,15 +292,10 @@ def run(plan, args={}):
plan.print("Succesfully launched execution layer forkmon")
elif additional_service == "beacon_metrics_gazer":
plan.print("Launching beacon metrics gazer")
beacon_metrics_gazer_config_template = read_file(
static_files.BEACON_METRICS_GAZER_CONFIG_TEMPLATE_FILEPATH
)
beacon_metrics_gazer_prometheus_metrics_job = (
beacon_metrics_gazer.launch_beacon_metrics_gazer(
plan,
beacon_metrics_gazer_config_template,
all_cl_client_contexts,
args_with_right_defaults.participants,
network_params,
)
)
Expand Down
39 changes: 5 additions & 34 deletions src/beacon_metrics_gazer/beacon_metrics_gazer_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ BEACON_METRICS_GAZER_CONFIG_FILENAME = "validator-ranges.yaml"

BEACON_METRICS_GAZER_CONFIG_MOUNT_DIRPATH_ON_SERVICE = "/config"

VALIDATOR_RANGES_ARTIFACT_NAME = "validator-ranges"

USED_PORTS = {
HTTP_PORT_ID: shared_utils.new_port_spec(
HTTP_PORT_NUMBER,
Expand All @@ -23,39 +25,8 @@ USED_PORTS = {
}


def launch_beacon_metrics_gazer(
plan, config_template, cl_client_contexts, participants, network_params
):
data = []
running_total_validator_count = 0
for index, client in enumerate(cl_client_contexts):
participant = participants[index]
if participant.validator_count == 0:
continue
start_index = running_total_validator_count
running_total_validator_count += participant.validator_count
end_index = start_index + participant.validator_count
service_name = client.beacon_service_name
data.append(
{
"ClientName": service_name,
"Range": "{0}-{1}".format(start_index, end_index),
}
)

template_data = {"Data": data}

template_and_data_by_rel_dest_filepath = {}
template_and_data_by_rel_dest_filepath[
BEACON_METRICS_GAZER_CONFIG_FILENAME
] = shared_utils.new_template_and_data(config_template, template_data)

config_files_artifact_name = plan.render_templates(
template_and_data_by_rel_dest_filepath, "validator-ranges"
)

def launch_beacon_metrics_gazer(plan, cl_client_contexts, network_params):
config = get_config(
config_files_artifact_name,
cl_client_contexts[0].ip_addr,
cl_client_contexts[0].http_port_num,
)
Expand All @@ -74,7 +45,7 @@ def launch_beacon_metrics_gazer(
)


def get_config(config_files_artifact_name, ip_addr, http_port_num):
def get_config(ip_addr, http_port_num):
config_file_path = shared_utils.path_join(
BEACON_METRICS_GAZER_CONFIG_MOUNT_DIRPATH_ON_SERVICE,
BEACON_METRICS_GAZER_CONFIG_FILENAME,
Expand All @@ -83,7 +54,7 @@ def get_config(config_files_artifact_name, ip_addr, http_port_num):
image=IMAGE_NAME,
ports=USED_PORTS,
files={
BEACON_METRICS_GAZER_CONFIG_MOUNT_DIRPATH_ON_SERVICE: config_files_artifact_name,
BEACON_METRICS_GAZER_CONFIG_MOUNT_DIRPATH_ON_SERVICE: VALIDATOR_RANGES_ARTIFACT_NAME,
},
cmd=[
"http://{0}:{1}".format(ip_addr, http_port_num),
Expand Down
39 changes: 13 additions & 26 deletions src/participant_network.star
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
cl_validator_keystores = import_module(
"./prelaunch_data_generator/cl_validator_keystores/cl_validator_keystore_generator.star"
validator_keystores = import_module(
"./prelaunch_data_generator/validator_keystores/validator_keystore_generator.star"
)

el_cl_genesis_data_generator = import_module(
"./prelaunch_data_generator/el_cl_genesis/el_cl_genesis_generator.star"
)
shared_utils = import_module("./shared_utils/shared_utils.star")

static_files = import_module("./static_files/static_files.star")

Expand Down Expand Up @@ -45,10 +46,6 @@ CL_NODE_STARTUP_TIME = 5

CL_CLIENT_CONTEXT_BOOTNODE = None

GLOBAL_INDEX_ZFILL = {
"zfill_values": [(1, 1), (2, 10), (3, 100), (4, 1000), (5, 10000)]
}


def launch_participant_network(
plan,
Expand All @@ -60,19 +57,17 @@ def launch_participant_network(
num_participants = len(participants)

plan.print("Generating cl validator key stores")
cl_validator_data = None
validator_data = None
if not parallel_keystore_generation:
cl_validator_data = cl_validator_keystores.generate_cl_validator_keystores(
validator_data = validator_keystores.generate_validator_keystores(
plan, network_params.preregistered_validator_keys_mnemonic, participants
)
else:
cl_validator_data = (
cl_validator_keystores.generate_cl_valdiator_keystores_in_parallel(
plan, network_params.preregistered_validator_keys_mnemonic, participants
)
validator_data = validator_keystores.generate_valdiator_keystores_in_parallel(
plan, network_params.preregistered_validator_keys_mnemonic, participants
)

plan.print(json.indent(json.encode(cl_validator_data)))
plan.print(json.indent(json.encode(validator_data)))

# We need to send the same genesis time to both the EL and the CL to ensure that timestamp based forking works as expected
final_genesis_timestamp = get_final_genesis_timestamp(
Expand Down Expand Up @@ -184,7 +179,7 @@ def launch_participant_network(
)

# Zero-pad the index using the calculated zfill value
index_str = zfill_custom(index + 1, zfill_calculator(participants))
index_str = shared_utils.zfill_custom(index + 1, len(str(len(participants))))

el_service_name = "el-{0}-{1}-{2}".format(
index_str, el_client_type, cl_client_type
Expand Down Expand Up @@ -228,8 +223,8 @@ def launch_participant_network(
package_io.CL_CLIENT_TYPE.prysm: {
"launcher": prysm.new_prysm_launcher(
el_cl_data,
cl_validator_data.prysm_password_relative_filepath,
cl_validator_data.prysm_password_artifact_uuid,
validator_data.prysm_password_relative_filepath,
validator_data.prysm_password_artifact_uuid,
),
"launch_method": prysm.launch,
},
Expand All @@ -241,7 +236,7 @@ def launch_participant_network(

all_snooper_engine_contexts = []
all_cl_client_contexts = []
preregistered_validator_keys_for_nodes = cl_validator_data.per_node_keystores
preregistered_validator_keys_for_nodes = validator_data.per_node_keystores

for index, participant in enumerate(participants):
cl_client_type = participant.cl_client_type
Expand All @@ -259,7 +254,7 @@ def launch_participant_network(
cl_launchers[cl_client_type]["launch_method"],
)

index_str = zfill_custom(index + 1, zfill_calculator(participants))
index_str = shared_utils.zfill_custom(index + 1, len(str(len(participants))))

cl_service_name = "cl-{0}-{1}-{2}".format(
index_str, cl_client_type, el_client_type
Expand Down Expand Up @@ -376,14 +371,6 @@ def launch_participant_network(
)


def zfill_calculator(participants):
for zf, par in GLOBAL_INDEX_ZFILL["zfill_values"]:
if len(participants) < par:
zfill = zf - 1
return zfill
break


def zfill_custom(value, width):
return ("0" * (width - len(str(value)))) + str(value)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
shared_utils = import_module("../../shared_utils/shared_utils.star")

prelaunch_data_generator_launcher = import_module(
"../../prelaunch_data_generator/prelaunch_data_generator_launcher/prelaunch_data_generator_launcher.star"
)

el_cl_genesis_data = import_module("./el_cl_genesis_data.star")

GENESIS_VALUES_PATH = "/opt"
Expand Down

This file was deleted.

Loading

0 comments on commit 59f15ca

Please sign in to comment.