moved chain_length up so it can be used in assert
authorForrest Voight <forrest@forre.st>
Wed, 7 Dec 2011 00:07:48 +0000 (19:07 -0500)
committerForrest Voight <forrest@forre.st>
Wed, 7 Dec 2011 00:07:48 +0000 (19:07 -0500)
p2pool/data.py

index d827619..5253a74 100644 (file)
@@ -192,8 +192,10 @@ def generate_transaction(tracker, share_data, block_target, desired_timestamp, n
     
     previous_share = tracker.shares[previous_share_hash] if previous_share_hash is not None else None
     
+    chain_length = getattr(net, 'REAL_CHAIN_LENGTH_FUNC', lambda _: net.REAL_CHAIN_LENGTH)(previous_share.timestamp if previous_share is not None else None)
+    
     height, last = tracker.get_height_and_last(previous_share_hash)
-    assert height >= net.CHAIN_LENGTH or last is None
+    assert height >= chain_length or last is None
     if height < net.TARGET_LOOKBEHIND:
         target = bitcoin_data.FloatingInteger.from_target_upper_bound(net.MAX_TARGET)
     else:
@@ -207,7 +209,6 @@ def generate_transaction(tracker, share_data, block_target, desired_timestamp, n
     max_att = net.SPREAD * attempts_to_block
     
     this_att = min(bitcoin_data.target_to_average_attempts(target), max_att)
-    chain_length = getattr(net, 'REAL_CHAIN_LENGTH_FUNC', lambda _: net.REAL_CHAIN_LENGTH)(previous_share.timestamp if previous_share is not None else None)
     other_weights, other_total_weight, other_donation_weight = tracker.get_cumulative_weights(previous_share_hash, min(height, chain_length), 65535*max(0, max_att - this_att))
     assert other_total_weight == sum(other_weights.itervalues()) + other_donation_weight, (other_total_weight, sum(other_weights.itervalues()) + other_donation_weight)
     weights, total_weight, donation_weight = math.add_dicts([{new_script: this_att*(65535-donation)}, other_weights]), this_att*65535 + other_total_weight, this_att*donation + other_donation_weight