示例#1
0
文件: daemon.py 项目: ssv1982/nuxhash
    def run(self):
        # Initialize miners.
        logging.info('Querying NiceHash for miner connection information...')
        payrates = stratums = None
        while payrates is None:
            try:
                payrates, stratums = nicehash.simplemultialgo_info(
                    self._settings)
            except NH_EXCEPTIONS as err:
                logging.warning('NiceHash stats: %s, retrying in 5 seconds' %
                                err)
                time.sleep(5)
            else:
                self._payrates = (payrates, datetime.now())
        for miner in self._miners:
            miner.stratums = stratums
            miner.load()
        self._algorithms = sum([miner.algorithms for miner in self._miners],
                               [])

        # Initialize profit-switching.
        self._profit_switch = NaiveSwitcher(self._settings)
        self._profit_switch.reset()

        # Attach the SIGINT signal for quitting.
        # NOTE: If running in a shell, Ctrl-C will get sent to our subprocesses too,
        #       because we are the foreground process group. Miners will get killed
        #       before we have a chance to properly shut them down.
        signal.signal(signal.SIGINT, lambda signum, frame: self.stop())

        self._scheduler.enter(0, MiningSession.PROFIT_PRIORITY,
                              self._switch_algos)
        self._scheduler.run()
示例#2
0
文件: daemon.py 项目: Kunal0cr7/fread
    def run(self):
        # Initialize miners.
        logging.info('Querying NiceHash for miner connection information...')
        payrates = stratums = None
        while payrates is None:
            try:
                payrates = nicehash.simplemultialgo_info(self._settings)
                stratums = nicehash.stratums(self._settings)
            except Exception as err:
                logging.warning(
                    f'NiceHash stats: {err}, retrying in 5 seconds')
                time.sleep(5)
            else:
                self._payrates = (payrates, datetime.now())
        for miner in self._miners:
            miner.stratums = stratums
            miner.load()
        self._algorithms = sum([miner.algorithms for miner in self._miners],
                               [])

        # Initialize profit-switching.
        self._profit_switch = NaiveSwitcher(self._settings)
        self._profit_switch.reset()

        self._scheduler.enter(0, MiningSession.PROFIT_PRIORITY,
                              self._switch_algos)
        self._scheduler.run()
示例#3
0
文件: mining.py 项目: richwu/nuxhash
    def run(self):
        # Initialize miners.
        stratums = None
        while stratums is None:
            try:
                payrates, stratums = nicehash.simplemultialgo_info(
                    self._settings)
            except (socket.error, socket.timeout, SSLError, URLError):
                time.sleep(5)
        self._miners = [miner(main.CONFIG_DIR) for miner in all_miners]
        for miner in self._miners:
            miner.settings = self._settings
            miner.stratums = stratums
        self._algorithms = sum([miner.algorithms for miner in self._miners],
                               [])

        # Initialize profit-switching.
        self._profit_switch = NaiveSwitcher(self._settings)
        self._profit_switch.reset()

        self._scheduler.enter(0, MiningThread.PROFIT_PRIORITY,
                              self._switch_algos)
        self._scheduler.enter(0, MiningThread.STATUS_PRIORITY,
                              self._read_status)
        self._scheduler.run()
示例#4
0
文件: mining.py 项目: ssv1982/nuxhash
    def run(self):
        # Initialize miners.
        stratums = None
        while stratums is None:
            try:
                payrates, stratums = nicehash.simplemultialgo_info(
                    self._settings)
            except NH_EXCEPTIONS as err:
                logging.warning('NiceHash stats: %s, retrying in 5 seconds' % err)
                time.sleep(5)
            else:
                self._payrates = payrates
        self._miners = [miner(main.CONFIG_DIR) for miner in all_miners]
        for miner in self._miners:
            miner.settings = self._settings
            miner.stratums = stratums
        self._algorithms = sum([miner.algorithms for miner in self._miners], [])

        # Initialize profit-switching.
        self._profit_switch = NaiveSwitcher(self._settings)
        self._profit_switch.reset()

        self._scheduler.enter(0, MiningThread.PROFIT_PRIORITY, self._switch_algos)
        self._scheduler.enter(0, MiningThread.STATUS_PRIORITY, self._read_status)
        self._scheduler.run()
示例#5
0
文件: daemon.py 项目: richwu/nuxhash
    def run(self):
        # Initialize miners.
        logging.info('Querying NiceHash for miner connection information...')
        payrates = stratums = None
        while payrates is None:
            try:
                payrates, stratums = nicehash.simplemultialgo_info(self._settings)
            except (socket.error, socket.timeout, SSLError, URLError):
                time.sleep(5)
            else:
                self._last_payrates = (payrates, datetime.now())
        for miner in self._miners:
            miner.stratums = stratums
            miner.load()
        self._algorithms = sum([miner.algorithms for miner in self._miners], [])

        # Initialize profit-switching.
        self._profit_switch = NaiveSwitcher(self._settings)
        self._profit_switch.reset()

        # Attach the SIGINT signal for quitting.
        signal.signal(signal.SIGINT, lambda signum, frame: self.stop())

        self._scheduler.enter(0, MiningSession.PROFIT_PRIORITY, self._switch_algos)
        self._scheduler.run()
