This change leverages the gRPC streaming API along with the elimination of bulk inserts to SQLite to reduce the amount of memory required to write blocks.
This includes a few different fixes that prevented the demo app and other SDK consumers from working.
First, initialization of the demo app was fixed to use the sapling activation height rather than the current latest checkpoint.
Second, CompactBlockProcessor wasn’t downloading blocks.
Third, a few potential thread safety issues were resolved by making fields that are accessed by multiple threads volatile.
- Replace int with type safe BlockHeight(Long) object
- Fix down casting bug, as BlockHeight is uint32 but Java only supports int32 or int64
- Rename WalletBirthday to Checkpoint and hide from the public API
This resolves several issues including:
- Updated checkpoints
- #550 Support for new checkpoint format with NU5
- #377 Removed explicit dependency on GSON
While there are a lot of changes, the most significant are:
- Update the main entrypoint of the SDK to use a suspending function and eliminate lazy initialization. This also resolves#310
- Changing Dao methods to `suspend`, allowing Room to implicitly manage the threading model under the hood
- Explicitly set the executor thread for the `CompactBlockDb` and `DerivedDataDb`, which is the same thread used when calling into the Rust native library. Room will then use this thread for `suspend` fun calls into it
- With the above set, remove unnecessary hops to Dispatchers.IO which is a thread pool
- Eliminate lazy initialization in `PagedTransactionRepository` to make it easier to reason about the threading model and resolve#355 where the database was being touched from the UI thread
Note that `PendingTransactionsDb` is not opted into this single-threaded approach, because that database is not shared with the Rust code
To quickly get this implemented, some calls in the demo-app have been wrapped in `runBlocking {}`. This is not ideal and will be addressed in followup issues.
In the process of refactoring the Gradle scripts, ktlint now is applied to all Gradle modules. The demo-app hadn't been linted before, so this applies a series of minor autocorrections to this module.
In addition to using build-conventions to make the build scripts more DRY, the following additional changes are included in this commit:
- Convert build scripts to kts
- Fix a double-build issue with the SDK
- Add configurable options for treating compiler warnings as errors (disabled for now, due to extensive warnings that need to be corrected first)
- Added detekt as an additional static analysis tool
Move SDK from the root gradle project to its own Gradle module
Move the demo app to be a peer of the SDK
This will simplify integration with CI on Bitrise.