Broadcast current best block header over P2P network
authorForrest Voight <forrest@forre.st>
Tue, 29 May 2012 06:21:49 +0000 (02:21 -0400)
committerForrest Voight <forrest@forre.st>
Wed, 30 May 2012 21:36:03 +0000 (17:36 -0400)
p2pool/main.py
p2pool/p2p.py

index 7f2c76f..1106645 100644 (file)
@@ -382,6 +382,17 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
                 f.write(json.dumps(p2p_node.addr_store.items()))
         task.LoopingCall(save_addrs).start(60)
         
+        best_block = variable.Variable(None)
+        @pre_current_work.changed.watch
+        def _(work):
+            best_block.set(work['previous_block'])
+        @best_block.changed.watch
+        @defer.inlineCallbacks
+        def _(block_hash):
+            header = yield factory.conn.value.get_block_header(block_hash)
+            for peer in p2p_node.peers.itervalues():
+                peer.send_bestblock(header=header)
+        
         def broadcast_share(share_hash):
             shares = []
             for share in tracker.get_chain(share_hash, min(5, tracker.get_height(share_hash))):
index 15889e7..4170414 100644 (file)
@@ -239,6 +239,11 @@ class Protocol(p2protocol.Protocol):
     def handle_sharereply(self, id, result, shares):
         self.node.handle_share_reply(id, result, shares, self)
     
+    message_bestblock = pack.ComposedType([
+        ('header', bitcoin_data.block_header_type),
+    ])
+    def handle_bestblock(self, header):
+        pass
     
     def connectionLost(self, reason):
         if self.connected2: