Skip to content

Commit

Permalink
Always send clear transactions for template work, during new block lo…
Browse files Browse the repository at this point in the history
…ngpoll and if user has no work yet
  • Loading branch information
luke-jr committed Nov 5, 2012
1 parent a4bb0b9 commit 83bbaad
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
15 changes: 12 additions & 3 deletions eloipool.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def blockChanged():
else:
networkTarget = Bits2Target(bits)
workLog.clear()
updateBlocks()
server.wakeLongpoll(wantClear=True)


from time import sleep, time
Expand Down Expand Up @@ -230,8 +230,15 @@ def getBlockHeader(username):
target = RegisterWork(username, merkleRoot, MRD)
return (hdr, workLog[username][merkleRoot], target)

def getBlockTemplate(username):
MC = MM.getMC()
def getBlockTemplate(username, p_magic = None):
if server.tls.wantClear:
wantClear = True
elif p_magic and username not in workLog:
wantClear = True
p_magic[0] = True
else:
wantClear = False
MC = MM.getMC(wantClear)
(dummy, merkleTree, coinbase, prevBlock, bits) = MC[:5]
wliPos = coinbase[0] + 2
wliLen = coinbase[wliPos - 1]
Expand Down Expand Up @@ -667,6 +674,8 @@ def restoreState():
import jsonrpc_setworkaux

server = JSONRPCServer()
server.tls = threading.local()
server.tls.wantClear = False
if hasattr(config, 'JSONRPCAddress'):
logging.getLogger('backwardCompatibility').warn('JSONRPCAddress configuration variable is deprecated; upgrade to JSONRPCAddresses list before 2013-03-05')
if not hasattr(config, 'JSONRPCAddresses'):
Expand Down
8 changes: 6 additions & 2 deletions jsonrpc_getblocktemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ def doJSON_getblocktemplate(self, params):
self.processLP(params['longpollid'])

rv = dict(self.getblocktemplate_rv_template)
(MC, wld, target) = self.server.getBlockTemplate(self.Username)
p_magic = [False]
(MC, wld, target) = self.server.getBlockTemplate(self.Username, p_magic=p_magic)
(height, merkleTree, cb, prevBlock, bits) = MC[:5]
rv['height'] = height
rv['previousblockhash'] = b2a_hex(prevBlock[::-1]).decode('ascii')
rv['longpollid'] = str(self.server.LPId)
if p_magic[0]:
rv['longpollid'] = 'bootstrap'
else:
rv['longpollid'] = str(self.server.LPId)
tl = []
for txn in merkleTree.data[1:]:
txno = {}
Expand Down
13 changes: 8 additions & 5 deletions jsonrpcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,19 @@ def cleanupLP(self):
pass
self.LPUntrack()

def wakeLongpoll(self):
def wakeLongpoll(self, wantClear = False):
now = time()
if now < self.waitTime:
self.changeTask(self.wakeLongpoll, self.waitTime)
self.changeTask(lambda: self.wakeLongpoll(wantClear), self.waitTime)
return
else:
self.changeTask(None)

self.LPUntrack()

self.server.tls.wantClear = wantClear
rv = self._doJSON_i(*self._LPCall, longpoll=True)
self.server.tls.wantClear = False
if 'NELH' not in self.quirks:
rv = rv[1:] # strip the '{' we already sent
self.push(('%x' % len(rv)).encode('utf8') + b"\r\n" + rv + b"\r\n0\r\n\r\n")
Expand Down Expand Up @@ -307,13 +309,14 @@ def pre_schedule(self):
if self.LPRequest == 1:
self._LPsch()

def wakeLongpoll(self):
def wakeLongpoll(self, wantClear = False):
if self.LPRequest:
self.logger.info('Ignoring longpoll attempt while another is waiting')
return
self.LPRequest = 1
self._LPId += 1
self.LPId = '%d %d' % (time(), self._LPId)
self._LPWantClear = wantClear
self.LPRequest = 1
self.wakeup()

def _LPsch(self):
Expand All @@ -340,7 +343,7 @@ def _actualLP(self):

for ic in C:
try:
ic.wakeLongpoll()
ic.wakeLongpoll(self._LPWantClear)
except socket.error:
OC -= 1
# Ignore socket errors; let the main event loop take care of them later
Expand Down
4 changes: 2 additions & 2 deletions merklemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ def getMRD(self):
(prevBlock, height, bits) = self.currentBlock
return (merkleRoot, merkleTree, cb, prevBlock, bits, rollPrevBlk)

def getMC(self):
def getMC(self, wantClear = False):
(prevBlock, height, bits) = self.currentBlock
mt = self.currentMerkleTree
mt = self.clearMerkleTree if wantClear else self.currentMerkleTree
cb = self.makeCoinbase(height=height)
rollPrevBlk = (mt == self.clearMerkleTree)
return (height, mt, cb, prevBlock, bits, rollPrevBlk)
Expand Down

0 comments on commit 83bbaad

Please sign in to comment.