]> Untitled Git - bdk/commitdiff
Merge bitcoindevkit/bdk#1547: Simplify wallet persistence
authorSteve Myers <steve@notmandatory.org>
Mon, 19 Aug 2024 15:49:57 +0000 (10:49 -0500)
committerSteve Myers <steve@notmandatory.org>
Mon, 19 Aug 2024 15:56:57 +0000 (10:56 -0500)
340808e820cc144c8b2756dd9c235fad1400ad76 docs(wallet): fixes/improvements for `persisted` and `params` types (志宇)
960029324d18dbb51408034efc05b0450867c15a feat(wallet)!: add persister (`P`) type param to `PersistedWallet<P>` (志宇)
06160574ba3997fa49449a251a8bc046fb1a96a5 revert(chain)!: rm `persit` module (志宇)
a9c5f761c4c6834f8a05f2eb64feb39d23b74c2a feat(wallet)!: remove dependency on `bdk_chain::Staged` (志宇)
06a9d6c722dd3e324d81ea5b9c2b65ab9f171a34 feat(chain,wallet)!: publicize `.init_sqlite_tables` changeset methods (志宇)
039622fd1de7ee331eceb7a4c77751bd8ecccda0 feat(wallet)!: introduce `WalletPersister` (志宇)

Pull request description:

  ### Description

  Removed the persistence module in `bdk_chain` (which contained the `PersistWith` and `PersistAsyncWith` traits and a `Persisted<T>` wrapper). Replaced it with simplified versions that are `Wallet`-specific.

  The new traits (`WalletPersister` and `AsyncWalletPersister`) are simpler since they have less type-parameters (being wallet-specific). The old versions were more complex as they were intended to be used with any type. However, we need more time to finalize a works-for-all-bdk-types persistence API.

  Additionally, `WalletPersister` and `AsyncWalletPersister` also introduce the `initialize` method. It is handy to contain db-initialization (i.e. create tables for SQL) here. We can call `initialize` in `PersistedWallet` constructors. So the `PersistedWallet::persist` method does not need to ensure the database is initialized. To accommodate this, I made the `.init_sqlite_table` methods on changeset-types public, and removed the call of this in `from_sqlite` and `.persist_to_sqlite`. The `initialize` method now loads from the persister, so the `load` associated function is removed.

  There was a bug in the old `PersistAsyncWith` trait where the lifetime bounds were not strict enough (refer to the conversation in #1552). This is now fixed in the new `AsyncWalletPersister` trait.

  Docs for the new types are clearer (hopefully). I mentioned implementation details about the new traits and what safety checks were guaranteed in `PersistedWallet`.

  I think it makes sense just to have a wallet-specific persistence API which we will maintain alongside wallet for v1.0. This is less baggage for users and maintainers alike.

  ### Notes to the reviewers

  **How breaking are these changes?**

  Unless if you were implementing your own persistence, then not breaking at all! If you were implementing your own persistence for BDK, the breakages are minimal. The main change is introducing the `initialize` method to persistence traits (which replaces `load`).

  **Acknowledgements**

  I came up with the idea of this while responding to @tnull's suggestions on Discord. Unfortunately we cannot fulfill all of his requests. However, I do believe that this will make things easier for our users.

  ### Changelog notice

  * Removed the `persist` module in `bdk_chain`.
  * Added `WalletPersister`/`AsyncWalletPersister` traits and `PersistedWallet` struct to `bdk_wallet`. These are simplified and safer versions of old structs provided by the `persist` module in `bdk_chain`.
  * Change `.init_sqlite_tables` method to be public on changeset types. `from_sqlite` and `persist_into_sqlite` methods no longer call `.init_sqlite_tables` internally.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### What is left to do:

  - [x] Better docs.

ACKs for top commit:
  notmandatory:
    ACK 340808e820cc144c8b2756dd9c235fad1400ad76

Tree-SHA512: 77643196543ad0a741f9ec51de4aad3893c6d608234ad6709c8688043bf1eef1e5e97e71681be0a6b29dec3fa255e2f0e63e08511c79ea4c0a6ef3286653d40c


Trivial merge