FIX: wrong wallet birthday on new wallets

This commit is contained in:
Francisco Gindre 2021-04-01 18:08:00 -03:00
parent 593f04b448
commit 8046bed300
3 changed files with 18 additions and 15 deletions

View File

@ -262,11 +262,13 @@ public class CompactBlockProcessor {
- Parameters: - Parameters:
- initializer: an instance that complies to CompactBlockDownloading protocol - initializer: an instance that complies to CompactBlockDownloading protocol
*/ */
public convenience init(initializer: Initializer, walletBirthday: BlockHeight = ZcashSDK.SAPLING_ACTIVATION_HEIGHT) { public convenience init(initializer: Initializer) {
self.init(downloader: initializer.downloader, self.init(downloader: initializer.downloader,
backend: initializer.rustBackend, backend: initializer.rustBackend,
config: Configuration(cacheDb: initializer.cacheDbURL, dataDb: initializer.dataDbURL, walletBirthday: walletBirthday), config: Configuration(cacheDb: initializer.cacheDbURL,
dataDb: initializer.dataDbURL,
walletBirthday: initializer.walletBirthday.height),
repository: initializer.transactionRepository) repository: initializer.transactionRepository)
} }
@ -768,7 +770,7 @@ public class CompactBlockProcessor {
value: Int64(utxo.valueZat), value: Int64(utxo.valueZat),
height: utxo.height) ? refreshed.append(utxo) : skipped.append(utxo) height: utxo.height) ? refreshed.append(utxo) : skipped.append(utxo)
} catch { } catch {
LoggerProxy.error("failed to put utxo - error: \(error)") LoggerProxy.info("failed to put utxo - error: \(error)")
skipped.append(utxo) skipped.append(utxo)
} }
} }

View File

@ -65,7 +65,7 @@ public class Initializer {
private(set) var lightWalletService: LightWalletService private(set) var lightWalletService: LightWalletService
private(set) var transactionRepository: TransactionRepository private(set) var transactionRepository: TransactionRepository
private(set) var downloader: CompactBlockDownloader private(set) var downloader: CompactBlockDownloader
private(set) public var walletBirthday: WalletBirthday? private(set) public var walletBirthday: WalletBirthday
/** /**
Constructs the Initializer Constructs the Initializer
- Parameters: - Parameters:
@ -82,6 +82,7 @@ public class Initializer {
endpoint: LightWalletEndpoint, endpoint: LightWalletEndpoint,
spendParamsURL: URL, spendParamsURL: URL,
outputParamsURL: URL, outputParamsURL: URL,
walletBirthday: BlockHeight = ZcashSDK.SAPLING_ACTIVATION_HEIGHT,
alias: String = "", alias: String = "",
loggerProxy: Logger? = nil) { loggerProxy: Logger? = nil) {
@ -91,7 +92,7 @@ public class Initializer {
let lwdService = LightWalletGRPCService(endpoint: endpoint) let lwdService = LightWalletGRPCService(endpoint: endpoint)
self.init(rustBackend: ZcashRustBackend.self, self.init(rustBackend: ZcashRustBackend.self,
lowerBoundHeight: ZcashSDK.SAPLING_ACTIVATION_HEIGHT, lowerBoundHeight: walletBirthday,
cacheDbURL: cacheDbURL, cacheDbURL: cacheDbURL,
dataDbURL: dataDbURL, dataDbURL: dataDbURL,
pendingDbURL: pendingDbURL, pendingDbURL: pendingDbURL,
@ -101,6 +102,7 @@ public class Initializer {
downloader: CompactBlockDownloader(service: lwdService, storage: storage), downloader: CompactBlockDownloader(service: lwdService, storage: storage),
spendParamsURL: spendParamsURL, spendParamsURL: spendParamsURL,
outputParamsURL: outputParamsURL, outputParamsURL: outputParamsURL,
walletBirthday: walletBirthday,
alias: alias, alias: alias,
loggerProxy: loggerProxy loggerProxy: loggerProxy
) )
@ -120,6 +122,7 @@ public class Initializer {
downloader: CompactBlockDownloader, downloader: CompactBlockDownloader,
spendParamsURL: URL, spendParamsURL: URL,
outputParamsURL: URL, outputParamsURL: URL,
walletBirthday: BlockHeight,
alias: String = "", alias: String = "",
loggerProxy: Logger? = nil loggerProxy: Logger? = nil
@ -137,6 +140,7 @@ public class Initializer {
self.lightWalletService = service self.lightWalletService = service
self.transactionRepository = repository self.transactionRepository = repository
self.downloader = downloader self.downloader = downloader
self.walletBirthday = WalletBirthday.birthday(with: walletBirthday)
} }
/** /**
@ -156,7 +160,7 @@ public class Initializer {
- numberOfAccounts: the number of accounts to create from this seed. - numberOfAccounts: the number of accounts to create from this seed.
*/ */
public func initialize(seedBytes: [UInt8], walletBirthdayHeight: BlockHeight, numberOfAccounts: Int = 1) throws -> [String]? { public func initialize(seedBytes: [UInt8], numberOfAccounts: Int = 1) throws -> [String]? {
do { do {
try rustBackend.initDataDb(dbData: dataDbURL) try rustBackend.initDataDb(dbData: dataDbURL)
@ -166,22 +170,17 @@ public class Initializer {
throw InitializerError.dataDbInitFailed throw InitializerError.dataDbInitFailed
} }
self.walletBirthday = WalletBirthday.birthday(with: walletBirthdayHeight)
guard let birthday = self.walletBirthday else {
throw InitializerError.falseStart
}
do { do {
try rustBackend.initBlocksTable(dbData: dataDbURL, height: Int32(birthday.height), hash: birthday.hash, time: birthday.time, saplingTree: birthday.tree) try rustBackend.initBlocksTable(dbData: dataDbURL, height: Int32(walletBirthday.height), hash: walletBirthday.hash, time: walletBirthday.time, saplingTree: walletBirthday.tree)
} catch RustWeldingError.dataDbNotEmpty { } catch RustWeldingError.dataDbNotEmpty {
// this is fine // this is fine
} catch { } catch {
throw InitializerError.dataDbInitFailed throw InitializerError.dataDbInitFailed
} }
let lastDownloaded = (try? downloader.storage.latestHeight()) ?? self.walletBirthday?.height ?? ZcashSDK.SAPLING_ACTIVATION_HEIGHT let lastDownloaded = (try? downloader.storage.latestHeight()) ?? self.walletBirthday.height
// resume from last downloaded block // resume from last downloaded block
lowerBoundHeight = max(birthday.height, lastDownloaded) lowerBoundHeight = max(walletBirthday.height, lastDownloaded)
var accounts: [String]? = nil var accounts: [String]? = nil
do { do {

View File

@ -98,7 +98,9 @@ public class SDKSynchronizer: Synchronizer {
*/ */
public convenience init(initializer: Initializer) throws { public convenience init(initializer: Initializer) throws {
var config = CompactBlockProcessor.Configuration(cacheDb: initializer.cacheDbURL, dataDb: initializer.dataDbURL) var config = CompactBlockProcessor.Configuration(cacheDb: initializer.cacheDbURL,
dataDb: initializer.dataDbURL,
walletBirthday: initializer.walletBirthday.height)
try self.init(status: .disconnected, try self.init(status: .disconnected,
initializer: initializer, initializer: initializer,