Merge pull request #1254 from LukasKorba/1240-Remove-previous-progress-reporting
[#1240] Remove previous progress reporting
This commit is contained in:
commit
a42fc87d73
|
@ -256,18 +256,10 @@ struct ProcessorMetrics {
|
|||
|
||||
static func accumulate(_ prev: ProcessorMetrics, current: SDKMetrics.BlockMetricReport) -> Self {
|
||||
.init(
|
||||
minHeight: min(prev.minHeight, current.startHeight),
|
||||
maxHeight: max(prev.maxHeight, current.progressHeight),
|
||||
maxDuration: compareDuration(
|
||||
prev.maxDuration,
|
||||
(current.duration, current.progressHeight - current.batchSize ... current.progressHeight),
|
||||
max
|
||||
),
|
||||
minDuration: compareDuration(
|
||||
prev.minDuration,
|
||||
(current.duration, current.progressHeight - current.batchSize ... current.progressHeight),
|
||||
min
|
||||
),
|
||||
minHeight: prev.minHeight,
|
||||
maxHeight: prev.maxHeight,
|
||||
maxDuration: prev.maxDuration,
|
||||
minDuration: prev.minDuration,
|
||||
cumulativeDuration: prev.cumulativeDuration + current.duration,
|
||||
measuredCount: prev.measuredCount + 1
|
||||
)
|
||||
|
@ -313,8 +305,6 @@ extension SDKMetrics.BlockMetricReport: CustomDebugStringConvertible {
|
|||
public var debugDescription: String {
|
||||
"""
|
||||
BlockMetric:
|
||||
startHeight: \(self.progressHeight - self.batchSize)
|
||||
endHeight: \(self.progressHeight)
|
||||
batchSize: \(self.batchSize)
|
||||
duration: \(self.duration)
|
||||
"""
|
||||
|
|
|
@ -79,7 +79,6 @@ extension EnhanceAction: Action {
|
|||
didEnhance: { progress in
|
||||
if let foundTx = progress.lastFoundTransaction, progress.newlyMined {
|
||||
await didUpdate(.minedTransaction(foundTx))
|
||||
await didUpdate(.progressPartialUpdate(.enhance(progress)))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -22,9 +22,7 @@ extension FetchUTXOsAction: Action {
|
|||
|
||||
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext {
|
||||
logger.debug("Fetching UTXOs")
|
||||
let result = try await utxoFetcher.fetch() { fetchProgress in
|
||||
await didUpdate(.progressPartialUpdate(.fetch(fetchProgress)))
|
||||
}
|
||||
let result = try await utxoFetcher.fetch() { _ in }
|
||||
await didUpdate(.storedUTXOs(result))
|
||||
|
||||
await context.update(state: .handleSaplingParams)
|
||||
|
|
|
@ -63,16 +63,9 @@ extension ScanAction: Action {
|
|||
|
||||
// report scan progress only if it's available
|
||||
if let scanProgress = try? await self?.rustBackend.getScanProgress() {
|
||||
// TODO: [#1240] remove BlockProgress, https://github.com/zcash/ZcashLightClientKit/issues/1240
|
||||
let progress = BlockProgress(
|
||||
startHeight: totalProgressRange.lowerBound,
|
||||
targetHeight: totalProgressRange.upperBound,
|
||||
progressHeight: incrementedprocessedHeight,
|
||||
scanProgress: try scanProgress.progress()
|
||||
)
|
||||
|
||||
let progress = try scanProgress.progress()
|
||||
self?.logger.debug("progress: \(progress)")
|
||||
await didUpdate(.progressPartialUpdate(.syncing(progress)))
|
||||
await didUpdate(.syncProgress(progress))
|
||||
}
|
||||
|
||||
// ScanAction is controlled locally so it must report back the updated scanned height
|
||||
|
|
|
@ -431,7 +431,7 @@ extension CompactBlockProcessor {
|
|||
case handledReorg(_ reorgHeight: BlockHeight, _ rewindHeight: BlockHeight)
|
||||
|
||||
/// Event sent when progress of some specific action happened.
|
||||
case progressPartialUpdate(CompactBlockProgressUpdate)
|
||||
case syncProgress(Float)
|
||||
|
||||
/// Event sent when progress of the sync process changes.
|
||||
case progressUpdated(Float)
|
||||
|
@ -630,7 +630,6 @@ extension CompactBlockProcessor {
|
|||
let lastEnhancedheight = await context.lastEnhancedHeight
|
||||
context = ActionContextImpl(state: .idle)
|
||||
await context.update(lastEnhancedHeight: lastEnhancedheight)
|
||||
await compactBlockProgress.reset()
|
||||
}
|
||||
|
||||
private func syncStarted() async {
|
||||
|
|
|
@ -201,12 +201,7 @@ actor BlockDownloaderImpl {
|
|||
|
||||
let pushMetrics: (BlockHeight, Date, Date) -> Void = { [metrics] lastDownloadedBlockHeight, startTime, finishTime in
|
||||
metrics.pushProgressReport(
|
||||
progress: BlockProgress(
|
||||
startHeight: totalProgressRange.lowerBound,
|
||||
targetHeight: totalProgressRange.upperBound,
|
||||
progressHeight: Int(lastDownloadedBlockHeight),
|
||||
scanProgress: 0
|
||||
),
|
||||
progress: 0,
|
||||
start: startTime,
|
||||
end: finishTime,
|
||||
batchSize: maxBlockBufferSize,
|
||||
|
|
|
@ -135,12 +135,7 @@ extension BlockEnhancerImpl: BlockEnhancer {
|
|||
}
|
||||
|
||||
metrics.pushProgressReport(
|
||||
progress: BlockProgress(
|
||||
startHeight: range.lowerBound,
|
||||
targetHeight: range.upperBound,
|
||||
progressHeight: range.upperBound,
|
||||
scanProgress: 0
|
||||
),
|
||||
progress: 0,
|
||||
start: startTime,
|
||||
end: Date(),
|
||||
batchSize: range.count,
|
||||
|
|
|
@ -86,12 +86,7 @@ extension UTXOFetcherImpl: UTXOFetcher {
|
|||
}
|
||||
|
||||
metrics.pushProgressReport(
|
||||
progress: BlockProgress(
|
||||
startHeight: 0,
|
||||
targetHeight: 1,
|
||||
progressHeight: 1,
|
||||
scanProgress: 0
|
||||
),
|
||||
progress: 0,
|
||||
start: startTime,
|
||||
end: Date(),
|
||||
batchSize: 1,
|
||||
|
|
|
@ -70,15 +70,8 @@ extension BlockScannerImpl: BlockScanner {
|
|||
if scannedNewBlocks {
|
||||
try await didScan(lastScannedHeight, batchSize)
|
||||
|
||||
let progress = BlockProgress(
|
||||
startHeight: totalProgressRange.lowerBound,
|
||||
targetHeight: totalProgressRange.upperBound,
|
||||
progressHeight: lastScannedHeight,
|
||||
scanProgress: 0
|
||||
)
|
||||
|
||||
metrics.pushProgressReport(
|
||||
progress: progress,
|
||||
progress: 0,
|
||||
start: scanStartTime,
|
||||
end: scanFinishTime,
|
||||
batchSize: Int(batchSize),
|
||||
|
|
|
@ -9,51 +9,16 @@ import Foundation
|
|||
|
||||
final actor CompactBlockProgress {
|
||||
static let zero = CompactBlockProgress()
|
||||
|
||||
enum Action: Equatable {
|
||||
case enhance
|
||||
case fetch
|
||||
case scan
|
||||
|
||||
func weight() -> Float {
|
||||
switch self {
|
||||
case .enhance: return 0.08
|
||||
case .fetch: return 0.02
|
||||
case .scan: return 1.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var actionProgresses: [Action: Float] = [:]
|
||||
|
||||
var progress: Float {
|
||||
var overallProgress = Float(0)
|
||||
actionProgresses.forEach { key, value in
|
||||
overallProgress += value * key.weight()
|
||||
}
|
||||
|
||||
return overallProgress
|
||||
}
|
||||
|
||||
var progress: Float = 0.0
|
||||
|
||||
func hasProgressUpdated(_ event: CompactBlockProcessor.Event) -> Bool {
|
||||
guard case .progressPartialUpdate(let update) = event else {
|
||||
guard case .syncProgress(let update) = event else {
|
||||
return false
|
||||
}
|
||||
|
||||
if case let .syncing(progress) = update {
|
||||
actionProgresses[.scan] = progress.scanProgress
|
||||
}
|
||||
|
||||
progress = update
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func reset() {
|
||||
actionProgresses.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
enum CompactBlockProgressUpdate: Equatable {
|
||||
case syncing(_ progress: BlockProgress)
|
||||
case enhance(_ progress: EnhancementProgress)
|
||||
case fetch(_ progress: Float)
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
//
|
||||
// BlockProgress.swift
|
||||
//
|
||||
//
|
||||
// Created by Michal Fousek on 03.02.2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct BlockProgress: Equatable {
|
||||
public let startHeight: BlockHeight
|
||||
public let targetHeight: BlockHeight
|
||||
public let progressHeight: BlockHeight
|
||||
public let scanProgress: Float
|
||||
|
||||
public var progress: Float {
|
||||
let overall = self.targetHeight - self.startHeight
|
||||
|
||||
return overall > 0 ? Float((self.progressHeight - self.startHeight)) / Float(overall) : 0
|
||||
}
|
||||
}
|
||||
|
||||
public extension BlockProgress {
|
||||
static let nullProgress = BlockProgress(
|
||||
startHeight: 0,
|
||||
targetHeight: 0,
|
||||
progressHeight: 0,
|
||||
scanProgress: 0
|
||||
)
|
||||
}
|
|
@ -32,9 +32,7 @@ import Foundation
|
|||
/// We encourage you to check`SDKMetricsTests` and other tests in the Test/PerformanceTests/ folder.
|
||||
public class SDKMetrics {
|
||||
public struct BlockMetricReport: Equatable {
|
||||
public let startHeight: BlockHeight
|
||||
public let progressHeight: BlockHeight
|
||||
public let targetHeight: BlockHeight
|
||||
public let progress: Float
|
||||
public let batchSize: Int
|
||||
public let startTime: TimeInterval
|
||||
public let endTime: TimeInterval
|
||||
|
@ -75,7 +73,7 @@ public class SDKMetrics {
|
|||
/// `SDKMetrics` focuses deeply on sync process and metrics related to it. By default there are reports around
|
||||
/// block operations like download, validate, etc. This method pushes data on a stack for the specific operation.
|
||||
func pushProgressReport(
|
||||
progress: BlockProgress,
|
||||
progress: Float,
|
||||
start: Date,
|
||||
end: Date,
|
||||
batchSize: Int,
|
||||
|
@ -84,9 +82,7 @@ public class SDKMetrics {
|
|||
guard isEnabled else { return }
|
||||
|
||||
let blockMetricReport = BlockMetricReport(
|
||||
startHeight: progress.startHeight,
|
||||
progressHeight: progress.progressHeight,
|
||||
targetHeight: progress.targetHeight,
|
||||
progress: 0,
|
||||
batchSize: batchSize,
|
||||
startTime: start.timeIntervalSinceReferenceDate,
|
||||
endTime: end.timeIntervalSinceReferenceDate
|
||||
|
|
|
@ -216,7 +216,7 @@ public class SDKSynchronizer: Synchronizer {
|
|||
case let .progressUpdated(progress):
|
||||
await self?.progressUpdated(progress: progress)
|
||||
|
||||
case .progressPartialUpdate:
|
||||
case .syncProgress:
|
||||
break
|
||||
|
||||
case let .storedUTXOs(utxos):
|
||||
|
|
|
@ -243,7 +243,7 @@ final class EnhanceActionTests: ZcashTestCase {
|
|||
|
||||
do {
|
||||
_ = try await enhanceAction.run(with: syncContext) { event in
|
||||
if case .progressPartialUpdate = event { return }
|
||||
if case .syncProgress = event { return }
|
||||
|
||||
guard case .minedTransaction(let minedTransaction) = event else {
|
||||
XCTFail("Event is expected to be .minedTransaction but received \(event)")
|
||||
|
@ -304,7 +304,7 @@ final class EnhanceActionTests: ZcashTestCase {
|
|||
|
||||
do {
|
||||
_ = try await enhanceAction.run(with: syncContext) { event in
|
||||
if case .progressPartialUpdate = event { return }
|
||||
if case .syncProgress = event { return }
|
||||
|
||||
guard case .minedTransaction(let minedTransaction) = event else {
|
||||
XCTFail("Event is expected to be .minedTransaction but received \(event)")
|
||||
|
|
|
@ -30,13 +30,10 @@ final class ScanActionTests: ZcashTestCase {
|
|||
|
||||
do {
|
||||
let nextContext = try await scanAction.run(with: syncContext) { event in
|
||||
guard case .progressPartialUpdate(.syncing(let progress)) = event else {
|
||||
XCTFail("event is expected to be .progressPartialUpdate(.syncing()) but received \(event)")
|
||||
guard case .syncProgress = event else {
|
||||
XCTFail("event is expected to be .syncProgress() but received \(event)")
|
||||
return
|
||||
}
|
||||
XCTAssertEqual(progress.startHeight, BlockHeight(1000))
|
||||
XCTAssertEqual(progress.targetHeight, BlockHeight(2000))
|
||||
XCTAssertEqual(progress.progressHeight, BlockHeight(1500))
|
||||
}
|
||||
XCTAssertTrue(loggerMock.debugFileFunctionLineCalled, "logger.debug(...) is expected to be called.")
|
||||
XCTAssertTrue(blockScannerMock.scanBlocksAtTotalProgressRangeDidScanCalled, "blockScanner.scanBlocks(...) is expected to be called.")
|
||||
|
|
|
@ -14,12 +14,7 @@ final class SDKMetricsTests: XCTestCase {
|
|||
metrics.enableMetrics()
|
||||
|
||||
metrics.pushProgressReport(
|
||||
progress: BlockProgress(
|
||||
startHeight: 1_730_000,
|
||||
targetHeight: 1_730_099,
|
||||
progressHeight: 1_730_050,
|
||||
scanProgress: 0
|
||||
),
|
||||
progress: 0,
|
||||
start: Date(timeIntervalSinceReferenceDate: 0.0),
|
||||
end: Date(timeIntervalSinceReferenceDate: 1.0),
|
||||
batchSize: 10,
|
||||
|
@ -149,18 +144,14 @@ final class SDKMetricsTests: XCTestCase {
|
|||
|
||||
extension SDKMetrics.BlockMetricReport {
|
||||
static let placeholderA = Self(
|
||||
startHeight: 1_730_000,
|
||||
progressHeight: 1_730_050,
|
||||
targetHeight: 1_730_099,
|
||||
progress: 0,
|
||||
batchSize: 10,
|
||||
startTime: Date(timeIntervalSinceReferenceDate: 0.0).timeIntervalSinceReferenceDate,
|
||||
endTime: Date(timeIntervalSinceReferenceDate: 1.0).timeIntervalSinceReferenceDate
|
||||
)
|
||||
|
||||
static let placeholderB = Self(
|
||||
startHeight: 1_730_000,
|
||||
progressHeight: 1_730_080,
|
||||
targetHeight: 1_730_099,
|
||||
progress: 0,
|
||||
batchSize: 10,
|
||||
startTime: Date(timeIntervalSinceReferenceDate: 0.0).timeIntervalSinceReferenceDate,
|
||||
endTime: Date(timeIntervalSinceReferenceDate: 6.0).timeIntervalSinceReferenceDate
|
||||
|
|
|
@ -18,7 +18,7 @@ class CompactBlockProcessorEventHandler {
|
|||
case minedTransaction
|
||||
case handleReorg
|
||||
case progressUpdated
|
||||
case progressPartialUpdate
|
||||
case syncProgress
|
||||
case storedUTXOs
|
||||
case startedEnhancing
|
||||
case startedFetching
|
||||
|
@ -64,8 +64,8 @@ extension CompactBlockProcessor.Event {
|
|||
return .stopped
|
||||
case .minedTransaction:
|
||||
return .minedTransaction
|
||||
case .progressPartialUpdate:
|
||||
return .progressPartialUpdate
|
||||
case .syncProgress:
|
||||
return .syncProgress
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue