Skip to content
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

multi: asyncify, use rusqlite-based persistence #169

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

torkelrogstad
Copy link
Contributor

@torkelrogstad torkelrogstad commented Feb 12, 2025

Currently struggling with the type check 😅

Need to be able to run async functions within with_mut of the wallet RwLockWriteGuardSome. Is that possible?

Cargo.toml Outdated Show resolved Hide resolved
@torkelrogstad torkelrogstad force-pushed the 2025-02-12-async-rusqlite branch 2 times, most recently from 7aa439a to 39f69ae Compare February 12, 2025 14:45

/// A simple thread‑safe wrapper around a rusqlite::Connection that implements AsyncWalletPersister.
#[derive(Debug)]
pub struct ThreadSafeConnection(Mutex<Connection>);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the right approach. If you want persisting the wallet to be async, you will need to use an async DB connection. This will still block on commits

To get truly async IO, you would need to use something like sqlx , and manage tables manually. BDK does provide a schema https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.ChangeSet.html#method.schema_v0

tokio-rusqlite is a drop-in replacement, but spawns a thread to handle a connection, whereas sqlx actually uses async IO AFAIK

Also, is there really a need for an internal mutex here? IMO it would make more sense to have the mutex external to the persister, so that a user has more control over locking behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be completely honest I'm not sure I follow all the details on the conversations we're having on async, blocking, etc.

If I understand you correctly: we might end up with multiple different operations trying to access the DB at the same time, and they'll have to wait on one another because we only permit a single access to the DB connection concurrently. Is that correct? If so, I actually think this is fine, at least for this first version. I believe the SQLite persistor is going to be orders of magnitude quicker than the file_store approach we have currently. If we still see issues, we can go with a connection pool.

Re. the internal mutex: the reason for that is that I need to ensure that wallet::WalletInner is Sync. Is there some other way to accomplish that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the mutexed rusqlite::Connection with a tokio_rusqlite implementation

@torkelrogstad torkelrogstad force-pushed the 2025-02-12-async-rusqlite branch from d7935b2 to 259bc67 Compare February 12, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants