Skip to content

Commit 8a2e2b9

Browse files
author
Atrides
committed
Failover server works now. Submit hashrates.
1 parent cb3db4e commit 8a2e2b9

File tree

9 files changed

+88
-57
lines changed

9 files changed

+88
-57
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ Originally developed for DwarfPool http://dwarfpool.com/eth
88

99
#Features
1010

11-
* Additional 10%~20% increase of earning compared to standard pools
11+
* Additional up to 20% increase of earning compared to standard pools
1212
* ETH stratum proxy
13+
* Automatically failover via proxy
1314
* Only one connection to the pool
1415
* Workers get new jobs immediately
1516
* Submit of shares without network delay, it's like solo-mining but with benefits of professional pool
1617
* Central Wallet configuration, miners doesn't need wallet as username
1718
* Support monitoring via email
1819
* Bypass worker_id for detailed statistic and per rig monitoring
19-
20+
* pass submitHashrate to pool
2021

2122
#How it works
2223

@@ -33,9 +34,7 @@ Originally developed for DwarfPool http://dwarfpool.com/eth
3334

3435
#ToDo
3536

36-
* Automatically failover via proxy
37-
* Create for Windows users compiled .exe file
38-
* pass submitHashrate to pool
37+
* ---
3938

4039

4140
#Configuration

eth-proxy.conf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
# You can provide workername:
1212
# - with url like "/rig1"
1313
# - or use automatically numbering(integer) based on IP of miner
14+
#
15+
# Servers:
16+
# EU-Server: eth-eu.dwarfpool.com (France)
17+
# US-Server: eth-us.dwarfpool.com (Montreal,Canada)
18+
# RU-Server: eth-ru.dwarfpool.com (Moscow)
19+
#
1420
###
1521

1622
# Host and port for your workers
@@ -29,12 +35,12 @@ MONITORING = False
2935
MONITORING_EMAIL = "[email protected]"
3036

3137
# Main pool
32-
POOL_HOST = "eth-ru.dwarfpool.com"
38+
POOL_HOST = "eth-eu.dwarfpool.com"
3339
POOL_PORT = 8008
3440

35-
# Failover pool. CURRENTLY DOESN'T WORK!
36-
POOL_FAILOVER_ENABLE = False
37-
POOL_HOST_FAILOVER = "eth-eu.dwarfpool.com"
41+
# Failover pool
42+
POOL_FAILOVER_ENABLE = True
43+
POOL_HOST_FAILOVER = "eth-us.dwarfpool.com"
3844
POOL_PORT_FAILOVER = 8008
3945

4046
# Logging

eth-proxy.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ def ping(f):
5050
def on_connect(f):
5151
'''Callback when proxy get connected to the pool'''
5252
log.info("Connected to Stratum pool at %s:%d" % f.main_host)
53+
f.is_connected = True
54+
f.remote_ip = f.client._get_ip()
5355
#reactor.callLater(30, f.client.transport.loseConnection)
5456

5557
# Hook to on_connect again
5658
f.on_connect.addCallback(on_connect)
5759

5860
# Get first job and user_id
59-
initial_job = (yield f.rpc('eth_submitLogin', [settings.WALLET, settings.CUSTOM_EMAIL], 'Proxy_'+version.VERSION))
61+
debug = "_debug" if settings.DEBUG else ""
62+
initial_job = (yield f.rpc('eth_submitLogin', [settings.WALLET, settings.CUSTOM_EMAIL], 'Proxy_'+version.VERSION+debug))
6063

6164
reactor.callLater(0, ping, f)
6265

@@ -65,51 +68,48 @@ def on_connect(f):
6568
def on_disconnect(f):
6669
'''Callback when proxy get disconnected from the pool'''
6770
log.info("Disconnected from Stratum pool at %s:%d" % f.main_host)
71+
f.is_connected = False
6872
f.on_disconnect.addCallback(on_disconnect)
6973

70-
# Prepare to failover, currently works very bad
71-
#if f.main_host==(settings.POOL_HOST, settings.POOL_PORT):
72-
# main()
73-
#else:
74-
# f.is_reconnecting = False
75-
#return f
76-
7774
@defer.inlineCallbacks
7875
def main():
7976
reactor.disconnectAll()
80-
failover = False
81-
if settings.POOL_FAILOVER_ENABLE:
82-
failover = settings.failover_pool
83-
settings.failover_pool = not settings.failover_pool
84-
85-
pool_host = settings.POOL_HOST
86-
pool_port = settings.POOL_PORT
87-
if failover and settings.POOL_FAILOVER_ENABLE:
88-
pool_host = settings.POOL_HOST_FAILOVER
89-
pool_port = settings.POOL_PORT_FAILOVER
9077

