예제 #1
0
 def _run(self):
     while True:
         if self.net_state['poll_connection'] is None:
             logger.warn(
                 "Couldn't connect to any RPC servers, sleeping for 1")
             sleep(1)
             continue
         try:
             auxblock = self.coinserv.getauxblock()
         except Exception as e:
             logger.warn(
                 "Unable to communicate with aux chain server. {}".format(
                     e))
             sleep(2)
             continue
         #logger.debug("Aux RPC returned: {}".format(auxblock))
         new_merged_work = dict(hash=int(auxblock['hash'], 16),
                                target=pack.IntType(256).unpack(
                                    auxblock['target'].decode('hex')),
                                merged_proxy=self.coinserv,
                                monitor=self)
         self.aux_state['chain_id'] = auxblock['chainid']
         if new_merged_work != self.net_state['merged_work'].get(
                 auxblock['chainid']):
             try:
                 height = self.coinserv.getblockcount()
             except Exception as e:
                 logger.warn(
                     "Unable to communicate with aux chain server. {}".
                     format(e))
                 sleep(2)
                 continue
             logger.info(
                 "New aux work announced! Diff {}. RPC returned: {}".format(
                     bitcoin_data.target_to_difficulty(
                         new_merged_work['target']), new_merged_work))
             self.net_state['merged_work'][
                 auxblock['chainid']] = new_merged_work
             self.aux_state[
                 'difficulty'] = bitcoin_data.target_to_difficulty(
                     pack.IntType(256).unpack(
                         auxblock['target'].decode('hex')))
             # only push the job if there's a new block height discovered.
             if self.aux_state['height'] != height:
                 self.aux_state['height'] = height
                 self.monitor_network.generate_job(push=True,
                                                   flush=self.flush)
                 self.aux_state['work_restarts'] += 1
             else:
                 self.monitor_network.generate_job()
                 self.aux_state['new_jobs'] += 1
         sleep(self.work_interval)
예제 #2
0
    def update(self, reason=None):
        if reason:
            self.logger.info(
                "Updating {} aux work from a signal recieved!".format(
                    self.config['name']))

        try:
            auxblock = self.call_rpc('getauxblock')
        except RPCException:
            sleep(2)
            return False

        new_merged_work = dict(hash=int(auxblock['hash'], 16),
                               target=pack.IntType(256).unpack(
                                   auxblock['target'].decode('hex')),
                               type=self.config['name'])
        if new_merged_work['hash'] != self.jobmanager.merged_work.get(
                auxblock['chainid'], {'hash': None})['hash']:
            # We fetch the block height so we can see if the hash changed
            # because of a new network block, or because new transactions
            try:
                height = self.call_rpc('getblockcount')
            except RPCException:
                sleep(2)
                return False
            self.logger.info(
                "New aux work announced! Diff {:,.4f}. Height {:,}".format(
                    bitcoin_data.target_to_difficulty(
                        new_merged_work['target']), height))
            # add height to work spec for future logging
            new_merged_work['height'] = height

            self.jobmanager.merged_work[auxblock['chainid']] = new_merged_work
            self.current_net['difficulty'] = bitcoin_data.target_to_difficulty(
                pack.IntType(256).unpack(auxblock['target'].decode('hex')))

            # only push the job if there's a new block height discovered.
            if self.current_net['height'] != height:
                self.current_net['height'] = height
                self.jobmanager.generate_job(push=True,
                                             flush=self.config['flush'])
                self.server[self.prefix + "work_restarts"].incr()
                self.server[self.prefix + "new_jobs"].incr()
            else:
                self.jobmanager.generate_job()
                self.server[self.prefix + "new_jobs"].incr()

        return True
예제 #3
0
    def _check_new_jobs(self, signal=False):
        if signal:
            self.last_signal = time.time()
            self.logger.info(
                "Updating {} aux work from a signal recieved!".format(
                    self.config['currency']))

        try:
            auxblock = self.call_rpc('getauxblock')
        except RPCException:
            sleep(2)
            return False

        hash = int(auxblock['hash'], 16)
        if hash != self.last_work['hash']:
            # We fetch the block height so we can see if the hash changed
            # because of a new network block, or because new transactions
            try:
                height = self.call_rpc('getblockcount')
            except RPCException:
                sleep(2)
                return False

            target_int = pack.IntType(256).unpack(
                auxblock['target'].decode('hex'))
            self.last_work.update(
                dict(hash=hash,
                     target=target_int,
                     type=self.config['currency'],
                     height=height,
                     found_block=self.found_block,
                     chainid=auxblock['chainid']))

            # only push the job if there's a new block height discovered.
            new_block = False
            if self.current_net['height'] != height:
                self.current_net['height'] = height
                self._incr("work_restarts")
                self._incr("new_jobs")
                self.new_job.flush = self.config['flush']
                new_block = True
            else:
                self._incr("new_jobs")
                self.new_job.flush = False
            self.new_job.set()
            self.new_job.clear()

            if new_block:
                self.current_net['last_block'] = time.time()
                self.current_net[
                    'difficulty'] = bitcoin_data.target_to_difficulty(
                        target_int)
                self.logger.info(
                    "New aux block announced! Diff {:,.4f}. Height {:,}".
                    format(self.current_net['difficulty'], height))

        return True
