Ejemplo n.º 1
0
def manage_queues(blocks_queue, txs_queue):
    def is_blocks_queue_empty():
        return blocks_queue.empty()

    def is_txs_queue_empty():
        return txs_queue.empty()

    def add_from_queue(queue, add_function, is_queue_empty, queue_name):
        # while the queue is not empty, in other words there are suggested blocks or transactions, call the corresponding add function
        while not is_queue_empty():
            time.sleep(0.0001)
            try:
                add_function(queue.get(False))
            except Exception as exc:
                tools.log('suggestions ' + queue_name)
                tools.log(exc)

    # start the loop until it gets stopped
    while True:
        time.sleep(0.1)
        if tools.db_get('stop'):
            # Free the queues
            tools.dump_out(blocks_queue)
            tools.dump_out(txs_queue)
            return
        while not is_blocks_queue_empty() or not is_txs_queue_empty():
            add_from_queue(blocks_queue, add_block, is_blocks_queue_empty, 'block')
            add_from_queue(txs_queue, add_tx, is_txs_queue_empty, 'tx')
Ejemplo n.º 2
0
def f(blocks_queue, txs_queue):
    def bb():
        return blocks_queue.empty()

    def tb():
        return txs_queue.empty()

    def ff(queue, g, b, s):
        while not b():
            time.sleep(0.0001)
            try:
                g(queue.get(False))
            except Exception as exc:
                tools.log('suggestions ' + s)
                tools.log(exc)

    while True:
        try:
            time.sleep(0.1)
            l = tools.local_get('length') + 1
            v = range(l - 10, l)
            v = filter(lambda x: x > 0, v)
            v = map(lambda x: tools.db_get(x), v)
            v = map(lambda x: x['block_hash'], v)
            if tools.local_get('stop'):
                tools.dump_out(blocks_queue)
                tools.dump_out(txs_queue)
                return
            while not bb() or not tb():
                ff(blocks_queue, lambda x: add_block(x, v), bb, 'block')
                ff(txs_queue, add_tx, tb, 'tx')
        except Exception as exc:
            tools.log(exc)
Ejemplo n.º 3
0
def f(blocks_queue, txs_queue):
    def bb(): return blocks_queue.empty()
    def tb(): return txs_queue.empty()
    def ff(queue, g, b, s):
        while not b():
            time.sleep(0.0001)
            try:
                g(queue.get(False))
            except Exception as exc:
                tools.log('suggestions ' + s)
                tools.log(exc)
    while True:
        try:
            time.sleep(0.1)
            l=tools.local_get('length')+1
            v=range(l-10, l)
            v=filter(lambda x: x>0, v)
            v=map(lambda x: tools.db_get(x), v)
            v=map(lambda x: x['block_hash'], v)
            if tools.local_get('stop'):
                tools.dump_out(blocks_queue)
                tools.dump_out(txs_queue)
                return
            while not bb() or not tb():
                ff(blocks_queue, lambda x: add_block(x, v), bb, 'block')
                ff(txs_queue, add_tx, tb, 'tx')
        except Exception as exc:
            tools.log(exc)
Ejemplo n.º 4
0
def f(blocks_queue, txs_queue):
    def bb():
        return blocks_queue.empty()

    def tb():
        return txs_queue.empty()

    def ff(queue, g, b, s):
        while not b():
            time.sleep(0.0001)
            try:
                g(queue.get(False))
            except Exception as exc:
                tools.log('suggestions ' + s)
                tools.log(exc)

    while True:
        time.sleep(0.1)
        if tools.db_get('stop'):
            tools.dump_out(blocks_queue)
            tools.dump_out(txs_queue)
            return
        while not bb() or not tb():
            ff(blocks_queue, add_block, bb, 'block')
            ff(txs_queue, add_tx, tb, 'tx')
