[#577] Fix: reduce batch size when reaching increased load part of the chain

Currently a 100 batch can take up to 3 minutes to scan. decrease the size of the batches when the increased load part of the chain is reached until a faster sync is implemented

See related counterpart to remove it issue #576

Closes #577
This commit is contained in:
Francisco Gindre 2022-10-25 18:21:32 -03:00
parent cbfa73181d
commit 545380b3e2
1 changed files with 14 additions and 1 deletions

View File

@ -13,7 +13,9 @@ extension CompactBlockProcessor {
try Task.checkCancellation()
setState(.scanning)
let batchSize = UInt32(config.scanningBatchSize)
// TODO: remove this arbitrary batch size https://github.com/zcash/ZcashLightClientKit/issues/576
let batchSize = scanBatchSize(for: range, network: self.config.network.networkType)
do {
if batchSize == 0 {
@ -92,6 +94,17 @@ extension CompactBlockProcessor {
throw error
}
}
fileprivate func scanBatchSize(for range: CompactBlockRange, network: NetworkType) -> UInt32 {
guard network == .mainnet else {
return UInt32(config.scanningBatchSize)
}
if range.lowerBound > 1_600_000 {
return 5
}
return UInt32(config.scanningBatchSize)
}
}
extension CompactBlockProcessor {