def add_bootstrap(self, config: DockerConfig, bootstrap_address: str = None) -> None: config.is_bootstrap = True config.bootstrap_address = bootstrap_address self._add_cl_node(config) self.wait_method(wait_for_node_started, 0) wait_for_genesis_block(self.docker_nodes[0])
def create_cl_network(self, node_count: int = 3, network_connections: List[List[int]] = None) -> None: """ Allow creation of a network where all nodes are not connected to node-0's network and therefore each other. Ex: Star Network node3 | node1 -- node0 -- node2 create_cl_network(node_count=4, network_connections=[[0, 1], [0, 2], [0, 3]]) :param node_count: Number of nodes to create. :param network_connections: A list of lists of node indexes that should be joined. """ self.network_names = {} kp = self.get_key() config = DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, network=self.create_docker_network(), node_account=kp, ) self.add_bootstrap(config) for i in range(1, node_count): kp = self.get_key() config = DockerConfig( self.docker_client, node_private_key=kp.private_key, network=self.create_docker_network(), node_account=kp, ) self.add_cl_node(config, network_with_bootstrap=False) for network_members in network_connections: self.connect(network_members) for node_number in range(1, node_count): self.wait_method(wait_for_approved_block_received_handler_state, node_number) # Calculate how many peers should be connected to each node. # Assumes duplicate network connections are not given, else wait_for_peers will time out. peer_counts = [0] * node_count for network in network_connections: for node_num in network: peer_counts[node_num] += len(network) - 1 timeout = self.docker_nodes[0].timeout for node_num, peer_count in enumerate(peer_counts): if peer_count > 0: wait_for_peers_count_at_least(self.docker_nodes[node_num], peer_count, timeout)
def add_cl_node( self, config: DockerConfig, network_with_bootstrap: bool = True, bootstrap_address: str = None, ) -> None: with self._lock: if self.node_count == 0: raise Exception("Must create bootstrap first") config.bootstrap_address = (bootstrap_address or self.cl_nodes[0].node.address) if network_with_bootstrap: config.network = self.cl_nodes[0].node.config.network self._add_cl_node(config)
def get_node_config(self, number, network): kp = self.get_key() return DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, node_account=kp, number=number, network=network, )
def docker_config(self, account): config = DockerConfig( self.docker_client, node_private_key=account.private_key, node_public_key=account.public_key, network=self.create_docker_network(), initial_motes=self.initial_motes, node_account=account, grpc_encryption=self.grpc_encryption, ) return config
def create_cl_network(self, node_count=2): kp = self.get_key() config = DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, network=self.create_docker_network(), node_account=kp, grpc_encryption=self.grpc_encryption, ) self.add_bootstrap(config) config = DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, network=self.create_docker_network(), node_account=kp, grpc_encryption=self.grpc_encryption, custom_docker_tag="dev", ) self.add_cl_node(config)
def get_node_config(self, network): kp = self.get_key() logging.debug(f"ENV: {self.NODE_ENV}") return DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, node_env=self.NODE_ENV, node_account=kp, network=network, number_of_bonds=3, )
def create_cl_network(self): kp = self.get_key() config = DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, network=self.create_docker_network(), node_account=kp, grpc_encryption=self.grpc_encryption, behind_proxy=True, ) self.add_bootstrap(config) self.add_new_node_to_network((lambda kp: DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, network=self.create_docker_network(), node_account=kp, grpc_encryption=self.grpc_encryption, behind_proxy=True, )))
def create_cl_network(self): kp = self.get_key() config = DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, network=self.create_docker_network(), node_account=kp, grpc_encryption=self.grpc_encryption, command_timeout=30, ) self.add_bootstrap(config) # Create accounts.csv of the second node with different bond amounts. self.add_new_node_to_network((lambda kp: DockerConfig( self.docker_client, node_private_key=kp.private_key, node_account=kp, grpc_encryption=self.grpc_encryption, behind_proxy=self.behind_proxy, bond_amount=lambda i, n: n + 3 * i, )))
def create_cl_network(self, node_count=10): kp = self.get_key() config = DockerConfig( self.docker_client, node_private_key=kp.private_key, node_public_key=kp.public_key, network=self.create_docker_network(), node_account=kp, ) self.add_bootstrap(config) for _ in range(1, node_count): kp = self.get_key() config = DockerConfig(self.docker_client, node_private_key=kp.private_key, node_account=kp) self.add_cl_node(config) for node_number in range(1, node_count): self.wait_method(wait_for_approved_block_received_handler_state, node_number) self.wait_for_peers()
def _add_cl_node(self, config: DockerConfig, number_of_retries=3) -> None: with self._lock: config.number = self.node_count for _ in range(number_of_retries): cl_node = CasperLabsNode(self, config) if node_started_and_not_failed_to_bind(cl_node.node): self.cl_nodes.append(cl_node) return else: logging.warning(f"Node failed to bind") raise Exception( f"Node started {number_of_retries} times but failed to bind each time" )
def add_new_node_to_network(self, generate_config=None, account: Account = None) -> Account: if account is None: account = self.get_key() if generate_config is not None: config = generate_config(account) else: config = DockerConfig( self.docker_client, node_private_key=account.private_key, node_account=account, grpc_encryption=self.grpc_encryption, behind_proxy=self.behind_proxy, ) self.add_cl_node(config) self.wait_method(wait_for_approved_block_received_handler_state, 1) self.wait_for_peers() return account
def _add_cl_node(self, config: DockerConfig) -> None: with self._lock: config.number = self.node_count cl_node = CasperLabsNode(self, config) self.cl_nodes.append(cl_node)