示例#6
0
def run_missing_benchmarks(miners, settings, devices, old_benchmarks):
    mbtc_per_hash, stratums = nicehash.simplemultialgo_info(settings)

    algorithms = sum([miner.algorithms for miner in miners], [])
    def algorithm(name): return next((algorithm for algorithm in algorithms
                                      if algorithm.name == name), None)

    # Temporarily suppress logging.
    logger = logging.getLogger()
    log_level = logger.getEffectiveLevel()
    logger.setLevel(logging.ERROR)
    for miner in miners:
        miner.stratums = stratums
        miner.load()

    done = sum([[(device, algorithm(algorithm_name))
                 for algorithm_name in benchmarks.keys()]
                for device, benchmarks in old_benchmarks.items()], [])
    all_targets = sum([[(device, algorithm) for algorithm in algorithms]
                       for device in devices], [])
    benchmarks = run_benchmarks(set(all_targets) - set(done))

    for miner in miners:
        miner.unload()
    logger.setLevel(log_level)

    for d in benchmarks:
        old_benchmarks[d].update(benchmarks[d])
    return old_benchmarks
示例#7
0
文件: mining.py 项目: richwu/nuxhash
    def _switch_algos(self):
        interval = self._settings['switching']['interval']

        # Get profitability information from NiceHash.
        try:
            payrates, stratums = nicehash.simplemultialgo_info(self._settings)
        except (socket.error, socket.timeout, SSLError, URLError) as err:
            logging.warning('NiceHash stats: %s' % err)
        except nicehash.BadResponseError:
            logging.warning('NiceHash stats: Bad response')
        else:
            download_time = datetime.now()
            self._current_payrates = payrates

        # Calculate BTC/day rates.
        def revenue(device, algorithm):
            benchmarks = self._benchmarks[device]
            if algorithm.name in benchmarks:
                return sum([
                    payrates[algorithm.algorithms[i]] *
                    benchmarks[algorithm.name][i]
                    for i in range(len(algorithm.algorithms))
                ])
            else:
                return 0.0

        revenues = {
            device: {
                algorithm: revenue(device, algorithm)
                for algorithm in self._algorithms
            }
            for device in self._devices
        }

        # Get device -> algorithm assignments from profit switcher.
        assigned_algorithm = self._profit_switch.decide(
            revenues, download_time)
        self._assignments = assigned_algorithm
        for this_algorithm in self._algorithms:
            this_devices = [
                device for device, algorithm in assigned_algorithm.items()
                if algorithm == this_algorithm
            ]
            this_algorithm.set_devices(this_devices)

        # Donation time.
        if not self._settings['donate']['optout'] and random() < DONATE_PROB:
            logging.warning('This interval will be donation time.')
            donate_settings = deepcopy(self._settings)
            donate_settings['nicehash']['wallet'] = DONATE_ADDRESS
            donate_settings['nicehash']['workername'] = 'nuxhash'
            for miner in self._miners:
                miner.settings = donate_settings
            self._scheduler.enter(interval, MiningThread.PROFIT_PRIORITY,
                                  self._reset_miners)

        self._scheduler.enter(interval, MiningThread.PROFIT_PRIORITY,
                              self._switch_algos)
示例#8
0
    def _switch_algos(self):
        # Get profitability information from NiceHash.
        try:
            ret_payrates = nicehash.simplemultialgo_info(self._settings)
        except Exception as err:
            logging.warning(f'NiceHash stats: {err}')
        else:
            self._payrates = (ret_payrates, datetime.now())

        interval = self._settings['switching']['interval']
        payrates, payrates_time = self._payrates

        # Calculate BTC/day rates.
        def revenue(device, algorithm):
            benchmarks = self._benchmarks[device]
            if algorithm.name in benchmarks:
                return sum([
                    payrates[sub_algo] * benchmarks[algorithm.name][i]
                    if sub_algo in payrates else 0.0
                    for i, sub_algo in enumerate(algorithm.algorithms)
                ])
            else:
                return 0.0

        revenues = {
            device: {
                algorithm: revenue(device, algorithm)
                for algorithm in self._algorithms
            }
            for device in self._devices
        }

        # Get device -> algorithm assignments from profit switcher.
        assigned_algorithm = self._profit_switch.decide(
            revenues, payrates_time)
        self._assignments = assigned_algorithm
        for this_algorithm in self._algorithms:
            this_devices = [
                device for device, algorithm in assigned_algorithm.items()
                if algorithm == this_algorithm
            ]
            this_algorithm.set_devices(this_devices)

        # Donation time.
        if not self._settings['donate']['optout'] and random() < DONATE_PROB:
            logging.warning('This interval will be donation time.')
            donate_settings = deepcopy(self._settings)
            donate_settings['nicehash']['wallet'] = DONATE_ADDRESS
            donate_settings['nicehash']['workername'] = 'nuxhash'
            for miner in self._miners:
                miner.settings = donate_settings
            self._scheduler.enter(interval, MiningThread.PROFIT_PRIORITY,
                                  self._reset_miners)

        self._scheduler.enter(interval, MiningThread.PROFIT_PRIORITY,
                              self._switch_algos)
