def __init__( self, net_config, txnvalidator=None, data_dir=None, endpoint_host=None, block_chain_archive=None, log_config=None, ): super(ValidatorCollectionController, self).__init__(net_config.n_mag) self._validators = [[None, x] for x in net_config.get_config_list()] if txnvalidator is None: txnvalidator = find_txn_validator() self.txnvalidator = txnvalidator self._endpoint_host = endpoint_host self.validator_log_config = log_config self.temp_data_dir = False if data_dir is None: self.temp_data_dir = True data_dir = tempfile.mkdtemp() self.data_dir = data_dir self.block_chain_archive = block_chain_archive if block_chain_archive is not None: if not os.path.isfile(block_chain_archive): raise ExitError("Block chain archive to load {} does not " "exist.".format(block_chain_archive)) else: self.unpack_blockchain(block_chain_archive) self.admin_node = ValidatorCollectionController.AdminNode()
def __init__(self, net_config, txnvalidator=None, data_dir=None, endpoint_host=None, block_chain_archive=None, log_config=None, ): super(ValidatorCollectionController, self).__init__(net_config.n_mag) self._validators = [[None, x] for x in net_config.get_config_list()] if txnvalidator is None: txnvalidator = find_txn_validator() self.txnvalidator = txnvalidator self._endpoint_host = endpoint_host self.validator_log_config = log_config self.temp_data_dir = False if data_dir is None: self.temp_data_dir = True data_dir = tempfile.mkdtemp() self.data_dir = data_dir self.block_chain_archive = block_chain_archive if block_chain_archive is not None: if not os.path.isfile(block_chain_archive): raise ExitError("Block chain archive to load {} does not " "exist.".format(block_chain_archive)) else: self.unpack_blockchain(block_chain_archive) self.admin_node = ValidatorCollectionController.AdminNode()
def __init__( self, txnvalidator=None, cfg=None, data_dir=None, http_port=8800, udp_port=5500, host='localhost', endpoint_host=None, block_chain_archive=None, log_config=None, static_network=None, ): self.static_network = static_network self._validators = [] self._validator_map = {} self.validator_config = None self._next_validator_id = 0 self._host = host or 'localhost' self._http_port_base = http_port self._udp_port_base = udp_port self._endpoint_host = endpoint_host self.validator_config = cfg or defaultValidatorConfig self.validator_log_config = log_config self.txnvalidator = txnvalidator or find_txn_validator() self.temp_data_dir = False if data_dir is None: self.temp_data_dir = True data_dir = tempfile.mkdtemp() self.data_dir = data_dir self.block_chain_archive = block_chain_archive if block_chain_archive is not None: if not os.path.isfile(block_chain_archive): raise ExitError("Block chain archive to load {} does not " "exist.".format(block_chain_archive)) else: self.unpack_blockchain(block_chain_archive) self.admin_node = ValidatorNetworkManager.AdminNode() self.validator_config['DataDirectory'] = self.data_dir self.validator_config["AdministrationNode"] = self.admin_node.Address self.timeout = 3
def __init__(self, txnvalidator=None, cfg=None, data_dir=None, http_port=8800, udp_port=5500, block_chain_archive=None, log_config=None, staticNetwork=None, ): self.staticNetwork = staticNetwork self._validators = [] self._validator_map = {} self.validator_config = None self._next_validator_id = 0 self.HttpPortBase = http_port self.UdpPortBase = udp_port if cfg is None: cfg = defaultValidatorConfig self.validator_config = cfg self.validator_log_config = log_config if txnvalidator is None: txnvalidator = find_txn_validator() self.txnvalidator = txnvalidator self.tempDataDir = False if data_dir is None: self.tempDataDir = True data_dir = tempfile.mkdtemp() self.data_dir = data_dir self.data_dir = data_dir self.block_chain_archive = block_chain_archive if block_chain_archive is not None: if not os.path.isfile(block_chain_archive): raise ExitError("Block chain archive to load {} does not " "exist.".format(block_chain_archive)) else: self.unpack_blockchain(block_chain_archive) self.AdminNode = ValidatorNetworkManager.AdminNode() self.validator_config['DataDirectory'] = self.data_dir self.validator_config["AdministrationNode"] = self.AdminNode.address self.validator_config['Restore'] = False
def __init__(self, txnvalidator=None, cfg=None, data_dir=None, http_port=8800, udp_port=5500, host='localhost', endpoint_host=None, block_chain_archive=None, log_config=None, static_network=None, ): self.static_network = static_network self._validators = [] self._validator_map = {} self.validator_config = None self._next_validator_id = 0 self._host = host or 'localhost' self._http_port_base = http_port self._udp_port_base = udp_port self._endpoint_host = endpoint_host self.validator_config = cfg or defaultValidatorConfig self.validator_log_config = log_config self.txnvalidator = txnvalidator or find_txn_validator() self.temp_data_dir = False if data_dir is None: self.temp_data_dir = True data_dir = tempfile.mkdtemp() self.data_dir = data_dir self.block_chain_archive = block_chain_archive if block_chain_archive is not None: if not os.path.isfile(block_chain_archive): raise ExitError("Block chain archive to load {} does not " "exist.".format(block_chain_archive)) else: self.unpack_blockchain(block_chain_archive) self.admin_node = ValidatorNetworkManager.AdminNode() self.validator_config['DataDirectory'] = self.data_dir self.validator_config["AdministrationNode"] = self.admin_node.Address self.validator_config['Restore'] = False
def __init__(self, net_config, txnvalidator=None, log_config=None, ): super(ValidatorCollectionController, self).__init__(net_config.n_mag) self.net_config = net_config self.hdls = [None for _ in range(net_config.n_mag)] self.data_dir = None if self.net_config.provider is not None: self.data_dir = self.net_config.provider.currency_home if txnvalidator is None: txnvalidator = find_txn_validator() self.txnvalidator = txnvalidator self.validator_log_config = log_config self.admin_node = ValidatorCollectionController.AdminNode()
def __init__( self, net_config, txnvalidator=None, log_config=None, ): super(ValidatorCollectionController, self).__init__(net_config.n_mag) self.net_config = net_config self.hdls = [None for _ in range(net_config.n_mag)] self.data_dir = None if self.net_config.provider is not None: self.data_dir = self.net_config.provider.currency_home if txnvalidator is None: txnvalidator = find_txn_validator() self.txnvalidator = txnvalidator self.validator_log_config = log_config self.admin_node = ValidatorCollectionController.AdminNode()
def __init__(self, txnvalidator=None, cfg=None, dataDir=None, httpPort=8800, udpPort=8900, blockChainArchive=None): self.Validators = [] self.ValidatorMap = {} self.ValidatorConfig = None self.NextValidatorId = 0 self.HttpPortBase = httpPort self.UdpPortBase = udpPort if cfg is None: cfg = defaultValidatorConfig self.ValidatorConfig = cfg if txnvalidator is None: txnvalidator = find_txn_validator() self.txnvalidator = txnvalidator self.tempDataDir = False if dataDir is None: self.tempDataDir = True dataDir = tempfile.mkdtemp() self.DataDir = dataDir self.blockChainArchive = blockChainArchive if blockChainArchive is not None: if not os.path.isfile(blockChainArchive): raise ExitError("Block chain archive to load {} does not " "exist.".format(blockChainArchive)) else: self.unpack_blockchain(blockChainArchive) self.AdminNode = ValidatorNetworkManager.AdminNode() self.ValidatorConfig['DataDirectory'] = self.DataDir self.ValidatorConfig['Host'] = "localhost" self.ValidatorConfig["AdministrationNode"] = self.AdminNode.Address self.ValidatorConfig['Restore'] = False
def configure(opts): scriptdir = os.path.dirname(os.path.realpath(__file__)) # Find the validator to use if opts.validator is None: opts.validator = find_txn_validator() if not os.path.isfile(opts.validator): print "txnvalidator: {}".format(opts.validator) raise ExitError("Could not find txnvalidator.") else: if not os.path.isfile(opts.validator): print "txnvalidator: {}".format(opts.validator) raise ExitError("txnvalidator script does not exist.") # Create directory -- after the params have been validated if opts.data_dir is None: opts.data_dir_is_tmp = True # did we make up a directory opts.data_dir = tempfile.mkdtemp() else: opts.data_dir = os.path.abspath(opts.data_dir) if not os.path.exists(opts.data_dir): os.makedirs(opts.data_dir) if opts.load_blockchain is not None: if not os.path.isfile(opts.load_blockchain): raise ExitError("Blockchain archive to load {} does not " "exist.".format(opts.load_blockchain)) else: opts.config = get_archive_config(opts.data_dir, opts.load_blockchain) if opts.config is None: raise ExitError("Could not read config from Blockchain " "archive: {}".format(opts.load_blockchain)) validator_config = {} if opts.config is not None: if os.path.exists(opts.config): validator_config = parse_configuration_file(opts.config) else: raise ExitError("Config file does not exist: {}".format( opts.config)) else: opts.config = os.path.realpath(os.path.join(scriptdir, "..", "etc", "txnvalidator.js")) print "No config file specified, loading {}".format(opts.config) if os.path.exists(opts.config): validator_config = parse_configuration_file(opts.config) else: raise ExitError( "Default config file does not exist: {}".format(opts.config)) keys = [ 'NodeName', 'Host', 'HttpPort', 'Port', 'LogFile', 'LogLevel', 'KeyFile', "AdministrationNode", "DataDirectory", "GenesisLedger", ] if any(k in validator_config for k in keys): print "Overriding the following keys from validator configuration " \ "file: {}".format(opts.config) for k in keys: if k in validator_config: print "\t{}".format(k) del validator_config[k] opts.count = max(1, opts.count) opts.validator_config = validator_config opts.validator_config['LogLevel'] = opts.log_level print "Configuration:" pp.pprint(opts.__dict__)
def configure(opts): scriptDir = os.path.dirname(os.path.realpath(__file__)) # Find the validator to use if opts.validator is None: opts.validator = find_txn_validator() if not os.path.isfile(opts.validator): print("txnvalidator: {}".format(opts.validator)) raise ExitError("Could not find txnvalidator.") else: if not os.path.isfile(opts.validator): print("txnvalidator: {}".format(opts.validator)) raise ExitError("txnvalidator script does not exist.") validatorConfig = {} if opts.config is not None: if os.path.exists(opts.config): validatorConfig = parse_configuration_file(opts.config) else: raise ExitError("Config file does not exist: {}".format( opts.config)) else: opts.config = os.path.realpath( os.path.join(scriptDir, "..", "etc", "txnvalidator.js")) print("No config file specified, loading {}".format(opts.config)) if os.path.exists(opts.config): validatorConfig = parse_configuration_file(opts.config) else: raise ExitError("Default config file does not exist: {}".format( opts.config)) if opts.load_blockchain is not None: if not os.path.isfile(opts.load_blockchain): raise ExitError("Blockchain archive to load {} does not " "exist.".format(opts.load_blockchain)) # Create directory -- after the params have been validated if opts.data_dir is None: opts.data_dir_is_tmp = True # did we make up a directory opts.data_dir = tempfile.mkdtemp() else: opts.data_dir = os.path.abspath(opts.data_dir) if not os.path.exists(opts.data_dir): os.makedirs(opts.data_dir) keys = [ 'NodeName', 'Host', 'HttpPort', 'Port', 'LogFile', 'LogLevel', 'KeyFile', "AdministrationNode", "DataDirectory", "GenesisLedger", ] if any(k in validatorConfig for k in keys): print "Overriding the following keys from validator configuration " \ "file: {}".format(opts.config) for k in keys: if k in validatorConfig: print "\t{}".format(k) del validatorConfig[k] opts.count = max(1, opts.count) opts.validator_config = validatorConfig opts.validator_config['LogLevel'] = opts.log_level print "Configuration:" pp.pprint(opts.__dict__)
def configure(args): opts = parse_args(args) script_dir = os.path.dirname(os.path.realpath(__file__)) # Find the validator to use if opts.validator is None: opts.validator = find_txn_validator() if not os.path.isfile(opts.validator): print "txnvalidator: {}".format(opts.validator) raise ExitError("Could not find txnvalidator.") else: if not os.path.isfile(opts.validator): print "txnvalidator: {}".format(opts.validator) raise ExitError("txnvalidator script does not exist.") # Create directory -- after the params have been validated if opts.data_dir is None: opts.data_dir_is_tmp = True # did we make up a directory opts.data_dir = tempfile.mkdtemp() else: opts.data_dir = os.path.abspath(opts.data_dir) if not os.path.exists(opts.data_dir): os.makedirs(opts.data_dir) if opts.load_blockchain is not None: if not os.path.isfile(opts.load_blockchain): raise ExitError("Blockchain archive to load {} does not " "exist.".format(opts.load_blockchain)) else: opts.config = get_archive_config(opts.data_dir, opts.load_blockchain) if opts.config is None: raise ExitError("Could not read config from Blockchain " "archive: {}".format(opts.load_blockchain)) if opts.config is not None: if os.path.exists(opts.config): validator_config = parse_configuration_file(opts.config) else: raise ExitError("Config file does not exist: {}".format( opts.config)) else: opts.config = os.path.realpath( os.path.join(script_dir, "..", "etc", "txnvalidator.js")) print "No config file specified, loading {}".format(opts.config) if os.path.exists(opts.config): validator_config = parse_configuration_file(opts.config) else: raise ExitError("Default config file does not exist: {}".format( opts.config)) opts.log_config_dict = None if opts.log_config is not None: if not os.path.exists(opts.log_config): raise ExitError("log-config file does not exist: {}".format( opts.log_config)) else: opts.log_config_dict = load_log_config(opts.log_config) keys = [ 'NodeName', 'Listen', 'KeyFile', 'AdministrationNode', 'DataDirectory', 'GenesisLedger', 'LedgerURL', ] if any(k in validator_config for k in keys): print "Overriding the following keys from validator configuration " \ "file: {}".format(opts.config) for k in keys: if k in validator_config: print "\t{}".format(k) del validator_config[k] if opts.log_config: print "\tLogConfigFile" opts.validator_config = validator_config opts.count = max(1, opts.count) print "Configuration:" pp.pprint(opts.__dict__) return vars(opts)
def test_genesis_util(self): print old_home = os.getenv('CURRENCYHOME') tmp_home = tempfile.mkdtemp() vcc = None try: # Set up env and config v_file = find_txn_validator() os.environ['CURRENCYHOME'] = tmp_home cfg = get_validator_configuration([], {}) # ...rewire for ValidatorManager compatibility cfg['KeyDirectory'] = tmp_home cfg['DataDirectory'] = tmp_home cfg['LogDirectory'] = tmp_home # En route, test keygen client via main key_name = cfg['NodeName'] key_dir = cfg['KeyDirectory'] cmd = 'keygen %s --key-dir %s' % (key_name, key_dir) entry_point(args=cmd.split(), with_loggers=False) base_name = key_dir + os.path.sep + key_name self.assertTrue(os.path.exists('%s.wif' % base_name)) self.assertTrue(os.path.exists('%s.addr' % base_name)) cfg['KeyFile'] = '%s.wif' % base_name # Test admin poet0-genesis tool fname = get_genesis_block_id_file_name(cfg['DataDirectory']) self.assertFalse(os.path.exists(fname)) config_file = tmp_home + os.path.sep + 'cfg.json' with open(config_file, 'w') as f: f.write(json.dumps(cfg, indent=4) + '\n') cmd = 'admin poet0-genesis --config %s' % config_file entry_point(args=cmd.split(), with_loggers=False) self.assertTrue(os.path.exists(fname)) dat = None with open(fname, 'r') as f: dat = json.load(f) self.assertTrue('GenesisId' in dat.keys()) tgt_block = dat['GenesisId'] # Verify genesis tool (also tests blockchain restoration) # ...initial connectivity must be zero for the initial validator cfg['InitialConnectivity'] = 0 # ...launch validator net_cfg = NetworkConfig.from_config_list([cfg]) vcc = ValidatorCollectionController(net_cfg, data_dir=tmp_home, txnvalidator=v_file) vcc.activate(0, probe_seconds=120) # ...verify validator is extending tgt_block to = TimeOut(64) blk_lists = None prog_str = 'TEST ROOT RESTORATION (expect %s)' % tgt_block with Progress(prog_str) as p: print while not to.is_timed_out() and blk_lists is None: try: blk_lists = get_blocklists(['http://localhost:8800']) print 'block_lists: %s' % blk_lists if len(blk_lists) < 1 or len(blk_lists[0]) < 2: blk_lists = None except MessageException as e: pass time.sleep(1) p.step() self.assertIsNotNone(blk_lists) root = blk_lists[0][0] self.assertEqual(tgt_block, root) finally: # Shut down validator if vcc is not None: vcc.shutdown() # Restore environmental vars if old_home is None: os.unsetenv('CURRENCYHOME') else: os.environ['CURRENCYHOME'] = old_home # Delete temp dir if os.path.exists(tmp_home): shutil.rmtree(tmp_home)