-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add bdk_sqlite crate implementing PersistBackend #1128
feat: add bdk_sqlite crate implementing PersistBackend #1128
Conversation
bcfa000
to
6603c60
Compare
hey @notmandatory. What do you think about the approach of just putting the the data in actual tables rather than serializing it in some blob? For reference the tables we'd have for this would be:
The advantage would be that the database would be intelligible on the sqlite cli and from other applications. The disadvantage would be that we couldn't use sqlite for just any type of changeset. You'd probably have some extra trait over changesets that applications would have to implement on their changesets that return the inner |
6603c60
to
18a0660
Compare
It's funny you should mention it, I started out with the multi tables/columns approach but thought maybe it wasn't in the spirit of the |
Sure if we do go blobs I think we should use |
18a0660
to
e1e0043
Compare
FYI I rebased off of #1203 so only look at my commits. |
e1e0043
to
f9447a1
Compare
I've implemented the #[derive(Clone, Debug, PartialEq)]
struct ChangeSet<K: Ord + for<'de> Deserialize<'de> + Serialize>(
local_chain::ChangeSet,
indexed_tx_graph::ChangeSet<ConfirmationTimeHeightAnchor, keychain::ChangeSet<K>>,
); EDIT: I updated PR to use |
3376ecc
to
fd7b709
Compare
I'm very happy with this codebase, thanks for spearheading this effort @notmandatory. Just the things I've mentioned above and I'll be happy to ACK. |
|
8c34d0d
to
d614e9e
Compare
I ran into a docs error that I fixed by removing the rust doc link in the README. Can add it back later after the crate is published but it's not that important. |
nursery/coin_select/src/bnb.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be removed? We should be using bdk_coin_select
imported from our new repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay it's not removed yet, that's pretty annoying. This is out of scope for this PR though.
Edit: Okay I got this wrong. We made |
I renamed
We discussed the naming at our 17:00 UTC BDK call today and consensus agrees with the shorter naming so I made the change in a0084dc. |
0280923
to
7357d93
Compare
@evanlinjin I merged your latest PR commits but removed
|
ConceptACK for removing Although there is an argument that the transform stuff might be useful if the caller wants to have custom changesets? However, I guess they can impl PersistBackend themselves. Let's leave it out for now. Let's squash! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I'm quite happy how this turned out.
In terms of styling, is the use of traits just to "section" the code? If that is the case, I would have preferred alternative ways to do so (i.e. you can have multiple impl Store {}
blocks with doc comments at the top of each block). Using traits makes it harder to read and adds weird quirks (i.e. the funky thing you needed to do with db_transaction
).
I'll ACK once we get rid of bdk_wallet
dependency from bdk_sqlite
.
It is a good idea to have common changeset types stored in `bdk_persist`. This will make it convenient for persistence crates and `bdk_wallet` interaction.
7357d93
to
658358b
Compare
@evanlinjin great styling tip, I redid as you suggested and it look much better (I don't know what I was thinking with the traits 🙃 ) and removed the wallet features, sorry I forgot to remove that last push. I also reorganized and squashed commits so it should be ready to merge. Thanks for all the help! |
… by a SQLite database
658358b
to
475c502
Compare
I amended/force pushed another good suggestion from @evanlinjin to impl impl<K, A, C> bdk_persist::PersistBackend<C> for Store<K, A>
where
K: Ord + for<'de> Deserialize<'de> + Serialize + Send,
A: Anchor + for<'de> Deserialize<'de> + Serialize + Send,
C: Clone + From<CombinedChangeSet<K, A>> + Into<CombinedChangeSet<K, A>>,
{
fn write_changes(&mut self, changeset: &C) -> anyhow::Result<()> {
self.write(&changeset.clone().into())
.map_err(|e| anyhow::anyhow!(e).context("unable to write changes to sqlite database"))
}
fn load_from_persistence(&mut self) -> anyhow::Result<Option<C>> {
self.read()
.map(|c| c.map(Into::into))
.map_err(|e| anyhow::anyhow!(e).context("unable to read changes from sqlite database"))
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 475c502
Description
Add "bdk_sqlite_store" crate implementing
PersistBackend
backed by a SQLite database.Notes to the reviewers
In addition to adding a SQLite based
PersistenceBackend
this PR also:CombinedChangeSet
inbdk_persist
and updatewallet
crate to use it.wallet/tests
to also use this new sqlite store crate.example-crates/wallet_esplora_async
to use this new sqlite store crate.build_docs
job to rustnightly-2024-05-12
.Changelog notice
Changed
Added
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features: