Skip to content

Commit

Permalink
refactor: call down to eth-network input parser (#192)
Browse files Browse the repository at this point in the history
Fix #161
  • Loading branch information
leoporoli authored Sep 18, 2023
1 parent 44b34b8 commit 30bd4a2
Showing 1 changed file with 13 additions and 159 deletions.
172 changes: 13 additions & 159 deletions src/package_io/parse_input.star
Original file line number Diff line number Diff line change
@@ -1,117 +1,27 @@
DEFAULT_EL_IMAGES = {
"geth": "ethereum/client-go:latest",
"erigon": "thorax/erigon:devel",
"nethermind": "nethermind/nethermind:latest",
"besu": "hyperledger/besu:develop",
"reth": "ghcr.io/paradigmxyz/reth",
"ethereumjs": "ethpandaops/ethereumjs:master",
}

DEFAULT_CL_IMAGES = {
"lighthouse": "sigp/lighthouse:latest",
"teku": "consensys/teku:latest",
"nimbus": "statusim/nimbus-eth2:multiarch-latest",
"prysm": "prysmaticlabs/prysm-beacon-chain:latest,prysmaticlabs/prysm-validator:latest",
"lodestar": "chainsafe/lodestar:latest",
}

NETHERMIND_NODE_NAME = "nethermind"
NIMBUS_NODE_NAME = "nimbus"

ATTR_TO_BE_SKIPPED_AT_ROOT = ("network_params", "participants", "mev_params")

# MEV Params
FLASHBOTS_MEV_BOOST_PORT = 18550
MEV_BOOST_SERVICE_NAME_PREFIX = "mev-boost-"

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

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

def parse_input(plan, input_args):
result = default_input_args()
result = package_io_parser.parse_input(input_args)

# add default eth2 input params
result["mev_type"] = None
result["mev_params"] = get_default_mev_params()
result["launch_additional_services"] = True


for attr in input_args:
value = input_args[attr]
# if its insterted we use the value inserted
if attr not in ATTR_TO_BE_SKIPPED_AT_ROOT and attr in input_args:
result[attr] = value
elif attr == "network_params":
for sub_attr in input_args["network_params"]:
sub_value = input_args["network_params"][sub_attr]
result["network_params"][sub_attr] = sub_value
elif attr == "mev_params":
# custom eth2 attributes config
if attr == "mev_params":
for sub_attr in input_args["mev_params"]:
sub_value = input_args["mev_params"][sub_attr]
result["mev_params"][sub_attr] = sub_value
elif attr == "participants":
participants = []
for participant in input_args["participants"]:
new_participant = default_participant()
for sub_attr, sub_value in participant.items():
# if the value is set in input we set it in participant
new_participant[sub_attr] = sub_value
participants.append(new_participant)
result["participants"] = participants

total_participant_count = 0
# validation of the above defaults
for index, participant in enumerate(result["participants"]):
el_client_type = participant["el_client_type"]
cl_client_type = participant["cl_client_type"]

if cl_client_type in (NIMBUS_NODE_NAME) and (result["network_params"]["seconds_per_slot"] < 12):
fail("nimbus can't be run with slot times below 12 seconds")

el_image = participant["el_client_image"]
if el_image == "":
default_image = DEFAULT_EL_IMAGES.get(el_client_type, "")
if default_image == "":
fail("{0} received an empty image name and we don't have a default for it".format(el_client_type))
participant["el_client_image"] = default_image

cl_image = participant["cl_client_image"]
if cl_image == "":
default_image = DEFAULT_CL_IMAGES.get(cl_client_type, "")
if default_image == "":
fail("{0} received an empty image name and we don't have a default for it".format(cl_client_type))
participant["cl_client_image"] = default_image

beacon_extra_params = participant.get("beacon_extra_params", [])
participant["beacon_extra_params"] = beacon_extra_params

validator_extra_params = participant.get("validator_extra_params", [])
participant["validator_extra_params"] = validator_extra_params

total_participant_count += participant["count"]

if result["network_params"]["network_id"].strip() == "":
fail("network_id is empty or spaces it needs to be of non zero length")

if result["network_params"]["deposit_contract_address"].strip() == "":
fail("deposit_contract_address is empty or spaces it needs to be of non zero length")

if result["network_params"]["preregistered_validator_keys_mnemonic"].strip() == "":
fail("preregistered_validator_keys_mnemonic is empty or spaces it needs to be of non zero length")

if result["network_params"]["slots_per_epoch"] == 0:
fail("slots_per_epoch is 0 needs to be > 0 ")

if result["network_params"]["seconds_per_slot"] == 0:
fail("seconds_per_slot is 0 needs to be > 0 ")

if result["network_params"]["genesis_delay"] == 0:
fail("genesis_delay is 0 needs to be > 0 ")

if result["network_params"]["deneb_fork_epoch"] == 0:
fail("deneb_fork_epoch is 0 needs to be > 0 ")

if total_participant_count < 1:
total_participant_count = 1

required_num_validators = 2 * result["network_params"]["slots_per_epoch"]
actual_num_validators = total_participant_count * result["network_params"]["num_validator_keys_per_node"]
if required_num_validators > actual_num_validators:
fail("required_num_validators - {0} is greater than actual_num_validators - {1}".format(required_num_validators, actual_num_validators))


if result.get("mev_type") in ("mock", "full"):
result = enrich_mev_extra_params(result, MEV_BOOST_SERVICE_NAME_PREFIX, FLASHBOTS_MEV_BOOST_PORT, result.get("mev_type"))
Expand Down Expand Up @@ -164,61 +74,6 @@ def parse_input(plan, input_args):
mev_type=result["mev_type"],
), result

