def from_genesis_config(cls, config_profile: str) -> 'BeaconChainConfig': """ Construct an instance of ``cls`` reading the genesis configuration data under the local data directory. """ if config_profile == "mainnet": beacon_chain_class = BeaconChain else: beacon_chain_class = SkeletonLakeChain try: with open(_get_eth2_genesis_config_file_path( config_profile)) as config_file: genesis_config = json.load(config_file) except FileNotFoundError as e: raise Exception("unable to load genesis config: %s", e) eth2_config = Eth2Config.from_formatted_dict( genesis_config["eth2_config"]) # NOTE: have to ``override_lengths`` before we can parse the ``BeaconState`` override_lengths(eth2_config) genesis_state = from_formatted_dict(genesis_config["genesis_state"], BeaconState) genesis_validator_key_map = load_genesis_key_map( genesis_config["genesis_validator_key_pairs"]) return cls(genesis_state, eth2_config, genesis_validator_key_map, beacon_chain_class=beacon_chain_class)
def main_validator() -> None: logger = _setup_logging() parser = parse_cli_args() arguments = parser.parse_args() trinity_config = load_trinity_config_from_parser_args( parser, arguments, APP_IDENTIFIER_VALIDATOR_CLIENT, (ValidatorClientAppConfig,) ) # NOTE: we do not want the rest of the functionality in # ``trinity.bootstrap.ensure_data_dir_is_initialized create_dir_if_missing(trinity_config.data_dir) validator_client_app_config = trinity_config.get_app_config( ValidatorClientAppConfig ) root_dir = validator_client_app_config.root_dir create_dir_if_missing(root_dir) try: genesis_config = _load_genesis_config_at( validator_client_app_config.genesis_config_path ) except FileNotFoundError: genesis_time = Timestamp(int(time.time())) genesis_config = generate_genesis_config("minimal", genesis_time) eth2_config = Eth2Config.from_formatted_dict(genesis_config["eth2_config"]) override_lengths(eth2_config) key_pairs = load_genesis_key_map(genesis_config["genesis_validator_key_pairs"]) genesis_state = from_formatted_dict(genesis_config["genesis_state"], BeaconState) slots_per_epoch = Slot(eth2_config.SLOTS_PER_EPOCH) seconds_per_slot = eth2_config.SECONDS_PER_SLOT genesis_time = genesis_state.genesis_time config = Config( key_pairs=key_pairs, root_data_dir=root_dir, slots_per_epoch=slots_per_epoch, seconds_per_slot=seconds_per_slot, genesis_time=genesis_time, ) # NOTE: we deviate from the multiprocess-driven Component-based # application machinery here until said machinery is more stable # with respect to boot, shutdown and general concurrent control. trio.run(arguments.func, logger, config, arguments)
def from_genesis_config(cls) -> 'BeaconChainConfig': """ Construct an instance of ``cls`` reading the genesis configuration data under the local data directory. """ try: with open(_get_eth2_genesis_config_file_path()) as config_file: genesis_config = json.load(config_file) except FileNotFoundError: genesis_config = generate_genesis_config("minimal") eth2_config = Eth2Config.from_formatted_dict(genesis_config["eth2_config"]) # NOTE: have to ``override_lengths`` before we can parse the ``BeaconState`` override_lengths(eth2_config) genesis_state = from_formatted_dict(genesis_config["genesis_state"], BeaconState) genesis_validator_key_map = load_genesis_key_map( genesis_config["genesis_validator_key_pairs"] ) return cls(genesis_state, eth2_config, genesis_validator_key_map)