Skip to content

Commit

Permalink
Support configuration of work update interval
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Jun 14, 2016
1 parent 460b0ca commit 28c9c02
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ WorkQueueSizeClear = (0x1000, 0x2000)
# (used for longpolls)
WorkQueueSizeLongpoll = (0x1000, 0x2000)

# How often to send new jobs to miners
WorkUpdateInterval = 55

# How long to wait between bitcoind GBT updates normally
MinimumTxnUpdateWait = 5

Expand Down
16 changes: 12 additions & 4 deletions eloipool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import argparse
import importlib
import struct
import util
argparser = argparse.ArgumentParser()
argparser.add_argument('-c', '--config', help='Config name to load from config_<ARG>.py')
args = argparser.parse_args()
Expand All @@ -38,6 +39,11 @@
if not hasattr(config, 'ShareTarget'):
config.ShareTarget = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff

if not hasattr(config, 'WorkUpdateInterval'):
config.WorkUpdateInterval = 55
config.StaleWorkTimeout = max(120, config.WorkUpdateInterval * 2)
util.UniqueSessionIdManager._defaultDelay = config.StaleWorkTimeout


import logging
import logging.handlers
Expand Down Expand Up @@ -172,7 +178,7 @@ def _WorkLogPruner_I(wl):
for username in wl:
userwork = wl[username]
for wli in tuple(userwork.keys()):
if now > userwork[wli][1] + 120:
if now > userwork[wli][1] + config.StaleWorkTimeout:
del userwork[wli]
pruned += 1
WorkLogPruner.logger.debug('Pruned %d jobs' % (pruned,))
Expand Down Expand Up @@ -473,7 +479,7 @@ def IsJobValid(wli, wluser = None):
if wli not in workLog[wluser]:
return False
(wld, issueT) = workLog[wluser][wli]
if time() < issueT - 120:
if time() < issueT - config.StaleWorkTimeout:
return False
return True

Expand Down Expand Up @@ -616,7 +622,7 @@ def checkShare(share):
share['_targethex'] = '%064x' % (workTarget,)

shareTimestamp = unpack('<L', data[68:72])[0]
if shareTime < issueT - 120:
if shareTime < issueT - config.StaleWorkTimeout:
raise RejectedShare('stale-work')
if shareTimestamp < shareTime - 300:
raise RejectedShare('time-too-old')
Expand Down Expand Up @@ -830,7 +836,7 @@ def restoreState(SAVE_STATE_FILENAME):
# Current format, from 2012-02-03 onward
DupeShareHACK = pickle.load(f)

if t + 120 >= time():
if t + config.StaleWorkTimeout >= time():
workLog = pickle.load(f)
else:
logger.debug('Skipping restore of expired workLog')
Expand Down Expand Up @@ -941,6 +947,7 @@ def restoreState(SAVE_STATE_FILENAME):
server.RaiseRedFlags = RaiseRedFlags
server.BlockVersion = config.BlockVersion
server.ShareTarget = config.ShareTarget
server.StaleWorkTimeout = config.StaleWorkTimeout
server.checkAuthentication = checkAuthentication

if hasattr(config, 'TrustedForwarders'):
Expand All @@ -957,6 +964,7 @@ def restoreState(SAVE_STATE_FILENAME):
stratumsrv.defaultTarget = config.ShareTarget
stratumsrv.IsJobValid = IsJobValid
stratumsrv.checkAuthentication = checkAuthentication
stratumsrv.WorkUpdateInterval = config.WorkUpdateInterval
if not hasattr(config, 'StratumAddresses'):
config.StratumAddresses = ()
for a in config.StratumAddresses:
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc_getblocktemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def final_init(server):
],
'noncerange': '00000000ffffffff',
'target': '00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
'expires': 120,
'version': 3,
'submitold': True,

Expand Down Expand Up @@ -78,7 +77,8 @@ def doJSON_getblocktemplate(self, params):
# FIXME: ensure mintime is always >= real mintime, both here and in share acceptance
rv['mintime'] = now - 180
rv['curtime'] = now
rv['maxtime'] = now + 120
rv['maxtime'] = now + self.server.StaleWorkTimeout
rv['expires'] = self.server.StaleWorkTimeout
rv['bits'] = b2a_hex(bits[::-1]).decode('ascii')
rv['target'] = '%064x' % (target,)
t = deepcopy(merkleTree.data[0])
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc_getwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def doJSON_getwork(self, data=None):
ShareTargetHexLE = b2a_hex(bytes.fromhex(ShareTargetHex)[::-1]).decode('ascii')
rv['target'] = ShareTargetHexLE

self._JSONHeaders['X-Roll-NTime'] = 'expire=120'
self._JSONHeaders['X-Roll-NTime'] = 'expire=%d' % (self.server.StaleWorkTimeout,)

return rv

Expand Down
1 change: 1 addition & 0 deletions jsonrpcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def __init__(self, *a, **ka):

self.SecretUser = None
self.ShareTarget = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
self.StaleWorkTimeout = 120

self._LPId = 0
self.LPId = '%d' % (time(),)
Expand Down
3 changes: 2 additions & 1 deletion stratumserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def __init__(self, *a, **ka):
self._JobId = 0
self.JobId = '%d' % (time(),)
self.WakeRequest = None
self.WorkUpdateInterval = 55
self.UpdateTask = None
self._PendingQuickUpdates = set()

Expand Down Expand Up @@ -321,7 +322,7 @@ def updateJob(self, wantClear = False):
self.WakeRequest = 1
self.wakeup()

self.UpdateTask = self.schedule(self.updateJob, time() + 55)
self.UpdateTask = self.schedule(self.updateJob, time() + self.WorkUpdateInterval)

def doQuickUpdate(self):
PQU = self._PendingQuickUpdates
Expand Down

0 comments on commit 28c9c02

Please sign in to comment.