예제 #1
0
 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_executable('txnvalidator')
     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_executable('txnvalidator')
     self.txnvalidator = txnvalidator
     self.validator_log_config = log_config
     self.admin_node = ValidatorCollectionController.AdminNode()
    def do_genesis(self, do_genesis_validator_idx=0, **kwargs):
        assert self._initialized

        cfg = self.get_configuration(do_genesis_validator_idx)
        overrides = {
            "InitialConnectivity": 0,
            "DevModePublisher": True,
        }
        cfg.update(overrides)
        self.set_configuration(do_genesis_validator_idx, cfg)
        config_file = self.write_configuration(do_genesis_validator_idx)
        cfg = self.get_configuration(do_genesis_validator_idx)
        ledger_type = cfg.get('LedgerType', 'poet0')
        # validate user input to Popen
        assert ledger_type in ['dev_mode', 'poet0', 'poet1']
        assert os.path.isfile(config_file)
        alg_name = ledger_type
        if ledger_type == 'dev_mode':
            alg_name = 'dev-mode'
        cli_args = 'admin %s-genesis --config %s' % (alg_name, config_file)
        try:
            executable = find_executable('sawtooth')
        except ExitError:
            path = os.path.dirname(self.node_controller.txnvalidator)
            executable = os.path.join(path, 'sawtooth')
        assert os.path.isfile(executable)
        cmd = '%s %s %s' % (sys.executable, executable, cli_args)
        proc = subprocess.Popen(cmd.split())
        proc.wait()
        if proc.returncode != 0:
            return
        # Get genesis block id
        gblock_file = genesis_info_file_name(cfg['DataDirectory'])
        assert os.path.exists(gblock_file) is True
        genesis_dat = None
        with open(gblock_file, 'r') as f:
            genesis_dat = json.load(f)
        assert 'GenesisId' in genesis_dat.keys()
        head = genesis_dat['GenesisId']
        print('created genesis block: %s' % head)
    def do_genesis(self, do_genesis_validator_idx=0, **kwargs):
        assert self._initialized

        cfg = self.get_configuration(do_genesis_validator_idx)
        overrides = {
            "InitialConnectivity": 0,
            "DevModePublisher": True,
        }
        cfg.update(overrides)
        self.set_configuration(do_genesis_validator_idx, cfg)
        config_file = self.write_configuration(do_genesis_validator_idx)
        cfg = self.get_configuration(do_genesis_validator_idx)
        ledger_type = cfg.get('LedgerType', 'poet1')
        # validate user input to Popen
        assert ledger_type in ['dev_mode', 'poet1']
        assert os.path.isfile(config_file)
        alg_name = ledger_type
        if ledger_type == 'dev_mode':
            alg_name = 'dev-mode'
        cli_args = 'admin %s-genesis --config %s' % (alg_name, config_file)
        try:
            executable = find_executable('sawtooth')
        except ExitError:
            path = os.path.dirname(self.node_controller.txnvalidator)
            executable = os.path.join(path, 'sawtooth')
        assert os.path.isfile(executable)
        cmd = '%s %s %s' % (sys.executable, executable, cli_args)
        proc = subprocess.Popen(cmd.split())
        proc.wait()
        if proc.returncode != 0:
            return
        # Get genesis block id
        gblock_file = genesis_info_file_name(cfg['DataDirectory'])
        assert os.path.exists(gblock_file) is True
        genesis_dat = None
        with open(gblock_file, 'r') as f:
            genesis_dat = json.load(f)
        assert 'GenesisId' in genesis_dat.keys()
        head = genesis_dat['GenesisId']
        print('created genesis block: %s' % head)
예제 #5
0
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_executable('txnvalidator')
        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',
        '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)