- For now I created `CompactBlockProcessorNG` where I started with
implementation of the state machine. I did it to not break the rest of
the SDK. This change will be merged to the feature branch. And before
it is merged to `main` branch code from `CompactBlockProcessorNG` will
be moved to `CompactBlockProcessor`.
- The new code is not used. It just shows and explains how it is done.
It is proof of concept.
- I did put either commented current code or comment to some places to
explain what should be done there.
- New important data types:
- `ActionContext` is context that can hold any data that needs to be
shared between actions. For example sync ranges or current state.
- `CBPState` is state of the `CompactBlockProcessor`. Each state is
handled by one action. This doesn't apply to terminal states like
`finished` or `failed`.
- `ActionProgress` is very similar to `CompactBlockProgress`.
Different actions reports progress differently and `ActionProgress`
represents this.
- `Action` is protocol that defines API of an action. It has one run
method that executes the code of the action
- CBP first creates actions for (almost) each state in `makeActions()`
method. Then the "magic" is done in `CompactBlockProcessorNG.run()` method.
Here is main loop which takes action for current state and execute it.
It's expected that action does it's work and then updates the context
with new state. And this happens until some terminal state
(`finished`, `failed`, `stopped`) is reached.
- After the transition to state machine API of the
`CompactBlockProcessor` should stay the same. No changes should be
required in `SDKSynchronizer`.
[#700] Add documentation for CompactBlockProcessor state machine
- plantuml tool is used to generate diagram.
[#1054] Add config to state machine CBP
Closes#1054
[#1043] Implement DownloadAction
Closes#1043
[#1049] Implement ValidateAction
Closes#1049
[#1050] Implement ValidateServerAction
Closes#1050
[#1056] Add constructors to state machine CBP
Closes#1056
[#1061] Add failure methods for state machine CBP
Closes#1061
[#1055] Implement retry timer to state machine CBP
Closes#1055
[#1057] Implement start for state machine CBP
Closes#1057
[#1058] Implement stop for state machine CBP
Closes#1058
[#1052] Implement AfterSyncHooksManager when using state machine CBP
Closes#1052
[#1060] Implement wipe for state machine CBP
Closes#1060
[#1059] Implement rewind for state machine CBP
Closes#1059
[#700] Add idle state to CBP state machine
This is required so the CBP can detect start of the sync process.
[#700] Implement sending of some events from CompactBlockProcessorNG
[#700] Implement progress reporting in state machine CBP
[#1045] Implement FetchUTXOsAction
- draft of the fetching
[#1045] Implement FetchUTXOsAction
- updated the way Actions communicate data back to the CBP
- used this mechanism to pass result of utxos fetch so it's passed to the SDKSynchronizer as an Event
[#1042] Implement ComputeSyncRangesAction
Closes#1042
[#700] Implement cache clearing when some actions fail
[#1043] Fix batch range computation in DownloadAction
[#1046] Implement SaplingParamsAction
- action for sapling param files finished
[#1048] Implement ScanDownloadedButUnscannedAction
- scan downloaded but unscanned blocks
[#1047] Implement ScanAction
- scan action with the proper ranges computed
[#1047] Implement ScanAction (#1085)
- fixed logger message
[#1044] Implement EnhanceAction
Closes#1044
[#1041] Implement ClearCacheAction
Closes#1041
[#1040] Implement ClearAlreadyScannedBlocksAction
Closes#1040
[#1039] Implement ChecksBeforeSyncAction
Closes#1039
[#700] Make CBP state machine work
[#1050] Implement ValidateServerAction
- broken tests commented out and tracked in the tickets
- new test for ValidateServerAction
[#1051] Update how progress is computed after switch to state machine
Closes#1051
- new proposal for the progress computation
- OverallProgress value is passed to the Synchronizer as a Float
- OverallProgress is a result of fetch, scan and enhance operations
- Order of actions no longer influences the computation
- Actions report partial updates, CompactBlockProgress actor holds current state and computes the OverallProgress
[#1049] Implement ValidateAction
- synchronizer offline tests updated so it compiles, review is requested in a different ticket
- ValidateAction tests added
- BlockValidator mock generated
[#1047] Implement ScanAction
- ScanAction tests
- refactor of validateAction -> validateServerAction
- generated few more mocks for the DI
[#1045] Implement FetchUTXOsAction
- FetchUTXOsAction tests
- UTXOFetcher mocks
[#1045] Implement FetchUTXOsAction
- enhanced with mocked values and more checks
[#1046] Implement SaplingParamsAction
- SaplingParamsAction tests
- added TODO for TestCoordinator reset()
- SaplingParametersHandler mock added
[#1046] Implement SaplingParamsAction
- SaplingParamsAction tests
- added TODO for TestCoordinator reset()
- SaplingParametersHandler mock added
[#1046] Implement SaplingParamsAction
- rebased so I get functionality of improved mock checks
- enhanced SaplingParamsAction tests
- enhanced ValidateAction tests
- enhanced ScanAction tests
[#1046] Implement SaplingParamsAction
- scanAction tests more checks added
[#1044] Implement EnhanceAction
- EnhanceAction tests focused on 2 different methods:
- decideWhatToDoNext covered separately, decisions where the state machine goes next
- run tests for different cases
- new mocks generated for enhacer
- some typos fixed
[#1044] Implement EnhanceAction (#1107)
- empty assert messages fixed
[#700] Get rid of ScanDownloadedButUnscannedAction
Before the state machine download and scan was called in one loop. And
processing range for one batch was same for both of them. Therefore
there was code which scanned downloaded but not scanned blocks.
But now download and scan are independent. So it is possible to remove
`ScanDownloadedButUnscannedAction`.
[#700] Make NetworkTests compilable
Some tests are disabled for now (list is in #1115). And `NetworkTests`
can be compiled and all the enabled tests work.
[#1043] Implement DownloadAction
- DownloadAction tests
- BlockDownloader mock
[#1043] Implement DownloadAction (#1110)
- support functions set to private
[#1039] Implement ChecksBeforeSyncAction
- ChecksBeforeSyncAction tests
- all support functions in Action tests are set to private
- let _ = -> _ = refactor
- CompactBlockRepository mock added
[#1040] Implement ClearAlreadyScannedBlocksAction
- Implement ClearAlreadyScannedBlocksAction tests
- CompactBlockRepository mock added
[#1041] Implement ClearCacheAction
- ClearCacheAction tests
- CompactBlockRepository mock added
[#1042] Implement ComputeSyncRangesAction
- ComputeSyncRangesAction tests
- fixed all tests after merge of latest SDK changes related InternalSyncProgress
- all actions marked as final class
[#1042] Implement ComputeSyncRangesAction (#1120)
- Custom LatestBlocksDataProviderMock removed from the project
[#1122] Implement FileManager protocol and dependency
- ZcashFileManager implemented
- MigrateLegacyCacheDBAction refactored to be dependent on ZcashFileManager
- ZcashFileManager mock added
[#1122] Implement FileManager protocol and dependency (#1124)
- code cleanup
[#1121] Implement MigrateLegacyCacheDBAction
- MigrateLegacyCacheDBAction tests WIP
- tests naming cleanup
[#1121] Implement MigrateLegacyCacheDBAction
- MigrateLegacyCacheDBAction tests finished
[#700] Fix DarksideTests
Closes#1102
Some tests that can't be compiled are disabled for now. List is in #1126.
This PR contains multiple fixes. Most of the fixes is done in the code.
Not in the tests. That is good news.
Fixes:
- `config` inside `CompactBlockProcessor` can be updated during the
tests. And it must be also updated inside the actions. So
`ConfigProvider` is added and it is wrapper for config that is passed
to any instance of `Action` and provides updated config.
- Fixed `EnhanceAction`. Now it should update all the blocks in the
enhance range even when the remaining count of blocks is lower than
1000.
- Fixed `fail()` and `validationFailed()`. These two were canceling
`syncTask`. But that stopped run loop in a bad way.
[#1129] Final check of all State Machine Action tests
- XTCAsset messages checked
- test naming checked and fixed
[#1126] Fix DarksideTests in state machine branch
Closes#1126
Fix offline tests
Closes#1098Closes#1095Closes#1094
Most of the tests is removed. Either the code that was tested doesn't
exists. Or now tests for state machine actions do this work.
[#1115] Fix NetworkTests in state machine branch
Closes#1115
[#700] Fix progress reporting
Some actions in the sync process may not run. For example there are no
transactions to enhance and therefore there is no enhance progress. And in
cases like this computation of final progress won't work properly.
So let's fake 100% progress at the end of the sync process.
* [#1108] Instrument rust backend tracing
This adds a parameter to the `Initializer` constructor that allows
developers to turn on performance trancing tooling on the Rust
backend. It can't be disabled on the fly. It's either OFF or ON
all the life-span for the Synchronizer.
Closes#1108
Update ffi framework commit hash
* update resolved filed
Closes#1111
- `InternalSyncProgress` has now new disk storage implementation:
`InternalSyncProgressDiskStorage`.
- When then `UserDefaults` was used as disk storage there were no IO errors
to handle. But now the code in `InternalSyncProgressDiskStorage`
writes to files and reads from files. So there are errors to handle.
Because of this protocol `InternalSyncProgressStorage` changed a bit
and API of `InternalSyncProgress` changed a bit. Now all the functions
throws.
- It is possible to make progress storage IO errors silent but I think
that storing of the progress is very essential to the sync process. So
I think that when progress storage fails then the sync process should
fail.
- `Initializer` has new parameter `generalStorageURL`. It is directory
where `InternalSyncProgressDiskStorage` stores progress files. In
future this can be used for storing any data the SDK wants.
- Rebuild download stream in `BlockDownloaderImpl` each 10 batches. So
currently stream downloads 1000 blocks and then new stream is created.
- Memory stays between 60MB and 70MB during sync in the Sample app.
fixes docs and deletes fixme for [#783]
closes#783
[#785]: Fix test testSingleNoteNoChangeTransaction
[#786] fix testVerifyChangeTransaction
Closes#786
[#790] mark as fixed testRewindAfterSendingTransaction
Closes#790
[#865] Fix test testStoringTenSandblastedBlocks
Closes#865
[#791] Fix test testRewindAfterSendingTransaction
Closes#791
[#783]: Fix test testMaxAmountSendBroadcast
Closes#783
* [#781] This fixes test `testMaxAmountMinusOneSend` by creating two separate
tests:
- testMaxAmountMinusOneSendFails
- testMaxAmountSend
Also includes new functionality that tracks sent transactions so
that users can be notified specifically when they are mined and uses "idea B" of
issue #1033.
closes#1033closes#781
* Fix tests
- new ZcashError.unknown that wraps and handles any Error added
[#1035] Create ZcashError.unknown (#1036)
- improved the conversion of error -> ZcashError
[#1035] Create ZcashError.unknown (#1036)
- detailed comments of the unknown case
- SyncStatus refactored to InternalSyncStatus, so the SDK works internally with the SyncStatus as previously
- new SyncStatus is a computed property that maps InternalSyncStatus to simplified SyncStatus
[#843] Simplify Synchronizer Status (#1010)
- simplification of SyncStatus done
- % computation moved to the mapping function so the rest of the SDK works just like before
- fixed unit tests
- new unit tests checking the boundaries of the new progress
[#843] Simplify Synchronizer Status (#1010)
- removed commented code
[#843] Simplify Synchronizer Status (#1010)
- package.resolved
[#843] Simplify Synchronizer Status (#1010)
- fixed dark side tests
[#843] Simplify Synchronizer Status (#1010)
- package.resolved
Closes#1012
- This is the first change for the dependency injection. This change
adds `DIContainer` which is used to register and resolve dependencies.
- Then this change shows how `DIContainer` can be used to resolve
dependencies. And it also shows how to mock dependencies in tests.
- Constructors of `Initializer` are changed to support mocking of
depedendencies. But it doesn't affect public API in any way.
- Depedencies are registered in `Dependencies.setup()`. Then in the code
`container.resolve(SomeType.self)` is called to get instance of the
dependency.
- `ZcashTestCase` class is added. It inherits from `XCTestCase` and
should be used for base class in tests. `ZcashTestCase` takes care of
creation of `DIContainer` for dependencies mocking. In future we can
maybe move there more things that are used in each test.
- Lot is missing here. Not all the code is using dependency injection.
Tests for `DIContainer` are missing. Only `OfflineTests` work now
(other tests can't be even compiled). It will be added in future
changes.
`lastError` inside the `BlockDownloaderImpl` was set even when
downloading task was canceled. And because it was canceled the
`lastError` has never been read by CBP before the next sync. And when
next sync was started it was immediately failed because of cancelation
error stored in `lastError`.
Changes the way unpadded bytes are turned into a UTF-8 Swift String
without using cString assuming APIs that would overflow memory and
add garbled trailing bytes.
Closes#1019
add changelog entry
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
- `BlockDownloaderImpl` is changed. It now spawns detached Task to
download blocks. So blocks can be downloaded in parallel with scanning
process.
- `Synchronizer.stop()` is no longer async.
- Blocks cache cleaning is changed. It's not possible to drop the whole
cache now. There are some blocks pre-downloaded which weren't scanned
yet.
It looks like that some methods in `ZcashKeyDerivationBackendWelding`
were left async by mistake. There is no reason for any method there to
be async.
After this change no method in `DerivationTool` has to async. It makes
things much easier.
This PR introduces `ZcashError` enum. This enum represents any error
that can be thrown inside of the SDK and outside of the SDK. Also
`ZcashError` is used in `LightWalletGRPCService` and handled in
`CompactBlockProcessor` as example.
Why enum? First I tried this with some structure which contained code,
message and underlyingError. Problem was when some specific place in the
SDK would like to attach some additional data to error. I didn't want to
add some generic dictionary to store anything with the error.
So I used enum to identify error. Each member can have specified amount
of associated values. So specific error can bring some context data. And
it's type safe.
Each error has also a code. Relationship between errors and codes is
1:1. It may looks bit redundant but it's important. The client app now
can choose how to process errors. Either identify those by the error
itself or by code.
Definition or errors and codes is in `ZcashErrorDefinition`. And then
`ZcashError` and `ZcashErrorCode` are generated by Sourcery. Thanks to
this it is easier to maintain the final code. And it gives us ability to
generate any kind of documentation for the errors and codes. I created
simple example of this in this PR. And it doesn't make the SDK
completely dependent on the Sourcery. Final structures aren't super
complicated and can be written manually if needed.
[#923] Update error handling in DatabaseStorageManager.swift
- cleanup of DatabaseStorageManager, not used anymore
- ZcashError for SimpleConnectionProvider
Revert "[#923] Update error handling in DatabaseStorageManager.swift"
This reverts commit 94e028d31a.
Fix script which generates ZcashError
[#922] Update error handling in DatabaseMigrationManager.swift
Closes#922
[#923] Update error handling in DatabaseStorageManager.swift
- The DatabaseStorageManager is not used so I deleted it
- SimpleConnectionProvider's errors updated
Fix tests
[#955] Update error handling in SaplingParameterDownloader
Closes#955
[#936] Update error handling in NotesDao
Closes#936
[#935] Update error handling in BlockDao
Closes#935
[#931] InternalSyncProgress.computeNextState doesn't need to throw
Closes#931
[#950] Update error handling in rust backend
Closes#949Closes#950
[#941] Update error handling in AccountEntity
Closes#941
[#928] Update error handling in FSCompactBlockRepository
Closes#928
[#925] Update error handling in BlockDownloaderService (#974)
- BlockDownloaderService errors updated
[#924] Update error handling in BlockDownloader (#973)
- BlockDownloaderStream nextBlock updated
[#942] Update error handling in TransactionEntity (#977)
- ZcashTransaction init errors converted to the ZcashError
[#939] Update error handling in TransactionDao (#976)
- TransactionRepositoryError removed and replaced with ZcashError
- all TransactionDAO errors converted to ZcashError
[#943] Update error handling in ZcashCompactBlock
Closes#943
[#945] Update error handling in Memo
Closes#945
[#934] Update error handling in Checkpoint
Closes#944Closes#934
[#938] Update error handling in PendingTransactionDao
Closes#938
[#926] Update error handling in BlockEnhancer
- WIP, switching to transaction repository to unblock this ticket
[#926] Update error handling in BlockEnhancer
- enhancer's errors done
[#926] Update error handling in BlockEnhancer (#994)
- cleanup
[#952] Update error handling in DerivationTool
Closes#952
[#932] Update error handling in BlockValidator
Closes#932
[#940] Update error handling in UnspentTransactionOutputDao
Closes#940
[#946] Update error handling in WalletTypes
Closes#946
[#954] Update error handling in WalletTransactionEncoder
Closes#954
[#953] Update error handling in PersistentTransactionManager
Closes#953
[#956] Update error handling in Initializer
Closes#956
[#947] Update error handling in Zatoshi (#996)
- Zatoshi's errors converted to ZcashError
[#927] Update error handling in UTXOFetcher (#997)
- UTXOFetcher resolved
Use let instead of var where applicable
In the SDK `var` was used on places where `let` would be sufficient. And
default strategy in Swift should use use `let` until mutability is
required. So all these places are changed. No logic is changed.
[#933] Update error handling in CompactBlockProcessor
- CompactBlockProcessor's errors refactored to ZcashError
[#933] Update error handling in CompactBlockProcessor #999
- comments addressed
[#951] Update error handling in SDKSynchronizer
- SDKSynchronizer's errors refactored to ZcashError
[#951] Update error handling in SDKSynchronizer (#1002)
- comments resolved
Make DerivationTool constructor public
DerivationTool.init should be public. This was removed by accident when
adopting async.
[#361] Add changelog
This change switches to a new (future) version of the rust crates
that will get rid of the sent and received transactions Views in
favor of a `v_transaction` view that will do better accounting of
outgoing and incoming funds. Additionally it will support an
outputs view for seeing the inner details of transactions enabling
the SDKs tell the users the precise movement of value that a tx
causes in its multiple possible ways according to the protocol.
the `v_tx_outputs` view is not yet implemented.
Sent and Received transaction sub-types are kept for compatibility
purposes but they are generated from Overviews instead of queried
from a specific view.
In the transaction Overview the value represents the whole value
transfer for the transaction from the point of view of a given
account including fees. This means that the value for a single
transaction Overview struct represents the addition or subtraction
of ZEC value to the account's balance.
Future updates will give clients the possibility to drill into the
inner workings of those value changes in a per-output basis for
each transaction.
Also, the field `pending_unmined` field was added to `v_transactions`
so that wallets can query `DataDb` for pending but yet unmined txs
This will prepare the field for removing the notion of a "PendingDb"
and its nuances.
Also updated test database `darkside_data.db`
Closes#959Closes#971 ZcashLightClientKitSample main target broken swiftlint script
Demo App improvements: Show Short date and value on transaction list