Skip to content

Commit

Permalink
Correct a simple mistake in user-supplied command-line address handling.
Browse files Browse the repository at this point in the history
Now it should work okay regardless of whether you're in dynamic mode or not.

But use dynamic mode, if everyone does it you all achieve additional privacy amongst one another.
  • Loading branch information
midnightmagic committed Jan 12, 2015
1 parent e3b016a commit 2af37a5
Showing 1 changed file with 53 additions and 55 deletions.
108 changes: 53 additions & 55 deletions p2pool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,52 @@
from . import networks, web, work
import p2pool, p2pool.data as p2pool_data, p2pool.node as p2pool_node

class keypool():
keys = []
keyweights = []
stamp = time.time()
payouttotal = 0.0

def addkey(self, n):
self.keys.append(n)
self.keyweights.append(random.uniform(0,100.0))
def delkey(self, n):
try:
i=self.keys.index(n)
self.keys.pop(i)
self.keyweights.pop(i)
except:
pass

def weighted(self):
choice=random.uniform(0,sum(self.keyweights))
tot = 0.0
ind = 0
for i in (self.keyweights):
tot += i
if tot >= choice:
return ind
ind += 1
return ind

def popleft(self):
if (len(self.keys) > 0):
dummyval=self.keys.pop(0)
if (len(self.keyweights) > 0):
dummyval=self.keyweights.pop(0)

def updatestamp(self, n):
self.stamp = n

def paytotal(self):
self.payouttotal = 0.0
for i in range(len(pubkeys.keys)):
self.payouttotal += node.get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(pubkeys.keys[i]), 0)*1e-8
return self.payouttotal

def getpaytotal(self):
return self.payouttotal

@defer.inlineCallbacks
def main(args, net, datadir_path, merged_urls, worker_endpoint):
try:
Expand Down Expand Up @@ -99,7 +145,8 @@ def poll_warnings():
print ' ...success! Payout address:', bitcoin_data.pubkey_hash_to_address(my_pubkey_hash, net.PARENT)
print
elif args.address != 'dynamic':
pubkeys = []
pubkeys = keypool()
pubkeys.addkey(args.pubkey_hash)
my_pubkey_hash = args.pubkey_hash
print ' ...success! Payout address:', bitcoin_data.pubkey_hash_to_address(my_pubkey_hash, net.PARENT)
print
Expand All @@ -109,52 +156,6 @@ def poll_warnings():
if args.numaddresses < 2:
print ' ERROR: Can not use fewer than 2 addresses in dynamic mode. Resetting to 2.'
args.numaddresses = 2
class keypool():
keys = []
keyweights = []
stamp = time.time()
payouttotal = 0.0

def addkey(self, n):
self.keys.append(n)
self.keyweights.append(random.uniform(0,100.0))
def delkey(self, n):
try:
i=self.keys.index(n)
self.keys.pop(i)
self.keyweights.pop(i)
except:
pass

def weighted(self):
choice=random.uniform(0,sum(self.keyweights))
tot = 0.0
ind = 0
for i in (self.keyweights):
tot += i
if tot >= choice:
return ind
ind += 1
return ind

def popleft(self):
if (len(self.keys) > 0):
dummyval=self.keys.pop(0)
if (len(self.keyweights) > 0):
dummyval=self.keyweights.pop(0)

def updatestamp(self, n):
self.stamp = n

def paytotal(self):
self.payouttotal = 0.0
for i in range(len(pubkeys.keys)):
self.payouttotal += node.get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(pubkeys.keys[i]), 0)*1e-8
return self.payouttotal

def getpaytotal(self):
return self.payouttotal

pubkeys = keypool()
for i in range(args.numaddresses):
address = yield deferral.retry('Error getting a dynamic address from bitcoind:', 5)(lambda: bitcoind.rpc_getnewaddress('p2pool'))()
Expand Down Expand Up @@ -391,14 +392,11 @@ def status_thread():

paystr = ''
paytot = 0.0
if args.address == 'dynamic':
for i in range(len(pubkeys.keys)):
curtot = node.get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(pubkeys.keys[i]), 0)
paytot += curtot*1e-8
paystr += "(%.4f)" % (curtot*1e-8,)
paystr += "=%.4f" % (paytot,)
else:
paystr = "%.4f" % (node.get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(pubkeys.keys[i]), 0)*1e-8,)
for i in range(len(pubkeys.keys)):
curtot = node.get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(pubkeys.keys[i]), 0)
paytot += curtot*1e-8
paystr += "(%.4f)" % (curtot*1e-8,)
paystr += "=%.4f" % (paytot,)
this_str += '\n Shares: %i (%i orphan, %i dead) Stale rate: %s Efficiency: %s Current payout: %s %s' % (
shares, stale_orphan_shares, stale_doa_shares,
math.format_binomial_conf(stale_orphan_shares + stale_doa_shares, shares, 0.95),
Expand Down

0 comments on commit 2af37a5

Please sign in to comment.