From d8ee9ff277e0cb3a9b4ded398b069f98081e6268 Mon Sep 17 00:00:00 2001 From: Francisco Gindre Date: Fri, 16 Sep 2022 18:08:31 -0300 Subject: [PATCH] - [#532] Download does not stop correctly Issue Reported on [0.16.x-beta] When the synchronizer is stopped, the processor does not cancel the download correctly. Then when attempting to resume sync, the synchronizer is not on `.stopped` and can't be resumed Fix: This commit makes sure that the download streamer checks cancelation before processing any block, or getting called back to report progress --- .../Block/Processor/CompactBlockDownload.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/ZcashLightClientKit/Block/Processor/CompactBlockDownload.swift b/Sources/ZcashLightClientKit/Block/Processor/CompactBlockDownload.swift index 58eefb02..db6cd260 100644 --- a/Sources/ZcashLightClientKit/Block/Processor/CompactBlockDownload.swift +++ b/Sources/ZcashLightClientKit/Block/Processor/CompactBlockDownload.swift @@ -29,6 +29,7 @@ extension CompactBlockProcessor { guard let latestHeight = targetHeightInternal else { throw LightWalletServiceError.generalError(message: "missing target height on compactBlockStreamDownload") } + try Task.checkCancellation() let latestDownloaded = try await storage.latestHeightAsync() let startHeight = max(startHeight ?? BlockHeight.empty(), latestDownloaded) @@ -38,6 +39,7 @@ extension CompactBlockProcessor { ) for try await zcashCompactBlock in stream { + try Task.checkCancellation() buffer.append(zcashCompactBlock) if buffer.count >= blockBufferSize { // TODO: writeAsync doesn't make sense here, awaiting it or calling blocking API have the same result and impact