Exemple #1
0
    def clean_up(self):
        node_utils.graceful_rm(self._thread_pool, self._context.nodes.values())
        logging.info('Removed all nodes')

        utils.sleep(1)

        bash.check_output(
            bitcoincmd.fix_data_dirs_permissions(self._context.run_dir))
        logging.info('Fixed permissions of dirs')
 def clean_up_docker_safe(self):
     try:
         with Pool(1) as pool:
             node_utils.graceful_rm(pool, self._context.nodes.values())
         utils.sleep(1)
         bash.check_output(dockercmd.rm_network())
         bash.check_output(
             dockercmd.fix_data_dirs_permissions(self._context.run_dir))
     except Exception:
         logging.debug("clean_up_docker_safe failed")
         pass
Exemple #3
0
    def _give_nodes_spendable_coins(self, threadpool):
        nodes = list(self._context.nodes.values())
        cbs = []
        for i, node in enumerate(nodes):
            cbs.append(
                threadpool.apply_async(
                    node_utils.start_node,
                    args=(node, (str(node.ip)
                                 for node in nodes[max(0, i - 5):i]))))
        for cb in cbs:
            cb.get()

        threadpool.map(node_utils.check_startup_node, nodes)

        amount_of_tx_chains = _calc_number_of_tx_chains(
            self._context.args.txs_per_tick,
            self._context.args.blocks_per_tick, len(nodes))
        logging.info(
            'Each node receives {} tx-chains'.format(amount_of_tx_chains))

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, i * amount_of_tx_chains)
            node.execute_rpc('generate', amount_of_tx_chains)
            logging.info(
                'Generated {} blocks for node={} for their tx-chains'.format(
                    amount_of_tx_chains, node.name))

        node_utils.wait_until_height_reached(nodes[0],
                                             amount_of_tx_chains * len(nodes))
        nodes[0].generate_blocks(
            config.blocks_needed_to_make_coinbase_spendable)
        current_height = config.blocks_needed_to_make_coinbase_spendable + amount_of_tx_chains * len(
            nodes)

        threadpool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        # TODO fix coinbase behaviour where [Example1](#AppendixA) does not occur
        # self._pool.map(node_utils.transfer_coinbase_tx_to_normal_tx, nodes)

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, current_height + i)
            node.execute_rpc('generate', 1)

        current_height += len(nodes)
        # TODO fix
        self._context.first_block_height = 0  # current_height

        threadpool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        threadpool.map(node_utils.rm_peers_file, nodes)
        node_utils.graceful_rm(threadpool, nodes)
Exemple #4
0
    def clean_up_docker(self):
        node_utils.graceful_rm(self._thread_pool, self._context.nodes.values())
        logging.info('Removed all nodes')

        utils.sleep(1)

        bash.check_output(dockercmd.rm_network())
        logging.info('Deleted docker network')

        bash.check_output(
            dockercmd.fix_data_dirs_permissions(self._context.run_dir))
        logging.info('Fixed permissions of dirs used by docker')
Exemple #5
0
    def _give_nodes_spendable_coins(self):
        # At start no node will have coins,
        # assign them manually to make for smooth run
        # We do this before the RPC is ready, making it perfect fit
        nodes = list(self._context.nodes.values())
        cbs = []
        for i, node in enumerate(nodes):
            cbs.append(
                self._pool.apply_async(
                    node_utils.start_node,
                    args=(node, (str(node.ip)
                                 for node in nodes[max(0, i - 5):i]))))
        for cb in cbs:
            cb.get()

        self._pool.map(node_utils.check_startup_node, nodes)

        amount_of_tx_chains = _calc_number_of_tx_chains(
            self._context.args.txs_per_tick,
            self._context.args.blocks_per_tick, len(nodes))
        logging.info('Each node got {} tx-chains'.format(amount_of_tx_chains))

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, i * amount_of_tx_chains)
            node.execute_rpc('generate', amount_of_tx_chains)
            logging.info(
                'Generated {} blocks for node'.format(amount_of_tx_chains))

        node_utils.wait_until_height_reached(nodes[0],
                                             amount_of_tx_chains * len(nodes))
        nodes[0].generate_blocks(
            config.blocks_needed_to_make_coinbase_spendable)
        current_height = config.blocks_needed_to_make_coinbase_spendable + amount_of_tx_chains * len(
            nodes)

        self._pool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        self._pool.map(node_utils.transfer_coinbase_tx_to_normal_tx, nodes)

        for i, node in enumerate(nodes):
            node_utils.wait_until_height_reached(node, current_height + i)
            node.execute_rpc('generate', 1)

        current_height += len(nodes)
        self._context.first_block_height = current_height

        self._pool.starmap(node_utils.wait_until_height_reached,
                           zip(nodes, itertools.repeat(current_height)))

        self._pool.map(node_utils.rm_peers_file, nodes)
        node_utils.graceful_rm(self._pool, nodes)