#t.remove(99)
- print "HEADS", t.heads
- print "TAILS", t.tails
+ print 'HEADS', t.heads
+ print 'TAILS', t.tails
import random
t.add(FakeShare(i, x))
while t.shares:
x = random.choice(list(t.shares))
- print "DEL", x, t.__dict__
+ print 'DEL', x, t.__dict__
try:
t.remove(x)
except NotImplementedError:
- print "aborted; not implemented"
+ print 'aborted; not implemented'
import time
time.sleep(.1)
- print "HEADS", t.heads
- print "TAILS", t.tails
+ print 'HEADS', t.heads
+ print 'TAILS', t.tails
#for share_hash, share in sorted(t.shares.iteritems()):
# print share_hash, share.previous_hash, t.heads.get(share_hash), t.tails.get(share_hash)
length, = struct.unpack('<I', (yield 4))
if length > self.max_net_payload_length:
- print "length too long"
+ print 'length too long'
continue
if self.use_checksum:
d = zlib.decompressobj()
payload = d.decompress(compressed_payload, self.max_payload_length)
if d.unconsumed_tail:
- print "compressed payload expanded too much"
+ print 'compressed payload expanded too much'
continue
assert not len(payload) > self.max_payload_length
except:
continue
else:
if len(compressed_payload) > self.max_payload_length:
- print "compressed payload expanded too much"
+ print 'compressed payload expanded too much'
continue
payload = compressed_payload
self.think()
if len(self.tracker.shares) > self.last_notified_size + 10:
- print "Have %i block headers" % len(self.tracker.shares)
+ print 'Have %i block headers' % len(self.tracker.shares)
self.last_notified_size = len(self.tracker.shares)
def heard_block(self, block_hash):
opcodes = {}
for i in xrange(256):
- opcodes[i] = "UNK_" + str(i), reads_nothing
+ opcodes[i] = 'UNK_' + str(i), reads_nothing
opcodes[0] = '0', reads_nothing
for i in xrange(1, 76):
if not self.attempt_verify(share, now):
break
if random.random() < .001:
- #print "YIELDING"
+ #print 'YIELDING'
yield deferral.sleep(.01)
if head_height < self.net.CHAIN_LENGTH and last_last_hash is not None:
desired.add((self.verified.shares[random.choice(list(self.verified.reverse_shares[last_hash]))].peer, last_last_hash))
best_share = self.verified.shares[best]
if ht.get_min_height(best_share.header['previous_block']) < ht.get_min_height(previous_block) and best_share.bitcoin_hash != previous_block and best_share.peer is not None:
if p2pool.DEBUG:
- print "Stale detected!"
+ print 'Stale detected!'
best = best_share.previous_hash
defer.returnValue((best, desired))
def p2p_shares(shares, peer=None):
if len(shares) > 5:
- print "Processing %i shares..." % (len(shares),)
+ print 'Processing %i shares...' % (len(shares),)
some_new = False
for share in shares:
tracker_updated.happened()
if len(shares) > 5:
- print "... done processing %i shares." % (len(shares),)
+ print '... done processing %i shares.' % (len(shares),)
def p2p_share_hashes(share_hashes, peer):
get_hashes = []
def compute(state, all_targets):
if state['best_share_hash'] is None:
- raise jsonrpc.Error(-12345, u"p2pool is downloading shares")
+ 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 = []
return False
share = p2pool.Share.from_block(block)
my_shares.add(share.hash)
- print 'GOT SHARE! %x prev %x age %.2fs' % (share.hash % 2**32, 0 if share.previous_hash is None else share.previous_hash % 2**32, time.time() - times[share.nonce]) + (" DEAD ON ARRIVAL" if share.previous_hash != current_work.value['best_share_hash'] else "")
+ print 'GOT SHARE! %x prev %x age %.2fs' % (share.hash % 2**32, 0 if share.previous_hash is None else share.previous_hash % 2**32, time.time() - times[share.nonce]) + (' DEAD ON ARRIVAL' if share.previous_hash != current_work.value['best_share_hash'] else '')
good = share.previous_hash == current_work.value['best_share_hash']
# maybe revert back to tracker being non-blocking so 'good' can be more accurate?
p2p_shares([share])
def new_tx(tx_hash):
try:
assert isinstance(tx_hash, (int, long))
- #print "REQUESTING", tx_hash
+ #print 'REQUESTING', tx_hash
tx = yield (yield factory.getProtocol()).get_tx(tx_hash)
- #print "GOT", tx
+ #print 'GOT', tx
tx_pool[bitcoin.data.tx_type.hash256(tx)] = Tx(tx, current_work.value['previous_block'])
except:
log.err(None, 'Error handling tx:')
class TimestampingPipe(object):
def __init__(self, inner_file):
self.inner_file = inner_file
- self.buf = ""
+ self.buf = ''
self.softspace = 0
def write(self, data):
buf = self.buf + data
lines = buf.split('\n')
for line in lines[:-1]:
- self.inner_file.write("%s %s\n" % (time.strftime("%H:%M:%S"), line))
+ self.inner_file.write('%s %s\n' % (time.strftime('%H:%M:%S'), line))
self.buf = lines[-1]
def flush(self):
self.inner_file.flush()
try:
args.pubkey_hash = bitcoin.data.address_to_pubkey_hash(args.address, args.net)
except Exception, e:
- raise ValueError("error parsing address: " + repr(e))
+ raise ValueError('error parsing address: ' + repr(e))
else:
args.pubkey_hash = None
raise Error(-32601, u'Method not found')
method_meth = getattr(self, method_name)
- if hasattr(method_meth, "takes_request"):
+ if hasattr(method_meth, 'takes_request'):
params = [request] + list(params)
try:
return dict((k, v) for k, v in res.iteritems() if v)
def format(x):
- prefixes = "kMGTPEZY"
+ prefixes = 'kMGTPEZY'
count = 0
while x >= 10000 and count < len(prefixes) - 2:
x = x//1000
count += 1
- s = "" if count == 0 else prefixes[count - 1]
- return "%i" % (x,) + s
+ s = '' if count == 0 else prefixes[count - 1]
+ return '%i' % (x,) + s
-if __name__ == "__main__":
+if __name__ == '__main__':
import random
a = 1
while True:
- print a, format(a) + "H/s"
+ print a, format(a) + 'H/s'
a = a * random.randrange(2, 5)
if 'cgminer' in user_agent2: return 1
if 'poclbm' in user_agent2: return 1
if 'phoenix' in user_agent2: return 2
- print "Unknown miner User-Agent:", repr(user_agent)
+ print 'Unknown miner User-Agent:', repr(user_agent)
return 0
def get_id(request):
try:
id = random.randrange(10000)
if p2pool.DEBUG:
- print "LONG POLL", id
+ print 'LONG POLL', id
request_id = get_id(request)
memory = get_memory(request.getHeader('User-Agent'))
if work != thought_work[-1]:
break
if p2pool.DEBUG:
- print "POLL %i WAITING" % (id,)
+ print 'POLL %i WAITING' % (id,)
yield defer.DeferredList([self.work.changed.get_deferred(), last_cache_invalidation[request_id].changed.get_deferred()], fireOnOneCallback=True)
if thought_work[-1] is not None and work != thought_work[-1] and any(x is None or work['previous_block'] == x['previous_block'] for x in thought_work[-memory or len(thought_work):]):
newwork = work.copy()
newwork['previous_block'] = random.randrange(2**256)
if p2pool.DEBUG:
- print "longpoll faked", id
+ print 'longpoll faked', id
res = self.compute(work, request.getHeader('X-All-Targets') is not None)
newres = self.compute(newwork, request.getHeader('X-All-Targets') is not None)
else:
if p2pool.DEBUG:
- print "END POLL %i %x" % (id, work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0)
+ print 'END POLL %i %x' % (id, work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0)
render_POST = render_GET
class RateInterface(deferred_resource.DeferredResource):
newwork = work.copy()
newwork['previous_block'] = random.randrange(2**256)
if p2pool.DEBUG:
- print "getwork faked"
+ print 'getwork faked'
res = self.compute(work, request.getHeader('X-All-Targets') is not None)
newres = self.compute(newwork, request.getHeader('X-All-Targets') is not None)
else:
reactor.callLater(.01, lambda: last_cache_invalidation[request_id].set((thought_work[-1], newwork)))
if p2pool.DEBUG:
- print "END GETWORK %i" % (work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0,)
+ print 'END GETWORK %i' % (work['best_share_hash'] % 2**32 if work['best_share_hash'] is not None else 0,)
return merge(newres.getwork(), res.getwork())
rpc_getwork.takes_request = True