def runmultiple(ctx, num_validators, seed): gevent.get_hub().SYSTEM_ERROR = BaseException base_port = 29870 # reduce key derivation iterations PBKDF2_CONSTANTS["c"] = 100 config = ctx.obj["config"] config["discovery"]["bootstrap_nodes"] = [get_bootstrap_node(seed, base_port)] for node_num in range(num_validators): n_config = copy.deepcopy(config) n_config, account = _configure_node_network(n_config, num_validators, node_num, seed) # set ports based on node n_config["discovery"]["listen_port"] = base_port + node_num n_config["p2p"]["listen_port"] = base_port + node_num n_config["p2p"]["min_peers"] = min(10, num_validators - 1) n_config["p2p"]["max_peers"] = num_validators * 2 n_config["jsonrpc"]["listen_port"] += node_num n_config["client_version_string"] = "NODE{}".format(node_num) # have multiple datadirs n_config["data_dir"] += str(node_num) konfig.setup_data_dir(n_config["data_dir"]) # deactivate console (note: maybe this could work with one console) n_config["deactivated_services"].append(Console.name) # n_config['deactivated_services'].append(ChainService.name) app = start_app(n_config, account) serve_until_stopped(app)
def runmultiple(ctx, num_validators, seed): gevent.get_hub().SYSTEM_ERROR = BaseException base_port = 29870 # reduce key derivation iterations PBKDF2_CONSTANTS['c'] = 100 config = ctx.obj['config'] config['discovery']['bootstrap_nodes'] = [get_bootstrap_node(seed, base_port)] apps = [] for node_num in range(num_validators): n_config = copy.deepcopy(config) n_config, account = _configure_node_network(n_config, num_validators, node_num, seed) # set ports based on node n_config['discovery']['listen_port'] = base_port + node_num n_config['p2p']['listen_port'] = base_port + node_num n_config['p2p']['min_peers'] = min(10, num_validators - 1) n_config['p2p']['max_peers'] = num_validators * 2 n_config['jsonrpc']['listen_port'] += node_num n_config['client_version_string'] = 'NODE{}'.format(node_num) # have multiple datadirs n_config['data_dir'] = os.path.join(n_config['data_dir'], str(node_num)) konfig.setup_data_dir(n_config['data_dir']) # activate ipython console for the first validator if node_num != 0: n_config['deactivated_services'].append(Console.name) # n_config['deactivated_services'].append(ChainService.name) app = start_app(n_config, [account]) apps.append(app) # hack to enable access to all apps in the console app.apps = apps serve_until_stopped(*apps)
def runmultiple(ctx, num_validators, seed): gevent.get_hub().SYSTEM_ERROR = BaseException base_port = 29870 # reduce key derivation iterations PBKDF2_CONSTANTS['c'] = 100 config = ctx.obj['config'] config['discovery']['bootstrap_nodes'] = [ get_bootstrap_node(seed, base_port) ] for node_num in range(num_validators): n_config = copy.deepcopy(config) n_config, account = _configure_node_network(n_config, num_validators, node_num, seed) # set ports based on node n_config['discovery']['listen_port'] = base_port + node_num n_config['p2p']['listen_port'] = base_port + node_num n_config['p2p']['min_peers'] = min(10, num_validators - 1) n_config['p2p']['max_peers'] = num_validators * 2 n_config['jsonrpc']['listen_port'] += node_num n_config['client_version_string'] = 'NODE{}'.format(node_num) # have multiple datadirs n_config['data_dir'] += str(node_num) konfig.setup_data_dir(n_config['data_dir']) # deactivate console (note: maybe this could work with one console) n_config['deactivated_services'].append(Console.name) # n_config['deactivated_services'].append(ChainService.name) app = start_app(n_config, account) serve_until_stopped(app)
def test_test_privkeys(): try: _services_orig = hydrachain.app.services hydrachain.app.services = services config = default_config() config['data_dir'] = tempfile.mktemp() konfig.setup_data_dir(config['data_dir']) config['node']['privkey_hex'] = '1' * 64 privkeys = [str(i) * 32 for i in range(5)] config['test_privkeys'] = privkeys config['hdc']['validators'] = [privtoaddr(privkeys[0])] app = hydrachain.app.start_app(config, accounts=[]) g = app.services.chain.chain.genesis for p in privkeys: a = privtoaddr(p) assert len(a) == 20 assert g.get_balance(a) > 0 assert a in app.services.accounts account = app.services.accounts[a] assert account.address == a app.stop() finally: hydrachain.app.services = _services_orig
def hydrachain_create_blockchain(private_keys, hydrachain_private_keys, p2p_base_port, base_datadir): """ Initializes a hydrachain network used for testing. """ # pylint: disable=too-many-locals from hydrachain.app import services, start_app, HPCApp import pyethapp.config as konfig def privkey_to_uri(private_key): host = b'0.0.0.0' pubkey = privtopub(private_key) return host_port_pubkey_to_uri(host, p2p_base_port, pubkey) account_addresses = [ privatekey_to_address(priv) for priv in private_keys ] alloc = { encode_hex(address): { 'balance': DEFAULT_BALANCE_BIN, } for address in account_addresses } genesis = { 'nonce': '0x00006d6f7264656e', 'difficulty': '0x20000', 'mixhash': '0x00000000000000000000000000000000000000647572616c65787365646c6578', 'coinbase': '0x0000000000000000000000000000000000000000', 'timestamp': '0x00', 'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'extraData': '0x', 'gasLimit': GAS_LIMIT_HEX, 'alloc': alloc, } bootstrap_nodes = [ privkey_to_uri(hydrachain_private_keys[0]), ] validators_addresses = [ privatekey_to_address(private_key) for private_key in hydrachain_private_keys ] all_apps = [] for number, private_key in enumerate(hydrachain_private_keys): config = konfig.get_default_config(services + [HPCApp]) config = update_config_from_genesis_json(config, genesis) datadir = os.path.join(base_datadir, str(number)) konfig.setup_data_dir(datadir) account = Account.new( password='', key=private_key, ) config['data_dir'] = datadir config['hdc']['validators'] = validators_addresses config['node']['privkey_hex'] = encode_hex(private_key) config['jsonrpc']['listen_port'] += number config['client_version_string'] = 'NODE{}'.format(number) # setting to 0 so that the CALLCODE opcode works at the start of the # network config['eth']['block']['HOMESTEAD_FORK_BLKNUM'] = 0 config['discovery']['bootstrap_nodes'] = bootstrap_nodes config['discovery']['listen_port'] = p2p_base_port + number config['p2p']['listen_port'] = p2p_base_port + number config['p2p']['min_peers'] = min(10, len(hydrachain_private_keys) - 1) config['p2p']['max_peers'] = len(hydrachain_private_keys) * 2 # only one of the nodes should have the Console service running if number != 0 and Console.name not in config['deactivated_services']: config['deactivated_services'].append(Console.name) hydrachain_app = start_app(config, accounts=[account]) all_apps.append(hydrachain_app) hydrachain_wait(private_keys, len(hydrachain_private_keys) - 1) return all_apps
def test_setup_data_dir_existing_config(tmpdir): data_dir = tmpdir.join('data') data_dir.ensure('config.yaml') config.setup_data_dir(str(data_dir)) assert data_dir.join(config.CONFIG_FILE_NAME).exists()
def test_setup_data_dir_existing_empty(tmpdir): data_dir = tmpdir.join('data').ensure_dir() config.setup_data_dir(str(data_dir)) assert data_dir.join(config.CONFIG_FILE_NAME).exists()
def test_setup_data_dir(tmpdir): data_dir = tmpdir.join('data') config.setup_data_dir(str(data_dir)) assert data_dir.join(config.CONFIG_FILE_NAME).exists()
def create_hydrachain_cluster(private_keys, hydrachain_private_keys, p2p_base_port, base_datadir): """ Initializes a hydrachain network used for testing. """ # pylint: disable=too-many-locals from hydrachain.app import services, start_app, HPCApp import pyethapp.config as konfig def privkey_to_uri(private_key): host = b'0.0.0.0' pubkey = privtopub(private_key) return host_port_pubkey_to_uri(host, p2p_base_port, pubkey) account_addresses = [ privtoaddr(priv) for priv in private_keys ] alloc = { encode_hex(address): { 'balance': DEFAULT_BALANCE, } for address in account_addresses } genesis = { 'nonce': '0x00006d6f7264656e', 'difficulty': '0x20000', 'mixhash': '0x00000000000000000000000000000000000000647572616c65787365646c6578', 'coinbase': '0x0000000000000000000000000000000000000000', 'timestamp': '0x00', 'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'extraData': '0x', 'gasLimit': GAS_LIMIT_HEX, 'alloc': alloc, } bootstrap_nodes = [ privkey_to_uri(hydrachain_private_keys[0]), ] validators_addresses = [ privtoaddr(private_key) for private_key in hydrachain_private_keys ] all_apps = [] for number, private_key in enumerate(hydrachain_private_keys): config = konfig.get_default_config(services + [HPCApp]) config = update_config_from_genesis_json(config, genesis) datadir = os.path.join(base_datadir, str(number)) konfig.setup_data_dir(datadir) account = Account.new( password='', key=private_key, ) config['data_dir'] = datadir config['hdc']['validators'] = validators_addresses config['node']['privkey_hex'] = encode_hex(private_key) config['jsonrpc']['listen_port'] += number config['client_version_string'] = 'NODE{}'.format(number) # setting to 0 so that the CALLCODE opcode works at the start of the # network config['eth']['block']['HOMESTEAD_FORK_BLKNUM'] = 0 config['discovery']['bootstrap_nodes'] = bootstrap_nodes config['discovery']['listen_port'] = p2p_base_port + number config['p2p']['listen_port'] = p2p_base_port + number config['p2p']['min_peers'] = min(10, len(hydrachain_private_keys) - 1) config['p2p']['max_peers'] = len(hydrachain_private_keys) * 2 # only one of the nodes should have the Console service running if number != 0 and Console.name not in config['deactivated_services']: config['deactivated_services'].append(Console.name) hydrachain_app = start_app(config, accounts=[account]) all_apps.append(hydrachain_app) hydrachain_wait(private_keys, len(hydrachain_private_keys) - 1) return all_apps
def hydrachain_network(private_keys, base_port, base_datadir): """ Initializes a hydrachain network used for testing. """ # pylint: disable=too-many-locals from hydrachain.app import services, start_app, HPCApp import pyethapp.config as konfig gevent.get_hub().SYSTEM_ERROR = BaseException PBKDF2_CONSTANTS['c'] = 100 quantity = len(private_keys) def privkey_to_uri(private_key): host = b'0.0.0.0' pubkey = privtopub(private_key) return host_port_pubkey_to_uri(host, base_port, pubkey) addresses = [ privtoaddr(priv) for priv in private_keys ] bootstrap_nodes = [ privkey_to_uri(private_keys[0]), ] validator_keys = [ mk_privkey('raidenvalidator:{}'.format(position)) for position in range(quantity) ] validator_addresses = [ privtoaddr(validator_keys[position]) for position in range(quantity) ] alloc = { addr.encode('hex'): { 'balance': '1606938044258990275541962092341162602522202993782792835301376', } for addr in addresses } genesis = { 'nonce': '0x00006d6f7264656e', 'difficulty': '0x20000', 'mixhash': '0x00000000000000000000000000000000000000647572616c65787365646c6578', 'coinbase': '0x0000000000000000000000000000000000000000', 'timestamp': '0x00', 'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'extraData': '0x', 'gasLimit': '0x5FEFD8', 'alloc': alloc, } all_apps = [] for number in range(quantity): port = base_port + number config = konfig.get_default_config(services + [HPCApp]) # del config['eth']['genesis_hash'] config = update_config_from_genesis_json(config, genesis) datadir = os.path.join(base_datadir, str(number)) konfig.setup_data_dir(datadir) account = Account.new( password='', key=validator_keys[number], ) config['data_dir'] = datadir config['node']['privkey_hex'] = private_keys[number].encode('hex') config['hdc']['validators'] = validator_addresses config['jsonrpc']['listen_port'] += number config['client_version_string'] = 'NODE{}'.format(number) # setting to 0 so that the CALLCODE opcode works at the start of the # network config['eth']['block']['HOMESTEAD_FORK_BLKNUM'] = 0 config['discovery']['bootstrap_nodes'] = bootstrap_nodes config['discovery']['listen_port'] = port config['p2p']['listen_port'] = port config['p2p']['min_peers'] = min(10, quantity - 1) config['p2p']['max_peers'] = quantity * 2 # only one of the nodes should have the Console service running if number != 0: config['deactivated_services'].append(Console.name) hydrachain_app = start_app(config, accounts=[account]) all_apps.append(hydrachain_app) return all_apps