Ejemplo n.º 5
0
def manage_queues(blocks_queue, txs_queue):
    def is_blocks_queue_empty():
        return blocks_queue.empty()

    def is_txs_queue_empty():
        return txs_queue.empty()

    def add_from_queue(queue, add_function, is_queue_empty, queue_name):
        # while the queue is not empty, in other words there are suggested blocks or transactions, call the corresponding add function
        while not is_queue_empty():
            time.sleep(0.0001)
            try:
                add_function(queue.get(False))
            except Exception as exc:
                tools.log('suggestions ' + queue_name)
                tools.log(exc)

    # start the loop until it gets stopped
    while True:
        time.sleep(0.1)
        if tools.db_get('stop'):
            # Free the queues
            tools.dump_out(blocks_queue)
            tools.dump_out(txs_queue)
            return
        while not is_blocks_queue_empty() or not is_txs_queue_empty():
            add_from_queue(blocks_queue, add_block, is_blocks_queue_empty,
                           'block')
            add_from_queue(txs_queue, add_tx, is_txs_queue_empty, 'tx')
Ejemplo n.º 6
0
 def f():
     time.sleep(0.1)
     l=tools.db_get('length')+1
     v=range(l-10, l)
     v=filter(lambda x: x>0, v)
     v=map(lambda x: tools.db_get(x), v)
     try:
         v=map(lambda x: x['prevHash'], v)
     except:
         #tools.log('v: ' +str(v))
         return
     if tools.db_get('stop'):
         tools.dump_out(blocks_queue)
         tools.dump_out(txs_queue)
         return
     while not bb() or not tb():
         ff(blocks_queue, lambda x: add_block(x, v), bb, 'block')
         ff(txs_queue, add_tx, tb, 'tx')
Ejemplo n.º 7
0
 def f():
     time.sleep(0.1)
     l = tools.db_get('length') + 1
     v = range(l - 10, l)
     v = filter(lambda x: x > 0, v)
     v = map(lambda x: tools.db_get(x), v)
     try:
         v = map(lambda x: x['prevHash'], v)
     except:
         #tools.log('v: ' +str(v))
         return
     if tools.db_get('stop'):
         tools.dump_out(blocks_queue)
         tools.dump_out(txs_queue)
         return
     while not bb() or not tb():
         ff(blocks_queue, lambda x: add_block(x, v), bb, 'block')
         ff(txs_queue, add_tx, tb, 'tx')
Ejemplo n.º 8
0
def main(pubkey, DB):
    num_cores = multiprocessing.cpu_count()
    solution_queue = multiprocessing.Queue()
    workers = [new_worker(solution_queue) for _ in range(num_cores)]
    try:
        while True:
            DB['heart_queue'].put('miner')
            if tools.db_get('stop'): 
                tools.dump_out(solution_queue)
                tools.log('shutting off miner')
                restart_workers(workers)
                return
            elif tools.db_get('mine'):
                main_once(pubkey, DB, num_cores, solution_queue, workers)
            else:
                time.sleep(1)
    except Exception as exc:
        tools.log('miner main: ')
        tools.log(exc)
Ejemplo n.º 9
0
def f(blocks_queue, txs_queue):
    def bb(): return blocks_queue.empty()
    def tb(): return txs_queue.empty()
    def ff(queue, g, b, s):
        while not b():
            time.sleep(0.0001)
            try:
                g(queue.get(False))
            except Exception as exc:
                tools.log('suggestions ' + s)
                tools.log(exc)
    while True:
        time.sleep(0.1)
        if tools.db_get('stop'):
            tools.dump_out(blocks_queue)
            tools.dump_out(txs_queue)
            return
        while not bb() or not tb():
            ff(blocks_queue, add_block, bb, 'block')
            ff(txs_queue, add_tx, tb, 'tx')
Ejemplo n.º 10
0
def restart_workers(workers):
    for worker in workers:
        tools.dump_out(worker['in_queue'])
        worker['restart'].set()