Skip to content

Commit

Permalink
Merge pull request vertcoin-project#51 from rldleblanc/aux_pow_update
Browse files Browse the repository at this point in the history
Allow for new AUX POW.
  • Loading branch information
jtoomim authored Apr 17, 2021
2 parents 6dac42e + 0a7889a commit 0d21dc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 12 additions & 2 deletions p2pool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ def run():
parser.add_argument('--merged',
help='call getauxblock on this url to get work for merged mining (example: http://ncuser:[email protected]:10332/)',
type=str, action='append', default=[], dest='merged_urls')
parser.add_argument('--merged_addr',
help='call createauxblock/submitauxblock on this url to get work for merged mining and use payout address (example: payout%http://ncuser:[email protected]:10332/)',
type=str, action='append', default=[], dest='merged_urls_addr')
parser.add_argument('--coinbtext',
help='append this text to the coinbase',
type=str, action='append', default=[], dest='coinb_texts')
Expand Down Expand Up @@ -655,13 +658,20 @@ def run():
else:
args.pubkey_hash = None

def separate_url(url):
def separate_url(url, addr=False):
paddr = None
if addr:
if '%' not in url:
parser.error('payoutaddress not specifed in merged url')
paddr, url = url.split('%')
print("Found payout %s for %s" % (paddr, url))
s = urlparse.urlsplit(url)
if '@' not in s.netloc:
parser.error('merged url netloc must contain an "@"')
userpass, new_netloc = s.netloc.rsplit('@', 1)
return urlparse.urlunsplit(s._replace(netloc=new_netloc)), userpass
return urlparse.urlunsplit(s._replace(netloc=new_netloc)), userpass, paddr
merged_urls = map(separate_url, args.merged_urls)
merged_urls += [separate_url(x, addr=True) for x in args.merged_urls_addr]

if args.logfile is None:
args.logfile = os.path.join(datadir_path, 'log')
Expand Down
18 changes: 13 additions & 5 deletions p2pool/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,23 @@ def _(share):
self.merged_work = variable.Variable({})

@defer.inlineCallbacks
def set_merged_work(merged_url, merged_userpass):
def set_merged_work(merged_url, merged_userpass, merged_address):
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 on %s:' % (merged_url,), 30)(merged_proxy.rpc_getauxblock)()
if merged_address:
auxblock = yield deferral.retry('Error while calling merged createauxblock on %s:' % (merged_url,), 30)(merged_proxy.rpc_createauxblock)(merged_address)
else:
auxblock = yield deferral.retry('Error while calling merged getauxblock on %s:' % (merged_url,), 30)(merged_proxy.rpc_getauxblock)()
target = auxblock['target'] if 'target' in auxblock else auxblock['_target']
self.merged_work.set(math.merge_dicts(self.merged_work.value, {auxblock['chainid']: dict(
hash=int(auxblock['hash'], 16),
target='p2pool' if target == 'p2pool' else pack.IntType(256).unpack(target.decode('hex')),
merged_proxy=merged_proxy,
merged_address=merged_address,
)}))
yield deferral.sleep(1)
for merged_url, merged_userpass in merged_urls:
set_merged_work(merged_url, merged_userpass)
for merged_url, merged_userpass, merged_address in merged_urls:
set_merged_work(merged_url, merged_userpass, merged_address)

@self.merged_work.changed.watch
def _(new_merged_work):
Expand Down Expand Up @@ -462,7 +466,11 @@ def got_response(header, username, coinbase_nonce, pseudoshare_target):
for aux_work, index, hashes in mm_later:
try:
if pow_hash <= aux_work['target'] or p2pool.DEBUG:
df = deferral.retry('Error submitting merged block: (will retry)', 10, 10)(aux_work['merged_proxy'].rpc_getauxblock)(
if aux_work['merged_address']:
sub_meth = aux_work['merged_proxy'].rpc_submitauxblock
else:
sub_meth = aux_work['merged_proxy'].rpc.getauxblock
df = deferral.retry('Error submitting merged block: (will retry)', 10, 10)(sub_meth)(
pack.IntType(256, 'big').pack(aux_work['hash']).encode('hex'),
bitcoin_data.aux_pow_type.pack(dict(
merkle_tx=dict(
Expand Down

0 comments on commit 0d21dc3

Please sign in to comment.