Пример #1
0
def work(port, sub_dir=None):
    # BlockChain setup
    set_database_path(sub_dir=sub_dir)
    builder.set_database_path()
    make_account_db()
    genesis_block, network_ver, connections = load_boot_file()
    logging.info("Start p2p network-ver{} .".format(network_ver))

    # P2P network setup
    setup_p2p_params(network_ver=network_ver, p2p_port=port, sub_dir=sub_dir)
    pc = PeerClient()
    pc.event.addevent(cmd=DirectCmd.BEST_INFO, f=DirectCmd.best_info)
    pc.event.addevent(cmd=DirectCmd.BLOCK_BY_HEIGHT,
                      f=DirectCmd.block_by_height)
    pc.event.addevent(cmd=DirectCmd.BLOCK_BY_HASH, f=DirectCmd.block_by_hash)
    pc.event.addevent(cmd=DirectCmd.TX_BY_HASH, f=DirectCmd.tx_by_hash)
    pc.event.addevent(cmd=DirectCmd.UNCONFIRMED_TX, f=DirectCmd.unconfirmed_tx)
    pc.event.addevent(cmd=DirectCmd.BIG_BLOCKS, f=DirectCmd.big_blocks)
    pc.start()
    V.PC_OBJ = pc

    if pc.p2p.create_connection('tipnem.tk', 2000):
        logging.info("1Connect!")
    elif pc.p2p.create_connection('nekopeg.tk', 2000):
        logging.info("2Connect!")

    for host, port in connections:
        pc.p2p.create_connection(host, port)
    set_blockchain_params(genesis_block)

    # BroadcastProcess setup
    pc.broadcast_check = broadcast_check

    # Update to newest blockchain
    builder.init(genesis_block, batch_size=500)
    builder.db.sync = False  # more fast
    sync_chain_loop()

    # Mining/Staking setup (nothing)

    # Contract watcher
    start_contract_watch()
    # Debug.F_STICKY_TX_REJECTION = False  # for debug
    logging.info("Finished all initialize. (no mining and staking)")

    try:
        create_rest_server(f_local=False,
                           port=port + 1000,
                           user='******',
                           pwd='password')
        P.F_STOP = True
        builder.close()
        pc.close()
    except KeyboardInterrupt:
        logging.debug("KeyboardInterrupt.")
Пример #2
0
def work(port, sub_dir=None):
    # BlockChain setup
    set_database_path(sub_dir=sub_dir)
    builder.set_database_path()
    make_account_db()
    genesis_block, network_ver, connections = load_boot_file()
    logging.info("Start p2p network-ver{} .".format(network_ver))

    # P2P network setup
    setup_p2p_params(network_ver=network_ver, p2p_port=port, sub_dir=sub_dir)
    pc = PeerClient()
    pc.event.addevent(cmd=DirectCmd.BEST_INFO, f=DirectCmd.best_info)
    pc.event.addevent(cmd=DirectCmd.BLOCK_BY_HEIGHT,
                      f=DirectCmd.block_by_height)
    pc.event.addevent(cmd=DirectCmd.BLOCK_BY_HASH, f=DirectCmd.block_by_hash)
    pc.event.addevent(cmd=DirectCmd.TX_BY_HASH, f=DirectCmd.tx_by_hash)
    pc.event.addevent(cmd=DirectCmd.UNCONFIRMED_TX, f=DirectCmd.unconfirmed_tx)
    pc.event.addevent(cmd=DirectCmd.BIG_BLOCKS, f=DirectCmd.big_blocks)
    config.C.MAX_RECEIVE_SIZE = 2000 * 1000  # 2Mb
    pc.start()
    V.PC_OBJ = pc

    if pc.p2p.create_connection('tipnem.tk', 2000):
        logging.info("Connect!")

    for host, port in connections:
        pc.p2p.create_connection(host, port)
    set_blockchain_params(genesis_block)

    # BroadcastProcess setup
    pc.broadcast_check = broadcast_check

    # Update to newest blockchain
    builder.init(genesis_block, batch_size=500)
    builder.db.sync = False  # more fast but unstable
    sync_chain_loop()

    # Mining/Staking setup
    start_work_hash()
    # Debug.F_CONSTANT_DIFF = True
    # Debug.F_SHOW_DIFFICULTY = True
    # Debug.F_STICKY_TX_REJECTION = False  # for debug
    Generate(consensus=C.BLOCK_YES_POW, power_limit=0.05).start()
    Generate(consensus=C.BLOCK_HMQ_POW, power_limit=0.05).start()
    Generate(consensus=C.BLOCK_X11_POW, power_limit=0.05).start()
    Generate(consensus=C.BLOCK_POS, power_limit=0.3).start()
    # Contract watcher
    start_contract_watch()
    Thread(target=mined_newblock, name='GeneBlock',
           args=(output_que, pc)).start()
    logging.info("Finished all initialize.")

    try:
        create_rest_server(f_local=True,
                           port=port + 1000,
                           user='******',
                           pwd='password')
        P.F_STOP = True
        builder.close()
        pc.close()
        close_contract_watch()
        close_generate()
        close_work_hash()
        close_sync()
    except KeyboardInterrupt:
        logging.debug("KeyboardInterrupt.")
