Skip to content

Commit

Permalink
Check if new headers are known by bitcoind
Browse files Browse the repository at this point in the history
  • Loading branch information
veqtrus committed Aug 15, 2017
1 parent 120dd61 commit 519486f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions p2pool/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,16 @@ def work_poller():
# PEER WORK

self.best_block_header = variable.Variable(None)
def handle_header(new_header):
def handle_header(new_header, valid=False):
new_hash = self.net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(new_header))
# check that header matches current target
if not (self.net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(new_header)) <= self.bitcoind_work.value['bits'].target):
if new_hash > self.bitcoind_work.value['bits'].target:
return
if not valid:
try:
_ = (yield self.bitcoind.rpc_getblockheader(new_hash))
except:
return
bitcoind_best_block = self.bitcoind_work.value['previous_block']
if (self.best_block_header.value is None
or (
Expand All @@ -215,7 +221,7 @@ def handle_header(new_header):
def poll_header():
if self.factory.conn.value is None:
return
handle_header((yield self.factory.conn.value.get_block_header(self.bitcoind_work.value['previous_block'])))
handle_header((yield self.factory.conn.value.get_block_header(self.bitcoind_work.value['previous_block'])), True)
self.bitcoind_work.changed.watch(lambda _: poll_header())
yield deferral.retry('Error while requesting best block header:')(poll_header)()

Expand Down

0 comments on commit 519486f

Please sign in to comment.