9178
log.warning("Ethereum Stratum proxy version: %s" % version.VERSION)
92-
log.warning("Trying to connect to Stratum pool at %s:%d" % (pool_host, pool_port))
9379

9480
# Connect to Stratum pool, main monitoring connection
95-
f = SocketTransportClientFactory(pool_host, pool_port,
81+
log.warning("Trying to connect to Stratum pool at %s:%d" % (settings.POOL_HOST, settings.POOL_PORT))
82+
f = SocketTransportClientFactory(settings.POOL_HOST, settings.POOL_PORT,
83+
debug=settings.DEBUG, proxy=None,
84+
event_handler=client_service.ClientMiningService)
85+
f.is_failover = False
86+
87+
ff = None
88+
if settings.POOL_FAILOVER_ENABLE:
89+
log.warning("Trying to connect to failover Stratum pool at %s:%d" % (settings.POOL_HOST_FAILOVER, settings.POOL_PORT_FAILOVER))
90+
ff = SocketTransportClientFactory(settings.POOL_HOST_FAILOVER, settings.POOL_PORT_FAILOVER,
9691
debug=settings.DEBUG, proxy=None,
9792
event_handler=client_service.ClientMiningService)
93+
ff.is_failover = True
9894

99-
job_registry = jobs.JobRegistry(f)
95+
job_registry = jobs.JobRegistry(f,ff)
10096
client_service.ClientMiningService.job_registry = job_registry
10197
client_service.ClientMiningService.reset_timeout()
10298

10399
f.on_connect.addCallback(on_connect)
104100
f.on_disconnect.addCallback(on_disconnect)
105101
# Cleanup properly on shutdown
106102
reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, f)
103+
if ff:
104+
ff.on_connect.addCallback(on_connect)
105+
ff.on_disconnect.addCallback(on_disconnect)
106+
reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, ff)
107107

108108
# Block until proxy connect to the pool
109109
try:
110110
yield f.on_connect
111111
except TransportException:
112-
log.warning("First pool server must be online first time to start failover")
112+
log.warning("First pool server must be online first time during start")
113113
return
114114

115115
conn = reactor.listenTCP(settings.PORT, Site(getwork_listener.Root(job_registry, settings.ENABLE_WORKER_ID)), interface=settings.HOST)
@@ -133,14 +133,13 @@ def main():
133133
if settings.MONITORING:
134134
log.warning("Email monitoring on %s" % settings.MONITORING_EMAIL)
135135
else:
136-
log.warning("Email monitoring diasbled")
137-
#log.warning("Failover enabled: %" % settings.POOL_FAILOVER_ENABLE)
136+
log.warning("Email monitoring disabled")
137+
log.warning("Failover enabled: %s" % settings.POOL_FAILOVER_ENABLE)
138138
log.warning("-----------------------------------------------------------------------")
139139

140140
if __name__ == '__main__':
141141
fp = file("eth-proxy.pid", 'w')
142142
fp.write(str(os.getpid()))
143143
fp.close()
144-
settings.failover_pool = False
145144
main()
146145
reactor.run()

mining_libs/client_service.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ def reset_timeout(cls):
1818
cls.timeout.cancel()
1919
cls.timeout = None
2020

21-
cls.timeout = reactor.callLater(960, cls.on_timeout)
21+
cls.timeout = reactor.callLater(180, cls.on_timeout)
2222

2323
@classmethod
2424
def on_timeout(cls):
2525
'''
26-
Try to reconnect to the pool after 16 minutes of no activity on the connection.
26+
Try to reconnect to the pool after 3 minutes of no activity on the connection.
2727
It will also drop all Stratum connections to sub-miners
2828
to indicate connection issues.
2929
'''
3030
log.error("Connection to upstream pool timed out")
3131
cls.reset_timeout()
32-
cls.job_registry.f.reconnect()
33-
32+
if not cls.job_registry.f.is_connected:
33+
cls.job_registry.f.reconnect()
34+
if cls.job_registry.ff and not cls.job_registry.ff.is_connected:
35+
cls.job_registry.ff.reconnect()
36+
3437
def handle_event(self, method, params, connection_ref):
3538
'''Handle RPC calls and notifications from the pool'''
3639
# Yay, we received something from the pool,
@@ -41,11 +44,7 @@ def handle_event(self, method, params, connection_ref):
4144
'''Proxy just received information about new mining job'''
4245
# Broadcast to getwork clients
4346
job = Job.build_from_pool(params)
44-
if stratum.logger.settings.DEBUG:
45-
log.debug("NEW_JOB %s" % params)
46-
else:
47-
log.info("NEW_JOB")
48-
self.job_registry.replace_job(job)
47+
self.job_registry.replace_job(job, connection_ref)
4948

