From 36206ef4fae7fc525d4807bbbe056f6a50d3c78c Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Mon, 25 Jul 2011 12:30:44 -0400 Subject: [PATCH] added --debug, few small fixes --- p2pool/__init__.py | 2 ++ p2pool/bitcoin/data.py | 22 ++++++++++++++-------- p2pool/data.py | 14 +------------- p2pool/main.py | 18 +++++++++++++----- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/p2pool/__init__.py b/p2pool/__init__.py index d5c401a..d52d625 100644 --- a/p2pool/__init__.py +++ b/p2pool/__init__.py @@ -9,3 +9,5 @@ try: except: __version__ = 'unknown' os.chdir(prev) + +DEBUG = False diff --git a/p2pool/bitcoin/data.py b/p2pool/bitcoin/data.py index 456977b..f49d1c9 100644 --- a/p2pool/bitcoin/data.py +++ b/p2pool/bitcoin/data.py @@ -6,7 +6,8 @@ import itertools import warnings from . import base58 -from p2pool.util import bases, math, skiplist +from p2pool.util import bases, math, skiplist, intern2 +import p2pool class EarlyEnd(Exception): pass @@ -58,17 +59,20 @@ class Type(object): def unpack(self, data): obj = self._unpack(data) - if __debug__: + if p2pool.DEBUG: data2 = self._pack(obj) if data2 != data: - assert self._unpack(data2) == obj + if self._unpack(data2) != obj: + raise AssertionError() return obj def pack(self, obj): data = self._pack(obj) - assert self._unpack(data) == obj + if p2pool.DEBUG: + if self._unpack(data) != obj: + raise AssertionError() return data @@ -272,9 +276,10 @@ class FloatingIntegerType(Type): def read(self, file): bits, file = self._inner.read(file) target = self._bits_to_target(bits) - if __debug__: + if p2pool.DEBUG: if self._target_to_bits(target) != bits: raise ValueError('bits in non-canonical form') + target = intern2.intern2(target) return target, file def write(self, file, item): @@ -285,8 +290,9 @@ class FloatingIntegerType(Type): def _bits_to_target(self, bits2): target = math.shift_left(bits2 & 0x00ffffff, 8 * ((bits2 >> 24) - 3)) - assert target == self._bits_to_target1(struct.pack(' 5: + print "Processing %i shares..." % (len(shares),) + for share in shares: if share.hash in tracker.shares: #print 'Got duplicate share, ignoring. Hash: %x' % (share.hash % 2**32,) @@ -190,6 +193,9 @@ def main(args): w = dict(current_work.value) w['best_share_hash'] = best current_work.set(w) + + if len(shares) > 5: + print "... done processing %i shares." % (len(shares),) def p2p_share_hashes(share_hashes, peer): get_hashes = [] @@ -271,7 +277,6 @@ def main(args): def compute(state, all_targets): start = time.time() - start = time.time() pre_extra_txs = [tx for tx in tx_pool.itervalues() if tx.is_good()] pre_extra_txs = pre_extra_txs[:2**16 - 1] # merkle_branch limit extra_txs = [] @@ -341,7 +346,7 @@ def main(args): return False share = p2pool.Share.from_block(block) my_shares.add(share.hash) - print 'GOT SHARE! %x %x' % (share.hash, 0 if share.previous_hash is None else share.previous_hash), "DEAD ON ARRIVAL" if share.previous_hash != current_work.value['best_share_hash'] else "", time.time() - times[share.nonce] + print 'GOT SHARE! %x %x' % (share.hash % 2**32, 0 if share.previous_hash is None else share.previous_hash), "DEAD ON ARRIVAL" if share.previous_hash != current_work.value['best_share_hash'] else "", time.time() - times[share.nonce] p2p_shares([share]) except: print @@ -501,14 +506,14 @@ def main(args): reactor.stop() def run(): - if __debug__: - defer.setDebugging(True) - parser = argparse.ArgumentParser(description='p2pool (version %s)' % (p2pool_init.__version__,)) parser.add_argument('--version', action='version', version=p2pool_init.__version__) parser.add_argument('--testnet', help='use the testnet', action='store_const', const=p2pool.Testnet, default=p2pool.Mainnet, dest='net') + parser.add_argument('--debug', + help='debugging mode', + action='store_const', const=True, default=False, dest='debug') parser.add_argument('-a', '--address', help='generate to this address (defaults to requesting one from bitcoind)', type=str, action='store', default=None, dest='address') @@ -549,6 +554,9 @@ def run(): args = parser.parse_args() + if args.debug: + p2pool_init.DEBUG = True + if args.bitcoind_p2p_port is None: args.bitcoind_p2p_port = args.net.BITCOIN_P2P_PORT -- 1.7.1