def contents_cleanup(transaction_service: TransactionService,
                     block_confirmation_message: AbstractCleanupMessage,
                     cleanup_tasks
                     ):
    start_datetime = datetime.utcnow()
    start_time = time.time()
    tx_service = typing.cast(ExtensionTransactionService, transaction_service)
    cleanup_task = cleanup_tasks.borrow_task()
    cleanup_task.init(tpe.InputBytes(block_confirmation_message.buf), tx_service.proxy)
    task_pool_proxy.run_task(cleanup_task)
    short_ids = cleanup_task.short_ids()
    total_content_removed = cleanup_task.total_content_removed()
    tx_count = cleanup_task.tx_count()
    message_hash = block_confirmation_message.message_hash()
    tx_service.update_removed_transactions(total_content_removed, short_ids)
    transaction_service.on_block_cleaned_up(message_hash)
    end_datetime = datetime.utcnow()
    end_time = time.time()
    duration = end_time - start_time
    logger.statistics(
        {
            "type": "MemoryCleanup",
            "event": "CacheStateAfterBlockCleanup",
            "data": transaction_service.get_cache_state_json(),
            "start_datetime": start_datetime,
            "end_datetime": end_datetime,
            "duration": duration,
            "total_content_removed": total_content_removed,
            "tx_count": tx_count,
            "short_ids_count": len(short_ids),
            "message_hash": repr(message_hash),
        }
    )
    cleanup_tasks.return_task(cleanup_task)
 def process_cleanup_message(
     self,
     msg: AbstractCleanupMessage,
     # pyre-fixme[11]: Annotation `AbstractGatewayNode` is not defined as a type.
     node: "AbstractGatewayNode",
 ):
     block_cleanup = msg.MESSAGE_TYPE == BloxrouteMessageType.BLOCK_CONFIRMATION
     message_hash = msg.message_hash()
     if not self.node.should_process_block_hash(message_hash):
         return
     transaction_service = node.get_tx_service()
     tracked_blocks = transaction_service.get_tracked_blocks()
     if message_hash in node.block_cleanup_processed_blocks:
         if message_hash in tracked_blocks and block_cleanup:
             logger.debug(
                 "Block confirmation message already processed: {}. Reprocessing tracked blocks: {}.",
                 message_hash, tracked_blocks)
         else:
             logger.debug(
                 "Cleanup message was already processed. Skipping: {}",
                 message_hash)
             return
     logger.debug("Processing cleanup message: {}", message_hash)
     node.block_cleanup_processed_blocks.add(message_hash)
     self.contents_cleanup(transaction_service, msg)
def contents_cleanup(transaction_service: TransactionService,
                     block_confirmation_message: AbstractCleanupMessage
                     ):
    message_hash = block_confirmation_message.message_hash()
    for short_id in block_confirmation_message.short_ids():
        transaction_service.remove_transaction_by_short_id(short_id, remove_related_short_ids=True)
    for tx_hash in block_confirmation_message.transaction_hashes():
        transaction_service.remove_transaction_by_tx_hash(tx_hash)
    transaction_service.on_block_cleaned_up(message_hash)
    logger.statistics(
        {
            "type": "MemoryCleanup",
            "event": "CacheStateAfterBlockCleanup",
            "message_hash": repr(message_hash),
            "data": transaction_service.get_cache_state_json()
        }
    )