5049
else:
5150
'''Pool just asked us for something which we don't support...'''

mining_libs/getwork_listener.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, job_registry, enable_worker_id):
1515
Resource.__init__(self)
1616
self.job_registry = job_registry
1717
self.isWorkerID = enable_worker_id
18+
self.submitHashrates = {}
1819

1920
def json_response(self, msg_id, result):
2021
resp = json.dumps({'id': msg_id, 'jsonrpc': '2.0', 'result': result})
@@ -47,7 +48,11 @@ def render_POST(self, request):
4748
else:
4849
worker_name = ''
4950

50-
if data['method'] == 'eth_submitWork': # ToFix!!!!
51+
if data['method'] == 'eth_submitHashrate':
52+
if worker_name and (not self.submitHashrates.has_key(worker_name) or int(time.time())-self.submitHashrates[worker_name]>=60):
53+
self.submitHashrates[worker_name] = int(time.time())
54+
threads.deferToThread(self.job_registry.submit, data['method'], data['params'], worker_name)
55+
elif data['method'] == 'eth_submitWork':
5156
threads.deferToThread(self.job_registry.submit, data['method'], data['params'], worker_name)
5257
response = self.json_response(data.get('id', 0), True)
5358
else:

mining_libs/jobs.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,44 @@ def build_from_pool(cls, getWorkParams):
1616
return job
1717

1818
class JobRegistry(object):
19-
def __init__(self, f):
19+
def __init__(self, f, ff):
2020
self.f = f
21+
self.ff = ff
2122
self.jobs = None
2223
# Hook for LP broadcasts
2324
self.on_block = defer.Deferred()
2425

25-
def replace_job(self, newjob):
26-
self.jobs = newjob
27-
# Force miners to reload jobs
28-
on_block = self.on_block
29-
self.on_block = defer.Deferred()
30-
on_block.callback(True)
26+
def replace_job(self, newjob, connection_ref):
27+
is_main_pool = connection_ref._get_ip() == self.f.remote_ip
28+
if is_main_pool:
29+
log_text = "MAIN NEW_JOB"
30+
else:
31+
log_text = "FAILOVER NEW_JOB"
32+
33+
if (self.f.is_connected and is_main_pool) or (not self.f.is_connected and self.ff and self.ff.is_connected and not is_main_pool):
34+
if stratum.logger.settings.DEBUG:
35+
log.debug("%s %s" % (log_text, newjob.params))
36+
else:
37+
log.info(log_text)
38+
self.jobs = newjob
39+
# Force miners to reload jobs
40+
on_block = self.on_block
41+
self.on_block = defer.Deferred()
42+
on_block.callback(True)
43+
elif stratum.logger.settings.DEBUG:
44+
log.debug("%s NOT_USED %s" % (log_text, newjob.params))
3145

3246
def submit(self, method, params, worker_name):
47+
log_text = ""
3348
if settings.DEBUG:
34-
log.info("%s by %s %s" % (method, worker_name, params))
35-
else:
36-
log.info("%s by %s" % (method, worker_name) )
37-
self.f.rpc(method, params, worker_name)
49+
log_text = "%s by %s %s" % (method, worker_name, params)
50+
elif method=="eth_submitWork":
51+
log_text = "%s by %s" % (method, worker_name)
52+
if self.f.is_connected:
53+
if log_text:
54+
log.info( "MAIN %s" % log_text )
55+
self.f.rpc(method, params, worker_name)
56+
elif self.ff and self.ff.is_connected:
57+
if log_text:
58+
log.info( "FAILOVER %s" % log_text )
59+
self.ff.rpc(method, params, worker_name)

mining_libs/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION='0.0.3'
1+
VERSION='0.0.4'

stratum/config_default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
POOL_HOST = 'eth-ru.dwarfpool.com'
157157
POOL_PORT = 8008
158158

159-
# Failover pool. CURRENTLY DOESN'T WORK!
159+
# Failover pool.
160160
POOL_FAILOVER_ENABLE = False
161161
POOL_HOST_FAILOVER = 'eth-eu.dwarfpool.com'
162162
POOL_PORT_FAILOVER = 8008

stratum/socket_transport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, host, port, allow_trusted=True, allow_untrusted=False,
3232
is_reconnecting=True, proxy=None,
3333
event_handler=GenericEventHandler):
3434
self.debug = debug
35+
self.maxDelay = 60
3536
self.is_reconnecting = is_reconnecting
3637
self.signing_key = signing_key
3738
self.signing_id = signing_id

0 commit comments

Comments
 (0)