[#614] make prepare(with:) and get{pool_type}Address() synchronous

Closes #614

fixes travis ci

Removed `setStartHeight` function

I’m going back in time and this setHeight is not something we are using anywhere else than in the prepare function. This comes from the times we had `initialize(seed:birthday) and we don’t have that anymore

See diff 246d10edaa (diff-414771774e10bc81260094ffcdc7b310a3be48758b2abd2bfae831c83912c02c)

The `func setStartHeight(_ startHeight: BlockHeight)` function assumes that
there might not be a wallet birthday set up or that it might be changed
in-flight which are things that are no longer happening.

remove test warning

Fix test compiler error
This commit is contained in:
Francisco Gindre 2022-11-09 18:01:43 -03:00
parent 6407820f77
commit b9e00055e9
8 changed files with 36 additions and 29 deletions

View File

@ -3,7 +3,7 @@ os: osx
osx_image: xcode14
xcode_project: ./Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj
xcode_scheme: ZcashLightClientSample
xcode_destination: platform=iOS Simulator,OS=15.5,name=iPhone 8
xcode_destination: platform=iOS Simulator,OS=16.0,name=iPhone 14
addons:
homebrew:
packages:

View File

@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi",
"state" : {
"revision" : "70bf6ae6538943f2b8453f424e607a05f4dc7be6",
"version" : "0.1.0-beta.2"
"revision" : "7febbfd74a7d963ec206e01f8ef6090bb8cee523",
"version" : "0.1.0-beta.3"
}
}
],

View File

@ -560,21 +560,6 @@ public actor CompactBlockProcessor {
self.lowerBoundHeight = try? downloader.lastDownloadedBlockHeight()
return BlockHeight(rewindHeight)
}
/**
changes the wallet birthday in configuration. Use this method when wallet birthday is not available and the processor can't be lazy initialized.
- Note: this does not rewind your chain state
- Parameter startHeight: the wallet birthday for this compact block processor
- Throws CompactBlockProcessorError.invalidConfiguration if block height is invalid or if processor is already started
*/
func setStartHeight(_ startHeight: BlockHeight) throws {
guard self.state == .stopped, startHeight >= config.network.constants.saplingActivationHeight else {
throw CompactBlockProcessorError.invalidConfiguration
}
var config = self.config
config.walletBirthday = startHeight
self.config = config
}
func validateServer() async {
do {

View File

@ -8,7 +8,7 @@
import Foundation
extension CompactBlockProcessor {
enum NextState {
enum NextState: Equatable {
case finishProcessing(height: BlockHeight)
case processNewBlocks(range: CompactBlockRange, latestBlockHeight: BlockHeight)
case wait(latestHeight: BlockHeight, latestDownloadHeight: BlockHeight)

View File

@ -384,3 +384,15 @@ extension InitializerError: LocalizedError {
}
}
}
/// Synchronous helpers that support clients that don't use structured concurrency yet
extension Initializer {
func getCurrentAddress(accountIndex: Int) -> UnifiedAddress? {
try? self.rustBackend.getCurrentAddress(
dbData: self.dataDbURL,
account: Int32(accountIndex),
networkType: self.network.networkType
)
}
}

View File

@ -156,12 +156,11 @@ public class SDKSynchronizer: Synchronizer {
}
}
public func prepare(with seed: [UInt8]?) async throws -> Initializer.InitializationResult {
public func prepare(with seed: [UInt8]?) throws -> Initializer.InitializationResult {
if case .seedRequired = try self.initializer.initialize(with: seed) {
return .seedRequired
}
try await self.blockProcessor.setStartHeight(initializer.walletBirthday)
self.status = .disconnected
return .success
@ -624,7 +623,6 @@ public class SDKSynchronizer: Synchronizer {
await blockProcessor.getTransparentAddress(accountIndex: accountIndex)
}
/// Returns the last stored transparent balance
public func getTransparentBalance(accountIndex: Int) async throws -> WalletBalance {
try await blockProcessor.getTransparentBalance(accountIndex: accountIndex)
@ -838,6 +836,21 @@ extension SDKSynchronizer {
}
}
extension SDKSynchronizer {
public func getUnifiedAddress(accountIndex: Int) -> UnifiedAddress? {
self.initializer.getCurrentAddress(accountIndex: accountIndex)
}
public func getSaplingAddress(accountIndex: Int) -> SaplingAddress? {
self.getUnifiedAddress(accountIndex: accountIndex)?.saplingReceiver()
}
public func getTransparentAddress(accountIndex: Int) -> TransparentAddress? {
self.getUnifiedAddress(accountIndex: accountIndex)?.transparentReceiver()
}
}
import GRPC
extension ConnectionState {
init(_ connectivityState: ConnectivityState) {

View File

@ -113,11 +113,7 @@ class CompactBlockProcessorTests: XCTestCase {
startedScanningNotificationExpectation.subscribe(to: Notification.Name.blockProcessorStartedScanning, object: processor)
idleNotificationExpectation.subscribe(to: Notification.Name.blockProcessorIdle, object: processor)
do {
try await processor.start()
} catch {
XCTFail("shouldn't fail")
}
await processor.start()
}
// FIXME: disabled see https://github.com/zcash/ZcashLightClientKit/issues/590

View File

@ -315,7 +315,8 @@ class BlockBatchValidationTests: XCTestCase {
latestHeight: expectedLatestHeight,
latestDownloadedHeight: expectedStoreLatestHeight,
walletBirthday: walletBirthday
)
),
latestBlockHeight: expectedLatestHeight
)
let storage = try! TestDbBuilder.inMemoryCompactBlockStorage()
let repository = ZcashConsoleFakeStorage(latestBlockHeight: expectedStoreLatestHeight)
@ -368,7 +369,7 @@ class BlockBatchValidationTests: XCTestCase {
XCTAssertTrue(
{
switch nextBatch {
case .processNewBlocks(range: CompactBlockRange(uncheckedBounds: (expectedStoreLatestHeight + 1, expectedLatestHeight))):
case .processNewBlocks(range: CompactBlockRange(uncheckedBounds: (expectedStoreLatestHeight + 1, expectedLatestHeight)), latestBlockHeight: expectedLatestHeight):
return true
default:
return false