Skip to content

Commit

Permalink
Implement planned 0.5% donation fee.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Young committed Oct 8, 2018
1 parent da40143 commit 1395f66
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ $ sudo pip3 install git+https://github.com/YoRyan/nuxhash

To start the daemon, run `nuxhashd`. To start the graphical interface, run `nuxhash-gui`.

### Donation Fee

nuxhash will donate 0.5% of its mining time to me. If you don't like this, you
may opt out by setting the flag in the configuration file (located by default at
`~/.config/nuxhash/settings.conf`). Currently, there are no penalties if you do
so, but please consider sending me a one-time donation.

## Roadmap

- [x] Daemon with basic mining logic
Expand Down
26 changes: 24 additions & 2 deletions nuxhash/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import socket
import sys
import time
from copy import deepcopy
from datetime import datetime
from pathlib import Path
from random import random
from ssl import SSLError
from threading import Event
from urllib.error import URLError
Expand All @@ -24,6 +26,8 @@


BENCHMARK_SECS = 60
DONATE_PROB = 0.005
DONATE_ADDRESS = '3Qe7nT9hBSVoXr8rM2TG6pq82AmLVKHy23'


def main():
Expand Down Expand Up @@ -228,6 +232,7 @@ def run(self):
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.
Expand All @@ -246,6 +251,8 @@ def stop(self):
self._quit_signal.set()

def _switch_algos(self):
interval = self._settings['switching']['interval']

# Get profitability information from NiceHash.
try:
payrates, stratums = nicehash.simplemultialgo_info(self._settings)
Expand Down Expand Up @@ -278,8 +285,23 @@ def revenue(device, algorithm):
if algorithm == this_algorithm]
this_algorithm.set_devices(this_devices)

self._scheduler.enter(self._settings['switching']['interval'],
MiningSession.PROFIT_PRIORITY, self._switch_algos)
# 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, MiningSession.PROFIT_PRIORITY,
self._reset_miners)

self._scheduler.enter(interval, MiningSession.PROFIT_PRIORITY,
self._switch_algos)

def _reset_miners(self):
for miner in self._miners:
miner.settings = self._settings

def _watch_algos(self):
running_algorithms = self._assignments.values()
Expand Down
24 changes: 22 additions & 2 deletions nuxhash/gui/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from copy import deepcopy
from datetime import datetime
from random import random
from ssl import SSLError
from urllib.error import URLError

Expand All @@ -24,6 +25,8 @@
MINING_UPDATE_SECS = 5
BALANCE_UPDATE_MIN = 5
NVIDIA_COLOR = (66, 244, 69)
DONATE_PROB = 0.005
DONATE_ADDRESS = '3Qe7nT9hBSVoXr8rM2TG6pq82AmLVKHy23'


class MiningScreen(wx.Panel):
Expand Down Expand Up @@ -339,6 +342,8 @@ def stop(self):
self.join()

def _switch_algos(self):
interval = self._settings['switching']['interval']

# Get profitability information from NiceHash.
try:
payrates, stratums = nicehash.simplemultialgo_info(self._settings)
Expand Down Expand Up @@ -372,8 +377,23 @@ def revenue(device, algorithm):
if algorithm == this_algorithm]
this_algorithm.set_devices(this_devices)

self._scheduler.enter(self._settings['switching']['interval'],
MiningThread.PROFIT_PRIORITY, self._switch_algos)
# 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, MiningSession.PROFIT_PRIORITY,
self._reset_miners)

self._scheduler.enter(interval, MiningThread.PROFIT_PRIORITY,
self._switch_algos)

def _reset_miners(self):
for miner in self._miners:
miner.settings = self._settings

def _read_status(self):
running_algorithms = self._assignments.values()
Expand Down
14 changes: 3 additions & 11 deletions nuxhash/miners/excavator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def settings(self, v):

def start(self):
"""Launches excavator."""

assert self._process is None
assert self._region is not None and self._auth is not None
self._address = ('127.0.0.1', get_port())

Expand Down Expand Up @@ -111,15 +111,9 @@ def _subscribe(self):
'subscribe', ['nhmp.%s.nicehash.com:%s' % (self._region, NHMP_PORT),
self._auth])

def restart(self):
"""Restarts excavator."""
self.stop()
self.start()

def stop(self):
"""Stops excavator."""
if self._process is None or self._process.poll() is not None:
return
assert self._process is not None and self._process.poll() is None

# Disconnect from NiceHash.
self.send_command('unsubscribe', [])
Expand All @@ -130,6 +124,7 @@ def stop(self):
s.sendall(js_data.encode('ascii'))

self._process.wait()
self._process = None

def is_running(self):
return (self._process is not None
Expand Down Expand Up @@ -344,9 +339,6 @@ def load(self):
def unload(self):
self.server.stop()

def reload(self):
self.server.restart()

def is_running(self):
return self.server.is_running()

Expand Down
6 changes: 1 addition & 5 deletions nuxhash/miners/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def unload(self):
"""Clean up after load()."""
pass

def reload(self):
"""Restart the miner in the event of an unusual condition (crash)."""
pass

def is_running(self):
"""Probe if the miner is operational."""
pass
Expand Down Expand Up @@ -108,7 +104,7 @@ def needs_miner_running(method):
@wraps(method)
def wrapper(self, *args, **kwargs):
if not self.parent.is_running():
self.parent.reload()
self.parent.load()
return method(self, *args, **kwargs)
return wrapper

Expand Down
6 changes: 6 additions & 0 deletions nuxhash/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
'gui': {
'units': 'mBTC'
},
'donate': {
'optout': False
}
}
EMPTY_BENCHMARKS = defaultdict(lambda: {})
Expand All @@ -45,6 +48,9 @@ def get_option(parser_method, section, option):
},
'gui': {
'units': get_option(parser.get, 'gui', 'units')
},
'donate': {
'optout': get_option(parser.getboolean, 'donate', 'optout')
}
}

Expand Down

0 comments on commit 1395f66

Please sign in to comment.