コード例 #1
0
ファイル: component.py プロジェクト: jaydeep-lchauhan/trinity
    async def do_run(cls, boot_info: BootInfo, event_bus: EndpointAPI) -> None:
        trinity_config = boot_info.trinity_config
        beacon_app_config = trinity_config.get_app_config(BeaconAppConfig)
        chain_config = beacon_app_config.get_chain_config()
        base_db = DBClient.connect(trinity_config.database_ipc_path)

        # TODO: For now we use fake eth1 monitor.
        # if boot_info.args.eth1client_rpc:
        #     w3: Web3 = Web3.HTTPProvider(boot_info.args.eth1client_rpc)
        # else:
        #     w3: Web3 = None

        # TODO: For now we use fake eth1 monitor. So we load validators data from
        # interop setting and hardcode the deposit data into fake eth1 data provider.
        chain = chain_config.beacon_chain_class(base_db,
                                                chain_config.genesis_config)
        config = chain.get_state_machine().config
        key_set = load_yaml_at(
            Path(
                "eth2/beacon/scripts/quickstart_state/keygen_16_validators.yaml"
            ))
        pubkeys, privkeys, withdrawal_credentials = create_keypair_and_mock_withdraw_credentials(
            config,
            key_set  # type: ignore
        )
        initial_deposits = (create_mock_deposit_data(
            config=config,
            pubkey=pubkey,
            privkey=privkey,
            withdrawal_credentials=withdrawal_credential,
        ) for pubkey, privkey, withdrawal_credential in zip(
            pubkeys, privkeys, withdrawal_credentials))

        # Set the timestamp of start block earlier enough so that eth1 monitor
        # can query up to 2 * `ETH1_FOLLOW_DISTANCE` of blocks in the beginning.
        start_block_timestamp = (chain_config.genesis_data.genesis_time -
                                 3 * ETH1_FOLLOW_DISTANCE * AVERAGE_BLOCK_TIME)
        with base_db:
            fake_eth1_data_provider = FakeEth1DataProvider(
                start_block_number=START_BLOCK_NUMBER,
                start_block_timestamp=Timestamp(start_block_timestamp),
                num_deposits_per_block=NUM_DEPOSITS_PER_BLOCK,
                initial_deposits=tuple(initial_deposits),
            )

            eth1_monitor_service: Service = Eth1Monitor(
                eth1_data_provider=fake_eth1_data_provider,
                num_blocks_confirmed=NUM_BLOCKS_CONFIRMED,
                polling_period=POLLING_PERIOD,
                start_block_number=BlockNumber(START_BLOCK_NUMBER - 1),
                event_bus=event_bus,
                base_db=base_db,
            )

            try:
                await TrioManager.run_service(eth1_monitor_service)
            except Exception:
                await event_bus.broadcast(
                    ShutdownRequest("Eth1 Monitor ended unexpectedly"))
                raise
コード例 #2
0
def _main():
    config_type = Minimal
    config = _load_config(config_type)
    override_lengths(config)

    key_set = load_yaml_at(KEY_DIR / KEY_SET_FILE)

    pubkeys, privkeys, withdrawal_credentials = create_keypair_and_mock_withdraw_credentials(
        config, key_set)
    keymap = {pubkey: privkey for pubkey, privkey in zip(pubkeys, privkeys)}

    deposits, _ = create_mock_deposits_and_root(pubkeys, keymap, config,
                                                withdrawal_credentials)

    eth1_block_hash = b"\x42" * 32
    # NOTE: this timestamp is a placeholder
    eth1_timestamp = 10000
    state = initialize_beacon_state_from_eth1(
        eth1_block_hash=eth1_block_hash,
        eth1_timestamp=eth1_timestamp,
        deposits=deposits,
        config=config,
    )

    genesis_time = int(time.time())
    print(f"creating genesis at time {genesis_time}")
    genesis_state = state.copy(genesis_time=genesis_time)
    print(genesis_state.hash_tree_root.hex())

    genesis_file_path = RESOURCE_DIR / GENESIS_FILE
    output_file = open(genesis_file_path, "wb")
    output_file.write(ssz.encode(genesis_state))
    output_file.close()
    print(f"genesis is saved in {genesis_file_path}")