-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft [#1165] Step 1 - Download note commitment tree data from lightwalletd - code cleanup after draft [#1165] Step 1 - Download note commitment tree data from lightwalletd - UpdateSubtreeRootsAction added, ensuring the roots are downloaded and stored in the DB [#1165] Step 1 - Download note commitment tree data from lightwalletd - added ZcashError for putSaplingSubtreeRoots failure - cleaned up action [#1165] Step 1 - Download note commitment tree data from lightwalletd - demo app config temporarily updated to Nighthawk server [#1165] Step 1 - Download note commitment tree data from lightwalletd - file header updated [#1165] Step 1 - Download note commitment tree data from lightwalletd (#1174) - demo app config cleaned up [#1165] Step 1 - Download note commitment tree data from lightwalletd (#1174) - offline tests fixed
- Loading branch information
1 parent
e4cea0c
commit fda0fed
Showing
17 changed files
with
278 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Sources/ZcashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// UpdateSubtreeRootsAction.swift | ||
// | ||
// | ||
// Created by Lukas Korba on 01.08.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
final class UpdateSubtreeRootsAction { | ||
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 UpdateSubtreeRootsAction: Action { | ||
var removeBlocksCacheWhenFailed: Bool { false } | ||
|
||
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext { | ||
var request = GetSubtreeRootsArg() | ||
request.shieldedProtocol = .sapling | ||
request.maxEntries = 65536 | ||
|
||
logger.info("Attempt to get subtree roots, this may fail because lightwalletd may not support DAG sync.") | ||
let stream = service.getSubtreeRoots(request) | ||
|
||
var roots: [SubtreeRoot] = [] | ||
var err: Error? | ||
|
||
do { | ||
for try await subtreeRoot in stream { | ||
roots.append(subtreeRoot) | ||
} | ||
} catch { | ||
logger.debug("getSubtreeRoots failed with error \(error.localizedDescription)") | ||
err = error | ||
} | ||
|
||
// In case of error, the lightwalletd doesn't support DAG sync -> switching to linear sync. | ||
// Likewise, no subtree roots results in switching to linear sync. | ||
if err != nil || roots.isEmpty { | ||
logger.info("DAG sync is not possible, switching to linear sync.") | ||
await context.update(state: .computeSyncControlData) | ||
} else { | ||
logger.info("Sapling tree has \(roots.count) subtrees") | ||
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) | ||
} catch { | ||
logger.debug("putSaplingSubtreeRoots failed with error \(error.localizedDescription)") | ||
throw ZcashError.compactBlockProcessorPutSaplingSubtreeRoots(error) | ||
} | ||
} | ||
|
||
return context | ||
} | ||
|
||
func stop() async { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.