Beispiel #1
0
def calculate_block(current_block):
    print 'calculate block called'
    if vec_mult(weights, extract_vector(current_block)) > 0:
        print 'triggered'
        btcnet_info.get_pool('deepbit').namespace.get_node('shares').set_value(0)
        #Reset shares on deepbit
        blocks_calculated[current_block] = 1
    else:
        blocks_calculated[current_block] = 0
Beispiel #2
0
def get_diff(pool):
    coin = btcnet_info.get_pool(pool)
    if coin:
        coin = coin.coin
    else:
        coin = 'btc'
    return float(btcnet_info.get_difficulty(coin))
Beispiel #3
0
def get_work( headers = {}):
    """
    Gets a work item
    """
    while True:
        server, username, password = bitHopper.Logic.get_server()
        url = btcnet_info.get_pool(server)
        if not url:
            bitHopper.LaggingLogic.lag(server, username, password)
            continue

        url = url['mine.address']
        request = {'params':[], 'id':1, 'method':'getwork'}

        try:
            content, server_headers = send_work( url, username, password, headers, request, timeout=1)
        except (socket.error, requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
            content, server_headers = None, None
        except:
            logging.error(traceback.format_exc())
            content, server_headers = None, None

        if not content:
            bitHopper.LaggingLogic.lag(server, username, password)
            continue

        gevent.spawn(Tracking.add_work_unit, content, server, username, password)
        gevent.spawn(Tracking.headers, server_headers, server)

        return content, deepcopy(server_headers)
Beispiel #4
0
def get_diff(pool):
    coin = btcnet_info.get_pool(pool)
    if coin:
        coin = coin.coin
    else:
        coin = 'btc'
    return float(btcnet_info.get_difficulty(coin))
Beispiel #5
0
def poke_deepbit():
    choices = list(bitHopper.Logic.generate_tuples('deepbit'))
    if len(choices) == 0:
        logging.info('No workers for deepbit. Disabling machine learning') 
        return
    server, username, password = random.choice(choices)
    url = btcnet_info.get_pool(server)['mine.address']
    bitHopper.Network.send_work_lp(url, username, password, 'deepbit')
Beispiel #6
0
def check_learning():
    print 'Check learning started'
    while True:
        gevent.sleep(60)
        deepbit_blocks = set(json.loads(btcnet_info.get_pool('deepbit').blocks))
        for block in blocks_timing:
            if block in blocks_actual and blocks_actual[block] == 1:
                continue
            if block in deepbit_blocks:
                blocks_actual[block] = 1
                print 'Block %s has training value %s' % (block, blocks_actual[block])
Beispiel #7
0
def _unlag_fetcher(server, worker, password):
    """
    Actually fetches and unlags the server
    """
    try:
        url = btcnet_info.get_pool(server)['mine.address']
        work = Network.send_work(url, worker, password)
        if work:
            bitHopper.LaggingLogic.lagged.remove((server, worker, password))
            return
    except:
        logging.debug(traceback.format_exc())
        pass
Beispiel #8
0
def add_address(server, url):
    """
    Adds an address and starts the polling function
    """

    if url[0] == '/' or url[0] == '\\':
        url = btcnet_info.get_pool(server)['mine.address'] + url

    if server not in known:
        known[server] = url
        logging.info('Spawning Listener %s' % server)
        gevent.spawn(poll, server)
    elif known[server] != url:
        known[server] = url
Beispiel #9
0
def add_address(server, url):
    """
    Adds an address and starts the polling function
    """
    
    if url[0] == '/' or url[0] == '\\':
        url = btcnet_info.get_pool(server)['mine.address'] + url
        
    if server not in known:
        known[server] = url
        logging.info('Spawning Listener %s' % server)
        gevent.spawn(poll, server)
    elif known[server] != url:
        known[server] = url
Beispiel #10
0
def _unlag( server, worker, password):
    """
    Function that checks for a server responding again
    """
    sleep_time = 1
    while True:
        try:
            url = btcnet_info.get_pool(server)['mine.address']
            work = Network.send_work(url, worker, password)
            if work:
                lagged.remove((server, worker, password))
                return
        except:
            pass
                
        gevent.sleep(60 * sleep_time)
        sleep_time = sleep_time+1 if sleep_time < 10 else 10
Beispiel #11
0
def submit_work(rpc_request, headers = {}):
    """
    Submits a work item
    """
    server, username, password = bitHopper.Tracking.get_work_unit(rpc_request)

    if not server:
        return rpc_error('Merkle Root Expired'), {}

    url = btcnet_info.get_pool(server)['mine.address']
    if not url:
        logging.error('NO URL FOR %s', server)
        return rpc_error('No Url for pool'), {}

    content, server_headers = bitHopper.Network.send_work(url, username, password, headers = headers, body = rpc_request)

    gevent.spawn(Tracking.add_result, content, server, username, password)
    gevent.spawn(Tracking.headers, server_headers, server)

    return content, deepcopy(server_headers)
Beispiel #12
0
def get_work(headers={}):
    """
    Gets a work item
    """
    while True:
        server, username, password = bitHopper.Logic.get_server()
        url = btcnet_info.get_pool(server)
        if not url:
            bitHopper.LaggingLogic.lag(server, username, password)
            continue

        url = url['mine.address']
        request = {'params': [], 'id': 1, 'method': 'getwork'}

        try:
            content, server_headers = send_work(url,
                                                username,
                                                password,
                                                headers,
                                                request,
                                                timeout=1)
        except (socket.error, requests.exceptions.ConnectionError,
                requests.exceptions.Timeout) as e:
            content, server_headers = None, None
        except:
            logging.error(traceback.format_exc())
            content, server_headers = None, None

        if not content:
            bitHopper.LaggingLogic.lag(server, username, password)
            continue

        gevent.spawn(Tracking.add_work_unit, content, server, username,
                     password)
        gevent.spawn(Tracking.headers, server_headers, server)

        return content, deepcopy(server_headers)
Beispiel #13
0
def submit_work(rpc_request, headers={}):
    """
    Submits a work item
    """
    server, username, password = bitHopper.Tracking.get_work_unit(rpc_request)

    if not server:
        return rpc_error('Merkle Root Expired'), {}

    url = btcnet_info.get_pool(server)['mine.address']
    if not url:
        logging.error('NO URL FOR %s', server)
        return rpc_error('No Url for pool'), {}

    content, server_headers = bitHopper.Network.send_work(url,
                                                          username,
                                                          password,
                                                          headers=headers,
                                                          body=rpc_request)

    gevent.spawn(Tracking.add_result, content, server, username, password)
    gevent.spawn(Tracking.headers, server_headers, server)

    return content, deepcopy(server_headers)