From: Forrest Voight Date: Mon, 31 Dec 2012 21:19:19 +0000 (-0500) Subject: made miner interfaces not assume coinbase nonce is 4 bytes X-Git-Tag: 11.0~8 X-Git-Url: https://git.novaco.in/?p=p2pool.git;a=commitdiff_plain;h=f1969c773280c63adb3e0e5077b2de506fe0385d made miner interfaces not assume coinbase nonce is 4 bytes --- diff --git a/p2pool/bitcoin/stratum.py b/p2pool/bitcoin/stratum.py index 30df691..464af52 100644 --- a/p2pool/bitcoin/stratum.py +++ b/p2pool/bitcoin/stratum.py @@ -21,7 +21,7 @@ class StratumRPCMiningProvider(object): return [ ["mining.notify", "ae6812eb4cd7735a302a8a9dd95cf71f"], # subscription details "", # extranonce1 - 4, # extranonce2_size + self.wb.COINBASE_NONCE_LENGTH, # extranonce2_size ] def rpc_authorize(self, username, password): @@ -54,8 +54,9 @@ class StratumRPCMiningProvider(object): print >>sys.stderr, '''Couldn't link returned work's job id with its handler. This should only happen if this process was recently restarted!''' return False x, got_response = self.handler_map[job_id] - coinb_nonce = pack.IntType(32).unpack(extranonce2.decode('hex')) - new_packed_gentx = x['coinb1'] + pack.IntType(32).pack(coinb_nonce) + x['coinb2'] + coinb_nonce = extranonce2.decode('hex') + assert len(coinb_nonce) == self.wb.COINBASE_NONCE_LENGTH + new_packed_gentx = x['coinb1'] + coinb_nonce + x['coinb2'] header = dict( version=x['version'], previous_block=x['previous_block'], diff --git a/p2pool/bitcoin/worker_interface.py b/p2pool/bitcoin/worker_interface.py index ca025fd..98daf21 100644 --- a/p2pool/bitcoin/worker_interface.py +++ b/p2pool/bitcoin/worker_interface.py @@ -64,7 +64,7 @@ class WorkerInterface(object): if header['merkle_root'] not in self.merkle_root_to_handler: print >>sys.stderr, '''Couldn't link returned work's merkle root with its handler. This should only happen if this process was recently restarted!''' defer.returnValue(False) - defer.returnValue(self.merkle_root_to_handler[header['merkle_root']](header, request.getUser() if request.getUser() is not None else '', 0)) + defer.returnValue(self.merkle_root_to_handler[header['merkle_root']](header, request.getUser() if request.getUser() is not None else '', '\0'*self.worker_bridge.COINBASE_NONCE_LENGTH)) if p2pool.DEBUG: id = random.randrange(1000, 10000) @@ -85,7 +85,7 @@ class WorkerInterface(object): res = getwork.BlockAttempt( version=x['version'], previous_block=x['previous_block'], - merkle_root=bitcoin_data.check_merkle_link(bitcoin_data.hash256(x['coinb1'] + pack.IntType(32).pack(0) + x['coinb2']), x['merkle_link']), + merkle_root=bitcoin_data.check_merkle_link(bitcoin_data.hash256(x['coinb1'] + '\0'*self.worker_bridge.COINBASE_NONCE_LENGTH + x['coinb2']), x['merkle_link']), timestamp=x['timestamp'], bits=x['bits'], share_target=x['share_target'], diff --git a/p2pool/work.py b/p2pool/work.py index 6e879d1..0444733 100644 --- a/p2pool/work.py +++ b/p2pool/work.py @@ -14,6 +14,8 @@ from util import forest, jsonrpc, variable, deferral, math, pack import p2pool, p2pool.data as p2pool_data class WorkerBridge(worker_interface.WorkerBridge): + COINBASE_NONCE_LENGTH = 4 + def __init__(self, node, my_pubkey_hash, donation_percentage, merged_urls, worker_fee): worker_interface.WorkerBridge.__init__(self) self.recent_shares_ts_work = [] @@ -277,9 +279,10 @@ class WorkerBridge(worker_interface.WorkerBridge): received_header_hashes = set() - def got_response(header, user, last_txout_nonce): - new_packed_gentx = packed_gentx[:-4-4] + pack.IntType(32).pack(last_txout_nonce) + packed_gentx[-4:] if last_txout_nonce != 0 else packed_gentx - new_gentx = bitcoin_data.tx_type.unpack(new_packed_gentx) if last_txout_nonce != 0 else gentx + def got_response(header, user, coinbase_nonce): + assert len(coinbase_nonce) == self.COINBASE_NONCE_LENGTH == 4 + new_packed_gentx = packed_gentx[:-4-4] + coinbase_nonce + packed_gentx[-4:] if coinbase_nonce != '\0'*self.COINBASE_NONCE_LENGTH else packed_gentx + new_gentx = bitcoin_data.tx_type.unpack(new_packed_gentx) if coinbase_nonce != '\0'*self.COINBASE_NONCE_LENGTH else gentx header_hash = bitcoin_data.hash256(bitcoin_data.block_header_type.pack(header)) pow_hash = self.node.net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(header)) @@ -328,7 +331,7 @@ class WorkerBridge(worker_interface.WorkerBridge): log.err(None, 'Error while processing merged mining POW:') if pow_hash <= share_info['bits'].target and header_hash not in received_header_hashes: - share = get_share(header, last_txout_nonce) + share = get_share(header, pack.IntType(32).unpack(coinbase_nonce)) print 'GOT SHARE! %s %s prev %s age %.2fs%s' % ( user,