Skip to content

Commit

Permalink
[#1167] Step 3 - Download chain tip metadata from lightwalletd
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
LukasKorba committed Aug 1, 2023
1 parent 3fd68f8 commit 0db27c4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions Sources/ZcashLightClientKit/Block/Actions/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum CBPState: CaseIterable {
case migrateLegacyCacheDB
case validateServer
case updateSubtreeRoots
case updateChainTip
case computeSyncControlData
case download
case scan
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Sources/ZcashLightClientKit/Block/CompactBlockProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -589,6 +591,8 @@ extension CompactBlockProcessor {
break
case .updateSubtreeRoots:
break
case .updateChainTip:
break
case .computeSyncControlData:
break
case .download:
Expand Down

0 comments on commit 0db27c4

Please sign in to comment.