Exemplo n.º 1
0
def _vm(genesis_block, start_tx, que, c, c_address, c_method, redeem_address,
        c_args):
    set_blockchain_params(genesis_block)
    c_args = c_args or list()
    virtual_machine = rpdb.Rpdb(port=0)
    try:
        c_obj = binary2contract(c_bin=c.binary, extra_imports=c.extra_imports)
        # notify listen port
        que.put((CMD_PORT, virtual_machine.port))
        # start emulate
        virtual_machine.server_start()
        virtual_machine.set_trace()
        # get method
        obj = c_obj(start_tx, c_address, c.storage, redeem_address)
        fnc = getattr(obj, c_method)
        result = fnc(*c_args)
        virtual_machine.do_quit(EMU_QUIT)
        que.put((CMD_SUCCESS, result))
    except bdb.BdbQuit as e:
        virtual_machine.do_quit(EMU_QUIT)
        que.put((CMD_ERROR, str(e)))
    except Exception:
        virtual_machine.do_quit(EMU_QUIT)
        tb = traceback.format_exc()
        que.put((CMD_ERROR, str(tb)))
    # close port
    try:
        virtual_machine.shutdown()
    except Exception:
        pass
Exemplo n.º 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)
    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.")
Exemplo n.º 3
0
def _work(params, start_tx, que):
    set_database_path(sub_dir=params["sub_dir"])
    set_blockchain_params(genesis_block=params['genesis_block'])
    try:
        virtual_machine = rpdb.Rpdb(port=0)
        que.put((CMD_PORT, virtual_machine.port))
        virtual_machine.server_start()
        c_obj = binary2contract(params['c_bin'])
        # remote emulate
        virtual_machine.set_trace()
        obj = c_obj(start_tx, params['c_address'])
        fnc = getattr(obj, params['c_method'])
        result = fnc(*params['args'])
        que.put((CMD_SUCCESS, result))
        virtual_machine.do_quit('quit')
    except BaseException:
        tb = traceback.format_exc()
        que.put((CMD_ERROR, str(tb)))
Exemplo n.º 4
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.")
Exemplo n.º 5
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.")
Exemplo n.º 6
0
def work(port, sub_dir):
    # BlockChain setup
    set_database_path(sub_dir=sub_dir)
    check_already_started()
    chain_builder.set_database_path()
    copy_boot(port)
    import_keystone(passphrase='hello python')
    check_account_db()
    genesis_block, genesis_params, 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)
    p2p = Peer2Peer(f_local=True, default_hook=default_hook, object_hook=object_hook)
    p2p.event.addevent(cmd=DirectCmd.BEST_INFO, f=DirectCmd.best_info)
    p2p.event.addevent(cmd=DirectCmd.BLOCK_BY_HEIGHT, f=DirectCmd.block_by_height)
    p2p.event.addevent(cmd=DirectCmd.BLOCK_BY_HASH, f=DirectCmd.block_by_hash)
    p2p.event.addevent(cmd=DirectCmd.TX_BY_HASH, f=DirectCmd.tx_by_hash)
    p2p.event.addevent(cmd=DirectCmd.UNCONFIRMED_TX, f=DirectCmd.unconfirmed_tx)
    p2p.event.addevent(cmd=DirectCmd.BIG_BLOCKS, f=DirectCmd.big_blocks)
    p2p.start()
    V.P2P_OBJ = p2p

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

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

    # BroadcastProcess setup
    p2p.broadcast_check = broadcast_check

    # Update to newest blockchain
    chain_builder.db.sync = False
    if chain_builder.init(genesis_block, batch_size=500):
        # only genesisBlock yoy have, try to import bootstrap.dat.gz
        load_bootstrap_file()
    sync_chain_loop()

    # Mining/Staking setup
    # Debug.F_CONSTANT_DIFF = True
    # Debug.F_SHOW_DIFFICULTY = True
    # Debug.F_STICKY_TX_REJECTION = False  # for debug
    if port == 2000:
        Generate(consensus=C.BLOCK_CAP_POS, power_limit=0.6, path='E:\\plots').start()
    elif port % 3 == 0:
        Generate(consensus=C.BLOCK_YES_POW, power_limit=0.03).start()
    elif port % 3 == 1:
        Generate(consensus=C.BLOCK_X16S_POW, power_limit=0.03).start()
    elif port % 3 == 2:
        Generate(consensus=C.BLOCK_X11_POW, power_limit=0.03).start()
    Generate(consensus=C.BLOCK_COIN_POS, power_limit=0.3).start()
    # contract emulator
    Emulate(c_address='CJ4QZ7FDEH5J7B2O3OLPASBHAFEDP6I7UKI2YMKF')
    # Emulate(c_address='CLBKXHOTXTLK3FENVTCH6YPM5MFZS4BNAXFYNWBD')
    start_emulators()
    Thread(target=mined_newblock, name='GeneBlock', args=(output_que,)).start()
    logging.info("Finished all initialize.")

    try:
        create_rest_server(user='******', pwd='password', port=port+1000)
        loop.run_forever()
    except Exception as e:
        logging.debug(e)
    P.F_STOP = True
    chain_builder.close()
    p2p.close()