Пример #1
0
 def _run_ff(blockchain):
     # this kind of works, but it's lame because we put
     # peers into a queue, so they'll never be garbage collected
     # even if they vanish. I think.
     while 1:
         priority, (peer, lbi, rate_dict) = yield from peer_queue.get()
         if lbi - blockchain.length() > 0:
             # let's get some headers from this guy!
             start_time = time.time()
             h = blockchain.last_block_hash()
             try:
                 headers = yield from asyncio.wait_for(get_headers_hashes(
                     peer, h),
                                                       timeout=10)
             except EOFError:
                 # this peer is dead... so don't put it back in the queue
                 continue
             except asyncio.TimeoutError:
                 # this peer timed out. How useless
                 continue
             # TODO: what if the stupid client sends us bogus headers?
             # how will we ever figure this out?
             # answer: go through headers and remove fake ones or ones that we've seen
             # check hash, difficulty, difficulty against hash, and that they form
             # a chain. This make it expensive to produce bogus headers
             time_elapsed = time.time() - start_time
             rate_dict["total_seconds"] += time_elapsed
             rate_dict["records"] += len(headers)
             priority = -rate_dict["records"] / rate_dict["total_seconds"]
             # let's make sure we actually extend the chain
             ops = blockchain.add_nodes(
                 (h.hash(), h.previous_block_hash, h.difficulty)
                 for h in headers)
             ## this hack is necessary because the stupid default client
             # does not send the genesis block!
             try:
                 while len(ops) == 0:
                     ops = yield from asyncio.wait_for(_fetch_missing(
                         peer, blockchain),
                                                       timeout=30)
             except Exception:
                 logging.exception("problem fetching missing parents")
             if len(ops) > 0:
                 peer_queue.put_nowait((priority, (peer, lbi, rate_dict)))
Пример #2
0
 def _run_ff(blockchain):
     # this kind of works, but it's lame because we put
     # peers into a queue, so they'll never be garbage collected
     # even if they vanish. I think.
     while 1:
         priority, (peer, lbi, rate_dict) = yield from peer_queue.get()
         if lbi - blockchain.length() > 0:
             # let's get some headers from this guy!
             start_time = time.time()
             h = blockchain.last_block_hash()
             try:
                 headers = yield from asyncio.wait_for(get_headers_hashes(peer, h), timeout=10)
             except EOFError:
                 # this peer is dead... so don't put it back in the queue
                 continue
             except asyncio.TimeoutError:
                 # this peer timed out. How useless
                 continue
             # TODO: what if the stupid client sends us bogus headers?
             # how will we ever figure this out?
             # answer: go through headers and remove fake ones or ones that we've seen
             # check hash, difficulty, difficulty against hash, and that they form
             # a chain. This make it expensive to produce bogus headers
             time_elapsed = time.time() - start_time
             rate_dict["total_seconds"] += time_elapsed
             rate_dict["records"] += len(headers)
             priority = - rate_dict["records"] / rate_dict["total_seconds"]
             # let's make sure we actually extend the chain
             ops = blockchain.add_headers(headers)
             ## this hack is necessary because the stupid default client
             # does not send the genesis block!
             try:
                 while len(ops) == 0:
                     ops = yield from asyncio.wait_for(_fetch_missing(peer, blockchain), timeout=30)
             except Exception:
                 logging.exception("problem fetching missing parents")
             if len(ops) > 0:
                 peer_queue.put_nowait((priority, (peer, lbi, rate_dict)))
 def run_peer2():
     r = []
     headers = yield from standards.get_headers_hashes(peer2, after_block_hash=b"\0" * 32)
     r.append(headers)
     return r
Пример #4
0
 def run_peer2():
     r = []
     headers = yield from standards.get_headers_hashes(
         peer2, after_block_hash=b'\0' * 32)
     r.append(headers)
     return r
Пример #5
0
 def run_peer2():
     r = []
     headers = yield from standards.get_headers_hashes(peer2, until_block_hash=b'\0' * 32)
     r.append(headers)
     return r