diff --git a/chia/full_node/full_node.py b/chia/full_node/full_node.py index 2e636c4ce2a5..ac6d6690531e 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,12 +599,11 @@ 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()): - try: - self._segment_task.cancel() - except Exception as e: - self.log.warning(f"failed to cancel segment task {e}") - self._segment_task = None + for task in self._segment_task_list[:]: + if task.done(): + self._segment_task_list.remove(task) + else: + cancel_task_safe(task=task, log=self.log) try: peer_info = peer.get_peer_logging() @@ -2223,8 +2222,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(