def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = Interfaces.timestamper.time() clean_jobs = is_new_block (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \ Interfaces.template_registry.get_last_broadcast_args() # Push new job to subscribed clients for subscription in Pubsub.iterate_subscribers(cls.event): try: if subscription != None: session = subscription.connection_ref().get_session() session.setdefault('authorized', {}) if session['authorized'].keys(): worker_name = session['authorized'].keys()[0] difficulty = session['difficulty'] work_id = Interfaces.worker_manager.register_work(worker_name, job_id, difficulty) subscription.emit_single(work_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) else: subscription.emit_single(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) except Exception as e: log.exception("Error broadcasting work to client %s" % str(e)) pass cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
def on_template(cls, is_new_block): """This is called when TemplateRegistry registers new block which we have to broadcast clients.""" start = Interfaces.timestamper.time() clean_jobs = is_new_block (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \ Interfaces.template_registry.get_last_broadcast_args() # Push new job to subscribed clients for subscription in Pubsub.iterate_subscribers(cls.event): try: if subscription != None: session = subscription.connection_ref().get_session() session.setdefault('authorized', {}) if session['authorized'].keys(): worker_name = session['authorized'].keys()[0] difficulty = session['difficulty'] work_id = Interfaces.worker_manager.register_work(worker_name, job_id, difficulty) #log.debug("emitting for work id %s job id %s block %s " % (work_id, job_id, prevhash)) subscription.emit_single(work_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) else: subscription.emit_single(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) except Exception as e: log.exception("Error broadcasting work to client %s" % str(e)) pass cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
def print_subs(cls): c = Pubsub.get_subscription_count(cls.event) log.info(c) for subs in Pubsub.iterate_subscribers(cls.event): s = Pubsub.get_subscription(subs.connection_ref(), cls.event, key=None) log.info(s)
def print_subs(cls): c = Pubsub.get_subscription_count(cls.event) log.info(c) for subs in Pubsub.iterate_subscribers(cls.event): s = Pubsub.get_subscription( subs.connection_ref(), cls.event, key=None) log.info(s)
class MiningSubscription(Subscription): u'''This subscription object implements logic for broadcasting new jobs to the clients.''' event = u'mining.notify' @classmethod def on_template(cls, is_new_block): u'''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = Interfaces.timestamper.time() clean_jobs = is_new_block (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = Interfaces.template_registry.get_last_broadcast_args() # Push new job to subscribed clients for subscription in Pubsub.iterate_subscribers(cls.event): try: if subscription is not None: session = subscription.connection_ref().get_session() session.setdefault(u'authorized', {}) if list(session[u'authorized'].keys()): worker_name = list(session[u'authorized'].keys())[0] difficulty = session[u'difficulty'] work_id = Interfaces.worker_manager.register_work( worker_name, job_id, difficulty) subscription.emit_single( work_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) else: subscription.emit_single( job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) except Exception, e: log.exception(u"Error broadcasting work to client %s" % unicode(e)) pass cnt = Pubsub.get_subscription_count(cls.event) log.info(u"BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = Interfaces.timestamper.time() clean_jobs = is_new_block (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \ Interfaces.template_registry.get_last_broadcast_args() # Push new job to subscribed clients cls.emit(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = Interfaces.timestamper.time() clean_jobs = is_new_block (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \ Interfaces.template_registry.get_last_broadcast_args() # Push new job to subscribed clients cls.emit(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = Interfaces.timestamper.time() clean_jobs = is_new_block #(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _, rsk_job) = \ # Interfaces.template_registry.get_last_broadcast_args() bc_args = Interfaces.template_registry.get_last_broadcast_args() (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _, rsk_flag) = bc_args # Push new job to subscribed clients cls.emit(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start))) if rsk_flag: log.info( json.dumps({ "rsk": "[RSKLOG]", "tag": "[RSK_BLOCK_RECEIVED_END]", "uuid": util.id_generator(), "start": start, "elapsed": Interfaces.timestamper.time() - start, "data": bc_args, "clients": cnt })) else: log.info( json.dumps({ "rsk": "[RSKLOG]", "tag": "[BTC_BLOCK_RECEIVED_END]", "uuid": util.id_generator(), "start": start, "elapsed": Interfaces.timestamper.time() - start, "data": bc_args, "clients": cnt })) log.info( json.dumps({ "rsk": "[RSKLOG]", "tag": "[WORK_SENT]", "uuid": util.id_generator(), "start": start, "elapsed": Interfaces.timestamper.time() - start }))
def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = Interfaces.timestamper.time() clean_jobs = is_new_block (job_id, height, version, prevhash, prevkeystone, secondkeystone, intermediate_merkles, time, difficulty, clean_jobs) = \ Interfaces.template_registry.get_last_broadcast_args() # Push new job to subscribed clients cls.emit(job_id, height, version, prevhash, prevkeystone, secondkeystone, intermediate_merkles, time, difficulty, clean_jobs) cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = Interfaces.timestamper.time() clean_jobs = is_new_block (job_id, prevhash, version, nbits, ntime, _) = Interfaces.template_registry.get_last_broadcast_args() # Push new job to subscribed clients for subscription in Pubsub.iterate_subscribers(cls.event): try: if subscription != None: session = subscription.connection_ref().get_session() session.setdefault('authorized', {}) if session['authorized'].keys(): worker_name = session['authorized'].keys()[0] extranonce1 = session.get('extranonce1', None) extranonce2 = struct.pack('>L', 0) coinbase_bin = Interfaces.template_registry.last_block.serialize_coinbase( extranonce1, extranonce2) coinbase_hash = util.doublesha(coinbase_bin) merkle_root_bin = Interfaces.template_registry.last_block.merkletree.withFirst( coinbase_hash) merkle_root = binascii.hexlify(merkle_root_bin) job = {} job['data'] = version + prevhash + merkle_root + ntime + nbits job['difficulty'] = session['difficulty'] work_id = Interfaces.worker_manager.register_work( extranonce1, merkle_root, session['difficulty'], job_id, session['basediff']) subscription.emit_single(job) else: continue except Exception as e: log.exception("Error broadcasting work to client %s" % str(e)) pass cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = posix_time() clean_jobs = is_new_block (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \ Interfaces.template_registry.get_last_template_broadcast_args() if not is_new_block: try: cls.before_broadcast.callback(True) cls.before_broadcast = defer.Deferred() except: log.exception("before_broadcast callback failed!") # Push new job to subscribed clients cls.emit("%x"%job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (posix_time() - start)))
def on_template(cls, is_new_block): '''This is called when TemplateRegistry registers new block which we have to broadcast clients.''' start = posix_time() clean_jobs = is_new_block (job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \ Interfaces.template_registry.get_last_template_broadcast_args() if not is_new_block: try: cls.before_broadcast.callback(True) cls.before_broadcast = defer.Deferred() except: log.exception("before_broadcast callback failed!") # Push new job to subscribed clients cls.emit("%x" % job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs) cnt = Pubsub.get_subscription_count(cls.event) log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (posix_time() - start)))
def get_num_connections(cls): return Pubsub.get_subscription_count(cls.event)
def get_num_connections(cls): return Pubsub.get_subscription_count(cls.event)