- [#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
This commit is contained in:
Francisco Gindre 2022-09-16 18:08:31 -03:00
parent db15465ebe
commit d8ee9ff277
1 changed files with 2 additions and 0 deletions

View File

@ -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