-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Conversation
7aa439a
to
39f69ae
Compare
lib/wallet/thread_safe_connection.rs
Outdated
|
||
/// A simple thread‑safe wrapper around a rusqlite::Connection that implements AsyncWalletPersister. | ||
#[derive(Debug)] | ||
pub struct ThreadSafeConnection(Mutex<Connection>); |
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.
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
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.
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?
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.
Replaced the mutexed rusqlite::Connection
with a tokio_rusqlite
implementation
39f69ae
to
cbbff7c
Compare
d7935b2
to
259bc67
Compare
Currently struggling with the type check 😅
Need to be able to run async functions within
with_mut
of the walletRwLockWriteGuardSome
. Is that possible?