Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 237ae44ec9516c5826b698da9d8ea29d23b1fc08 Mon Sep 17 00:00:00 2001
- From: Luke Dashjr <luke-jr+git@utopios.org>
- Date: Mon, 10 Oct 2011 14:54:28 -0400
- Subject: [PATCH] Hack in support for getworkaux/gotwork design
- ---
- contrib/merged-mine-proxy | 64 ++++++++++++++++++--------------------------
- 1 files changed, 26 insertions(+), 38 deletions(-)
- diff --git a/contrib/merged-mine-proxy b/contrib/merged-mine-proxy
- index 4c38215..ab8b1dc 100755
- --- a/contrib/merged-mine-proxy
- +++ b/contrib/merged-mine-proxy
- @@ -282,10 +282,16 @@ class Listener(Server):
- self.aux_targets[chain] = reverse_chunks(aux_block['target'], 2) # fix endian
- # create merkle tree
- - merkle_tree = (yield self.parent.rpc_buildmerkletree(*merkle_leaves))
- + #merkle_tree = (yield self.parent.rpc_buildmerkletree(*merkle_leaves))
- + merkle_tree = merkle_leaves # HACK
- merkle_root = merkle_tree[-1]
- if not self.merkle_trees.has_key(merkle_root):
- + # Tell bitcoind the new merkle root
- + MMAux = merkle_root + ("%02x000000" % self.merkle_size) + "00000000"
- + MMAux = '4d4d3d3d' + MMAux
- + self.parent.rpc_setworkaux('MM', MMAux)
- +
- # remember new tree
- self.merkle_trees[merkle_root] = merkle_tree
- self.merkle_tree_queue.append(merkle_root)
- @@ -324,26 +330,23 @@ class Listener(Server):
- raise
- @defer.inlineCallbacks
- - def rpc_getwork(self, data=None):
- - ''' This rpc call generates bitcoin miner compatible work from data received
- - from the aux and parent chains.
- - '''
- + def rpc_gotwork(self, solution):
- try:
- - if data:
- # Submit work upstream
- any_solved = False
- aux_solved = []
- - # get merkle root
- - solution = (yield self.parent.rpc_getworkaux("", data))
- -
- - if solution is False:
- - logger.error("stale work")
- + parent_hash = solution['hash']
- + blkhdr = solution['header']
- + coinbaseMerkle = solution['coinbaseMrkl']
- + pos = coinbaseMerkle.find('4d4d3d3d') + 8
- + if not pos:
- + logger.error("failed to find aux in coinbase")
- defer.returnValue(False)
- return
- + slnaux = coinbaseMerkle[pos:pos+80]
- - parent_hash = solution['hash']
- - merkle_root = solution['aux'][:-16] # strip off size and nonce
- + merkle_root = slnaux[:-16] # strip off size and nonce
- if not self.merkle_trees.has_key(merkle_root):
- logger.error("stale merkle root %s", merkle_root)
- defer.returnValue(False)
- @@ -356,42 +359,27 @@ class Listener(Server):
- chain_merkle_index = self.calc_merkle_index(chain)
- aux_solved.append(False)
- # try submitting if under target
- - if self.aux_targets[chain] > parent_hash and not chain_merkle_index is None:
- + # TODO: self.aux_targets[chain] > parent_hash and
- + if not chain_merkle_index is None:
- branch = self.merkle_branch(chain_merkle_index, merkle_tree)
- + """
- proof = (
- yield self.parent.rpc_getworkaux("", data, chain_merkle_index, *branch))
- if proof is False:
- logger.error("aux pow request rejected by parent, chain %d", chain)
- else:
- - aux_hash = merkle_tree[chain_merkle_index]
- - aux_solved[-1] = (
- - yield self.auxs[chain].rpc_getauxblock(aux_hash, proof['auxpow']))
- - any_solved = any_solved or aux_solved[-1]
- -
- - # submit to parent
- - parent_solved = (yield self.parent.rpc_getworkaux("submit", data))
- - any_solved = any_solved or parent_solved
- + """
- + auxpow = coinbaseMerkle + "0000000000" + blkhdr
- + aux_hash = merkle_tree[chain_merkle_index]
- + aux_solved[-1] = (
- + yield self.auxs[chain].rpc_getauxblock(aux_hash, auxpow))
- + any_solved = any_solved or aux_solved[-1]
- logger.info("%s,solve,%s,%s,%s", datetime.utcnow().isoformat(),
- - "1" if parent_solved else "0",
- + "?",
- ",".join(["1" if solve else "0" for solve in aux_solved]),
- parent_hash)
- defer.returnValue(any_solved)
- - else:
- - # Get work based on the latest tree
- - merkle_root = self.merkle_tree_queue[-1]
- - # nonce = 0, one byte merkle size
- - aux = merkle_root + ("%02x000000" % self.merkle_size) + "00000000"
- - work = (yield self.parent.rpc_getworkaux(aux))
- - if self.rewrite_target:
- - work['target'] = self.rewrite_target
- - else:
- - # Find highest target
- - targets = [reverse_chunks(work['target'], 2)] # fix endian
- - targets.extend(self.aux_targets)
- - targets.sort()
- - work['target'] = reverse_chunks(targets[-1], 2) # fix endian
- - defer.returnValue(work)
- except Exception:
- # Exceptions here are normally already handled by the rpc functions
- #logger.debug(traceback.format_exc())
- --
- 1.7.3.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement