removed HeightTracker's backing
authorForrest Voight <forrest.voight@gmail.com>
Sun, 4 Dec 2011 19:23:05 +0000 (14:23 -0500)
committerForrest Voight <forrest@forre.st>
Wed, 7 Dec 2011 20:59:25 +0000 (15:59 -0500)
p2pool/bitcoin/p2p.py
p2pool/main.py

index e0aaa56..993a08e 100644 (file)
@@ -299,10 +299,9 @@ class HeaderWrapper(object):
 class HeightTracker(object):
     '''Point this at a factory and let it take care of getting block heights'''
     
-    def __init__(self, factory, backing):
+    def __init__(self, factory):
         self.factory = factory
         self.tracker = forest.Tracker()
-        self.backing = backing
         self.most_recent = None
         
         self._watch1 = self.factory.new_headers.watch(self.heard_headers)
@@ -316,29 +315,8 @@ class HeightTracker(object):
         
         self.updated = variable.Event()
         
-        self._load_backing()
-        
         self.think()
     
-    def _load_backing(self):
-        open(self.backing, 'ab').close()
-        with open(self.backing, 'rb') as f:
-            count = 0
-            for line in f:
-                try:
-                    hash, previous_hash, checksum = (int(x, 16) for x in line.strip().split(' '))
-                except Exception:
-                    print "skipping over bad data in headers.dat"
-                else:
-                    if (hash - previous_hash) % 2**256 != checksum:
-                        print "checksum failed"
-                        continue
-                    if previous_hash == 0: previous_hash = None
-                    count += 1
-                    if count % 10000 == 0 and count: print count
-                    if hash not in self.tracker.shares:
-                        self.tracker.add(HeaderWrapper(hash, previous_hash))
-    
     def think(self):
         highest_head = max(self.tracker.heads, key=lambda h: self.tracker.get_height_and_last(h)[0]) if self.tracker.heads else None
         height, last = self.tracker.get_height_and_last(highest_head)
@@ -371,16 +349,12 @@ class HeightTracker(object):
     
     def heard_headers(self, headers):
         changed = False
-        b = open(self.backing, 'ab')
         for header in headers:
             hw = HeaderWrapper.from_header(header)
             if hw.hash in self.tracker.shares:
                 continue
             changed = True
             self.tracker.add(hw)
-            hash, prev = hw.hash, 0 if hw.previous_hash is None else hw.previous_hash
-            b.write('%x %x %x\n' % (hash, prev, (hash - prev) % 2**256))
-        b.close()
         if changed:
             self.updated.happened()
         self.think()
@@ -412,6 +386,10 @@ class HeightTracker(object):
         #    self.request([], last)
         return height
     
+    def get_dist_below_highest(self, block_hash):
+        pass
+        # 0, 1, 2, 3, 4
+    
     def get_highest_height(self):
         return self.tracker.get_highest_height()
     
index 275c8f5..cdee056 100644 (file)
@@ -94,10 +94,7 @@ def main(args, net):
         print '    Payout script:', bitcoin_data.script2_to_human(my_script, net)
         print
         
-        print 'Loading cached block headers...'
-        ht = bitcoin_p2p.HeightTracker(factory, net.NAME + '_headers.dat')
-        print '   ...done loading %i cached block headers.' % (len(ht.tracker.shares),)
-        print
+        ht = bitcoin_p2p.HeightTracker(factory)
         
         tracker = p2pool_data.OkayTracker(net)
         shared_share_hashes = set()