From: Forrest Voight Date: Tue, 10 Jan 2012 00:48:54 +0000 (-0500) Subject: cleaned up anti-bitdust patch X-Git-Tag: 0.8.2~23 X-Git-Url: https://git.novaco.in/?a=commitdiff_plain;h=eeb5fc7266d2e4f24cdb97a24ffd305f7212cab5;p=p2pool.git cleaned up anti-bitdust patch --- diff --git a/p2pool/main.py b/p2pool/main.py index 14b037b..8fa6d49 100644 --- a/p2pool/main.py +++ b/p2pool/main.py @@ -585,58 +585,51 @@ def main(args, net, datadir_path): res[bitcoin_data.script2_to_human(script, net.PARENT)] = weights[script]/total_weight return json.dumps(res) - def get_current_txouts(scale=1e8): + def get_current_txouts(): wb = WorkerBridge() tmp_tag = str(random.randrange(2**64)) outputs = wb.merkle_root_to_transactions[wb.get_work(tmp_tag).merkle_root][1][0]['tx_outs'] total = sum(out['value'] for out in outputs) total_without_tag = sum(out['value'] for out in outputs if out['script'] != tmp_tag) - total_diff = total-total_without_tag - return dict((out['script'], (out['value']+math.perfect_round(out['value']*total_diff/total))/scale) for out in outputs if out['script'] != tmp_tag and out['value']) + total_diff = total - total_without_tag + return dict((out['script'], out['value'] + math.perfect_round(out['value']*total_diff/total)) for out in outputs if out['script'] != tmp_tag and out['value']) - def get_current_scaled_txouts(scale=1e8,trunc=0): - txouts = get_current_txouts(scale=1) + def get_current_scaled_txouts(scale, trunc=0): + txouts = get_current_txouts() total = sum(txouts.itervalues()) - results = dict((script, int(scale*value/total)) for script, value in txouts.iteritems()) - if trunc>0: - total_random=0 - random_set=set() + results = dict((script, value*scale//total) for script, value in txouts.iteritems()) + if trunc > 0: + total_random = 0 + random_set = set() for s in sorted(results, key=results.__getitem__): - value=results[s] - total_random += value + total_random += results[s] random_set.add(s) - if total_random>=trunc and value>=trunc: + if total_random >= trunc and results[s] >= trunc: break - target = random.randrange(0,total_random) - for s in random_set: - if target0: - target = random.randrange(0,total) - for s in results.keys(): - if target target: + return item + target -= weight + raise AssertionError() + if __name__ == '__main__': import random a = 1