[#1167] Step 3 - Download chain tip metadata from lightwalletd

- update chain tip action added

[#1167] Step 3 - Download chain tip metadata from lightwalletd

- roots removed from the ActionContext

[#1167] Step 3 - Download chain tip metadata from lightwalletd

- fallback to linear sync until next step is implemented

[#1167] Step 3 - Download chain tip metadata from lightwalletd

- offline tests fixed
This commit is contained in:
Lukas Korba 2023-08-01 13:04:50 +02:00
parent d493e9b84b
commit 01ecb57a1a
4 changed files with 45 additions and 3 deletions

View File

@ -35,6 +35,7 @@ enum CBPState: CaseIterable {
case migrateLegacyCacheDB
case validateServer
case updateSubtreeRoots
case updateChainTip
case computeSyncControlData
case download
case scan

View File

@ -0,0 +1,39 @@
//
// UpdateChainTipAction.swift
//
//
// Created by Lukáš Korba on 01.08.2023.
//
import Foundation
final class UpdateChainTipAction {
let rustBackend: ZcashRustBackendWelding
let service: LightWalletService
let logger: Logger
init(container: DIContainer) {
service = container.resolve(LightWalletService.self)
rustBackend = container.resolve(ZcashRustBackendWelding.self)
logger = container.resolve(Logger.self)
}
}
extension UpdateChainTipAction: Action {
var removeBlocksCacheWhenFailed: Bool { false }
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext {
let latestBlockHeight = try await service.latestBlockHeight()
logger.info("Latest block height is \(latestBlockHeight)")
try await rustBackend.updateChainTip(height: Int32(latestBlockHeight))
// TODO: [#1169] Switching back to linear sync for now before step 5 & 6 are implemented
// https://github.com/zcash/ZcashLightClientKit/issues/1169
await context.update(state: .computeSyncControlData)
return context
}
func stop() async { }
}

View File

@ -52,9 +52,7 @@ extension UpdateSubtreeRootsAction: Action {
do {
try await rustBackend.putSaplingSubtreeRoots(startIndex: UInt64(request.startIndex), roots: roots)
// TODO: [#1167] Switching back to linear sync for now before step 3 & 4 are implemented
// https://github.com/zcash/ZcashLightClientKit/issues/1167
await context.update(state: .computeSyncControlData)
await context.update(state: .updateChainTip)
} catch {
logger.debug("putSaplingSubtreeRoots failed with error \(error.localizedDescription)")
throw ZcashError.compactBlockProcessorPutSaplingSubtreeRoots(error)

View File

@ -216,6 +216,8 @@ actor CompactBlockProcessor {
action = ValidateServerAction(container: container, configProvider: configProvider)
case .updateSubtreeRoots:
action = UpdateSubtreeRootsAction(container: container)
case .updateChainTip:
action = UpdateChainTipAction(container: container)
case .computeSyncControlData:
action = ComputeSyncControlDataAction(container: container, configProvider: configProvider)
case .download:
@ -589,6 +591,8 @@ extension CompactBlockProcessor {
break
case .updateSubtreeRoots:
break
case .updateChainTip:
break
case .computeSyncControlData:
break
case .download: