Ejemplo n.º 1
0
 def get_rate():
     if current_work.value['best_share_hash'] is not None:
         height, last = tracker.get_height_and_last(current_work.value['best_share_hash'])
         att_s = p2pool_data.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], min(height - 1, 720))
         fracs = [share.stale_frac for share in tracker.get_chain(current_work.value['best_share_hash'], min(120, height)) if share.stale_frac is not None]
         return json.dumps(int(att_s / (1. - (math.median(fracs) if fracs else 0))))
     return json.dumps(None)
Ejemplo n.º 2
0
 def status_thread():
     last_str = None
     last_time = 0
     while True:
         yield deferral.sleep(3)
         try:
             if time.time() > current_work2.value['last_update'] + 60:
                 print '''---> LOST CONTACT WITH BITCOIND for 60 seconds, check that it isn't frozen or dead <---'''
             if current_work.value['best_share_hash'] is not None:
                 height, last = tracker.get_height_and_last(current_work.value['best_share_hash'])
                 if height > 2:
                     att_s = p2pool_data.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], min(height - 1, 720))
                     weights, total_weight, donation_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 720), 65535*2**256)
                     shares, stale_doa_shares, stale_not_doa_shares = get_share_counts(True)
                     stale_shares = stale_doa_shares + stale_not_doa_shares
                     fracs = [share.stale_frac for share in tracker.get_chain(current_work.value['best_share_hash'], min(120, height)) if share.stale_frac is not None]
                     this_str = 'Pool: %sH/s in %i shares (%i/%i verified) Recent: %.02f%% >%sH/s Shares: %i (%i orphan, %i dead) Peers: %i' % (
                         math.format(int(att_s / (1. - (math.median(fracs) if fracs else 0)))),
                         height,
                         len(tracker.verified.shares),
                         len(tracker.shares),
                         weights.get(my_script, 0)/total_weight*100,
                         math.format(int(weights.get(my_script, 0)*att_s//total_weight / (1. - (math.median(fracs) if fracs else 0)))),
                         shares,
                         stale_not_doa_shares,
                         stale_doa_shares,
                         len(p2p_node.peers),
                     ) + (' FDs: %i R/%i W' % (len(reactor.getReaders()), len(reactor.getWriters())) if p2pool.DEBUG else '')
                     if fracs:
                         med = math.median(fracs)
                         this_str += '\nPool stales: %i%%' % (int(100*med+.5),)
                         conf = 0.95
                         if shares:
                             this_str += u' Own: %i±%i%%' % tuple(int(100*x+.5) for x in math.interval_to_center_radius(math.binomial_conf_interval(stale_shares, shares, conf)))
                             if med < .99:
                                 this_str += u' Own efficiency: %i±%i%%' % tuple(int(100*x+.5) for x in math.interval_to_center_radius((1 - y)/(1 - med) for y in math.binomial_conf_interval(stale_shares, shares, conf)[::-1]))
                     if this_str != last_str or time.time() > last_time + 15:
                         print this_str
                         last_str = this_str
                         last_time = time.time()
         except:
             log.err()
Ejemplo n.º 3
0
 def get_rate():
     if current_work.value['best_share_hash'] is not None:
         height, last = tracker.get_height_and_last(
             current_work.value['best_share_hash'])
         att_s = p2pool_data.get_pool_attempts_per_second(
             tracker, current_work.value['best_share_hash'],
             min(height - 1, 720))
         fracs = [
             share.stale_frac for share in tracker.get_chain(
                 current_work.value['best_share_hash'], min(
                     120, height)) if share.stale_frac is not None
         ]
         return json.dumps(
             int(att_s / (1. - (math.median(fracs) if fracs else 0))))
     return json.dumps(None)
Ejemplo n.º 4
0
Archivo: main.py Proyecto: gyver/p2pool
 def compute(state, payout_script):
     if payout_script is None:
         payout_script = my_script
     if state['best_share_hash'] is None and args.net.PERSIST:
         raise jsonrpc.Error(-12345, u'p2pool is downloading shares')
     pre_extra_txs = [tx for tx in tx_pool.itervalues() if tx.is_good()]
     pre_extra_txs = pre_extra_txs[:2**16 - 1] # merkle_branch limit
     extra_txs = []
     size = 0
     for tx in pre_extra_txs:
         this_size = len(bitcoin.data.tx_type.pack(tx.tx))
         if size + this_size > 500000:
             break
         extra_txs.append(tx)
         size += this_size
     # XXX check sigops!
     # XXX assuming generate_tx is smallish here..
     generate_tx = p2pool.generate_transaction(
         tracker=tracker,
         previous_share_hash=state['best_share_hash'],
         new_script=payout_script,
         subsidy=(50*100000000 >> (state['height'] + 1)//210000) + sum(tx.value_in - tx.value_out for tx in extra_txs),
         nonce=run_identifier + struct.pack('<Q', random.randrange(2**64)),
         block_target=state['target'],
         net=args.net,
     )
     print 'Generating! Difficulty: %.06f Payout if block: %.6f BTC' % (0xffff*2**208/p2pool.coinbase_type.unpack(generate_tx['tx_ins'][0]['script'])['share_data']['target'], generate_tx['tx_outs'][-1]['value']*1e-8)
     #print 'Target: %x' % (p2pool.coinbase_type.unpack(generate_tx['tx_ins'][0]['script'])['share_data']['target'],)
     #, have', shares.count(my_script) - 2, 'share(s) in the current chain. Fee:', sum(tx.value_in - tx.value_out for tx in extra_txs)/100000000
     transactions = [generate_tx] + [tx.tx for tx in extra_txs]
     merkle_root = bitcoin.data.merkle_hash(transactions)
     merkle_root_to_transactions[merkle_root] = transactions # will stay for 1000 seconds
     
     timestamp = int(time.time() - current_work2.value['clock_offset'])
     if state['best_share_hash'] is not None:
         timestamp2 = math.median((s.timestamp for s in itertools.islice(tracker.get_chain_to_root(state['best_share_hash']), 11)), use_float=False) + 1
         if timestamp2 > timestamp:
             print 'Toff', timestamp2 - timestamp
             timestamp = timestamp2
     target2 = p2pool.coinbase_type.unpack(generate_tx['tx_ins'][0]['script'])['share_data']['target']
     times[p2pool.coinbase_type.unpack(generate_tx['tx_ins'][0]['script'])['share_data']['nonce']] = time.time()
     #print 'SENT', 2**256//p2pool.coinbase_type.unpack(generate_tx['tx_ins'][0]['script'])['share_data']['target']
     return bitcoin.getwork.BlockAttempt(state['version'], state['previous_block'], merkle_root, timestamp, state['target'], target2)
Ejemplo n.º 5
0
 def status_thread():
     last_str = None
     last_time = 0
     while True:
         yield deferral.sleep(3)
         try:
             if time.time() > current_work2.value['last_update'] + 60:
                 print '''---> LOST CONTACT WITH BITCOIND for 60 seconds, check that it isn't frozen or dead <---'''
             if current_work.value['best_share_hash'] is not None:
                 height, last = tracker.get_height_and_last(
                     current_work.value['best_share_hash'])
                 if height > 2:
                     att_s = p2pool_data.get_pool_attempts_per_second(
                         tracker, current_work.value['best_share_hash'],
                         min(height - 1, 720))
                     weights, total_weight, donation_weight = tracker.get_cumulative_weights(
                         current_work.value['best_share_hash'],
                         min(height, 720), 65535 * 2**256)
                     shares, stale_doa_shares, stale_not_doa_shares = get_share_counts(
                         True)
                     stale_shares = stale_doa_shares + stale_not_doa_shares
                     fracs = [
                         share.stale_frac
                         for share in tracker.get_chain(
                             current_work.value['best_share_hash'],
                             min(120, height))
                         if share.stale_frac is not None
                     ]
                     this_str = 'Pool: %sH/s in %i shares (%i/%i verified) Recent: %.02f%% >%sH/s Shares: %i (%i orphan, %i dead) Peers: %i' % (
                         math.format(
                             int(att_s /
                                 (1. -
                                  (math.median(fracs) if fracs else 0)))
                         ),
                         height,
                         len(tracker.verified.shares),
                         len(tracker.shares),
                         weights.get(my_script, 0) / total_weight * 100,
                         math.format(
                             int(
                                 weights.get(my_script, 0) * att_s //
                                 total_weight /
                                 (1. -
                                  (math.median(fracs) if fracs else 0)))
                         ),
                         shares,
                         stale_not_doa_shares,
                         stale_doa_shares,
                         len(p2p_node.peers),
                     ) + (' FDs: %i R/%i W' %
                          (len(reactor.getReaders()),
                           len(reactor.getWriters()))
                          if p2pool.DEBUG else '')
                     if fracs:
                         med = math.median(fracs)
                         this_str += '\nPool stales: %i%%' % (
                             int(100 * med + .5), )
                         conf = 0.95
                         if shares:
                             this_str += u' Own: %i±%i%%' % tuple(
                                 int(100 * x + .5) for x in
                                 math.interval_to_center_radius(
                                     math.binomial_conf_interval(
                                         stale_shares, shares, conf)))
                             if med < .99:
                                 this_str += u' Own efficiency: %i±%i%%' % tuple(
                                     int(100 * x + .5) for x in
                                     math.interval_to_center_radius(
                                         (1 - y) / (1 - med) for y in
                                         math.binomial_conf_interval(
                                             stale_shares, shares,
                                             conf)[::-1]))
                     if this_str != last_str or time.time(
                     ) > last_time + 15:
                         print this_str
                         last_str = this_str
                         last_time = time.time()
         except:
             log.err()