separated CHAIN_LENGTH and REAL_CHAIN_LENGTH, documented both, and gave REAL_CHAIN_LE...
authorForrest Voight <forrest@forre.st>
Tue, 6 Dec 2011 23:05:38 +0000 (18:05 -0500)
committerForrest Voight <forrest@forre.st>
Tue, 6 Dec 2011 23:05:38 +0000 (18:05 -0500)
p2pool/data.py
p2pool/networks.py

index 507bb82..db19252 100644 (file)
@@ -207,7 +207,8 @@ 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)
-    other_weights, other_total_weight, other_donation_weight = tracker.get_cumulative_weights(previous_share_hash, min(height, net.CHAIN_LENGTH), 65535*max(0, max_att - this_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
     assert total_weight == sum(weights.itervalues()) + donation_weight, (total_weight, sum(weights.itervalues()) + donation_weight)
index 7c7ec2a..6de759d 100644 (file)
@@ -1,8 +1,15 @@
 from p2pool.bitcoin import networks
 
+# CHAIN_LENGTH = number of shares back client keeps
+# REAL_CHAIN_LENGTH = maximum number of shares back client uses to compute payout
+# REAL_CHAIN_LENGTH must always be <= CHAIN_LENGTH
+# REAL_CHAIN_LENGTH must be changed in sync with all other clients
+# changes can be done by changing one, then the other
+
 class BitcoinMainnet(networks.BitcoinMainnet):
     SHARE_PERIOD = 10 # seconds
     CHAIN_LENGTH = 24*60*60//10//2 # shares
+    REAL_CHAIN_LENGTH = 24*60*60//10//2 # shares
     TARGET_LOOKBEHIND = 200 # shares
     SPREAD = 3 # blocks
     IDENTIFIER = 'fc70035c7a81bc6f'.decode('hex')
@@ -16,6 +23,7 @@ class BitcoinMainnet(networks.BitcoinMainnet):
 class BitcoinTestnet(networks.BitcoinTestnet):
     SHARE_PERIOD = 1 # seconds
     CHAIN_LENGTH = 24*60*60//10//2 # shares
+    REAL_CHAIN_LENGTH = 24*60*60//10//2 # shares
     TARGET_LOOKBEHIND = 200 # shares
     SPREAD = 3 # blocks
     IDENTIFIER = '5fc2be2d4f0d6bfb'.decode('hex')
@@ -29,6 +37,7 @@ class BitcoinTestnet(networks.BitcoinTestnet):
 class NamecoinMainnet(networks.NamecoinMainnet):
     SHARE_PERIOD = 10 # seconds
     CHAIN_LENGTH = 24*60*60//10 # shares
+    REAL_CHAIN_LENGTH = 24*60*60//10 # shares
     TARGET_LOOKBEHIND = 3600//10 # shares
     SPREAD = 3 # blocks
     IDENTIFIER = 'd5b1192062c4c454'.decode('hex')
@@ -42,6 +51,7 @@ class NamecoinMainnet(networks.NamecoinMainnet):
 class NamecoinTestnet(networks.NamecoinTestnet):
     SHARE_PERIOD = 1 # seconds
     CHAIN_LENGTH = 24*60*60//5 # shares
+    REAL_CHAIN_LENGTH = 24*60*60//5 # shares
     TARGET_LOOKBEHIND = 200 # shares
     SPREAD = 3 # blocks
     IDENTIFIER = '8dd303d014a01a60'.decode('hex')
@@ -55,6 +65,7 @@ class NamecoinTestnet(networks.NamecoinTestnet):
 class LitecoinMainnet(networks.LitecoinMainnet):
     SHARE_PERIOD = 10 # seconds
     CHAIN_LENGTH = 24*60*60//10//2 # shares
+    REAL_CHAIN_LENGTH = 24*60*60//10//2 # shares
     TARGET_LOOKBEHIND = 200 # shares
     SPREAD = 12 # blocks
     IDENTIFIER = 'e037d5b8c6923410'.decode('hex')
@@ -68,6 +79,7 @@ class LitecoinMainnet(networks.LitecoinMainnet):
 class LitecoinTestnet(networks.LitecoinTestnet):
     SHARE_PERIOD = 1 # seconds
     CHAIN_LENGTH = 24*60*60//5 # shares
+    REAL_CHAIN_LENGTH = 24*60*60//5 # shares
     TARGET_LOOKBEHIND = 200 # shares
     SPREAD = 12 # blocks
     IDENTIFIER = 'cca5e24ec6408b1e'.decode('hex')