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') if settings.CONFIG_VERSION == None: settings.CONFIG_VERSION = 0 else: pass from interfaces import Interfaces from lib.block_updater import BlockUpdater from lib.template_registry import TemplateRegistry from lib.bitcoin_rpc_manager import BitcoinRPCManager from lib.block_template import BlockTemplate from lib.coinbaser import SimpleCoinbaser bitcoin_rpc = BitcoinRPCManager() # Check litecoind # Check we can connect (sleep) # Check the results: # - getblocktemplate is avalible (Die if not) # - we are not still downloading the blockchain (Sleep) log.info("Connecting to litecoind...") while True: try: result = (yield bitcoin_rpc.check_submitblock()) if result == True: log.info("Found submitblock") elif result == False: log.info("Did not find submitblock") else: log.info("unknown submitblock result") except ConnectionRefusedError, e: log.error( "Connection refused while trying to connect to the coind (are your COIND_* settings correct?)" ) reactor.stop() break except Exception, e: log.debug(str(e))
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_manager import BitcoinRPCManager from lib.block_template import BlockTemplate from lib.coinbaser import SimpleCoinbaser bitcoin_rpc = BitcoinRPCManager() mm_rpc = BitcoinRPCManager(settings.MM_HOST, settings.MM_PORT, settings.MM_USER, settings.MM_PASSWORD) # Check litecoind # Check we can connect (sleep) # Check the results: # - getblocktemplate is avalible (Die if not) # - we are not still downloading the blockchain (Sleep) log.info("Connecting to master coind...") while True: try: result = (yield bitcoin_rpc.check_submitblock()) if result == True: log.info("Found submitblock") elif result == False: log.info("Did not find submitblock") else: log.info("unknown submitblock result") except ConnectionRefusedError, e: log.error("Connection refused while trying to connect to the coind (are your COIND_* settings correct?)") reactor.stop() break except Exception, e: log.debug(str(e))
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_manager import BitcoinRPCManager from lib.template_generator import BlockTemplateGenerator from lib.coinbaser import Coinbaser from lib.factories import ConstructionYard from lib.Factory import Factory bitcoin_rpc = BitcoinRPCManager() # Check coind # Check we can connect (sleep) # Check the results: # - getblocktemplate is avalible (Die if not) # - we are not still downloading the blockchain (Sleep) log.debug("Connecting to upstream blockchain network daemon...") upstream_connection_ready = False while True: try: # Check for 'submitblock' RPC function # Wait for this to complete log.debug("Starting check_submitblock") yield bitcoin_rpc.check_submitblock() log.debug("Finished check_submitblock") # Check for 'getblocktemplate' RPC function # Wait for this to complete log.debug("Starting check_getblocktemplate") yield bitcoin_rpc.check_getblocktemplate() log.debug("Completed check_getblocktemplate") # Check for 'getinfo' RPC function # Wait for this to complete log.debug("Starting check_getinfo") yield bitcoin_rpc.check_getinfo() log.debug("Completed check_getinfo") # All is good upstream_connection_ready = True break except ConnectionRefusedError, e: # No sense in continuing execution log.error("Upstream network daemon refused connection: %s" % (str(e))) break except Exception, e: # Possible race condition (critical, waitTime, message) = startup_exception_handler(e) if critical: # Unrecoverable error prevents us from starting up log.error(message) break else: # Wait before trying again log.warning(message) time.sleep(waitTime)
def changeCoin(cls, res, host, port, user, password, address, powpos, txcomments): cls.template_registry.update_in_progress = True settings.COINDAEMON_TRUSTED_HOST = str(host) settings.COINDAEMON_TRUSTED_PORT = port settings.COINDAEMON_TRUSTED_USER = str(user) settings.COINDAEMON_TRUSTED_PASSWORD = str(password) settings.CENTRAL_WALLET = str(address) settings.COINDAEMON_TX = 'yes' if txcomments else 'no' # TODO add coin name option so username doesn't have to be the same as coin name settings.COINDAEMON_NAME = str(user) log.info("CHANGING COIN # "+str(user)+" txcomments: "+settings.COINDAEMON_TX) ''' Function to add a litecoind instance live ''' from lib.coinbaser import SimpleCoinbaser from lib.bitcoin_rpc_manager import BitcoinRPCManager from lib.block_template import BlockTemplate from subscription import MiningSubscription #(host, port, user, password) = args bitcoin_rpc = BitcoinRPCManager() result = (yield bitcoin_rpc.check_submitblock()) if result == True: log.info("Found submitblock") elif result == False: log.info("Did not find submitblock") else: log.info("unknown submitblock result") data = (yield bitcoin_rpc.getblocktemplate()) if isinstance(data, dict): # litecoind implements version 1 of getblocktemplate if data['version'] >= 1: result = (yield bitcoin_rpc.getdifficulty()) if isinstance(result,dict): if 'proof-of-stake' in result: settings.COINDAEMON_Reward = 'POS' log.info("Coin detected as POS") else: settings.COINDAEMON_Reward = 'POW' log.info("Coin detected as POW") else: log.error("Block Version mismatch: %s" % result['version']) coinbaser = SimpleCoinbaser(bitcoin_rpc, getattr(settings, 'CENTRAL_WALLET')) (yield coinbaser.on_load) cls.template_registry.update(BlockTemplate, coinbaser, bitcoin_rpc, 31, MiningSubscription.on_template, cls.share_manager.on_network_block, data) log.info("New litecoind connection changed %s:%s" % (host, port)) defer.returnValue(True)