コード例 #1
0
def genesis_config_with_validators(
        config_profile: Literal["minimal", "mainnet"],
        genesis_time: Timestamp = None) -> Dict[str, Any]:
    eth2_config = _get_eth2_config(config_profile)
    override_lengths(eth2_config)

    validator_count = eth2_config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
    validator_key_pairs = create_key_pairs_for(validator_count)
    deposits = create_genesis_deposits_from(
        validator_key_pairs,
        withdrawal_credentials_provider=mk_withdrawal_credentials_from(
            eth2_config.BLS_WITHDRAWAL_PREFIX),
        amount_provider=lambda _public_key: eth2_config.MAX_EFFECTIVE_BALANCE,
    )
    eth1_block_hash = ZERO_HASH32
    eth1_timestamp = eth2_config.MIN_GENESIS_TIME
    genesis_state = initialize_beacon_state_from_eth1(
        eth1_block_hash=eth1_block_hash,
        eth1_timestamp=Timestamp(eth1_timestamp),
        deposits=deposits,
        config=eth2_config,
    )

    if genesis_time:
        genesis_state = genesis_state.set("genesis_time", genesis_time)

    key_pairs = mk_genesis_key_map(validator_key_pairs, genesis_state)

    return _create_genesis_config(config_profile, eth2_config, genesis_state,
                                  key_pairs)
コード例 #2
0
ファイル: genesis.py プロジェクト: pamir-s/trinity
def generate_genesis_config(
    config_profile: Literal["minimal", "mainnet"],
    genesis_time: Optional[Timestamp] = None,
) -> Dict[str, Any]:
    eth2_config = _get_eth2_config(config_profile)
    override_lengths(eth2_config)
    validator_count = eth2_config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT

    validator_key_pairs = create_key_pairs_for(validator_count)
    deposits = create_genesis_deposits_from(
        validator_key_pairs,
        withdrawal_credentials_provider=mk_withdrawal_credentials_from(
            eth2_config.BLS_WITHDRAWAL_PREFIX.to_bytes(1, byteorder="little")
        ),
        amount_provider=lambda _public_key: eth2_config.MAX_EFFECTIVE_BALANCE,
    )
    eth1_block_hash = ZERO_HASH32
    eth1_timestamp = eth2_config.MIN_GENESIS_TIME
    initial_state = initialize_beacon_state_from_eth1(
        eth1_block_hash=eth1_block_hash,
        eth1_timestamp=Timestamp(eth1_timestamp),
        deposits=deposits,
        config=eth2_config,
    )

    if genesis_time:
        initial_state.set("genesis_time", genesis_time)

    return {
        "eth2_config": eth2_config.to_formatted_dict(),
        "genesis_validator_key_pairs": mk_genesis_key_map(
            validator_key_pairs, initial_state
        ),
        "genesis_state": to_formatted_dict(initial_state),
    }
コード例 #3
0
ファイル: component.py プロジェクト: onyb/trinity
    def _generate_network_as_json(cls, args: Namespace,
                                  trinity_config: TrinityConfig) -> None:
        config = _get_eth2_config(args.config_profile)
        validator_count = config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
        output_file_path = (args.output if args.output else
                            _get_network_config_path_from())

        cls.logger.info(
            "generating a configuration file at '%s'"
            " for %d validators and the genesis state containing them...",
            output_file_path,
            validator_count,
        )
        validator_key_pairs = create_key_pairs_for(validator_count)
        deposits = create_genesis_deposits_from(
            validator_key_pairs,
            withdrawal_credentials_provider=mk_withdrawal_credentials_from(
                config.BLS_WITHDRAWAL_PREFIX.to_bytes(1, byteorder="little")),
            amount_provider=lambda _public_key: config.MAX_EFFECTIVE_BALANCE,
        )
        eth1_block_hash = ZERO_HASH32
        eth1_timestamp = config.MIN_GENESIS_TIME
        genesis_state = initialize_beacon_state_from_eth1(
            eth1_block_hash=eth1_block_hash,
            eth1_timestamp=Timestamp(eth1_timestamp),
            deposits=deposits,
            config=config,
        )
        output = {
            "eth2_config":
            serialize(config),
            "genesis_validator_key_pairs":
            mk_genesis_key_map(validator_key_pairs, genesis_state),
            "genesis_state":
            to_formatted_dict(genesis_state),
        }
        cls.logger.info(
            "configuration generated; genesis state has root %s",
            humanize_hash(genesis_state.hash_tree_root),
        )
        output_file_path.parent.mkdir(parents=True, exist_ok=True)
        with open(output_file_path, "w") as output_file:
            output_file.write(json.dumps(output))
コード例 #4
0
ファイル: conftest.py プロジェクト: behradkhodayar/trinity
def sample_bls_key_pairs(validator_count):
    return create_key_pairs_for(validator_count)