Merge pull request #1354 from LukasKorba/1346-Troubleshooting--synchronization
[#1346] Troubleshooting synchronization
This commit is contained in:
commit
cf6a1e7923
|
@ -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/),
|
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).
|
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
|
# 2.0.5 - 2023-12-15
|
||||||
|
|
||||||
## Added
|
## Added
|
||||||
|
|
|
@ -8,11 +8,16 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
final class ScanAction {
|
final class ScanAction {
|
||||||
|
enum Constants {
|
||||||
|
static let reportDelay = 5
|
||||||
|
}
|
||||||
|
|
||||||
let configProvider: CompactBlockProcessor.ConfigProvider
|
let configProvider: CompactBlockProcessor.ConfigProvider
|
||||||
let blockScanner: BlockScanner
|
let blockScanner: BlockScanner
|
||||||
let rustBackend: ZcashRustBackendWelding
|
let rustBackend: ZcashRustBackendWelding
|
||||||
let latestBlocksDataProvider: LatestBlocksDataProvider
|
let latestBlocksDataProvider: LatestBlocksDataProvider
|
||||||
let logger: Logger
|
let logger: Logger
|
||||||
|
var progressReportReducer = Constants.reportDelay
|
||||||
|
|
||||||
init(container: DIContainer, configProvider: CompactBlockProcessor.ConfigProvider) {
|
init(container: DIContainer, configProvider: CompactBlockProcessor.ConfigProvider) {
|
||||||
self.configProvider = configProvider
|
self.configProvider = configProvider
|
||||||
|
@ -55,20 +60,29 @@ extension ScanAction: Action {
|
||||||
do {
|
do {
|
||||||
try await blockScanner.scanBlocks(at: batchRange) { [weak self] lastScannedHeight, increment in
|
try await blockScanner.scanBlocks(at: batchRange) { [weak self] lastScannedHeight, increment in
|
||||||
let processedHeight = await context.processedHeight
|
let processedHeight = await context.processedHeight
|
||||||
let incrementedprocessedHeight = processedHeight + BlockHeight(increment)
|
let incrementedProcessedHeight = processedHeight + BlockHeight(increment)
|
||||||
await context.update(processedHeight: incrementedprocessedHeight)
|
await context.update(processedHeight: incrementedProcessedHeight)
|
||||||
await self?.latestBlocksDataProvider.updateScannedData()
|
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
|
// ScanAction is controlled locally so it must report back the updated scanned height
|
||||||
await context.update(lastScannedHeight: lastScannedHeight)
|
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) {
|
} catch ZcashError.rustScanBlocks(let errorMsg) {
|
||||||
if isContinuityError(errorMsg) {
|
if isContinuityError(errorMsg) {
|
||||||
await context.update(requestedRewindHeight: batchRange.lowerBound - 10)
|
await context.update(requestedRewindHeight: batchRange.lowerBound - 10)
|
||||||
|
@ -84,7 +98,9 @@ extension ScanAction: Action {
|
||||||
return await update(context: context)
|
return await update(context: context)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stop() async { }
|
func stop() async {
|
||||||
|
progressReportReducer = Constants.reportDelay
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension ScanAction {
|
private extension ScanAction {
|
||||||
|
|
Loading…
Reference in New Issue