Esempio n. 1
0
    def test_aging_cache_get_item_in_status(self):
        # GIVEN
        cache = AgingCache(max_age_seconds=5)
        for i in range(10):
            cache[i] = f"value_{i}"
            # util.logger.spam(f"test_cache cache size({len(cache)}) max_size({cache.maxlen})")
        util.logger.spam(f"test_aging_cache_pop cache size({len(cache)}) max_age_seconds({cache.max_age_seconds})")
        self.assertGreaterEqual(len(cache), 10)

        # WHEN
        for i in range(10):
            item = cache.get_item_in_status(AgingCache.DEFAULT_ITEM_STATUS, "Some Status")
            util.logger.spam(f"item({item})")

        # THEN
        item_count = 0
        for i in range(10):
            item = cache.get_item_in_status(AgingCache.DEFAULT_ITEM_STATUS, "Some Status")
            if item:
                item_count += 1

        self.assertEqual(len(cache), 10)
        self.assertEqual(item_count, 0)
Esempio n. 2
0
    def __makeup_block(self, tx_queue: AgingCache):
        """Queue 에 수집된 tx 를 block 으로 만든다.
        setttings 에 정의된 조건에 따라 한번의 작업으로 여러개의 candidate_block 으로 나뉘어진 블럭을 생성할 수 있다.
        (주의! 성능상의 이유로 가능한 운행 조건에서 블럭이 나누어지지 않도록 설정하는 것이 좋다.)
        """
        while tx_queue:
            if self.__block_tx_size >= conf.MAX_TX_SIZE_IN_BLOCK:
                logging.debug(
                    f"Proposer:: total size({self.__block_tx_size}) "
                    f"count({len(self.__block.confirmed_transaction_list)}) "
                    f"_txQueue size ({len(tx_queue)})")
                break

            # 수집된 tx 가 있으면 Block 에 집어 넣는다.
            tx = tx_queue.get_item_in_status(
                TransactionStatusInQueue.normal,
                TransactionStatusInQueue.added_to_block)

            if tx is None:
                break

            if isinstance(tx, Transaction):
                # Check tx_hash is unique!
                if self.__block_manager.get_tx(tx.tx_hash) is None:
                    # util.logger.spam(f"Proposer:__make_block:: txQueue get tx: {tx.tx_hash}")
                    if self.__block.put_transaction(tx):
                        self.__block_tx_size += sys.getsizeof(pickle.dumps(tx))
                else:
                    logging.warning(f"tx hash conflict ({tx.tx_hash})")
            else:
                logging.error("Load Transaction Error!")
                continue

            if self.__block is None:
                logging.error("Proposer Leader Can't Add tx...")

        consensus = self.__channel_service.consensus
        self.__block.peer_id = consensus.leader_id
        self.__block.generate_block(self.__precommit_block)