From 9f3c22e477bec23cf9b1bae83ffec038963647e9 Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Sat, 13 Oct 2012 12:49:25 -0400 Subject: [PATCH] add transactions from bitcoind over p2p connection to known_txs --- p2pool/bitcoin/p2p.py | 5 ++--- p2pool/main.py | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/p2pool/bitcoin/p2p.py b/p2pool/bitcoin/p2p.py index 4d04d54..fd403f1 100644 --- a/p2pool/bitcoin/p2p.py +++ b/p2pool/bitcoin/p2p.py @@ -53,7 +53,6 @@ class Protocol(p2protocol.Protocol): def handle_verack(self): self.get_block = deferral.ReplyMatcher(lambda hash: self.send_getdata(requests=[dict(type='block', hash=hash)])) self.get_block_header = deferral.ReplyMatcher(lambda hash: self.send_getheaders(version=1, have=[], last=hash)) - self.get_tx = deferral.ReplyMatcher(lambda hash: self.send_getdata(requests=[dict(type='tx', hash=hash)])) if hasattr(self.factory, 'resetDelay'): self.factory.resetDelay() @@ -72,7 +71,7 @@ class Protocol(p2protocol.Protocol): def handle_inv(self, invs): for inv in invs: if inv['type'] == 'tx': - self.factory.new_tx.happened(inv['hash']) + self.send_getdata(requests=[inv]) elif inv['type'] == 'block': self.factory.new_block.happened(inv['hash']) else: @@ -110,7 +109,7 @@ class Protocol(p2protocol.Protocol): ('tx', bitcoin_data.tx_type), ]) def handle_tx(self, tx): - self.get_tx.got_response(bitcoin_data.hash256(bitcoin_data.tx_type.pack(tx)), tx) + self.factory.new_tx.happened(tx) message_block = pack.ComposedType([ ('block', bitcoin_data.block_type), diff --git a/p2pool/main.py b/p2pool/main.py index e01041c..7b3ed2f 100644 --- a/p2pool/main.py +++ b/p2pool/main.py @@ -256,6 +256,12 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint): new_known_txs[tx_hash] = tx mining_txs_var.set(new_mining_txs) known_txs_var.set(new_known_txs) + # add p2p transactions from bitcoind to known_txs + @factory.new_tx.watch + def _(tx): + new_known_txs = dict(known_txs_var.value) + new_known_txs[bitcoin_data.hash256(bitcoin_data.tx_type.pack(tx))] = tx + known_txs_var.set(new_known_txs) # forward transactions seen to bitcoind @known_txs_var.transitioned.watch def _(before, after): -- 1.7.1