fixes for v3 blocks
[p2pool.git] / p2pool / data.py
index a9bae81..d1d8cbe 100644 (file)
@@ -5,7 +5,7 @@ import os
 import random
 import sys
 import time
-import math
+from math import floor, ceil
 
 from twisted.python import log
 
@@ -114,13 +114,36 @@ class Share(object):
     def generate_transaction(cls, tracker, share_data, block_target, desired_timestamp, desired_target, ref_merkle_link, desired_other_transaction_hashes_and_fees, net, known_txs=None, last_txout_nonce=0, base_subsidy=None):
         previous_share = tracker.items[share_data['previous_share_hash']] if share_data['previous_share_hash'] is not None else None
 
-        def get_coinbase_fee(outpointsnum):
+        def get_coinbase_fee(share_data, outpointsnum):
             # calculate neccessary coinbase fee
-            coinbase_size = 59 + outpointsnum * 44 + 50
+
+            # coinbase usually seems like this:
+            #
+            # 01000000 - nVersion
+            # 1a184351 - nTimestamp
+
+            # 01 - Inputs num
+            # 0000000000000000000000000000000000000000000000000000000000000000 - Input hash
+            # ffffffff - Input index (-1)
+            # 0a02732a062f503253482f - Scriptsig
+            # ffffffff - nSequence
+
+            # 15 - Outpoints num
+            # (User outpoints, 44 bytes per each)
+            # (Donation outpoint, 76 bytes)
+
+            # P2Pool service outpoint (contains merkle link), 46 bytes
+            #
+            # 1027000000000000
+            # 25
+            # 2417cc2063b11fd5255c7e5605780de78163ffc698ed22856bff1a5d880c3c44e400000000
+
+            # Giving users some time to upgrade
+            coinbase_size = 50 + (1 + len(share_data['coinbase'])) + outpointsnum * 44 + 76 + 46
 
             # if coinbase size is greater than 1000 bytes, it should pay fee (0.01 per 1000 bytes)
             if coinbase_size > 1000:
-                return math.floor(coinbase_size / 1000.0) * minout
+                return int(ceil(coinbase_size / 1000.0) * minout)
 
             return 0
 
@@ -177,7 +200,7 @@ class Share(object):
         )
 
         # calculate "raw" subsidy
-        raw_subsidy = share_data['subsidy'] - 3 * minout - get_coinbase_fee(len(raw_weights) + 1)
+        raw_subsidy = share_data['subsidy'] - 3 * minout - get_coinbase_fee(share_data, len(raw_weights) + 1)
 
         # calculate "raw" amounts
         raw_amounts = dict((script, raw_subsidy*weight//total_weight) for script, weight in raw_weights.iteritems()) 
@@ -199,7 +222,7 @@ class Share(object):
 
         # base subsidy value calculated as:
         # [subsidy - (0.01 for donation + 0.01 for current user + 0.01 for p2pool outpoint) - netfee]
-        my_subsidy = share_data['subsidy'] - 3 * minout - get_coinbase_fee(len(weights) + 1)
+        my_subsidy = share_data['subsidy'] - 3 * minout - get_coinbase_fee(share_data, len(weights) + 1)
 
         # subsidy goes according to weights prior to this share
         amounts = dict((script, my_subsidy*weight//total_weight) for script, weight in weights.iteritems()) 
@@ -685,9 +708,9 @@ def get_warnings(tracker, best_share, net, bitcoind_warning, bitcoind_work_value
     desired_version_counts = get_desired_version_counts(tracker, best_share,
         min(net.CHAIN_LENGTH, 60*60//net.SHARE_PERIOD, tracker.get_height(best_share)))
     majority_desired_version = max(desired_version_counts, key=lambda k: desired_version_counts[k])
-    if majority_desired_version > 11 and desired_version_counts[majority_desired_version] > sum(desired_version_counts.itervalues())/2:
+    if majority_desired_version > 14 and desired_version_counts[majority_desired_version] > sum(desired_version_counts.itervalues())/2:
         res.append('A MAJORITY OF SHARES CONTAIN A VOTE FOR AN UNSUPPORTED SHARE IMPLEMENTATION! (v%i with %i%% support)\n'
-            'An upgrade is likely necessary. Check http://p2pool.forre.st/ for more information.' % (
+            'An upgrade is likely necessary. Check https://github.com/CryptoManiac/p2pool for more information.' % (
                 majority_desired_version, 100*desired_version_counts[majority_desired_version]/sum(desired_version_counts.itervalues())))
     
     if bitcoind_warning is not None: