self.donation_percentage = donation_percentage
self.worker_fee = worker_fee
+ self.running = True
self.pseudoshare_received = variable.Event()
self.share_received = variable.Event()
self.local_rate_monitor = math.RateMonitor(10*60)
@defer.inlineCallbacks
def set_merged_work(merged_url, merged_userpass):
- merged_proxy = jsonrpc.Proxy(merged_url, dict(Authorization='Basic ' + base64.b64encode(merged_userpass)))
- while True:
+ merged_proxy = jsonrpc.HTTPProxy(merged_url, dict(Authorization='Basic ' + base64.b64encode(merged_userpass)))
+ while self.running:
auxblock = yield deferral.retry('Error while calling merged getauxblock:', 30)(merged_proxy.rpc_getauxblock)()
self.merged_work.set(dict(self.merged_work.value, **{auxblock['chainid']: dict(
hash=int(auxblock['hash'], 16),
height=t['height'] + 1,
time=bb['timestamp'] + 600, # better way?
transactions=[],
+ transaction_fees=[],
merkle_link=bitcoin_data.calculate_merkle_link([None], 0),
subsidy=self.node.net.PARENT.SUBSIDY_FUNC(self.node.bitcoind_work.value['height']),
last_update=self.node.bitcoind_work.value['last_update'],
self.merged_work.changed.watch(lambda _: self.new_work_event.happened())
self.node.best_share_var.changed.watch(lambda _: self.new_work_event.happened())
+ def stop(self):
+ self.running = False
+
def get_stale_counts(self):
'''Returns (orphans, doas), total, (orphans_recorded_in_chain, doas_recorded_in_chain)'''
my_shares = len(self.my_share_hashes)
return (my_shares_not_in_chain - my_doa_shares_not_in_chain, my_doa_shares_not_in_chain), my_shares, (orphans_recorded_in_chain, doas_recorded_in_chain)
- def get_user_details(self, request):
- user = request.getUser() if request.getUser() is not None else ''
-
+ def get_user_details(self, user):
desired_pseudoshare_target = None
if '+' in user:
user, desired_pseudoshare_difficulty_str = user.rsplit('+', 1)
return user, pubkey_hash, desired_share_target, desired_pseudoshare_target
- def preprocess_request(self, request):
- user, pubkey_hash, desired_share_target, desired_pseudoshare_target = self.get_user_details(request)
+ def preprocess_request(self, user):
+ user, pubkey_hash, desired_share_target, desired_pseudoshare_target = self.get_user_details(user)
return pubkey_hash, desired_share_target, desired_pseudoshare_target
def get_work(self, pubkey_hash, desired_share_target, desired_pseudoshare_target):
'doa' if doas > doas_recorded_in_chain else
None
)(*self.get_stale_counts()),
- desired_version=share_type.SUCCESSOR.VERSION if share_type.SUCCESSOR is not None else share_type.VERSION,
+ desired_version=10,
),
block_target=self.current_work.value['bits'].target,
desired_timestamp=int(time.time() + 0.5),
desired_target=desired_share_target,
ref_merkle_link=dict(branch=[], index=0),
- desired_other_transaction_hashes=tx_hashes,
+ desired_other_transaction_hashes_and_fees=zip(tx_hashes, self.current_work.value['transaction_fees']),
net=self.node.net,
known_txs=tx_map,
+ base_subsidy=self.node.net.PARENT.SUBSIDY_FUNC(self.current_work.value['height']),
)
- transactions = [gentx] + [tx_map[tx_hash] for tx_hash in other_transaction_hashes]
+ packed_gentx = bitcoin_data.tx_type.pack(gentx)
+ other_transactions = [tx_map[tx_hash] for tx_hash in other_transaction_hashes]
mm_later = [(dict(aux_work, target=aux_work['target'] if aux_work['target'] != 'p2pool' else share_info['bits'].target), index, hashes) for aux_work, index, hashes in mm_later]
getwork_time = time.time()
lp_count = self.new_work_event.times
- merkle_link = bitcoin_data.calculate_merkle_link([bitcoin_data.hash256(bitcoin_data.tx_type.pack(tx)) for tx in transactions], 0)
+ merkle_link = bitcoin_data.calculate_merkle_link([None] + other_transaction_hashes, 0)
print 'New work for worker! Difficulty: %.06f Share difficulty: %.06f Total block value: %.6f %s including %i transactions' % (
bitcoin_data.target_to_difficulty(target),
len(self.current_work.value['transactions']),
)
- ba = bitcoin_getwork.BlockAttempt(
+ ba = dict(
version=min(self.current_work.value['version'], 2),
previous_block=self.current_work.value['previous_block'],
- merkle_root=bitcoin_data.check_merkle_link(bitcoin_data.hash256(bitcoin_data.tx_type.pack(transactions[0])), merkle_link),
+ merkle_link=merkle_link,
+ coinb1=packed_gentx[:-4-4],
+ coinb2=packed_gentx[-4:],
timestamp=self.current_work.value['time'],
bits=self.current_work.value['bits'],
share_target=target,
received_header_hashes = set()
- def got_response(header, request):
+ 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
+
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))
try:
if pow_hash <= header['bits'].target or p2pool.DEBUG:
- helper.submit_block(dict(header=header, txs=transactions), False, self.node.factory, self.node.bitcoind, self.node.bitcoind_work, self.node.net)
+ helper.submit_block(dict(header=header, txs=[new_gentx] + other_transactions), False, self.node.factory, self.node.bitcoind, self.node.bitcoind_work, self.node.net)
if pow_hash <= header['bits'].target:
print
print 'GOT BLOCK FROM MINER! Passing to bitcoind! %s%064x' % (self.node.net.PARENT.BLOCK_EXPLORER_URL_PREFIX, header_hash)
except:
log.err(None, 'Error while processing potential block:')
- user, _, _, _ = self.get_user_details(request)
- assert header['previous_block'] == ba.previous_block
- assert header['merkle_root'] == ba.merkle_root
- assert header['bits'] == ba.bits
+ user, _, _, _ = self.get_user_details(user)
+ assert header['previous_block'] == ba['previous_block']
+ assert header['merkle_root'] == bitcoin_data.check_merkle_link(bitcoin_data.hash256(new_packed_gentx), merkle_link)
+ assert header['bits'] == ba['bits']
on_time = self.new_work_event.times == lp_count
pack.IntType(256, 'big').pack(aux_work['hash']).encode('hex'),
bitcoin_data.aux_pow_type.pack(dict(
merkle_tx=dict(
- tx=transactions[0],
+ tx=new_gentx,
block_hash=header_hash,
merkle_link=merkle_link,
),
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, transactions)
+ share = get_share(header, last_txout_nonce)
print 'GOT SHARE! %s %s prev %s age %.2fs%s' % (
- request.getUser(),
+ user,
p2pool_data.format_hash(share.hash),
p2pool_data.format_hash(share.previous_hash),
time.time() - getwork_time,
self.my_doa_share_hashes.add(share.hash)
self.node.tracker.add(share)
- if not p2pool.DEBUG:
- self.node.tracker.verified.add(share)
self.node.set_best_share()
try:
- if pow_hash <= header['bits'].target or p2pool.DEBUG:
+ if (pow_hash <= header['bits'].target or p2pool.DEBUG) and self.node.p2p_node is not None:
self.node.p2p_node.broadcast_share(share.hash)
except:
log.err(None, 'Error forwarding block solution:')
self.share_received.happened(bitcoin_data.target_to_average_attempts(share.target), not on_time)
if pow_hash > target:
- print 'Worker %s submitted share with hash > target:' % (request.getUser(),)
+ print 'Worker %s submitted share with hash > target:' % (user,)
print ' Hash: %56x' % (pow_hash,)
print ' Target: %56x' % (target,)
elif header_hash in received_header_hashes:
- print >>sys.stderr, 'Worker %s @ %s submitted share more than once!' % (request.getUser(), request.getClientIP())
+ print >>sys.stderr, 'Worker %s submitted share more than once!' % (user,)
else:
received_header_hashes.add(header_hash)