コード例 #1
0
ファイル: main_validator.py プロジェクト: nondejus/trinity
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)
コード例 #2
0
    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)
コード例 #3
0
ファイル: component.py プロジェクト: nondejus/trinity
    def _generate_network_as_json(cls, args: Namespace,
                                  trinity_config: TrinityConfig) -> None:
        if args.genesis_time:
            genesis_time = args.genesis_time
            cls.logger.info("genesis time specified from config: %d",
                            genesis_time)
        else:
            # this arm is guaranteed given the argparse config...
            genesis_time = int(time.time()) + args.genesis_delay
            cls.logger.info("genesis delay specified from config: %d",
                            args.genesis_delay)

        cls.logger.info("using config profile: %s", args.config_profile)

        if args.output:
            output_file_path = args.output
        else:
            output_file_path = _get_network_config_path_for(
                args.config_profile)

        if output_file_path.exists():
            with open(output_file_path, "r") as config_file:
                existing_genesis_config = json.load(config_file)
                genesis_config = update_genesis_config_with_time(
                    existing_genesis_config, genesis_time)
        else:
            genesis_config = generate_genesis_config(args.config_profile,
                                                     genesis_time)
        cls.logger.info(
            "configuration generated; genesis state has root %s with genesis time %d (%s); "
            "writing to '%s'",
            genesis_config["genesis_state_root"],
            genesis_time,
            time.strftime("%Y-%m-%d %I:%M%z", time.localtime(genesis_time)),
            output_file_path,
        )
        output_file_path.parent.mkdir(parents=True, exist_ok=True)
        with open(output_file_path, "w") as output_file:
            json.dump(genesis_config, output_file)
コード例 #4
0
    def _generate_network_as_json(cls, args: Namespace,
                                  trinity_config: TrinityConfig) -> None:
        if args.genesis_time:
            genesis_time = args.genesis_time
        elif args.genesis_delay:
            genesis_time = int(time.time()) + args.genesis_delay
        else:
            genesis_time = None

        genesis_config = generate_genesis_config(args.config_profile,
                                                 genesis_time)

        output_file_path = args.output
        cls.logger.info(
            "configuration generated; genesis state has root %s with genesis time %d; "
            "writing to '%s'",
            humanize_hash(genesis_config["genesis_state"].hash_tree_root),
            genesis_config["genesis_state"].genesis_time,
            output_file_path,
        )
        output_file_path.parent.mkdir(parents=True, exist_ok=True)
        with open(output_file_path, "w") as output_file:
            output_file.write(json.dumps(genesis_config))