[#1346] Troubleshooting synchronization

- changelog update
- the sync time has been reduced by ~33%. The progress reporting frequency has been lowered down 5-times
- this is just first step and a quick improvement before we introduce advanced solution, covered in #1353

[#1346] Troubleshooting synchronization (#1354)

- typo fixed
This commit is contained in:
Lukas Korba 2024-01-24 16:22:29 +01:00
parent 0e4e1190e3
commit bca6ceb15f
2 changed files with 33 additions and 10 deletions

View File

@ -4,6 +4,13 @@ All notable changes to this library will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# [Unreleased]
## Changed
### [#1346] Troubleshooting synchronization
We focused on performance of the synchronization and found out a root cause in progress reporting. Simple change reduced the synchronization significantly by reporting less frequently. This affect the UX a bit because the % of the sync is updated only every 500 scanned blocks instead of every 100. Proper solution is going to be handled in #1353.
# 2.0.5 - 2023-12-15
## Added

View File

@ -8,11 +8,16 @@
import Foundation
final class ScanAction {
enum Constants {
static let reportDelay = 5
}
let configProvider: CompactBlockProcessor.ConfigProvider
let blockScanner: BlockScanner
let rustBackend: ZcashRustBackendWelding
let latestBlocksDataProvider: LatestBlocksDataProvider
let logger: Logger
var progressReportReducer = Constants.reportDelay
init(container: DIContainer, configProvider: CompactBlockProcessor.ConfigProvider) {
self.configProvider = configProvider
@ -55,20 +60,29 @@ extension ScanAction: Action {
do {
try await blockScanner.scanBlocks(at: batchRange) { [weak self] lastScannedHeight, increment in
let processedHeight = await context.processedHeight
let incrementedprocessedHeight = processedHeight + BlockHeight(increment)
await context.update(processedHeight: incrementedprocessedHeight)
let incrementedProcessedHeight = processedHeight + BlockHeight(increment)
await context.update(processedHeight: incrementedProcessedHeight)
await self?.latestBlocksDataProvider.updateScannedData()
// report scan progress only if it's available
if let scanProgress = try? await self?.rustBackend.getScanProgress() {
let progress = try scanProgress.progress()
self?.logger.debug("progress: \(progress)")
await didUpdate(.syncProgress(progress))
}
// ScanAction is controlled locally so it must report back the updated scanned height
await context.update(lastScannedHeight: lastScannedHeight)
}
// This is a simple change that reduced the synchronization time significantly while affecting the UX only a bit.
// The frequency of UI progress update is lowered x5 times.
// Proper solution is handled in
// TODO: [#1353] Advanced progress reporting, https://github.com/Electric-Coin-Company/zcash-swift-wallet-sdk/issues/1353
if progressReportReducer == 0 {
// report scan progress only if it's available
if let scanProgress = try? await rustBackend.getScanProgress() {
let progress = try scanProgress.progress()
logger.debug("progress: \(progress)")
await didUpdate(.syncProgress(progress))
}
progressReportReducer = Constants.reportDelay
} else {
progressReportReducer -= 1
}
} catch ZcashError.rustScanBlocks(let errorMsg) {
if isContinuityError(errorMsg) {
await context.update(requestedRewindHeight: batchRange.lowerBound - 10)
@ -84,7 +98,9 @@ extension ScanAction: Action {
return await update(context: context)
}
func stop() async { }
func stop() async {
progressReportReducer = Constants.reportDelay
}
}
private extension ScanAction {