import binascii
from twisted.internet import defer
+from stratum import settings
from stratum.services import GenericService, admin
from stratum.pubsub import Pubsub
from interfaces import Interfaces
'''Connect this RPC call to 'bitcoind -blocknotify' for
instant notification about new block on the network.
See blocknotify.sh in /scripts/ for more info.'''
+
+ log.info("New block notification received")
Interfaces.template_registry.update_block()
return True
del session['authorized'][worker_name]
return False
- def subscribe(self):
+ def subscribe(self,*arg):
'''Subscribe for receiving mining jobs. This will
return subscription details, extranonce1_hex and extranonce2_size'''
extranonce1 = Interfaces.template_registry.get_new_extranonce1()
extranonce2_size = Interfaces.template_registry.extranonce2_size
-
+ extranonce1_hex = binascii.hexlify(extranonce1)
+
session = self.connection_ref().get_session()
session['extranonce1'] = extranonce1
- session['difficulty'] = 1 # Following protocol specs, default diff is 1
+ session['difficulty'] = settings.POOL_TARGET # Following protocol specs, default diff is 1
- extranonce1_hex = binascii.hexlify(extranonce1)
-
return Pubsub.subscribe(self.connection_ref(), MiningSubscription()) + (extranonce1_hex, extranonce2_size)
'''
log.info("LEN %.03f" % (time.time() - start))
return ret
'''
-
+
def submit(self, worker_name, job_id, extranonce2, ntime, nonce):
'''Try to solve block candidate using given parameters.'''
raise SubmitException("Connection is not subscribed for mining")
difficulty = session['difficulty']
-
submit_time = Interfaces.timestamper.time()
-
+ ip = self.connection_ref()._get_ip()
+
+ Interfaces.share_limiter.submit(self.connection_ref, job_id, difficulty, submit_time, worker_name)
+
# This checks if submitted share meet all requirements
# and it is valid proof of work.
try:
- (block_header, block_hash, on_submit) = Interfaces.template_registry.submit_share(job_id,
- worker_name, extranonce1_bin, extranonce2, ntime, nonce, difficulty)
- except SubmitException:
+ (block_header, block_hash, share_diff, on_submit) = Interfaces.template_registry.submit_share(job_id,
+ worker_name, session, extranonce1_bin, extranonce2, ntime, nonce, difficulty)
+ except SubmitException as e:
# block_header and block_hash are None when submitted data are corrupted
Interfaces.share_manager.on_submit_share(worker_name, None, None, difficulty,
- submit_time, False)
+ submit_time, False, ip, e[0], 0)
raise
Interfaces.share_manager.on_submit_share(worker_name, block_header, block_hash, difficulty,
- submit_time, True)
+ submit_time, True, ip, '', share_diff)
if on_submit != None:
# Pool performs submitblock() to bitcoind. Let's hook
# to result and report it to share manager
on_submit.addCallback(Interfaces.share_manager.on_submit_block,
- worker_name, block_header, block_hash, submit_time)
+ worker_name, block_header, block_hash, submit_time,ip,share_diff)
return True
('extranonce2', 'string', 'hex-encoded big-endian extranonce2, length depends on extranonce2_size from mining.notify.'),
('ntime', 'string', 'UNIX timestamp (32bit integer, big-endian, hex-encoded), must be >= ntime provided by mining,notify and <= current time'),
('nonce', 'string', '32bit integer, hex-encoded, big-endian'),]
-
\ No newline at end of file
+