From 6e1b0c8102144d0b76d29c4167f3789c2e4f3857 Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Fri, 2 Nov 2012 00:58:24 -0400 Subject: [PATCH] added MIN_TARGET attribute to p2pool network definitions for testing --- p2pool/data.py | 4 ++-- p2pool/networks.py | 4 ++++ p2pool/test/test_node.py | 33 +++++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/p2pool/data.py b/p2pool/data.py index ef77a18..94f8149 100644 --- a/p2pool/data.py +++ b/p2pool/data.py @@ -123,7 +123,7 @@ class Share(object): attempts_per_second = get_pool_attempts_per_second(tracker, share_data['previous_share_hash'], net.TARGET_LOOKBEHIND, min_work=True, integer=True) pre_target = 2**256//(net.SHARE_PERIOD*attempts_per_second) - 1 if attempts_per_second else 2**256-1 pre_target2 = math.clip(pre_target, (previous_share.max_target*9//10, previous_share.max_target*11//10)) - pre_target3 = math.clip(pre_target2, (0, net.MAX_TARGET)) + pre_target3 = math.clip(pre_target2, (net.MIN_TARGET, net.MAX_TARGET)) max_bits = bitcoin_data.FloatingInteger.from_target_upper_bound(pre_target3) bits = bitcoin_data.FloatingInteger.from_target_upper_bound(math.clip(desired_target, (pre_target3//10, pre_target3))) @@ -356,7 +356,7 @@ class NewShare(object): attempts_per_second = get_pool_attempts_per_second(tracker, share_data['previous_share_hash'], net.TARGET_LOOKBEHIND, min_work=True, integer=True) pre_target = 2**256//(net.SHARE_PERIOD*attempts_per_second) - 1 if attempts_per_second else 2**256-1 pre_target2 = math.clip(pre_target, (previous_share.max_target*9//10, previous_share.max_target*11//10)) - pre_target3 = math.clip(pre_target2, (0, net.MAX_TARGET)) + pre_target3 = math.clip(pre_target2, (net.MIN_TARGET, net.MAX_TARGET)) max_bits = bitcoin_data.FloatingInteger.from_target_upper_bound(pre_target3) bits = bitcoin_data.FloatingInteger.from_target_upper_bound(math.clip(desired_target, (pre_target3//10, pre_target3))) diff --git a/p2pool/networks.py b/p2pool/networks.py index d44a803..168331c 100644 --- a/p2pool/networks.py +++ b/p2pool/networks.py @@ -18,6 +18,7 @@ nets = dict( IDENTIFIER='fc70035c7a81bc6f'.decode('hex'), PREFIX='2472ef181efcd37b'.decode('hex'), P2P_PORT=9333, + MIN_TARGET=0, MAX_TARGET=2**256//2**32 - 1, PERSIST=True, WORKER_PORT=9332, @@ -35,6 +36,7 @@ nets = dict( IDENTIFIER='5fc2be2d4f0d6bfb'.decode('hex'), PREFIX='3f6057a15036f441'.decode('hex'), P2P_PORT=19333, + MIN_TARGET=0, MAX_TARGET=2**256//2**32 - 1, PERSIST=False, WORKER_PORT=19332, @@ -53,6 +55,7 @@ nets = dict( IDENTIFIER='e037d5b8c6923410'.decode('hex'), PREFIX='7208c1a53ef629b0'.decode('hex'), P2P_PORT=9338, + MIN_TARGET=0, MAX_TARGET=2**256//2**20 - 1, PERSIST=True, WORKER_PORT=9327, @@ -70,6 +73,7 @@ nets = dict( IDENTIFIER='cca5e24ec6408b1e'.decode('hex'), PREFIX='ad9614f6466a39cf'.decode('hex'), P2P_PORT=19338, + MIN_TARGET=0, MAX_TARGET=2**256 - 1, PERSIST=False, WORKER_PORT=19327, diff --git a/p2pool/test/test_node.py b/p2pool/test/test_node.py index acf2868..73738ee 100644 --- a/p2pool/test/test_node.py +++ b/p2pool/test/test_node.py @@ -6,9 +6,9 @@ from twisted.internet import defer, reactor from twisted.trial import unittest from twisted.web import resource, server -from p2pool import networks, node, work -from p2pool.bitcoin import worker_interface -from p2pool.util import deferral, jsonrpc, variable +from p2pool import node, work +from p2pool.bitcoin import networks, worker_interface +from p2pool.util import deferral, jsonrpc, math, variable class factory(object): new_headers = variable.Event() @@ -54,6 +54,25 @@ class bitcoind(object): "height" : 205801 } +mynet = math.Object( + PARENT=networks.nets['litecoin_testnet'], + SHARE_PERIOD=3, # seconds + CHAIN_LENGTH=20*60//3, # shares + REAL_CHAIN_LENGTH=20*60//3, # shares + TARGET_LOOKBEHIND=200, # shares + SPREAD=12, # blocks + IDENTIFIER='cca5e24ec6408b1e'.decode('hex'), + PREFIX='ad9614f6466a39cf'.decode('hex'), + P2P_PORT=19338, + MIN_TARGET=2**256 - 1, + MAX_TARGET=2**256 - 1, + PERSIST=False, + WORKER_PORT=19327, + BOOTSTRAP_ADDRS='72.14.191.28'.split(' '), + ANNOUNCE_CHANNEL='#p2pool-alt', + VERSION_CHECK=lambda v: True, +) + class MiniNode(object): @classmethod @defer.inlineCallbacks @@ -83,8 +102,7 @@ class MiniNode(object): class Test(unittest.TestCase): @defer.inlineCallbacks def test_node(self): - net = networks.nets['litecoin_testnet'] - n = node.Node(factory, bitcoind, [], [], net) + n = node.Node(factory, bitcoind, [], [], mynet) yield n.start() wb = work.WorkerBridge(node=n, my_pubkey_hash=42, donation_percentage=2, merged_urls=[], worker_fee=3) @@ -108,7 +126,7 @@ class Test(unittest.TestCase): n.stop() yield port.stopListening() - del net, n, wb, web_root, port, proxy + del n, wb, web_root, port, proxy import gc gc.collect() gc.collect() @@ -118,12 +136,11 @@ class Test(unittest.TestCase): @defer.inlineCallbacks def test_nodes(self): - net = networks.nets['litecoin_testnet'] N = 3 nodes = [] for i in xrange(N): - nodes.append((yield MiniNode.start(net, factory, bitcoind, [mn.n.p2p_node.serverfactory.listen_port.getHost().port for mn in nodes]))) + nodes.append((yield MiniNode.start(mynet, factory, bitcoind, [mn.n.p2p_node.serverfactory.listen_port.getHost().port for mn in nodes]))) yield deferral.sleep(3) -- 1.7.1