예제 #4
0
    def update(self, reason=None):
        if reason:
            self.logger.info("Updating {} aux work from a signal recieved!"
                             .format(self.config['name']))

        try:
            auxblock = self.call_rpc('getauxblock')
        except RPCException:
            sleep(2)
            return False

        new_merged_work = dict(
            hash=int(auxblock['hash'], 16),
            target=pack.IntType(256).unpack(auxblock['target'].decode('hex')),
            type=self.config['name']
        )
        if new_merged_work['hash'] != self.jobmanager.merged_work.get(auxblock['chainid'], {'hash': None})['hash']:
            # We fetch the block height so we can see if the hash changed
            # because of a new network block, or because new transactions
            try:
                height = self.call_rpc('getblockcount')
            except RPCException:
                sleep(2)
                return False
            self.logger.info("New aux work announced! Diff {:,.4f}. Height {:,}"
                             .format(bitcoin_data.target_to_difficulty(new_merged_work['target']),
                                     height))
            # add height to work spec for future logging
            new_merged_work['height'] = height

            self.jobmanager.merged_work[auxblock['chainid']] = new_merged_work
            self.current_net['difficulty'] = bitcoin_data.target_to_difficulty(pack.IntType(256).unpack(auxblock['target'].decode('hex')))

            # only push the job if there's a new block height discovered.
            if self.current_net['height'] != height:
                self.current_net['height'] = height
                self.jobmanager.generate_job(push=True, flush=self.config['flush'])
                self.server[self.prefix + "work_restarts"].incr()
                self.server[self.prefix + "new_jobs"].incr()
            else:
                self.jobmanager.generate_job()
                self.server[self.prefix + "new_jobs"].incr()

        return True
예제 #5
0
 def _run(self):
     while True:
         if self.net_state['poll_connection'] is None:
             logger.warn("Couldn't connect to any RPC servers, sleeping for 1")
             sleep(1)
             continue
         try:
             auxblock = self.coinserv.getauxblock()
         except Exception as e:
             logger.warn("Unable to communicate with aux chain server. {}"
                         .format(e))
             sleep(2)
             continue
         #logger.debug("Aux RPC returned: {}".format(auxblock))
         new_merged_work = dict(
             hash=int(auxblock['hash'], 16),
             target=pack.IntType(256).unpack(auxblock['target'].decode('hex')),
             merged_proxy=self.coinserv,
             monitor=self
         )
         self.aux_state['chain_id'] = auxblock['chainid']
         if new_merged_work != self.net_state['merged_work'].get(auxblock['chainid']):
             try:
                 height = self.coinserv.getblockcount()
             except Exception as e:
                 logger.warn("Unable to communicate with aux chain server. {}"
                             .format(e))
                 sleep(2)
                 continue
             logger.info("New aux work announced! Diff {}. RPC returned: {}"
                         .format(bitcoin_data.target_to_difficulty(new_merged_work['target']),
                                 new_merged_work))
             self.net_state['merged_work'][auxblock['chainid']] = new_merged_work
             self.aux_state['difficulty'] = bitcoin_data.target_to_difficulty(pack.IntType(256).unpack(auxblock['target'].decode('hex')))
             # only push the job if there's a new block height discovered.
             if self.aux_state['height'] != height:
                 self.aux_state['height'] = height
                 self.monitor_network.generate_job(push=True, flush=self.flush)
                 self.aux_state['work_restarts'] += 1
             else:
                 self.monitor_network.generate_job()
                 self.aux_state['new_jobs'] += 1
         sleep(self.work_interval)
예제 #6
0
    def _check_new_jobs(self, signal=False):
        if signal:
            self.last_signal = time.time()
            self.logger.info("Updating {} aux work from a signal recieved!"
                             .format(self.config['currency']))

        try:
            auxblock = self.call_rpc('getauxblock')
        except RPCException:
            sleep(2)
            return False

        hash = int(auxblock['hash'], 16)
        if hash != self.last_work['hash']:
            # We fetch the block height so we can see if the hash changed
            # because of a new network block, or because new transactions
            try:
                height = self.call_rpc('getblockcount')
            except RPCException:
                sleep(2)
                return False

            target_int = pack.IntType(256).unpack(auxblock['target'].decode('hex'))
            self.last_work.update(dict(
                hash=hash,
                target=target_int,
                type=self.config['currency'],
                height=height,
                found_block=self.found_block,
                chainid=auxblock['chainid']
            ))

            # only push the job if there's a new block height discovered.
            new_block = False
            if self.current_net['height'] != height:
                self.current_net['height'] = height
                self._incr("work_restarts")
                self._incr("new_jobs")
                self.new_job.flush = self.config['flush']
                new_block = True
            else:
                self._incr("new_jobs")
                self.new_job.flush = False
            self.new_job.set()
            self.new_job.clear()

            if new_block:
                self.current_net['last_block'] = time.time()
                self.current_net['difficulty'] = bitcoin_data.target_to_difficulty(target_int)
                self.logger.info("New aux block announced! Diff {:,.4f}. Height {:,}"
                                 .format(self.current_net['difficulty'], height))

        return True