ZcashLightClientKit/Tests/TestUtils/SDKSynchronizer+Utils.swift

38 lines
1.4 KiB
Swift
Raw Normal View History

[#895] Add Sync Session ID Synchronizer State (#906) Closes #895 Add Sync Session ID to `SynchronizerState`. A SyncSession is an attempt to sync the blockchain within the lifetime of a Synchronizer. A Synchronizer can sync many times, when synced it will refresh every ~20 seconds +- random padding. each sync attempt will have a different UUID even if it's from the same instance of SDKSynchronizer. **How are SyncSessions are delimited? With `SyncStatus` changes.** changes from [`.unprepared`|`.error`|`.disconnected`|`.stopped`] to `.syncing` assign a new sessionID to the synchronizer. Any other transitions won't. `areTwoStatusesDifferent ` was refactored to a helper function of `SyncStatus` **How are IDs generated?** ID generation is not mandated but delegated to a protocol `SyncSessionIDGenerator`. Tests inject their own deterministic generator to avoid test flakiness. Default implementation of SyncSessionIDGenerator is ````Swift struct UniqueSyncSessionIDGenerator {} extension UniqueSyncSessionIDGenerator: SyncSessionIDGenerator { func nextID() -> UUID { UUID() } } ```` **SyncSession Pseudo-Atomicity and thread safety** SyncSession is a type alias of a GenericActor holding a UUID ```` typealias SyncSession = GenericActor<UUID> extension SyncSession { /// updates the current sync session to a new value with the given generator /// - Parameters generator: a `SyncSessionIDGenerator` /// - returns: the `UUID` of the newly updated value. @discardableResult func newSession(with generator: SyncSessionIDGenerator) async -> UUID { return await self.update(generator.nextID()) } } ```` Closes #895 SessionTicker struct to control session transitions. switching to `.unprepared` now makes syncID to be `.nullID`
2023-04-07 05:02:05 -07:00
//
// SDKSynchronizer+Utils.swift
[#895] Add Sync Session ID Synchronizer State (#906) Closes #895 Add Sync Session ID to `SynchronizerState`. A SyncSession is an attempt to sync the blockchain within the lifetime of a Synchronizer. A Synchronizer can sync many times, when synced it will refresh every ~20 seconds +- random padding. each sync attempt will have a different UUID even if it's from the same instance of SDKSynchronizer. **How are SyncSessions are delimited? With `SyncStatus` changes.** changes from [`.unprepared`|`.error`|`.disconnected`|`.stopped`] to `.syncing` assign a new sessionID to the synchronizer. Any other transitions won't. `areTwoStatusesDifferent ` was refactored to a helper function of `SyncStatus` **How are IDs generated?** ID generation is not mandated but delegated to a protocol `SyncSessionIDGenerator`. Tests inject their own deterministic generator to avoid test flakiness. Default implementation of SyncSessionIDGenerator is ````Swift struct UniqueSyncSessionIDGenerator {} extension UniqueSyncSessionIDGenerator: SyncSessionIDGenerator { func nextID() -> UUID { UUID() } } ```` **SyncSession Pseudo-Atomicity and thread safety** SyncSession is a type alias of a GenericActor holding a UUID ```` typealias SyncSession = GenericActor<UUID> extension SyncSession { /// updates the current sync session to a new value with the given generator /// - Parameters generator: a `SyncSessionIDGenerator` /// - returns: the `UUID` of the newly updated value. @discardableResult func newSession(with generator: SyncSessionIDGenerator) async -> UUID { return await self.update(generator.nextID()) } } ```` Closes #895 SessionTicker struct to control session transitions. switching to `.unprepared` now makes syncID to be `.nullID`
2023-04-07 05:02:05 -07:00
//
//
// Created by Francisco Gindre on 3/31/23.
//
import Foundation
@testable import ZcashLightClientKit
extension SDKSynchronizer {
convenience init(initializer: Initializer, sessionGenerator: SyncSessionIDGenerator, sessionTicker: SessionTicker) {
let metrics = SDKMetrics()
let latestBlocksDataProvider = LatestBlocksDataProviderImpl(
service: initializer.lightWalletService,
transactionRepository: initializer.transactionRepository
)
[#895] Add Sync Session ID Synchronizer State (#906) Closes #895 Add Sync Session ID to `SynchronizerState`. A SyncSession is an attempt to sync the blockchain within the lifetime of a Synchronizer. A Synchronizer can sync many times, when synced it will refresh every ~20 seconds +- random padding. each sync attempt will have a different UUID even if it's from the same instance of SDKSynchronizer. **How are SyncSessions are delimited? With `SyncStatus` changes.** changes from [`.unprepared`|`.error`|`.disconnected`|`.stopped`] to `.syncing` assign a new sessionID to the synchronizer. Any other transitions won't. `areTwoStatusesDifferent ` was refactored to a helper function of `SyncStatus` **How are IDs generated?** ID generation is not mandated but delegated to a protocol `SyncSessionIDGenerator`. Tests inject their own deterministic generator to avoid test flakiness. Default implementation of SyncSessionIDGenerator is ````Swift struct UniqueSyncSessionIDGenerator {} extension UniqueSyncSessionIDGenerator: SyncSessionIDGenerator { func nextID() -> UUID { UUID() } } ```` **SyncSession Pseudo-Atomicity and thread safety** SyncSession is a type alias of a GenericActor holding a UUID ```` typealias SyncSession = GenericActor<UUID> extension SyncSession { /// updates the current sync session to a new value with the given generator /// - Parameters generator: a `SyncSessionIDGenerator` /// - returns: the `UUID` of the newly updated value. @discardableResult func newSession(with generator: SyncSessionIDGenerator) async -> UUID { return await self.update(generator.nextID()) } } ```` Closes #895 SessionTicker struct to control session transitions. switching to `.unprepared` now makes syncID to be `.nullID`
2023-04-07 05:02:05 -07:00
self.init(
status: .unprepared,
initializer: initializer,
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
transactionEncoder: WalletTransactionEncoder(initializer: initializer),
[#895] Add Sync Session ID Synchronizer State (#906) Closes #895 Add Sync Session ID to `SynchronizerState`. A SyncSession is an attempt to sync the blockchain within the lifetime of a Synchronizer. A Synchronizer can sync many times, when synced it will refresh every ~20 seconds +- random padding. each sync attempt will have a different UUID even if it's from the same instance of SDKSynchronizer. **How are SyncSessions are delimited? With `SyncStatus` changes.** changes from [`.unprepared`|`.error`|`.disconnected`|`.stopped`] to `.syncing` assign a new sessionID to the synchronizer. Any other transitions won't. `areTwoStatusesDifferent ` was refactored to a helper function of `SyncStatus` **How are IDs generated?** ID generation is not mandated but delegated to a protocol `SyncSessionIDGenerator`. Tests inject their own deterministic generator to avoid test flakiness. Default implementation of SyncSessionIDGenerator is ````Swift struct UniqueSyncSessionIDGenerator {} extension UniqueSyncSessionIDGenerator: SyncSessionIDGenerator { func nextID() -> UUID { UUID() } } ```` **SyncSession Pseudo-Atomicity and thread safety** SyncSession is a type alias of a GenericActor holding a UUID ```` typealias SyncSession = GenericActor<UUID> extension SyncSession { /// updates the current sync session to a new value with the given generator /// - Parameters generator: a `SyncSessionIDGenerator` /// - returns: the `UUID` of the newly updated value. @discardableResult func newSession(with generator: SyncSessionIDGenerator) async -> UUID { return await self.update(generator.nextID()) } } ```` Closes #895 SessionTicker struct to control session transitions. switching to `.unprepared` now makes syncID to be `.nullID`
2023-04-07 05:02:05 -07:00
transactionRepository: initializer.transactionRepository,
utxoRepository: UTXORepositoryBuilder.build(initializer: initializer),
blockProcessor: CompactBlockProcessor(
initializer: initializer,
metrics: metrics,
logger: initializer.logger,
latestBlocksDataProvider: latestBlocksDataProvider,
[#895] Add Sync Session ID Synchronizer State (#906) Closes #895 Add Sync Session ID to `SynchronizerState`. A SyncSession is an attempt to sync the blockchain within the lifetime of a Synchronizer. A Synchronizer can sync many times, when synced it will refresh every ~20 seconds +- random padding. each sync attempt will have a different UUID even if it's from the same instance of SDKSynchronizer. **How are SyncSessions are delimited? With `SyncStatus` changes.** changes from [`.unprepared`|`.error`|`.disconnected`|`.stopped`] to `.syncing` assign a new sessionID to the synchronizer. Any other transitions won't. `areTwoStatusesDifferent ` was refactored to a helper function of `SyncStatus` **How are IDs generated?** ID generation is not mandated but delegated to a protocol `SyncSessionIDGenerator`. Tests inject their own deterministic generator to avoid test flakiness. Default implementation of SyncSessionIDGenerator is ````Swift struct UniqueSyncSessionIDGenerator {} extension UniqueSyncSessionIDGenerator: SyncSessionIDGenerator { func nextID() -> UUID { UUID() } } ```` **SyncSession Pseudo-Atomicity and thread safety** SyncSession is a type alias of a GenericActor holding a UUID ```` typealias SyncSession = GenericActor<UUID> extension SyncSession { /// updates the current sync session to a new value with the given generator /// - Parameters generator: a `SyncSessionIDGenerator` /// - returns: the `UUID` of the newly updated value. @discardableResult func newSession(with generator: SyncSessionIDGenerator) async -> UUID { return await self.update(generator.nextID()) } } ```` Closes #895 SessionTicker struct to control session transitions. switching to `.unprepared` now makes syncID to be `.nullID`
2023-04-07 05:02:05 -07:00
walletBirthdayProvider: { initializer.walletBirthday }
),
metrics: metrics,
syncSessionIDGenerator: sessionGenerator,
syncSessionTicker: sessionTicker,
latestBlocksDataProvider: latestBlocksDataProvider
[#895] Add Sync Session ID Synchronizer State (#906) Closes #895 Add Sync Session ID to `SynchronizerState`. A SyncSession is an attempt to sync the blockchain within the lifetime of a Synchronizer. A Synchronizer can sync many times, when synced it will refresh every ~20 seconds +- random padding. each sync attempt will have a different UUID even if it's from the same instance of SDKSynchronizer. **How are SyncSessions are delimited? With `SyncStatus` changes.** changes from [`.unprepared`|`.error`|`.disconnected`|`.stopped`] to `.syncing` assign a new sessionID to the synchronizer. Any other transitions won't. `areTwoStatusesDifferent ` was refactored to a helper function of `SyncStatus` **How are IDs generated?** ID generation is not mandated but delegated to a protocol `SyncSessionIDGenerator`. Tests inject their own deterministic generator to avoid test flakiness. Default implementation of SyncSessionIDGenerator is ````Swift struct UniqueSyncSessionIDGenerator {} extension UniqueSyncSessionIDGenerator: SyncSessionIDGenerator { func nextID() -> UUID { UUID() } } ```` **SyncSession Pseudo-Atomicity and thread safety** SyncSession is a type alias of a GenericActor holding a UUID ```` typealias SyncSession = GenericActor<UUID> extension SyncSession { /// updates the current sync session to a new value with the given generator /// - Parameters generator: a `SyncSessionIDGenerator` /// - returns: the `UUID` of the newly updated value. @discardableResult func newSession(with generator: SyncSessionIDGenerator) async -> UUID { return await self.update(generator.nextID()) } } ```` Closes #895 SessionTicker struct to control session transitions. switching to `.unprepared` now makes syncID to be `.nullID`
2023-04-07 05:02:05 -07:00
)
}
}