[#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:
parent
df7d86f4ff
commit
2a095d270f
|
@ -35,6 +35,7 @@ enum CBPState: CaseIterable {
|
|||
case migrateLegacyCacheDB
|
||||
case validateServer
|
||||
case updateSubtreeRoots
|
||||
case updateChainTip
|
||||
case computeSyncControlData
|
||||
case download
|
||||
case scan
|
||||
|
|
|
@ -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 { }
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue