Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
feat: add resource management (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasbusa authored Jul 25, 2023
1 parent b3de5e4 commit a8240b1
Show file tree
Hide file tree
Showing 18 changed files with 653 additions and 82 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ these and other parameters are configurable through a json file Read more about
// ]
"builder_network_params": null,

// Execution node minimum and maximum CPU (millicpu) and memory (MB) limits
// Defaults are configured per client
"el_min_cpu": 0,
"el_max_cpu": 0,
"el_min_mem": 0,
"el_max_mem": 0,

// Beacon node minimum and maximum CPU (millicpu) and memory (MB) limits
// Defaults are configured per client
"bn_min_cpu": 0,
"bn_max_cpu": 0,
"bn_min_mem": 0,
"bn_max_mem": 0,

// Validator node minimum and maximum CPU (millicpu) and memory (MB) limits
// Defaults are configured per client
"v_min_cpu": 0,
"v_max_cpu": 0,
"v_min_mem": 0,
"v_max_mem": 0,

// The number of times this participant should be repeated
// defaults to 1(i.e no repetition). This is optional.
"count": 1
Expand Down
3 changes: 2 additions & 1 deletion default-network-params.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"deposit_contract_address": "0x4242424242424242424242424242424242424242",
"seconds_per_slot": 12,
"genesis_delay": 120,
"capella_fork_epoch": 5
"capella_fork_epoch": 5,
"deneb_fork_epoch": 500
},
"global_client_log_level": "info"
}
2 changes: 2 additions & 0 deletions package_io/constants.star
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ GLOBAL_CLIENT_LOG_LEVEL = struct(
debug="debug",
trace="trace",
)

