Comments addressed

- all comments from the review (round 1) resolved
This commit is contained in:
Lukas Korba 2023-09-13 09:24:26 +02:00
parent 2ac984a0dd
commit 4b45c15a96
25 changed files with 44 additions and 127 deletions

View File

@ -49,9 +49,9 @@ extension DownloadAction: Action {
let potentialDownloadLimit = batchRange.upperBound + (2 * config.batchSize)
let downloadLimit = await context.syncControlData.latestBlockHeight >= potentialDownloadLimit ? potentialDownloadLimit : batchRangeEnd
logger.debug("Starting download with range: \(batchRange.lowerBound)...\(batchRange.upperBound)")
logger.debug("Starting download with range: \(batchRangeStart)...\(batchRangeEnd)")
await downloader.update(latestDownloadedBlockHeight: batchRange.lowerBound, force: true) // SbS
await downloader.update(latestDownloadedBlockHeight: batchRangeStart, force: true)
try await downloader.setSyncRange(lastScannedHeight...latestBlockHeight, batchSize: config.batchSize)
await downloader.setDownloadLimit(downloadLimit)
await downloader.startDownload(maxBlockBufferSize: config.downloadBufferSize)

View File

@ -27,24 +27,24 @@ extension ProcessSuggestedScanRangesAction: Action {
let scanRanges = try await rustBackend.suggestScanRanges()
if let firstRange = scanRanges.first {
let lowerBound = firstRange.range.lowerBound - 1
let upperBound = firstRange.range.upperBound - 1
let rangeStartExclusive = firstRange.range.lowerBound - 1
let rangeEndInclusive = firstRange.range.upperBound - 1
let syncControlData = SyncControlData(
latestBlockHeight: upperBound,
latestScannedHeight: lowerBound,
firstUnenhancedHeight: lowerBound + 1
latestBlockHeight: rangeEndInclusive,
latestScannedHeight: rangeStartExclusive,
firstUnenhancedHeight: rangeStartExclusive + 1
)
logger.debug("""
Init numbers:
latestBlockHeight [BC]: \(upperBound)
latestScannedHeight [DB]: \(lowerBound)
firstUnenhancedHeight [DB]: \(lowerBound + 1)
latestBlockHeight [BC]: \(rangeEndInclusive)
latestScannedHeight [DB]: \(rangeStartExclusive)
firstUnenhancedHeight [DB]: \(rangeStartExclusive + 1)
""")
await context.update(lastScannedHeight: lowerBound)
await context.update(lastDownloadedHeight: lowerBound)
await context.update(lastScannedHeight: rangeStartExclusive)
await context.update(lastDownloadedHeight: rangeStartExclusive)
await context.update(syncControlData: syncControlData)
// the total progress range is computed only for the first time
@ -65,7 +65,7 @@ extension ProcessSuggestedScanRangesAction: Action {
// If there is a range of blocks that needs to be verified, it will always
// be returned as the first element of the vector of suggested ranges.
if firstRange.priority == .verify {
await context.update(requestedRewindHeight: lowerBound + 1)
await context.update(requestedRewindHeight: rangeStartExclusive + 1)
await context.update(state: .rewind)
} else {
await context.update(state: .download)

View File

@ -27,7 +27,6 @@ extension UpdateSubtreeRootsAction: Action {
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext {
var request = GetSubtreeRootsArg()
request.shieldedProtocol = .sapling
request.maxEntries = await configProvider.config.network.networkType == .testnet ? 65536 : 0
logger.info("Attempt to get subtree roots, this may fail because lightwalletd may not support Spend before Sync.")
let stream = service.getSubtreeRoots(request)

View File

@ -568,21 +568,10 @@ extension CompactBlockProcessor {
await ifTaskIsNotCanceledClearCompactBlockCache()
}
if case let ZcashError.rustValidateCombinedChainInvalidChain(height) = error {
logger.error("Sync failed because of validation error: \(error)")
do {
try await validationFailed(at: BlockHeight(height))
// Start sync all over again
return true
} catch {
await failure(error)
return false
}
} else {
logger.error("Sync failed with error: \(error)")
await failure(error)
return false
}
logger.error("Sync failed with error: \(error)")
await failure(error)
return false
}
// swiftlint:disable:next cyclomatic_complexity
@ -665,25 +654,6 @@ extension CompactBlockProcessor {
}
}
private func validationFailed(at height: BlockHeight) async throws {
// rewind
let rewindHeight = determineLowerBound(
errorHeight: height,
consecutiveErrors: consecutiveChainValidationErrors,
walletBirthday: config.walletBirthday
)
consecutiveChainValidationErrors += 1
try await rustBackend.rewindToHeight(height: Int32(rewindHeight))
try await blockDownloaderService.rewind(to: rewindHeight)
try await rewindDownloadBlockAction(to: rewindHeight)
await send(event: .handledReorg(height, rewindHeight))
}
private func failure(_ error: Error) async {
await context.update(state: .failed)

View File

@ -199,9 +199,8 @@ actor BlockDownloaderImpl {
var counter = 0
var lastDownloadedBlockHeight = -1
let pushMetrics: (BlockHeight, Date, Date) -> Void = { [metrics] lastDownloadedBlockHeight, startTime, finishTime in
let pushMetrics: (BlockHeight, Date, Date) -> Void = { [metrics] _, startTime, finishTime in
metrics.pushProgressReport(
progress: 0,
start: startTime,
end: finishTime,
batchSize: maxBlockBufferSize,

View File

@ -135,7 +135,6 @@ extension BlockEnhancerImpl: BlockEnhancer {
}
metrics.pushProgressReport(
progress: 0,
start: startTime,
end: Date(),
batchSize: range.count,

View File

@ -86,7 +86,6 @@ extension UTXOFetcherImpl: UTXOFetcher {
}
metrics.pushProgressReport(
progress: 0,
start: startTime,
end: Date(),
batchSize: 1,

View File

@ -64,6 +64,8 @@ extension BlockScannerImpl: BlockScanner {
let scanFinishTime = Date()
// TODO: [#1259] potential bug when rustBackend.scanBlocks scan less blocks than batchSize,
// https://github.com/zcash/ZcashLightClientKit/issues/1259
lastScannedHeight = startHeight + Int(batchSize) - 1
scannedNewBlocks = previousScannedHeight != lastScannedHeight
@ -71,7 +73,6 @@ extension BlockScannerImpl: BlockScanner {
try await didScan(lastScannedHeight, batchSize)
metrics.pushProgressReport(
progress: 0,
start: scanStartTime,
end: scanFinishTime,
batchSize: Int(batchSize),

View File

@ -223,10 +223,6 @@ public enum ZcashError: Equatable, Error {
/// - `rustError` contains error generated by the rust layer.
/// ZRUST0030
case rustValidateCombinedChainValidationFailed(_ rustError: String)
/// Error from rust layer which means that combined chain isn't valid.
/// - `upperBound` is the height of the highest invalid block (on the assumption that the highest block in the cache database is correct).
/// ZRUST0031
case rustValidateCombinedChainInvalidChain(_ upperBound: Int32)
/// Error from rust layer when calling ZcashRustBackend.rewindToHeight
/// - `rustError` contains error generated by the rust layer.
/// ZRUST0032
@ -645,7 +641,6 @@ public enum ZcashError: Equatable, Error {
case .rustListTransparentReceiversInvalidAddress: return "Transparent receiver generated by rust layer is invalid when calling ZcashRustBackend.listTransparentReceivers"
case .rustPutUnspentTransparentOutput: return "Error from rust layer when calling ZcashRustBackend.putUnspentTransparentOutput"
case .rustValidateCombinedChainValidationFailed: return "Error unrelated to chain validity from rust layer when calling ZcashRustBackend.validateCombinedChain"
case .rustValidateCombinedChainInvalidChain: return "Error from rust layer which means that combined chain isn't valid."
case .rustRewindToHeight: return "Error from rust layer when calling ZcashRustBackend.rewindToHeight"
case .rustRewindCacheToHeight: return "Error from rust layer when calling ZcashRustBackend.rewindCacheToHeight"
case .rustScanBlocks: return "Error from rust layer when calling ZcashRustBackend.scanBlocks"
@ -817,7 +812,6 @@ public enum ZcashError: Equatable, Error {
case .rustListTransparentReceiversInvalidAddress: return .rustListTransparentReceiversInvalidAddress
case .rustPutUnspentTransparentOutput: return .rustPutUnspentTransparentOutput
case .rustValidateCombinedChainValidationFailed: return .rustValidateCombinedChainValidationFailed
case .rustValidateCombinedChainInvalidChain: return .rustValidateCombinedChainInvalidChain
case .rustRewindToHeight: return .rustRewindToHeight
case .rustRewindCacheToHeight: return .rustRewindCacheToHeight
case .rustScanBlocks: return .rustScanBlocks

View File

@ -125,8 +125,6 @@ public enum ZcashErrorCode: String {
case rustPutUnspentTransparentOutput = "ZRUST0029"
/// Error unrelated to chain validity from rust layer when calling ZcashRustBackend.validateCombinedChain
case rustValidateCombinedChainValidationFailed = "ZRUST0030"
/// Error from rust layer which means that combined chain isn't valid.
case rustValidateCombinedChainInvalidChain = "ZRUST0031"
/// Error from rust layer when calling ZcashRustBackend.rewindToHeight
case rustRewindToHeight = "ZRUST0032"
/// Error from rust layer when calling ZcashRustBackend.rewindCacheToHeight

View File

@ -254,10 +254,6 @@ enum ZcashErrorDefinition {
/// - `rustError` contains error generated by the rust layer.
// sourcery: code="ZRUST0030"
case rustValidateCombinedChainValidationFailed(_ rustError: String)
/// Error from rust layer which means that combined chain isn't valid.
/// - `upperBound` is the height of the highest invalid block (on the assumption that the highest block in the cache database is correct).
// sourcery: code="ZRUST0031"
case rustValidateCombinedChainInvalidChain(_ upperBound: Int32)
/// Error from rust layer when calling ZcashRustBackend.rewindToHeight
/// - `rustError` contains error generated by the rust layer.
// sourcery: code="ZRUST0032"

View File

@ -430,7 +430,7 @@ public class Initializer {
_ = try await rustBackend.createAccount(
seed: seed,
treeState: try checkpoint.treeState().serializedData(partial: false).bytes,
treeState: checkpoint.treeState(),
recoverUntil: chainTip
)
}

View File

@ -32,7 +32,6 @@ 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 progress: Float
public let batchSize: Int
public let startTime: TimeInterval
public let endTime: TimeInterval
@ -41,7 +40,6 @@ public class SDKMetrics {
public enum Operation {
case downloadBlocks
case validateBlocks
case scanBlocks
case enhancement
case fetchUTXOs
@ -73,7 +71,6 @@ 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: Float,
start: Date,
end: Date,
batchSize: Int,
@ -82,7 +79,6 @@ public class SDKMetrics {
guard isEnabled else { return }
let blockMetricReport = BlockMetricReport(
progress: 0,
batchSize: batchSize,
startTime: start.timeIntervalSinceReferenceDate,
endTime: end.timeIntervalSinceReferenceDate
@ -154,7 +150,6 @@ public class SDKMetrics {
extension SDKMetrics {
public struct CumulativeSummary: Equatable {
public let downloadedBlocksReport: ReportSummary?
public let validatedBlocksReport: ReportSummary?
public let scannedBlocksReport: ReportSummary?
public let enhancementReport: ReportSummary?
public let fetchUTXOsReport: ReportSummary?
@ -173,7 +168,6 @@ extension SDKMetrics {
/// independently. A `ReportSummary` is the result per `operation`, providing min, max and avg times.
public func cumulativeSummary() -> CumulativeSummary {
let downloadReport = summaryFor(reports: reports[.downloadBlocks])
let validateReport = summaryFor(reports: reports[.validateBlocks])
let scanReport = summaryFor(reports: reports[.scanBlocks])
let enhancementReport = summaryFor(reports: reports[.enhancement])
let fetchUTXOsReport = summaryFor(reports: reports[.fetchUTXOs])
@ -185,7 +179,6 @@ extension SDKMetrics {
return CumulativeSummary(
downloadedBlocksReport: downloadReport,
validatedBlocksReport: validateReport,
scannedBlocksReport: scanReport,
enhancementReport: enhancementReport,
fetchUTXOsReport: fetchUTXOsReport,
@ -213,7 +206,6 @@ extension SDKMetrics {
cumulativeSummaries.forEach { summary in
finalSummary = CumulativeSummary(
downloadedBlocksReport: accumulate(left: finalSummary?.downloadedBlocksReport, right: summary.downloadedBlocksReport),
validatedBlocksReport: accumulate(left: finalSummary?.validatedBlocksReport, right: summary.validatedBlocksReport),
scannedBlocksReport: accumulate(left: finalSummary?.scannedBlocksReport, right: summary.scannedBlocksReport),
enhancementReport: accumulate(left: finalSummary?.enhancementReport, right: summary.enhancementReport),
fetchUTXOsReport: accumulate(left: finalSummary?.fetchUTXOsReport, right: summary.fetchUTXOsReport),

View File

@ -9,7 +9,7 @@ import Foundation
struct ScanRange {
enum Priority: UInt8 {
case unknown = 0
case ignored = 0
case scanned = 10
case historic = 20
case openAdjacent = 30
@ -18,7 +18,7 @@ struct ScanRange {
case verify = 60
init(_ value: UInt8) {
self = Priority(rawValue: value) ?? .unknown
self = Priority(rawValue: value) ?? .ignored
}
}

View File

@ -11,10 +11,6 @@ protocol TransactionRepository {
func closeDBConnection()
func countAll() async throws -> Int
func countUnmined() async throws -> Int
// func blockForHeight(_ height: BlockHeight) async throws -> Block?
// func lastScannedHeight() async throws -> BlockHeight
// func lastScannedBlock() async throws -> Block?
// func firstUnenhancedHeight() throws -> BlockHeight?
func isInitialized() async throws -> Bool
func find(id: Int) async throws -> ZcashTransaction.Overview
func find(rawID: Data) async throws -> ZcashTransaction.Overview

View File

@ -47,20 +47,22 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
}
}
func createAccount(seed: [UInt8], treeState: [UInt8], recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
func createAccount(seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
var rUntil: Int64 = -1
if let recoverUntil {
rUntil = Int64(recoverUntil)
}
let treeStateBytes = try treeState.serializedData(partial: false).bytes
let ffiBinaryKeyPtr = zcashlc_create_account(
dbData.0,
dbData.1,
seed,
UInt(seed.count),
treeState,
UInt(treeState.count),
treeStateBytes,
UInt(treeStateBytes.count),
rUntil,
networkType.networkId
)

View File

@ -35,11 +35,11 @@ protocol ZcashRustBackendWelding {
/// have been received by the currently-available account (in order to enable
/// automated account recovery).
/// - parameter seed: byte array of the zip32 seed
/// - parameter treeState: byte array containing the TreeState Protobuf object for the height prior to the account birthday
/// - parameter treeState: The TreeState Protobuf object for the height prior to the account birthday
/// - parameter recoverUntil: the fully-scanned height up to which the account will be treated as "being recovered"
/// - Returns: The `UnifiedSpendingKey` structs for the number of accounts created
/// - Throws: `rustCreateAccount`.
func createAccount(seed: [UInt8], treeState: [UInt8], recoverUntil: UInt32?) async throws -> UnifiedSpendingKey
func createAccount(seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?) async throws -> UnifiedSpendingKey
/// Creates a transaction to the given address from the given account
/// - Parameter usk: `UnifiedSpendingKey` for the account that controls the funds to be spent.

View File

@ -122,7 +122,9 @@ public protocol Synchronizer: AnyObject {
/// - Parameters:
/// - seed: ZIP-32 Seed bytes for the wallet that will be initialized
/// - walletBirthday: Birthday of wallet.
/// - walletMode: Set `.newWallet` when preparing synchronizer for a brand new generated wallet, `.restoreWallet` when wallet is about to be restored from a seed and `.existingWallet` for all other scenarios.
/// - for: [walletMode] Set `.newWallet` when preparing synchronizer for a brand new generated wallet,
/// `.restoreWallet` when wallet is about to be restored from a seed
/// and `.existingWallet` for all other scenarios.
/// - Throws:
/// - `aliasAlreadyInUse` if the Alias used to create this instance is already used by other instance.
/// - `cantUpdateURLWithAlias` if the updating of paths in `Initilizer` according to alias fails. When this happens it means that

View File

@ -80,7 +80,7 @@ class TransactionEnhancementTests: ZcashTestCase {
do {
_ = try await rustBackend.createAccount(
seed: Environment.seedBytes,
treeState: birthday.treeState().serializedData(partial: false).bytes,
treeState: birthday.treeState(),
recoverUntil: nil
)
} catch {

View File

@ -87,12 +87,7 @@ class CompactBlockReorgTests: ZcashTestCase {
return
}
rustBackendMockHelper = await RustBackendMockHelper(
rustBackend: rustBackend,
mockValidateCombinedChainFailAfterAttempts: 3,
mockValidateCombinedChainKeepFailing: false,
mockValidateCombinedChainFailureError: .rustValidateCombinedChainInvalidChain(Int32(network.constants.saplingActivationHeight + 320))
)
rustBackendMockHelper = await RustBackendMockHelper(rustBackend: rustBackend)
Dependencies.setup(
in: mockContainer,

View File

@ -57,7 +57,7 @@ class ZcashRustBackendTests: XCTestCase {
do {
_ = try await rustBackend.createAccount(
seed: Array(seed.utf8),
treeState: treeState.serializedData(partial: false).bytes,
treeState: treeState,
recoverUntil: nil
)
XCTFail("createAccount should fail here.")
@ -109,7 +109,7 @@ class ZcashRustBackendTests: XCTestCase {
let treeState = Checkpoint.birthday(with: 1234567, network: ZcashMainnet()).treeState()
let usk = try await rustBackend.createAccount(seed: seed, treeState: treeState.serializedData(partial: false).bytes, recoverUntil: nil)
let usk = try await rustBackend.createAccount(seed: seed, treeState: treeState, recoverUntil: nil)
XCTAssertEqual(usk.account, 0)
let expectedReceivers = try testVector.map {

View File

@ -14,7 +14,6 @@ final class SDKMetricsTests: XCTestCase {
metrics.enableMetrics()
metrics.pushProgressReport(
progress: 0,
start: Date(timeIntervalSinceReferenceDate: 0.0),
end: Date(timeIntervalSinceReferenceDate: 1.0),
batchSize: 10,
@ -55,7 +54,6 @@ final class SDKMetricsTests: XCTestCase {
let summary = SDKMetrics.CumulativeSummary(
downloadedBlocksReport: SDKMetrics.ReportSummary(minTime: 1.0, maxTime: 1.0, avgTime: 1.0),
validatedBlocksReport: nil,
scannedBlocksReport: nil,
enhancementReport: nil,
fetchUTXOsReport: nil,
@ -84,7 +82,6 @@ final class SDKMetricsTests: XCTestCase {
let summary = SDKMetrics.CumulativeSummary(
downloadedBlocksReport: SDKMetrics.ReportSummary(minTime: 1.0, maxTime: 1.0, avgTime: 1.0),
validatedBlocksReport: nil,
scannedBlocksReport: nil,
enhancementReport: nil,
fetchUTXOsReport: nil,
@ -105,7 +102,6 @@ final class SDKMetricsTests: XCTestCase {
let summary = SDKMetrics.CumulativeSummary(
downloadedBlocksReport: SDKMetrics.ReportSummary(minTime: 1.0, maxTime: 6.0, avgTime: 3.5),
validatedBlocksReport: nil,
scannedBlocksReport: nil,
enhancementReport: nil,
fetchUTXOsReport: nil,
@ -129,7 +125,6 @@ final class SDKMetricsTests: XCTestCase {
let summary = SDKMetrics.CumulativeSummary(
downloadedBlocksReport: SDKMetrics.ReportSummary(minTime: 1.0, maxTime: 6.0, avgTime: 3.5),
validatedBlocksReport: nil,
scannedBlocksReport: nil,
enhancementReport: nil,
fetchUTXOsReport: nil,
@ -144,14 +139,12 @@ final class SDKMetricsTests: XCTestCase {
extension SDKMetrics.BlockMetricReport {
static let placeholderA = Self(
progress: 0,
batchSize: 10,
startTime: Date(timeIntervalSinceReferenceDate: 0.0).timeIntervalSinceReferenceDate,
endTime: Date(timeIntervalSinceReferenceDate: 1.0).timeIntervalSinceReferenceDate
)
static let placeholderB = Self(
progress: 0,
batchSize: 10,
startTime: Date(timeIntervalSinceReferenceDate: 0.0).timeIntervalSinceReferenceDate,
endTime: Date(timeIntervalSinceReferenceDate: 6.0).timeIntervalSinceReferenceDate

View File

@ -99,7 +99,6 @@ class SynchronizerTests: ZcashTestCase {
if let cumulativeSummary = synchronizer?.metrics.summarizedCumulativeReports() {
let downloadedBlocksReport = cumulativeSummary.downloadedBlocksReport ?? .zero
let validatedBlocksReport = cumulativeSummary.validatedBlocksReport ?? .zero
let scannedBlocksReport = cumulativeSummary.scannedBlocksReport ?? .zero
let enhancementReport = cumulativeSummary.enhancementReport ?? .zero
let fetchUTXOsReport = cumulativeSummary.fetchUTXOsReport ?? .zero
@ -109,7 +108,6 @@ class SynchronizerTests: ZcashTestCase {
LoggerProxy.debug("""
testHundredBlocksSync() SUMMARY min max avg REPORT:
downloadedBlocksTimes: min: \(downloadedBlocksReport.minTime) max: \(downloadedBlocksReport.maxTime) avg: \(downloadedBlockAVGTime)
validatedBlocksTimes: min: \(validatedBlocksReport.minTime) max: \(validatedBlocksReport.maxTime) avg: \(validatedBlocksReport.avgTime)
scannedBlocksTimes: min: \(scannedBlocksReport.minTime) max: \(scannedBlocksReport.maxTime) avg: \(scannedBlocksReport.avgTime)
enhancementTimes: min: \(enhancementReport.minTime) max: \(enhancementReport.maxTime) avg: \(enhancementReport.avgTime)
fetchUTXOsTimes: min: \(fetchUTXOsReport.minTime) max: \(fetchUTXOsReport.maxTime) avg: \(fetchUTXOsReport.avgTime)

View File

@ -2094,17 +2094,17 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
var createAccountSeedTreeStateRecoverUntilCalled: Bool {
return createAccountSeedTreeStateRecoverUntilCallsCount > 0
}
var createAccountSeedTreeStateRecoverUntilReceivedArguments: (seed: [UInt8], treeState: [UInt8], recoverUntil: UInt32?)?
var createAccountSeedTreeStateRecoverUntilReceivedArguments: (seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?)?
var createAccountSeedTreeStateRecoverUntilReturnValue: UnifiedSpendingKey!
func setCreateAccountSeedTreeStateRecoverUntilReturnValue(_ param: UnifiedSpendingKey) async {
createAccountSeedTreeStateRecoverUntilReturnValue = param
}
var createAccountSeedTreeStateRecoverUntilClosure: (([UInt8], [UInt8], UInt32?) async throws -> UnifiedSpendingKey)?
func setCreateAccountSeedTreeStateRecoverUntilClosure(_ param: (([UInt8], [UInt8], UInt32?) async throws -> UnifiedSpendingKey)?) async {
var createAccountSeedTreeStateRecoverUntilClosure: (([UInt8], TreeState, UInt32?) async throws -> UnifiedSpendingKey)?
func setCreateAccountSeedTreeStateRecoverUntilClosure(_ param: (([UInt8], TreeState, UInt32?) async throws -> UnifiedSpendingKey)?) async {
createAccountSeedTreeStateRecoverUntilClosure = param
}
func createAccount(seed: [UInt8], treeState: [UInt8], recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
func createAccount(seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
if let error = createAccountSeedTreeStateRecoverUntilThrowableError {
throw error
}

View File

@ -53,17 +53,11 @@ extension LightWalletServiceMockResponse {
class RustBackendMockHelper {
let rustBackendMock: ZcashRustBackendWeldingMock
var mockValidateCombinedChainFailAfterAttempts: Int?
init(
rustBackend: ZcashRustBackendWelding,
consensusBranchID: Int32? = nil,
mockValidateCombinedChainSuccessRate: Float? = nil,
mockValidateCombinedChainFailAfterAttempts: Int? = nil,
mockValidateCombinedChainKeepFailing: Bool = false,
mockValidateCombinedChainFailureError: ZcashError = .rustValidateCombinedChainValidationFailed("mock fail")
consensusBranchID: Int32? = nil
) async {
self.mockValidateCombinedChainFailAfterAttempts = mockValidateCombinedChainFailAfterAttempts
self.rustBackendMock = ZcashRustBackendWeldingMock(
consensusBranchIdForHeightClosure: { height in
if let consensusBranchID {
@ -73,20 +67,10 @@ class RustBackendMockHelper {
}
}
)
await setupDefaultMock(
rustBackend: rustBackend,
mockValidateCombinedChainSuccessRate: mockValidateCombinedChainSuccessRate,
mockValidateCombinedChainKeepFailing: mockValidateCombinedChainKeepFailing,
mockValidateCombinedChainFailureError: mockValidateCombinedChainFailureError
)
await setupDefaultMock(rustBackend: rustBackend)
}
private func setupDefaultMock(
rustBackend: ZcashRustBackendWelding,
mockValidateCombinedChainSuccessRate: Float? = nil,
mockValidateCombinedChainKeepFailing: Bool = false,
mockValidateCombinedChainFailureError: ZcashError
) async {
private func setupDefaultMock(rustBackend: ZcashRustBackendWelding) async {
await rustBackendMock.setLatestCachedBlockHeightReturnValue(.empty())
await rustBackendMock.setInitBlockMetadataDbClosure() { }
await rustBackendMock.setWriteBlocksMetadataBlocksClosure() { _ in }