[#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
fb4cdd3dcc
commit
4a78b4bd16
|
@ -35,6 +35,7 @@ enum CBPState: CaseIterable {
|
||||||
case migrateLegacyCacheDB
|
case migrateLegacyCacheDB
|
||||||
case validateServer
|
case validateServer
|
||||||
case updateSubtreeRoots
|
case updateSubtreeRoots
|
||||||
|
case updateChainTip
|
||||||
case computeSyncControlData
|
case computeSyncControlData
|
||||||
case download
|
case download
|
||||||
case scan
|
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 {
|
do {
|
||||||
try await rustBackend.putSaplingSubtreeRoots(startIndex: UInt64(request.startIndex), roots: roots)
|
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
|
await context.update(state: .updateChainTip)
|
||||||
// https://github.com/zcash/ZcashLightClientKit/issues/1167
|
|
||||||
await context.update(state: .computeSyncControlData)
|
|
||||||
} catch {
|
} catch {
|
||||||
logger.debug("putSaplingSubtreeRoots failed with error \(error.localizedDescription)")
|
logger.debug("putSaplingSubtreeRoots failed with error \(error.localizedDescription)")
|
||||||
throw ZcashError.compactBlockProcessorPutSaplingSubtreeRoots(error)
|
throw ZcashError.compactBlockProcessorPutSaplingSubtreeRoots(error)
|
||||||
|
|
|
@ -216,6 +216,8 @@ actor CompactBlockProcessor {
|
||||||
action = ValidateServerAction(container: container, configProvider: configProvider)
|
action = ValidateServerAction(container: container, configProvider: configProvider)
|
||||||
case .updateSubtreeRoots:
|
case .updateSubtreeRoots:
|
||||||
action = UpdateSubtreeRootsAction(container: container)
|
action = UpdateSubtreeRootsAction(container: container)
|
||||||
|
case .updateChainTip:
|
||||||
|
action = UpdateChainTipAction(container: container)
|
||||||
case .computeSyncControlData:
|
case .computeSyncControlData:
|
||||||
action = ComputeSyncControlDataAction(container: container, configProvider: configProvider)
|
action = ComputeSyncControlDataAction(container: container, configProvider: configProvider)
|
||||||
case .download:
|
case .download:
|
||||||
|
@ -589,6 +591,8 @@ extension CompactBlockProcessor {
|
||||||
break
|
break
|
||||||
case .updateSubtreeRoots:
|
case .updateSubtreeRoots:
|
||||||
break
|
break
|
||||||
|
case .updateChainTip:
|
||||||
|
break
|
||||||
case .computeSyncControlData:
|
case .computeSyncControlData:
|
||||||
break
|
break
|
||||||
case .download:
|
case .download:
|
||||||
|
|
Loading…
Reference in New Issue