Пример #3
0
def work(port, sub_dir):
    # BlockChain setup
    set_database_path(sub_dir=sub_dir)
    builder.set_database_path()
    copy_boot(port)
    make_account_db()
    genesis_block, network_ver, connections = load_boot_file()
    logging.info("Start p2p network-ver{} .".format(network_ver))

    # P2P network setup
    setup_p2p_params(network_ver=network_ver, p2p_port=port, sub_dir=sub_dir)
    pc = PeerClient(f_local=True)
    pc.event.addevent(cmd=DirectCmd.BEST_INFO, f=DirectCmd.best_info)
    pc.event.addevent(cmd=DirectCmd.BLOCK_BY_HEIGHT,
                      f=DirectCmd.block_by_height)
    pc.event.addevent(cmd=DirectCmd.BLOCK_BY_HASH, f=DirectCmd.block_by_hash)
    pc.event.addevent(cmd=DirectCmd.TX_BY_HASH, f=DirectCmd.tx_by_hash)
    pc.event.addevent(cmd=DirectCmd.UNCONFIRMED_TX, f=DirectCmd.unconfirmed_tx)
    pc.event.addevent(cmd=DirectCmd.BIG_BLOCKS, f=DirectCmd.big_blocks)
    pc.start()
    V.PC_OBJ = pc

    # for debug node
    if port != 2000 and pc.p2p.create_connection('127.0.0.1', 2000):
        logging.info("Connect!")
    else:
        pc.p2p.create_connection('127.0.0.1', 2001)

    for host, port in connections:
        pc.p2p.create_connection(host, port)
    set_blockchain_params(genesis_block)

    # BroadcastProcess setup
    pc.broadcast_check = broadcast_check

    # Update to newest blockchain
    builder.init(genesis_block, batch_size=500)
    # builder.db.sync = False  # more fast
    sync_chain_loop()

    # Mining/Staking setup
    start_work_hash()
    # Debug.F_CONSTANT_DIFF = True
    # Debug.F_SHOW_DIFFICULTY = True
    # Debug.F_STICKY_TX_REJECTION = False  # for debug
    if port % 3 == 0:
        Generate(consensus=C.BLOCK_YES_POW, power_limit=0.01).start()
    if port % 3 == 1:
        Generate(consensus=C.BLOCK_HMQ_POW, power_limit=0.01).start()
    if port % 3 == 2:
        Generate(consensus=C.BLOCK_X11_POW, power_limit=0.01).start()
    Generate(consensus=C.BLOCK_POS, power_limit=0.3).start()
    # Contract watcher
    start_contract_watch()
    Emulate(c_address='CJ4QZ7FDEH5J7B2O3OLPASBHAFEDP6I7UKI2YMKF')
    start_emulators(genesis_block)
    # Stratum
    # Stratum(port=port+2000, consensus=C.BLOCK_HMQ_POW, first_difficulty=4)
    Thread(target=mined_newblock, name='GeneBlock',
           args=(output_que, pc)).start()
    logging.info("Finished all initialize.")

    try:
        # start_stratum(f_blocking=False)
        create_rest_server(f_local=True,
                           port=port + 1000,
                           user='******',
                           pwd='password')
        P.F_STOP = True
        close_contract_watch()
        builder.close()
        # close_stratum()
        pc.close()
        close_emulators()
        close_contract_watch()
        close_generate()
        close_work_hash()
    except KeyboardInterrupt:
        logging.debug("KeyboardInterrupt.")