Commit 3fa46b96 authored by Gyanendra Mishra's avatar Gyanendra Mishra

this seems cleaner

parent 4dd2ab9d
......@@ -10,7 +10,7 @@ def main(input_args):
network_params = input_args_with_right_defaults.network_params
print("Launching participant network with {0} participants and the following network params {1}".format(num_participants, network_params))
launch_participant_network(num_participants, network_params)
# TODO replace with actual values
#TODO replace with actual values
grafana_info = module_io.GrafanaInfo({
"dashboard_path": "dummy_path",
"user": "user",
......
......@@ -16,42 +16,31 @@ DEFAULT_CL_IMAGES = {
BESU_NODE_NAME = "besu"
NETHERMIND_NODE_NAME = "nethermind"
LAUNCH_ADDITIONAL_ATTR = "launch_additional_services"
DESCRIPTOR_ATTR_NAME = "descriptor"
ATTR_TO_BE_SKIPPED_AT_ROOT = ("network_params", "participants", DESCRIPTOR_ATTR_NAME)
ENUM_TYPE = "proto.EnumValueDescriptor"
def parse_input(input_args):
default_input = default_module_input()
result = {}
for attr in dir(input_args):
value = getattr(input_args, attr)
print(value, type(value), attr, type(attr))
# this is a builtin attribute we don't care about
if attr == "descriptor":
continue
# if there's an optional that exists don't change anything just move on
elif attr == LAUNCH_ADDITIONAL_ATTR:
if proto.has(input_args, LAUNCH_ADDITIONAL_ATTR):
result[attr] = value
else:
result[attr] = default_input[attr]
elif type(value) == "bool" and value == False:
result[attr] = default_input[attr]
elif type(value) == "int" and value == 0:
result[attr] = default_input[attr]
elif type(value) == "string" and value == "":
# if its insterted we use the value inserted
if attr not in ATTR_TO_BE_SKIPPED_AT_ROOT and proto.has(input_args, attr):
result[attr] = get_value_or_name(value)
# if not we grab the value from the default value dictionary
elif attr not in ATTR_TO_BE_SKIPPED_AT_ROOT:
result[attr] = default_input[attr]
elif attr == "network_params":
result["network_params"] = {}
for attr_ in dir(input_args.network_params):
value_ = getattr(input_args.network_params, attr_)
if type(value_) == "int" and value_ == 0:
result["network_params"][attr_] = default_input["network_params"][attr_]
elif type(value_) == "string" and value_ == "":
result["network_params"][attr_] = default_input["network_params"][attr_]
# if there are some string, int values we assign it
elif type(value_) in ("int", "string", "bool"):
result["network_params"][attr_] = value_
elif type(value) in "proto.EnumValueDescriptor":
result[attr] = value.name
for sub_attr in dir(input_args.network_params):
sub_value = getattr(input_args.network_params, sub_attr)
# if its insterted we use the value inserted
if sub_attr not in (DESCRIPTOR_ATTR_NAME) and proto.has(input_args.network_params, sub_attr):
result["network_params"][sub_attr] = get_value_or_name(sub_value)
# if not we grab the value from the default value dictionary
elif sub_attr not in (DESCRIPTOR_ATTR_NAME):
result["network_params"][sub_attr] = default_input["network_params"][sub_attr]
# no participants are assigned at all
elif attr == "participants" and len(value) == 0:
result["participants"] = default_input["participants"]
......@@ -59,26 +48,20 @@ def parse_input(input_args):
participants = []
for participant in input_args.participants:
participant_value = {}
for attr_ in dir(participant):
value_ = getattr(participant, attr_)
if type(attr_) == "int" and value_ == 0:
participant_value[attr_] = getattr(default_input[participants][0], attr_, 0)
elif type(attr_) == "str" and value_ == "":
participant_value[attr_] = getattr(default_input[participants][0], attr_, "")
elif type(value_) in ("int", "string", "bool"):
result["participants"][attr_] = value_
elif type(value_) in "proto.EnumValueDescriptor":
participant_value[attr_] = value.name
for sub_attr in dir(participant):
sub_value = getattr(participant, sub_attr)
# if its insterted we use the value inserted
if sub_attr not in (DESCRIPTOR_ATTR_NAME) and proto.has(participant, sub_attr):
participant_value[sub_attr] = get_value_or_name(sub_value)
# if not we grab the value from the default value dictionary
elif sub_attr not in (DESCRIPTOR_ATTR_NAME):
participant_value[attr] = default_input["participants"][0].get(sub_attr, "")
participants.append(participant_value)
result["participants"] = participants
# if there are some string, int values we assign it
elif type(value) in ("int", "string", "bool"):
result[attr] = value
elif type(value) in "proto.EnumValueDescriptor":
result[attr] = value.name
# validation of the above defaults
for index, participant in enumerate(result["participants"]):
# this is really ugly we need some primitive to throw an error
el_client_type = participant["el_client_type"]
cl_client_type = participant["cl_client_type"]
......@@ -129,12 +112,15 @@ def parse_input(input_args):
if len(result["participants"]) >= 2 and result["participants"][1]["el_client_type"] == NETHERMIND_NODE_NAME:
fail("nethermind can't be the first or second node")
encoded_json = json.encode(result)
return result
def get_value_or_name(value):
if type(value) == ENUM_TYPE:
return value.name
return value
def default_module_input():
network_params = default_network_params()
......@@ -142,7 +128,7 @@ def default_module_input():
return {
"participants": participants,
"network_params": network_params,
LAUNCH_ADDITIONAL_ATTR: True,
"launch_additional_services" : True,
"wait_for_finalization": False,
"wait_for_verifications": False,
"verifications_epoch_limit": 5,
......
......@@ -6,7 +6,7 @@ message ModuleInput {
repeated Participant participants = 1;
// Parameters controlling the settings of the network itself
NetworkParams network_params = 2;
optional NetworkParams network_params = 2;
// True by defaults such that in addition to the Ethereum network:
// - A transaction spammer is launched to fake transactions sent to the network
......@@ -22,16 +22,16 @@ message ModuleInput {
// If set, the module will block until a finalized epoch has occurred.
// If `waitForVerifications` is set to true, this extra wait will be skipped.
bool wait_for_finalization = 4;
optional bool wait_for_finalization = 4;
// If set to true, the module will block until all verifications have passed
bool wait_for_verifications = 5;
optional bool wait_for_verifications = 5;
// If set, after the merge, this will be the maximum number of epochs wait for the verifications to succeed.
uint64 verifications_epoch_limit = 6;
optional uint64 verifications_epoch_limit = 6;
// The log level that the started clients should log at
GlobalLogLevel global_log_level = 7;
optional GlobalLogLevel global_log_level = 7;
}
enum GlobalLogLevel {
......@@ -64,30 +64,30 @@ message BuilderNetworkParams {
message Participant {
// The type of EL client that should be started
ELClientType el_client_type = 1;
optional ELClientType el_client_type = 1;
// The Docker image that should be used for the EL client; leave blank to use the default
string el_client_image = 2;
optional string el_client_image = 2;
// The log level string that this participant's EL client should log at
// If this is emptystring then the global `logLevel` parameter's value will be translated into a string appropriate for the client (e.g. if
// global `logLevel` = `info` then Geth would receive `3`, Besu would receive `INFO`, etc.)
// If this is not emptystring, then this value will override the global `logLevel` setting to allow for fine-grained control
// over a specific participant's logging
string el_client_log_level = 3;
optional string el_client_log_level = 3;
// Optional extra parameters that will be passed to the EL client
repeated string el_extra_params = 4;
// The type of CL client that should be started
CLClientType cl_client_type = 5;
optional CLClientType cl_client_type = 5;
// The Docker image that should be used for the EL client; leave blank to use the default
// NOTE: Prysm is different in that it requires two images - a Beacon and a validator
// For Prysm and Prysm only, this field should contain a comma-separated string of "beacon_image,validator_image"
string cl_client_image = 6;
optional string cl_client_image = 6;
// The log level string that this participant's CL client should log at
// If this is emptystring then the global `logLevel` parameter's value will be translated into a string appropriate for the client (e.g. if
// global `logLevel` = `info` then Nimbus would receive `INFO`, Prysm would receive `info`, etc.)
// If this is not emptystring, then this value will override the global `logLevel` setting to allow for fine-grained control
// over a specific participant's logging
string cl_client_log_level = 7;
optional string cl_client_log_level = 7;
// Extra parameters that will be passed to the Beacon container (if a separate one exists), or to the combined node if
// the Beacon and validator are combined
......@@ -97,23 +97,23 @@ message Participant {
// the Beacon and validator are combined
repeated string validator_extra_params = 9;
BuilderNetworkParams builder_network_params = 10;
optional BuilderNetworkParams builder_network_params = 10;
}
message NetworkParams {
// The network ID of the Eth1 network
string network_id = 1;
optional string network_id = 1;
// The address of the staking contract address on the Eth1 chain
string deposit_contract_address = 2;
optional string deposit_contract_address = 2;
// Number of seconds per slot on the Beacon chain
uint32 seconds_per_slot = 3;
optional uint32 seconds_per_slot = 3;
// Number of slots in an epoch on the Beacon chain
uint32 slots_per_epoch = 4;
optional uint32 slots_per_epoch = 4;
// The number of validator keys that each CL validator node should get
uint32 num_validators_per_keynode = 5;
optional uint32 num_validators_per_keynode = 5;
// This menmonic will a) be used to create keystores for all the types of validators that we have and b) be used to generate a CL genesis.ssz that has the children
// validator keys already preregistered as validators
string preregistered_validator_keys_mnemonic = 6;
optional string preregistered_validator_keys_mnemonic = 6;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment