Merge branch 'master' of github.com:zcash/ZcashLightClientKit
This commit is contained in:
commit
75cbd3a9cf
|
@ -11,7 +11,7 @@ import Foundation
|
|||
class CompactBlockDownloadOperation: ZcashOperation {
|
||||
|
||||
override var isConcurrent: Bool { false }
|
||||
|
||||
|
||||
override var isAsynchronous: Bool { false }
|
||||
|
||||
private var downloader: CompactBlockDownloading
|
||||
|
|
|
@ -335,7 +335,11 @@ public class CompactBlockProcessor {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
processes new blocks on the given range based on the configuration set for this instance
|
||||
the way operations are queued is implemented based on the following good practice https://forums.developer.apple.com/thread/25761
|
||||
|
||||
*/
|
||||
func processNewBlocks(range: CompactBlockRange) {
|
||||
|
||||
self.backoffTimer?.invalidate()
|
||||
|
@ -346,9 +350,7 @@ public class CompactBlockProcessor {
|
|||
let downloadBlockOperation = CompactBlockDownloadOperation(downloader: self.downloader, range: range)
|
||||
|
||||
downloadBlockOperation.startedHandler = { [weak self] in
|
||||
|
||||
self?.state = .downloading
|
||||
|
||||
}
|
||||
|
||||
downloadBlockOperation.errorHandler = { [weak self] (error) in
|
||||
|
@ -358,9 +360,12 @@ public class CompactBlockProcessor {
|
|||
self.fail(error)
|
||||
|
||||
}
|
||||
|
||||
let validateChainOperation = CompactBlockValidationOperation(rustWelding: self.rustBackend, cacheDb: cfg.cacheDb, dataDb: cfg.dataDb)
|
||||
|
||||
let downloadValidateAdapterOperation = BlockOperation {
|
||||
validateChainOperation.error = downloadBlockOperation.error
|
||||
}
|
||||
|
||||
validateChainOperation.completionHandler = { (finished, cancelled) in
|
||||
guard !cancelled else {
|
||||
LoggerProxy.debug("Warning: operation cancelled")
|
||||
|
@ -396,6 +401,9 @@ public class CompactBlockProcessor {
|
|||
|
||||
let scanBlocksOperation = CompactBlockScanningOperation(rustWelding: self.rustBackend, cacheDb: cfg.cacheDb, dataDb: cfg.dataDb)
|
||||
|
||||
let validateScanningAdapterOperation = BlockOperation {
|
||||
scanBlocksOperation.error = validateChainOperation.error
|
||||
}
|
||||
scanBlocksOperation.startedHandler = { [weak self] in
|
||||
self?.state = .scanning
|
||||
}
|
||||
|
@ -417,9 +425,15 @@ public class CompactBlockProcessor {
|
|||
|
||||
}
|
||||
|
||||
scanBlocksOperation.addDependency(downloadBlockOperation)
|
||||
scanBlocksOperation.addDependency(validateChainOperation)
|
||||
queue.addOperations([downloadBlockOperation, validateChainOperation, scanBlocksOperation], waitUntilFinished: false)
|
||||
downloadValidateAdapterOperation.addDependency(downloadBlockOperation)
|
||||
validateChainOperation.addDependency(downloadValidateAdapterOperation)
|
||||
scanBlocksOperation.addDependency(validateScanningAdapterOperation)
|
||||
|
||||
queue.addOperations([downloadBlockOperation,
|
||||
downloadValidateAdapterOperation,
|
||||
validateChainOperation,
|
||||
validateScanningAdapterOperation,
|
||||
scanBlocksOperation], waitUntilFinished: false)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ class CompactBlockValidationOperation: ZcashOperation {
|
|||
let error = CompactBlockValidationError.validationFailed(height: BlockHeight(result))
|
||||
self.error = error
|
||||
LoggerProxy.debug("block scanning failed with error: \(String(describing: self.error))")
|
||||
self.cancel()
|
||||
self.fail()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -29,9 +29,7 @@ class ZcashOperation: Operation {
|
|||
completionBlock = { [weak self] in
|
||||
guard let self = self, let handler = self.completionHandler else { return }
|
||||
|
||||
// self.handlerDispatchQueue.async {
|
||||
handler(self.isFinished, self.isCancelled)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +45,7 @@ class ZcashOperation: Operation {
|
|||
}
|
||||
|
||||
func shouldCancel() -> Bool {
|
||||
isCancelled || dependencyCancelled()
|
||||
self.error != nil || isCancelled || dependencyCancelled()
|
||||
}
|
||||
|
||||
func dependencyCancelled() -> Bool {
|
||||
|
|
|
@ -115,9 +115,10 @@ class CompactBlockReorgTests: XCTestCase {
|
|||
downloadStartedExpect,
|
||||
startedValidatingNotificationExpectation,
|
||||
startedScanningNotificationExpectation,
|
||||
|
||||
reorgNotificationExpectation,
|
||||
idleNotificationExpectation,
|
||||
], timeout: 10,enforceOrder: true)
|
||||
], timeout: 3000,enforceOrder: true)
|
||||
}
|
||||
|
||||
private func expectedBatches(currentHeight: BlockHeight, targetHeight: BlockHeight, batchSize: Int) -> Int {
|
||||
|
|
Loading…
Reference in New Issue