def get_client_log_level_or_default(participant_log_level, global_log_level, client_log_levels):
log_level = participant_log_level
if log_level == "":
log_level = client_log_levels.get(global_log_level, "")
if log_level == "":
fail("No participant log level defined, and the client log level has no mapping for global log level '{0}'".format(global_log_level))
return log_level

def default_input_args():
network_params = default_network_params()
participants = [default_participant()]
mev_params = get_default_mev_params()
return {
"mev_type": None,
"participants": participants,
"network_params": network_params,
"launch_additional_services": True,
"wait_for_finalization": False,
"wait_for_verifications": False,
"verifications_epoch_limit": 5,
"global_client_log_level": "info",
"mev_params": mev_params,
"snooper_enabled": False,
}

def default_network_params():
# this is temporary till we get params working
return {
"preregistered_validator_keys_mnemonic": "giant issue aisle success illegal bike spike question tent bar rely arctic volcano long crawl hungry vocal artwork sniff fantasy very lucky have athlete",
"num_validator_keys_per_node": 64,
"network_id": "3151908",
"deposit_contract_address": "0x4242424242424242424242424242424242424242",
"seconds_per_slot": 12,
"slots_per_epoch": 32,
"genesis_delay": 120,
"capella_fork_epoch": 0,
"deneb_fork_epoch": 500
}

def default_participant():
# TODO(now) add support for mev boost image and extra parameters
return {
"el_client_type": "geth",
"el_client_image": "",
"el_client_log_level": "",
"cl_client_type": "lighthouse",
"cl_client_image": "",
"cl_client_log_level": "",
"beacon_extra_params": [],
"el_extra_params": [],
"validator_extra_params": [],
"builder_network_params": None,
"count": 1
}

def get_default_mev_params():
return {
"mev_relay_image": "flashbots/mev-boost-relay",
Expand All @@ -236,7 +91,6 @@ def get_default_mev_params():
"launch_custom_flood": False
}


# TODO perhaps clean this up into a map
def enrich_mev_extra_params(parsed_arguments_dict, mev_prefix, mev_port, mev_type):
for index, participant in enumerate(parsed_arguments_dict["participants"]):
Expand Down Expand Up @@ -287,7 +141,7 @@ def enrich_mev_extra_params(parsed_arguments_dict, mev_prefix, mev_port, mev_typ
"--builder.beacon_endpoints=http://cl-{0}-lighthouse-geth:4000".format(num_participants+1),
"--builder.bellatrix_fork_version=0x30000038",
"--builder.genesis_fork_version=0x10000038",
"--builder.genesis_validators_root={0}".format(package_io.GENESIS_VALIDATORS_ROOT_PLACEHOLDER),
"--builder.genesis_validators_root={0}".format(package_io_constants.GENESIS_VALIDATORS_ROOT_PLACEHOLDER),
"--miner.extradata=\"Illuminate Dmocratize Dstribute\"",
"--builder.algotype=greedy"
] + parsed_arguments_dict["mev_params"]["mev_builder_extra_args"],
Expand Down

0 comments on commit 30bd4a2

Please sign in to comment.