示例#9
0
def do_mining(nx_miners, nx_settings, nx_benchmarks, nx_devices):
    # Initialize miners.
    logging.info('Querying NiceHash for miner connection information...')
    mbtc_per_hash = download_time = stratums = None
    while mbtc_per_hash is None:
        try:
            mbtc_per_hash, stratums = nicehash.simplemultialgo_info(nx_settings)
        except (socket.error, socket.timeout, SSLError, URLError):
            sleep(5)
        else:
            download_time = datetime.now()
    for miner in nx_miners:
        miner.stratums = stratums
    algorithms = sum([miner.algorithms for miner in nx_miners], [])

    # Initialize profit-switching.
    profit_switch = NaiveSwitcher(nx_settings)
    profit_switch.reset()

    # SIGINT signal for quitting.
    quit = Event()
    signal.signal(signal.SIGINT, lambda signum, frame: quit.set())

    current_algorithm = {d: None for d in nx_devices}
    revenues = {d: defaultdict(lambda: 0.0) for d in nx_devices}
    while not quit.is_set():
        # Calculate BTC/day rates.
        def revenue(device, algorithm):
            benchmarks = nx_benchmarks[device]
            if algorithm.name in benchmarks:
                return sum([mbtc_per_hash[algorithm.algorithms[i]]
                            *benchmarks[algorithm.name][i]]
                            for i in range(len(algorithm.algorithms))])
            else:
                return 0.0
        revenues = {device: {algorithm: revenue(device, algorithm)
                             for algorithm in algorithms}
                    for device in nx_devices}

        # Get device -> algorithm assignments from profit switcher.
        current_algorithm = profit_switch.decide(revenues, download_time)
        for this_algorithm in algorithms:
            this_devices = [device for device, algorithm
                            in current_algorithm.items()
                            if algorithm == this_algorithm]
            this_algorithm.set_devices(my_devices)
示例#10
0
    def _switch_algos(self):
        # Get profitability information from NiceHash.
        try:
            payrates, stratums = nicehash.simplemultialgo_info(self._settings)
        except (socket.error, socket.timeout, SSLError, URLError) as err:
            logging.warning('NiceHash stats: %s' % err)
        except nicehash.BadResponseError:
            logging.warning('NiceHash stats: Bad response')
        else:
            download_time = datetime.now()
            self._current_payrates = payrates

        # Calculate BTC/day rates.
        def revenue(device, algorithm):
            benchmarks = self._benchmarks[device]
            if algorithm.name in benchmarks:
                return sum([
                    payrates[algorithm.algorithms[i]] *
                    benchmarks[algorithm.name][i]
                    for i in range(len(algorithm.algorithms))
                ])
            else:
                return 0.0

        revenues = {
            device: {
                algorithm: revenue(device, algorithm)
                for algorithm in self._algorithms
            }
            for device in self._devices
        }

        # Get device -> algorithm assignments from profit switcher.
        assigned_algorithm = self._profit_switch.decide(
            revenues, download_time)
        self._assignments = assigned_algorithm
        for this_algorithm in self._algorithms:
            this_devices = [
                device for device, algorithm in assigned_algorithm.items()
                if algorithm == this_algorithm
            ]
            this_algorithm.set_devices(this_devices)

        self._scheduler.enter(self._settings['switching']['interval'],
                              MiningThread.PROFIT_PRIORITY, self._switch_algos)
示例#11
0
 def setUp(self):
     settings = DEFAULT_SETTINGS
     settings['nicehash']['region'] = 'eu'
     self.payrates, self.stratums = nicehash.simplemultialgo_info(settings)
示例#12
0
        # Get device -> algorithm assignments from profit switcher.
        current_algorithm = profit_switch.decide(revenues, download_time)
        for this_algorithm in algorithms:
            this_devices = [device for device, algorithm
                            in current_algorithm.items()
                            if algorithm == this_algorithm]
            this_algorithm.set_devices(my_devices)

        quit.wait(nx_settings['switching']['interval'])

        for algorithm in current_algorithm.values():
            if not algorithm.parent.is_running():
                logging.error('Detected %s crash, restarting miner'
                              % algorithm.name)
                algorithm.parent.reload()

        try:
            mbtc_per_hash, stratums = nicehash.simplemultialgo_info(nx_settings)
        except (socket.error, socket.timeout, SSLError, URLError) as err:
            logging.warning('NiceHash stats: %s' % err)
        except nicehash.BadResponseError:
            logging.warning('NiceHash stats: Bad response')
        else:
            download_time = datetime.now()

    logging.info('Cleaning up')
    for miner in nx_miners:
        miner.unload()

示例#13
0
 def test_payrate(self):
     mbtc_per_hash = nh.simplemultialgo_info(self.settings)
     self.assertGreater(mbtc_per_hash['cryptonight'], 0.0)