def setup(on_startup): '''Setup mining service internal environment. You should not need to change this. If you want to use another Worker manager or Share manager, you should set proper reference to Interfaces class *before* you call setup() in the launcher script.''' from stratum import settings from interfaces import Interfaces # Let's wait until share manager and worker manager boot up (yield Interfaces.share_manager.on_load) (yield Interfaces.worker_manager.on_load) from lib.block_updater import BlockUpdater from lib.template_registry import TemplateRegistry from lib.bitcoin_rpc import BitcoinRPC from lib.block_template import BlockTemplate from lib.coinbaser import SimpleCoinbaser bitcoin_rpc = BitcoinRPC(settings.NOVACOIN_TRUSTED_HOST, settings.NOVACOIN_TRUSTED_PORT, settings.NOVACOIN_TRUSTED_USER, settings.NOVACOIN_TRUSTED_PASSWORD) import stratum.logger log = stratum.logger.get_logger('mining') log.info('Waiting for novacoin RPC...') while True: try: result = (yield bitcoin_rpc.getblocktemplate()) if isinstance(result, dict): log.info('Response from novacoin RPC OK') break except: time.sleep(1) coinbaser = SimpleCoinbaser(bitcoin_rpc, settings.CENTRAL_WALLET) (yield coinbaser.on_load) registry = TemplateRegistry(BlockTemplate, coinbaser, bitcoin_rpc, settings.INSTANCE_ID, MiningSubscription.on_template, Interfaces.share_manager.on_network_block) # Template registry is the main interface between Stratum service # and pool core logic Interfaces.set_template_registry(registry) # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(registry, bitcoin_rpc) log.info("MINING SERVICE IS READY") on_startup.callback(True)
def __init__(self, block_template_class, bitcoin_rpc, instance_id, on_template_callback, on_block_callback): self.prevhashes = {} self.jobs = weakref.WeakValueDictionary() self.extranonce_counter = ExtranonceCounter(instance_id) self.extranonce2_size = block_template_class.coinbase_transaction_class.extranonce_size \ - self.extranonce_counter.get_size() self.coinbasers_value = [] for address, percent in settings.BITCOIN_ADDRESSES.iteritems(): coinbaser = SimpleCoinbaser(address, bitcoin_rpc) self.coinbasers_value.append((coinbaser, percent)) self.block_template_class = block_template_class self.bitcoin_rpc = bitcoin_rpc self.on_block_callback = on_block_callback self.on_template_callback = on_template_callback self.last_block = None self.last_update = None
if isinstance(json.loads(e[2])['error']['message'], str): error = json.loads(e[2])['error']['message'] if error == "Method not found": log.error("Litecoind does not support getblocktemplate!!! (time to upgrade.)") reactor.stop() elif error == "Litecoind is downloading blocks...": log.error("Litecoind downloading blockchain... will check back in 30 sec") time.sleep(29) else: log.error("Litecoind Error: %s", error) time.sleep(1) # If we didn't get a result or the connect failed log.info('Connected to litecoind - Ready to GO!') # Start the coinbaser coinbaser = SimpleCoinbaser(bitcoin_rpc, getattr(settings, 'CENTRAL_WALLET')) (yield coinbaser.on_load) registry = TemplateRegistry(BlockTemplate, coinbaser, bitcoin_rpc, getattr(settings, 'INSTANCE_ID'), MiningSubscription.on_template, Interfaces.share_manager.on_network_block) # Template registry is the main interface between Stratum service # and pool core logic Interfaces.set_template_registry(registry) # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify
) #reactor.stop() failure = 1 break time.sleep(1) # If we didn't get a result or the connect failed if (failure == 1): log.error("Problems with Coind %s, retry in 30 sec" % wallet) yield sleep(29) wallet_connect(wallet, bitcoin_rpc) log.info( 'Connected to the coind - Begining to load Address and Module Checks!') # Start the coinbaser coinbaser = SimpleCoinbaser(bitcoin_rpc, wallet) log.info('Starting registry') (yield coinbaser.on_load) log.info('Starting registry') mining_subscription = MiningSubscription() mining_subscription.wallet = wallet registry = TemplateRegistry(wallet, BlockTemplate, coinbaser, bitcoin_rpc, getattr(settings, 'INSTANCE_ID'), mining_subscription.on_template, Interfaces.share_manager.on_network_block) log.info('Set template registry for %s' % wallet)
log.error( "Bitcoind does not support getblocktemplate!!! (time to upgrade.)" ) reactor.stop() elif error == "Bitcoin is downloading blocks...": log.error( "Bitcoind downloading blockchain... will check back in 30 sec" ) time.sleep(29) else: log.error("Bitcoind Error: %s", error) time.sleep(1) # If we didn't get a result or the connect failed log.info('Connected to bitcoind - Ready to GO!') # Start the coinbaser coinbaser = SimpleCoinbaser(bitcoin_rpc, settings.CENTRAL_WALLET) (yield coinbaser.on_load) registry = TemplateRegistry(BlockTemplate, coinbaser, bitcoin_rpc, settings.INSTANCE_ID, MiningSubscription.on_template, Interfaces.share_manager.on_network_block) # Template registry is the main interface between Stratum service # and pool core logic Interfaces.set_template_registry(registry) # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(registry, bitcoin_rpc)
def setup(on_startup): '''Setup mining service internal environment. You should not need to change this. If you want to use another Worker manager or Share manager, you should set proper reference to Interfaces class *before* you call setup() in the launcher script.''' import lib.settings as settings # Get logging online as soon as possible import lib.logger log = lib.logger.get_logger('mining') from interfaces import Interfaces from lib.block_updater import BlockUpdater from lib.template_registry import TemplateRegistry from lib.bitcoin_rpc import BitcoinRPC from lib.block_template import BlockTemplate from lib.coinbaser import SimpleCoinbaser bitcoin_rpc = BitcoinRPC(settings.DAEMON_TRUSTED_HOST, settings.DAEMON_TRUSTED_PORT, settings.DAEMON_TRUSTED_USER, settings.DAEMON_TRUSTED_PASSWORD) log.info("Connecting to RPC...") while True: try: log.info('Waiting for RPC...') result = (yield bitcoin_rpc.getblocktemplate()) if isinstance(result, dict): break except: time.sleep(1) log.info('Connected to RPC - Ready to GO!') # Start the coinbaser coinbaser = SimpleCoinbaser(bitcoin_rpc, getattr(settings, 'CENTRAL_WALLET')) (yield coinbaser.on_load) registry = TemplateRegistry(BlockTemplate, coinbaser, bitcoin_rpc, getattr(settings, 'INSTANCE_ID'), MiningSubscription.on_template, Interfaces.share_manager.on_network_block) # Template registry is the main interface between Stratum service # and pool core logic Interfaces.set_template_registry(registry) # Set up polling mechanism for detecting new block on the network # This is just failsafe solution when -blocknotify # mechanism is not working properly BlockUpdater(registry, bitcoin_rpc) prune_thr = threading.Thread(target=WorkLogPruner, args=(Interfaces.worker_manager.job_log, )) prune_thr.daemon = True prune_thr.start() log.info("MINING SERVICE IS READY") on_startup.callback(True)