From c6540d69580143aee7d193bbf2c4d426d115f201 Mon Sep 17 00:00:00 2001 From: almogdepaz Date: Tue, 19 Nov 2024 13:19:13 +0200 Subject: [PATCH 1/2] keep track of wp tasks --- chia/full_node/full_node.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/chia/full_node/full_node.py b/chia/full_node/full_node.py index 2e636c4ce2a5..928c64a91d33 100644 --- a/chia/full_node/full_node.py +++ b/chia/full_node/full_node.py @@ -126,7 +126,7 @@ class FullNode: log: logging.Logger db_path: Path wallet_sync_queue: asyncio.Queue[WalletUpdate] - _segment_task: Optional[asyncio.Task[None]] = None + _segment_task_list: list[asyncio.Task[None]] = dataclasses.field(default_factory=list) initialized: bool = False _server: Optional[ChiaServer] = None _shut_down: bool = False @@ -599,13 +599,13 @@ async def short_sync_batch(self, peer: WSChiaConnection, start_height: uint32, t return False batch_size = self.constants.MAX_BLOCK_COUNT_PER_REQUESTS - if self._segment_task is not None and (not self._segment_task.done()): + for task in self._segment_task_list[:]: + if task.done(): + self._segment_task_list.remove(task) try: - self._segment_task.cancel() + task.cancel() except Exception as e: self.log.warning(f"failed to cancel segment task {e}") - self._segment_task = None - try: peer_info = peer.get_peer_logging() if start_height > 0: @@ -2223,8 +2223,12 @@ async def add_block( record = self.blockchain.block_record(block.header_hash) if self.weight_proof_handler is not None and record.sub_epoch_summary_included is not None: - if self._segment_task is None or self._segment_task.done(): - self._segment_task = asyncio.create_task(self.weight_proof_handler.create_prev_sub_epoch_segments()) + self._segment_task_list.append( + asyncio.create_task(self.weight_proof_handler.create_prev_sub_epoch_segments()) + ) + for task in self._segment_task_list[:]: + if task.done(): + self._segment_task_list.remove(task) return None async def add_unfinished_block( From d3aee2b941145332eef010461591e6ee7afb7db7 Mon Sep 17 00:00:00 2001 From: almogdepaz Date: Tue, 19 Nov 2024 13:21:57 +0200 Subject: [PATCH 2/2] use cancel_task_safe --- chia/full_node/full_node.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/chia/full_node/full_node.py b/chia/full_node/full_node.py index 928c64a91d33..ac6d6690531e 100644 --- a/chia/full_node/full_node.py +++ b/chia/full_node/full_node.py @@ -602,10 +602,9 @@ async def short_sync_batch(self, peer: WSChiaConnection, start_height: uint32, t for task in self._segment_task_list[:]: if task.done(): self._segment_task_list.remove(task) - try: - task.cancel() - except Exception as e: - self.log.warning(f"failed to cancel segment task {e}") + else: + cancel_task_safe(task=task, log=self.log) + try: peer_info = peer.get_peer_logging() if start_height > 0: