def create_txs_service_msg( transaction_service: TransactionService, tx_service_snap: List[Sha256Hash], sync_tx_content: bool = True) -> List[TxContentShortIds]: task_start = time.time() txs_content_short_ids: List[TxContentShortIds] = [] txs_msg_len = 0 while tx_service_snap: transaction_key = transaction_service.get_transaction_key( tx_service_snap.pop()) short_ids = list( transaction_service.get_short_ids_by_key(transaction_key)) if sync_tx_content: tx_content = transaction_service.get_transaction_by_key( transaction_key) else: tx_content = bytearray(0) # TODO: evaluate short id quota type flag value short_id_flags = [ transaction_service.get_short_id_transaction_type(short_id) for short_id in short_ids ] tx_content_short_ids: TxContentShortIds = TxContentShortIds( transaction_key.transaction_hash, tx_content, short_ids, short_id_flags) txs_msg_len += txs_serializer.get_serialized_tx_content_short_ids_bytes_len( tx_content_short_ids) txs_content_short_ids.append(tx_content_short_ids) if txs_msg_len >= constants.TXS_MSG_SIZE or time.time( ) - task_start > constants.TXS_SYNC_TASK_DURATION: break return txs_content_short_ids
def create_txs_service_msg_from_time( transaction_service: TransactionService, start_time: float = 0, sync_tx_content: bool = True, snapshot_cache_keys: Optional[Set[TransactionCacheKeyType]] = None ) -> Tuple[List[TxContentShortIds], float, bool, Set[TransactionCacheKeyType]]: task_start = time.time() txs_content_short_ids: List[TxContentShortIds] = [] txs_msg_len = 0 if snapshot_cache_keys is None: snapshot_cache_keys = set() done = False timestamp = start_time expire_short_ids = [] for short_id, timestamp in transaction_service._tx_assignment_expire_queue.queue.items( ): if timestamp > start_time: cache_key = transaction_service._short_id_to_tx_cache_key.get( short_id, None) if cache_key is not None: transaction_key = transaction_service.get_transaction_key( None, cache_key) if cache_key not in snapshot_cache_keys: snapshot_cache_keys.add( transaction_key.transaction_cache_key) short_ids = list( transaction_service._tx_cache_key_to_short_ids[ transaction_key.transaction_cache_key]) if sync_tx_content and transaction_service.has_transaction_contents_by_key( transaction_key): tx_content = transaction_service._tx_cache_key_to_contents[ transaction_key.transaction_cache_key] else: tx_content = bytearray(0) short_id_flags = [ transaction_service.get_short_id_transaction_type( short_id) for short_id in short_ids ] tx_content_short_ids: TxContentShortIds = TxContentShortIds( transaction_key.transaction_hash, tx_content, short_ids, short_id_flags) txs_msg_len += txs_serializer.get_serialized_tx_content_short_ids_bytes_len( tx_content_short_ids) txs_content_short_ids.append(tx_content_short_ids) if txs_msg_len >= constants.TXS_MSG_SIZE or ( time.time() - task_start > constants.TXS_SYNC_TASK_DURATION): break else: expire_short_ids.append(short_id) else: done = True for short_id in expire_short_ids: transaction_service._tx_assignment_expire_queue.remove(short_id) return txs_content_short_ids, timestamp, done, snapshot_cache_keys