Final GetWork Proxy Commit

This commit is contained in:
Ahmed Bodiwala 2013-11-20 11:39:36 +00:00
parent 429baa72a5
commit 61c3400098
4 changed files with 107 additions and 3 deletions

View File

@ -16,6 +16,12 @@ COINDAEMON_TRUSTED_PORT = 8332
COINDAEMON_TRUSTED_USER = 'user'
COINDAEMON_TRUSTED_PASSWORD = 'somepassword'
# Coin Algorithm is the option used to determine the algortithm used by stratum
# This currently only works with POW SHA256 and Scrypt Coins
# The available options are scrypt and sha256d.
# If the option does not meet either of these criteria stratum defaults to scrypt
COINDAEMON_ALGO = 'scrypt'
# ******************** BASIC SETTINGS ***************
# Backup Coin Daemon address's (consider having at least 1 backup)
# You can have up to 99
@ -61,7 +67,7 @@ ENABLE_EXAMPLE_SERVICE = False
HOSTNAME = 'localhost'
# Port used for Socket transport. Use 'None' for disabling the transport.
LISTEN_SOCKET_TRANSPORT = 3333
LISTEN_SOCKET_TRANSPORT = 3313
# Port used for HTTP Poll transport. Use 'None' for disabling the transport
LISTEN_HTTP_TRANSPORT = None
# Port used for HTTPS Poll transport
@ -142,6 +148,13 @@ VDIFF_VARIANCE_PERCENT = 20 # Allow average time to very this % from target with
# For block confirmation, we have an option to send the block hash in
# Please make sure your front end is compatible with the block hash in the solutions table.
# For People using the MPOS frontend enabling this is recommended. It allows the frontend to compare the block hash to the coin daemon reducing the liklihood of missing share error's for blocks
SOLUTION_BLOCK_HASH = False # If enabled, enter the block hash. If false enter the scrypt/sha hash into the shares table
SOLUTION_BLOCK_HASH = True # If enabled, enter the block hash. If false enter the scrypt/sha hash into the shares table
# ******************** Getwork Proxy Settings *********************
# This enables a copy of slush's getwork proxy for old clients
# It will also auto-redirect new clients to the stratum interface
# so you can point ALL clients to: http://<yourserver>:<GW_PORT>
GW_ENABLE = True # Enable the Proxy
GW_PORT = 3333 # Getwork Proxy Port
GW_DISABLE_MIDSTATE = False # Disable midstate's (Faster but breaks some clients)
GW_SEND_REAL_TARGET = True # Propigate >1 difficulty to Clients (breaks some clients)

3
externals/update_submodules vendored Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
git submodule foreach git pull origin master

View File

@ -34,3 +34,7 @@ Interfaces.set_worker_manager(WorkerManagerInterface())
Interfaces.set_timestamper(TimestamperInterface())
mining.setup(on_startup)
if settings.GW_ENABLE == True :
from lib.getwork_proxy import GetworkProxy
GetworkProxy(on_startup)

84
lib/getwork_proxy.py Normal file
View File

@ -0,0 +1,84 @@
import stratum.logger
log = stratum.logger.get_logger('Getwork Proxy')
from stratum import settings
from stratum.socket_transport import SocketTransportClientFactory
from twisted.internet import reactor, defer
from twisted.web import server
from mining_libs import getwork_listener
from mining_libs import client_service
from mining_libs import jobs
from mining_libs import worker_registry
from mining_libs import version
class Site(server.Site):
def log(self, request):
pass
def on_shutdown(f):
log.info("Shutting down proxy...")
f.is_reconnecting = False # Don't let stratum factory to reconnect again
@defer.inlineCallbacks
def on_connect(f, workers, job_registry):
log.info("Connected to Stratum pool at %s:%d" % f.main_host)
# Hook to on_connect again
f.on_connect.addCallback(on_connect, workers, job_registry)
# Every worker have to re-autorize
workers.clear_authorizations()
# Subscribe for receiving jobs
log.info("Subscribing for mining jobs")
(_, extranonce1, extranonce2_size) = (yield f.rpc('mining.subscribe', []))
job_registry.set_extranonce(extranonce1, extranonce2_size)
defer.returnValue(f)
def on_disconnect(f, workers, job_registry):
log.info("Disconnected from Stratum pool at %s:%d" % f.main_host)
f.on_disconnect.addCallback(on_disconnect, workers, job_registry)
# Reject miners because we don't give a *job :-)
workers.clear_authorizations()
return f
@defer.inlineCallbacks
def GetworkProxy_main(cb):
log.info("Stratum proxy version %s Connecting to Pool..." % version.VERSION)
# Connect to Stratum pool
f = SocketTransportClientFactory(settings.HOSTNAME, settings.LISTEN_SOCKET_TRANSPORT,
debug=False, proxy=None, event_handler=client_service.ClientMiningService)
job_registry = jobs.JobRegistry(f, cmd='', no_midstate=settings.GW_DISABLE_MIDSTATE, real_target=settings.GW_SEND_REAL_TARGET)
client_service.ClientMiningService.job_registry = job_registry
client_service.ClientMiningService.reset_timeout()
workers = worker_registry.WorkerRegistry(f)
f.on_connect.addCallback(on_connect, workers, job_registry)
f.on_disconnect.addCallback(on_disconnect, workers, job_registry)
# Cleanup properly on shutdown
reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, f)
# Block until proxy connects to the pool
yield f.on_connect
# Setup getwork listener
gw_site = Site(getwork_listener.Root(job_registry, workers,
stratum_host=settings.HOSTNAME, stratum_port=settings.LISTEN_SOCKET_TRANSPORT,
custom_lp=False, custom_stratum=False,
custom_user=False, custom_password=False
))
gw_site.noisy = False
reactor.listenTCP(settings.GW_PORT, gw_site, interface='0.0.0.0')
log.info("Getwork Proxy is online, Port: %d" % (settings.GW_PORT))
def GetworkProxy(start_event):
start_event.addCallback(GetworkProxy_main)