Skip to content

Commit f44f2c6

Browse files
committed
Merge bitcoindevkit/bdk#1874: fix(wallet): allow PersistedWallet to be Send + Sync
14251a4 fix(wallet): allow PersistedWallet<P> to be Send + Sync even if P is !Sync (Steve Myers) Pull request description: ### Description fixes #1873 based on solution proposed by @praveenperera . ### Notes to the reviewers This is not a breaking change since it's only changing the internal `_marker` field's type. ### Changelog notice - Fix PersistedWallet to be Send + Sync, even when used with a !Sync persister type such as rusqlite::Connection. ### 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 #### Bugfixes: * [ ] This pull request breaks the existing API * [x] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: ValuedMammal: ACK 14251a4 Tree-SHA512: 8ce8ad7d9b2d962114e225074b485bc91671164fe2f2fcd59f48a6c4f53a885bb215d0017584292629fa02b5ca19a67a40a7855fcd4c2490fefd2b3be65f717f
2 parents 3abde00 + 14251a4 commit f44f2c6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

crates/wallet/src/wallet/persisted.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub trait AsyncWalletPersister {
120120
#[derive(Debug)]
121121
pub struct PersistedWallet<P> {
122122
inner: Wallet,
123-
marker: PhantomData<P>,
123+
_marker: PhantomData<fn(&mut P)>,
124124
}
125125

126126
impl<P> Deref for PersistedWallet<P> {
@@ -155,7 +155,7 @@ impl<P: WalletPersister> PersistedWallet<P> {
155155
}
156156
Ok(Self {
157157
inner,
158-
marker: PhantomData,
158+
_marker: PhantomData,
159159
})
160160
}
161161

@@ -169,7 +169,7 @@ impl<P: WalletPersister> PersistedWallet<P> {
169169
.map(|opt| {
170170
opt.map(|inner| PersistedWallet {
171171
inner,
172-
marker: PhantomData,
172+
_marker: PhantomData,
173173
})
174174
})
175175
.map_err(LoadWithPersistError::InvalidChangeSet)
@@ -214,7 +214,7 @@ impl<P: AsyncWalletPersister> PersistedWallet<P> {
214214
}
215215
Ok(Self {
216216
inner,
217-
marker: PhantomData,
217+
_marker: PhantomData,
218218
})
219219
}
220220

@@ -230,7 +230,7 @@ impl<P: AsyncWalletPersister> PersistedWallet<P> {
230230
.map(|opt| {
231231
opt.map(|inner| PersistedWallet {
232232
inner,
233-
marker: PhantomData,
233+
_marker: PhantomData,
234234
})
235235
})
236236
.map_err(LoadWithPersistError::InvalidChangeSet)

crates/wallet/tests/wallet.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use bdk_wallet::psbt::PsbtUtils;
1212
use bdk_wallet::signer::{SignOptions, SignerError};
1313
use bdk_wallet::test_utils::*;
1414
use bdk_wallet::tx_builder::AddForeignUtxoError;
15-
use bdk_wallet::{AddressInfo, Balance, ChangeSet, Update, Wallet, WalletPersister, WalletTx};
15+
use bdk_wallet::{
16+
AddressInfo, Balance, ChangeSet, PersistedWallet, Update, Wallet, WalletPersister, WalletTx,
17+
};
1618
use bdk_wallet::{KeychainKind, LoadError, LoadMismatch, LoadWithPersistError};
1719
use bitcoin::constants::{ChainHash, COINBASE_MATURITY};
1820
use bitcoin::hashes::Hash;
@@ -4209,6 +4211,7 @@ fn test_tx_cancellation() {
42094211
fn test_thread_safety() {
42104212
fn thread_safe<T: Send + Sync>() {}
42114213
thread_safe::<Wallet>(); // compiles only if true
4214+
thread_safe::<PersistedWallet<bdk_chain::rusqlite::Connection>>();
42124215
}
42134216

42144217
#[test]

0 commit comments

Comments
 (0)