VALIDATING_REWARDS_ACCOUNT = "0x878705ba3f8Bc32FCf7F4CAa1A35E72AF65CF766"
27 changes: 26 additions & 1 deletion package_io/input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,20 @@ def parse_input(input_args):
beacon_extra_params=participant["beacon_extra_params"],
el_extra_params=participant["el_extra_params"],
validator_extra_params=participant["validator_extra_params"],
builder_network_params=participant["builder_network_params"]
builder_network_params=participant["builder_network_params"],
el_min_cpu=participant["el_min_cpu"],
el_max_cpu=participant["el_max_cpu"],
el_min_mem=participant["el_min_mem"],
el_max_mem=participant["el_max_mem"],
bn_min_cpu=participant["bn_min_cpu"],
bn_max_cpu=participant["bn_max_cpu"],
bn_min_mem=participant["bn_min_mem"],
bn_max_mem=participant["bn_max_mem"],
v_min_cpu=participant["v_min_cpu"],
v_max_cpu=participant["v_max_cpu"],
v_min_mem=participant["v_min_mem"],
v_max_mem=participant["v_max_mem"],
count=participant["count"]
) for participant in result["participants"]],
network_params=struct(
preregistered_validator_keys_mnemonic=result["network_params"]["preregistered_validator_keys_mnemonic"],
Expand Down Expand Up @@ -184,5 +197,17 @@ def default_participant():
"el_extra_params": [],
"validator_extra_params": [],
"builder_network_params": None,
"el_min_cpu": 0,
"el_max_cpu": 0,
"el_min_mem": 0,
"el_max_mem": 0,
"bn_min_cpu": 0,
"bn_max_cpu": 0,
"bn_min_mem": 0,
"bn_max_mem": 0,
"v_min_cpu": 0,
"v_max_cpu": 0,
"v_min_mem": 0,
"v_max_mem": 0,
"count": 1
}
9 changes: 8 additions & 1 deletion src/cl/cl_client_context.star
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
def new_cl_client_context(client_name, enr, ip_addr, http_port_num, cl_nodes_metrics_info, beacon_service_name, validator_service_name = ""):
def new_cl_client_context(
client_name,
enr,
ip_addr,
http_port_num,
cl_nodes_metrics_info,
beacon_service_name,
validator_service_name = ""):
return struct(
client_name = client_name,
enr = enr,
Expand Down
62 changes: 57 additions & 5 deletions src/cl/lighthouse/lighthouse_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ BEACON_DISCOVERY_PORT_NUM = 9000
BEACON_HTTP_PORT_NUM = 4000
BEACON_METRICS_PORT_NUM = 5054

# ---------------------------------- Validator client -------------------------------------
VALIDATING_REWARDS_ACCOUNT = "0x878705ba3f8Bc32FCf7F4CAa1A35E72AF65CF766"
# The min/max CPU/memory that the beacon node can use
BEACON_MIN_CPU = 50
BEACON_MAX_CPU = 1000
BEACON_MIN_MEMORY = 256
BEACON_MAX_MEMORY = 1024

# ---------------------------------- Validator client -------------------------------------
VALIDATOR_HTTP_PORT_ID = "http"
VALIDATOR_METRICS_PORT_ID = "metrics"
VALIDATOR_HTTP_PORT_NUM = 5042
Expand All @@ -40,6 +44,12 @@ VALIDATOR_HTTP_PORT_WAIT_DISABLED = None
METRICS_PATH = "/metrics"
VALIDATOR_SUFFIX_SERVICE_NAME = "validator"

# The min/max CPU/memory that the validator node can use
VALIDATOR_MIN_CPU = 50
VALIDATOR_MAX_CPU = 300
VALIDATOR_MIN_MEMORY = 128
VALIDATOR_MAX_MEMORY = 512

PRIVATE_IP_ADDRESS_PLACEHOLDER = "KURTOSIS_IP_ADDR_PLACEHOLDER"

BEACON_USED_PORTS = {
Expand Down Expand Up @@ -72,6 +82,14 @@ def launch(
bootnode_context,
el_client_context,
node_keystore_files,
bn_min_cpu,
bn_max_cpu,
bn_min_mem,
bn_max_mem,
v_min_cpu,
v_max_cpu,
v_min_mem,
v_max_mem,
extra_beacon_params,
extra_validator_params):

Expand All @@ -80,13 +98,27 @@ def launch(

log_level = input_parser.get_client_log_level_or_default(participant_log_level, global_log_level, LIGHTHOUSE_LOG_LEVELS)

bn_min_cpu = int(bn_min_cpu) if int(bn_min_cpu) > 0 else BEACON_MIN_CPU
bn_max_cpu = int(bn_max_cpu) if int(bn_max_cpu) > 0 else BEACON_MAX_CPU
bn_min_mem = int(bn_min_mem) if int(bn_min_mem) > 0 else BEACON_MIN_MEMORY
bn_max_mem = int(bn_max_mem) if int(bn_max_mem) > 0 else BEACON_MAX_MEMORY

v_min_cpu = int(v_min_cpu) if int(v_min_cpu) > 0 else VALIDATOR_MIN_CPU
v_max_cpu = int(v_max_cpu) if int(v_max_cpu) > 0 else VALIDATOR_MAX_CPU
v_min_mem = int(v_min_mem) if int(v_min_mem) > 0 else VALIDATOR_MIN_MEMORY
v_max_mem = int(v_max_mem) if int(v_max_mem) > 0 else VALIDATOR_MAX_MEMORY

# Launch Beacon node
beacon_config = get_beacon_config(
launcher.genesis_data,
image,
bootnode_context,
el_client_context,
log_level,
bn_min_cpu,
bn_max_cpu,
bn_min_mem,
bn_max_mem,
extra_beacon_params,
)

Expand All @@ -103,6 +135,10 @@ def launch(
log_level,
beacon_http_url,
node_keystore_files,
v_min_cpu,
v_max_cpu,
v_min_mem,
v_max_mem,
extra_validator_params,
)

Expand Down Expand Up @@ -145,6 +181,10 @@ def get_beacon_config(
boot_cl_client_ctx,
el_client_ctx,
log_level,
bn_min_cpu,
bn_max_cpu,
bn_min_mem,
bn_max_mem,
extra_params):

el_client_engine_rpc_url_str = "http://{0}:{1}".format(
Expand Down Expand Up @@ -188,7 +228,7 @@ def get_beacon_config(
"--disable-packet-filter",
"--execution-endpoints=" + el_client_engine_rpc_url_str,
"--jwt-secrets=" + jwt_secret_filepath,
"--suggested-fee-recipient=" + VALIDATING_REWARDS_ACCOUNT,
"--suggested-fee-recipient=" + package_io.VALIDATING_REWARDS_ACCOUNT,
# Set per Paris' recommendation to reduce noise in the logs
"--subscribe-all-subnets",
# vvvvvvvvvvvvvvvvvvv METRICS CONFIG vvvvvvvvvvvvvvvvvvvvv
Expand Down Expand Up @@ -230,7 +270,11 @@ def get_beacon_config(
RUST_BACKTRACE_ENVVAR_NAME: RUST_FULL_BACKTRACE_KEYWORD
},
private_ip_address_placeholder = PRIVATE_IP_ADDRESS_PLACEHOLDER,
ready_conditions = ready_conditions
ready_conditions = ready_conditions,
min_cpu = bn_min_cpu,
max_cpu = bn_max_cpu,
min_memory = bn_min_mem,
max_memory = bn_max_mem
)


Expand All @@ -240,6 +284,10 @@ def get_validator_config(
log_level,
beacon_client_http_url,
node_keystore_files,
v_min_cpu,
v_max_cpu,
v_min_mem,
v_max_mem,
extra_params):

# For some reason, Lighthouse takes in the parent directory of the config file (rather than the path to the config file itself)
Expand All @@ -264,7 +312,7 @@ def get_validator_config(
"--beacon-nodes=" + beacon_client_http_url,
#"--enable-doppelganger-protection", // Disabled to not have to wait 2 epochs before validator can start
# burn address - If unset, the validator will scream in its logs
"--suggested-fee-recipient="+VALIDATING_REWARDS_ACCOUNT,
"--suggested-fee-recipient="+package_io.VALIDATING_REWARDS_ACCOUNT,
# vvvvvvvvvvvvvvvvvvv PROMETHEUS CONFIG vvvvvvvvvvvvvvvvvvvvv
"--metrics",
"--metrics-address=0.0.0.0",
Expand All @@ -288,6 +336,10 @@ def get_validator_config(
env_vars = {
RUST_BACKTRACE_ENVVAR_NAME: RUST_FULL_BACKTRACE_KEYWORD
},
min_cpu = v_min_cpu,
max_cpu = v_max_cpu,
min_memory = v_min_mem,
max_memory = v_max_mem
)


Expand Down
67 changes: 62 additions & 5 deletions src/cl/lodestar/lodestar_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ cl_node_ready_conditions = import_module("github.com/kurtosis-tech/eth-network-p

package_io = import_module("github.com/kurtosis-tech/eth-network-package/package_io/constants.star")

CONSENSUS_DATA_DIRPATH_ON_SERVICE_CONTAINER = "/consensus-data"
GENESIS_DATA_MOUNT_DIRPATH_ON_SERVICE_CONTAINER = "/genesis"
VALIDATOR_KEYS_MOUNT_DIRPATH_ON_SERVICE_CONTAINER = "/validator-keys"

# ---------------------------------- Beacon client -------------------------------------
CONSENSUS_DATA_DIRPATH_ON_SERVICE_CONTAINER = "/consensus-data"
# Port IDs
TCP_DISCOVERY_PORT_ID = "tcp-discovery"
UDP_DISCOVERY_PORT_ID = "udp-discovery"
Expand All @@ -22,6 +21,20 @@ DISCOVERY_PORT_NUM = 9000
HTTP_PORT_NUM = 4000
METRICS_PORT_NUM = 8008

# The min/max CPU/memory that the beacon node can use
BEACON_MIN_CPU = 50
BEACON_MAX_CPU = 1000
BEACON_MIN_MEMORY = 256
BEACON_MAX_MEMORY = 1024

# ---------------------------------- Validator client -------------------------------------
VALIDATOR_KEYS_MOUNT_DIRPATH_ON_SERVICE_CONTAINER = "/validator-keys"
# The min/max CPU/memory that the validator node can use
VALIDATOR_MIN_CPU = 50
VALIDATOR_MAX_CPU = 300
VALIDATOR_MIN_MEMORY = 128
VALIDATOR_MAX_MEMORY = 512

VALIDATOR_SUFFIX_SERVICE_NAME = "validator"

METRICS_PATH = "/metrics"
Expand Down Expand Up @@ -59,6 +72,14 @@ def launch(
bootnode_context,
el_client_context,
node_keystore_files,
bn_min_cpu,
bn_max_cpu,
bn_min_mem,
bn_max_mem,
v_min_cpu,
v_max_cpu,
v_min_mem,
v_max_mem,
extra_beacon_params,
extra_validator_params):

Expand All @@ -67,13 +88,28 @@ def launch(

log_level = input_parser.get_client_log_level_or_default(participant_log_level, global_log_level, LODESTAR_LOG_LEVELS)

bn_min_cpu = int(bn_min_cpu) if int(bn_min_cpu) > 0 else BEACON_MIN_CPU
bn_max_cpu = int(bn_max_cpu) if int(bn_max_cpu) > 0 else BEACON_MAX_CPU
bn_min_mem = int(bn_min_mem) if int(bn_min_mem) > 0 else BEACON_MIN_MEMORY
bn_max_mem = int(bn_max_mem) if int(bn_max_mem) > 0 else BEACON_MAX_MEMORY

v_min_cpu = int(v_min_cpu) if int(v_min_cpu) > 0 else VALIDATOR_MIN_CPU
v_max_cpu = int(v_max_cpu) if int(v_max_cpu) > 0 else VALIDATOR_MAX_CPU
v_min_mem = int(v_min_mem) if int(v_min_mem) > 0 else VALIDATOR_MIN_MEMORY
v_max_mem = int(v_max_mem) if int(v_max_mem) > 0 else VALIDATOR_MAX_MEMORY


# Launch Beacon node
beacon_config = get_beacon_config(
launcher.cl_genesis_data,
image,
bootnode_context,
el_client_context,
log_level,
bn_min_cpu,
bn_max_cpu,
bn_min_mem,
bn_max_mem,
extra_beacon_params,
)

Expand All @@ -92,6 +128,10 @@ def launch(
log_level,
beacon_http_url,
node_keystore_files,
v_min_cpu,
v_max_cpu,
v_min_mem,
v_max_mem,
extra_validator_params,
)

Expand Down Expand Up @@ -131,6 +171,10 @@ def get_beacon_config(
boot_cl_client_ctx,
el_client_ctx,
log_level,
bn_min_cpu,
bn_max_cpu,
bn_min_mem,
bn_max_mem,
extra_params):

el_client_rpc_url_str = "http://{0}:{1}".format(
Expand Down Expand Up @@ -192,7 +236,11 @@ def get_beacon_config(
GENESIS_DATA_MOUNT_DIRPATH_ON_SERVICE_CONTAINER: genesis_data.files_artifact_uuid
},
private_ip_address_placeholder = PRIVATE_IP_ADDRESS_PLACEHOLDER,
ready_conditions = cl_node_ready_conditions.get_ready_conditions(HTTP_PORT_ID)
ready_conditions = cl_node_ready_conditions.get_ready_conditions(HTTP_PORT_ID),
min_cpu = bn_min_cpu,
max_cpu = bn_max_cpu,
min_memory = bn_min_mem,
max_memory = bn_max_mem
)


Expand All @@ -203,6 +251,10 @@ def get_validator_config(
log_level,
beacon_client_http_url,
node_keystore_files,
v_min_cpu,
v_max_cpu,
v_min_mem,
v_max_mem,
extra_params):

root_dirpath = shared_utils.path_join(CONSENSUS_DATA_DIRPATH_ON_SERVICE_CONTAINER, service_name)
Expand All @@ -219,6 +271,7 @@ def get_validator_config(
"--beaconNodes=" + beacon_client_http_url,
"--keystoresDir=" + validator_keys_dirpath,
"--secretsDir=" + validator_secrets_dirpath,
"--suggestedFeeRecipient=" + package_io.VALIDATING_REWARDS_ACCOUNT,
# vvvvvvvvvvvvvvvvvvv PROMETHEUS CONFIG vvvvvvvvvvvvvvvvvvvvv
"--metrics",
"--metrics.address=0.0.0.0",
Expand All @@ -239,7 +292,11 @@ def get_validator_config(
GENESIS_DATA_MOUNT_DIRPATH_ON_SERVICE_CONTAINER: genesis_data.files_artifact_uuid,
VALIDATOR_KEYS_MOUNT_DIRPATH_ON_SERVICE_CONTAINER: node_keystore_files.files_artifact_uuid,
},
private_ip_address_placeholder = PRIVATE_IP_ADDRESS_PLACEHOLDER
private_ip_address_placeholder = PRIVATE_IP_ADDRESS_PLACEHOLDER,
min_cpu = v_min_cpu,
max_cpu = v_max_cpu,
min_memory = v_min_mem,
max_memory = v_max_mem
)


Expand Down
Loading

0 comments on commit a8240b1

Please sign in to comment.