store total share count and work within shares
authorForrest Voight <forrest@forre.st>
Fri, 28 Jun 2013 19:02:32 +0000 (15:02 -0400)
committerForrest Voight <forrest@forre.st>
Wed, 3 Jul 2013 18:31:03 +0000 (14:31 -0400)
p2pool/data.py
p2pool/web.py
web-static/share.html

index 29fbfc6..b0edf1f 100644 (file)
@@ -83,6 +83,8 @@ class NewShare(object):
         ('max_bits', bitcoin_data.FloatingIntegerType()),
         ('bits', bitcoin_data.FloatingIntegerType()),
         ('timestamp', pack.IntType(32)),
+        ('absheight', pack.IntType(32)),
+        ('abswork', pack.IntType(128)),
     ])
     
     share_type = pack.ComposedType([
@@ -184,6 +186,8 @@ class NewShare(object):
             )) if previous_share is not None else desired_timestamp,
             new_transaction_hashes=new_transaction_hashes,
             transaction_hash_refs=transaction_hash_refs,
+            absheight=((previous_share.absheight if previous_share is not None else 0) + 1) % 2**32,
+            abswork=((previous_share.abswork if previous_share is not None else 0) + bitcoin_data.target_to_average_attempts(bits.target)) % 2**128,
         )
         
         gentx = dict(
@@ -222,7 +226,7 @@ class NewShare(object):
             share_info=share_info,
         ))), ref_merkle_link))
     
-    __slots__ = 'net peer_addr contents min_header share_info hash_link merkle_link hash share_data max_target target timestamp previous_hash new_script desired_version gentx_hash header pow_hash header_hash new_transaction_hashes time_seen'.split(' ')
+    __slots__ = 'net peer_addr contents min_header share_info hash_link merkle_link hash share_data max_target target timestamp previous_hash new_script desired_version gentx_hash header pow_hash header_hash new_transaction_hashes time_seen absheight abswork'.split(' ')
     
     def __init__(self, net, peer_addr, contents):
         self.net = net
@@ -249,6 +253,8 @@ class NewShare(object):
         self.previous_hash = self.share_data['previous_share_hash']
         self.new_script = bitcoin_data.pubkey_hash_to_script2(self.share_data['pubkey_hash'])
         self.desired_version = self.share_data['desired_version']
+        self.absheight = self.share_info['absheight']
+        self.abswork = self.share_info['abswork']
         
         n = set()
         for share_count, tx_count in self.iter_transaction_hash_refs():
@@ -373,6 +379,8 @@ class Share(object):
     VOTING_VERSION = 11
     SUCCESSOR = NewShare
     
+    absheight = abswork = 0
+    
     small_block_header_type = pack.ComposedType([
         ('version', pack.VarIntType()),
         ('previous_block', pack.PossiblyNoneType(0, pack.IntType(256))),
index a8fa9cd..6b9f575 100644 (file)
@@ -292,6 +292,8 @@ def get_web_root(wb, datadir_path, bitcoind_warning_var, stop_event=variable.Eve
                 stale_info=share.share_data['stale_info'],
                 nonce=share.share_data['nonce'],
                 desired_version=share.share_data['desired_version'],
+                absheight=share.absheight,
+                abswork=share.abswork,
             ),
             block=dict(
                 hash='%064x' % share.header_hash,
index 4414ae7..9d53127 100644 (file)
@@ -56,6 +56,8 @@
                     b.append('p').text('Last stale: ' + share.share_data.stale_info);
                     b.append('p').text('Nonce: ' + share.share_data.nonce);
                     b.append('p').text('Desired version: ' + share.share_data.desired_version);
+                    b.append('p').text('Absolute height: ' + share.share_data.absheight);
+                    b.append('p').text('Absolute work: ' + share.share_data.abswork);
                     b.append('h2').text('Block');
                     var block = b.append('p')
                         block.append('span').text('Hash: ')