Skip to content

Commit 99dacf0

Browse files
committed
Merge #208: deps!: update bdk_chain to 0.22.0
e125014 feat(examples): Change `example_wallet_rpc` to detect evictions. (志宇) 12b00e0 feat(wallet): Add method `apply_evicted_txs` (valued mammal) a247215 deps!: update bdk_chain to 0.22.0 (valued mammal) f882945 ci: Unpin some dependencies (valued mammal) Pull request description: This PR updates `bdk_chain` dependency to the latest version 0.22.0 ### Notes to the reviewers This PR doesn't make use of `CanonicalizationParams` for any advanced use cases - instead we rely on the default params for all tx-graph queries. fixes #202 fixes #224 ### Changelog notice - deps: bump `bdk_chain` to 0.22.0 - deps: bump `bdk_file_store` to 0.20.0 #### Added - Added `start_sync_with_revealed_spks_at` - Added `start_full_scan_at` - Added `apply_evicted_txs` #### Changed - `start_sync_with_revealed_spks` is feature gated by "std", as it uses the system time to provide the time of the sync and also the tx last-seen. - `apply_update` no longer requires std, as the timestamp is provided in the sync / full scan request - `start_full_scan` is also gated behind "std" - `start_sync_*` now includes the expected SPK history (via `list_expected_spk_txids`) #### Removed - Removed `apply_update_at` #### BREAKING - `bdk_core::TxUpdate` is non-exhaustive bitcoindevkit/bdk#1838 - For the optional file_store feature, the Load variant of the `FileStoreError` is changed to hold a new inner type bitcoindevkit/bdk#1684 #### Changes to persisted data The `tx_graph::ChangeSet` gained a new default-able field `last_evicted` to persist the fact that a tx is no longer part of the canonical chain. ### 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 * [x] I've added docs for the new feature * [x] This pull request breaks the existng API * [x] I'm linking the issue being fixed by this PR ACKs for top commit: notmandatory: ACK e125014 Tree-SHA512: 91f77e4268aac0aaee2503a3fdca13754fc291159b9f37b0997be8c011b02b8ac16b4b6a7edbbb731005c83b37d438666fb803dbe18a6b9496b11f7e3e1ab155
2 parents 8eaf1c0 + e125014 commit 99dacf0

File tree

14 files changed

+171
-103
lines changed

14 files changed

+171
-103
lines changed

ci/pin-msrv.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,4 @@ set -euo pipefail
1010
# cargo clean
1111
# rustup override set 1.63.0
1212

13-
cargo update -p home --precise "0.5.5"
14-
cargo update -p url --precise "2.5.0"
15-
cargo update -p tokio --precise "1.38.1"
16-
cargo update -p tokio-util --precise "0.7.11"
17-
cargo update -p indexmap --precise "2.5.0"
18-
cargo update -p security-framework-sys --precise "2.11.1"
19-
cargo update -p ring --precise "0.17.12"
2013
cargo update -p once_cell --precise "1.20.3"
21-
cargo update -p minreq --precise "2.13.2"
22-
cargo update -p native-tls --precise "0.2.13"

examples/example_wallet_electrum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ edition = "2021"
55

66
[dependencies]
77
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
8-
bdk_electrum = { version = "0.21" }
8+
bdk_electrum = { version = "0.22.0" }
99
anyhow = "1"

examples/example_wallet_electrum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const ELECTRUM_URL: &str = "ssl://electrum.blockstream.info:60002";
2222
fn main() -> Result<(), anyhow::Error> {
2323
let db_path = "bdk-electrum-example.db";
2424

25-
let mut db = Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), db_path)?;
25+
let (mut db, _) = Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), db_path)?;
2626

2727
let wallet_opt = Wallet::load()
2828
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))

examples/example_wallet_esplora_async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ edition = "2021"
77

88
[dependencies]
99
bdk_wallet = { path = "../../wallet", features = ["rusqlite"] }
10-
bdk_esplora = { version = "0.20", features = ["async-https", "tokio"] }
10+
bdk_esplora = { version = "0.21.0", features = ["async-https", "tokio"] }
1111
tokio = { version = "1.38.1", features = ["rt", "rt-multi-thread", "macros"] }
1212
anyhow = "1"

examples/example_wallet_esplora_blocking/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ publish = false
88

99
[dependencies]
1010
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
11-
bdk_esplora = { version = "0.20", features = ["blocking"] }
11+
bdk_esplora = { version = "0.21.0", features = ["blocking"] }
1212
anyhow = "1"

examples/example_wallet_esplora_blocking/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const INTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7
1919
const ESPLORA_URL: &str = "http://signet.bitcoindevkit.net";
2020

2121
fn main() -> Result<(), anyhow::Error> {
22-
let mut db = Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), DB_PATH)?;
22+
let (mut db, _) = Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), DB_PATH)?;
2323

2424
let wallet_opt = Wallet::load()
2525
.descriptor(KeychainKind::External, Some(EXTERNAL_DESC))

examples/example_wallet_rpc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
bdk_wallet = { path = "../../wallet", features = ["file_store"] }
10-
bdk_bitcoind_rpc = { version = "0.18" }
10+
bdk_bitcoind_rpc = { version = "0.19.0" }
1111

1212
anyhow = "1"
1313
clap = { version = "4.5.17", features = ["derive", "env"] }

examples/example_wallet_rpc/src/main.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
use bdk_bitcoind_rpc::{
22
bitcoincore_rpc::{Auth, Client, RpcApi},
3-
Emitter,
3+
Emitter, MempoolEvent,
44
};
55
use bdk_wallet::{
6-
bitcoin::{Block, Network, Transaction},
6+
bitcoin::{Block, Network},
77
file_store::Store,
88
KeychainKind, Wallet,
99
};
1010
use clap::{self, Parser};
11-
use std::{path::PathBuf, sync::mpsc::sync_channel, thread::spawn, time::Instant};
11+
use std::{
12+
path::PathBuf,
13+
sync::{mpsc::sync_channel, Arc},
14+
thread::spawn,
15+
time::Instant,
16+
};
1217

1318
const DB_MAGIC: &str = "bdk-rpc-wallet-example";
1419

@@ -73,21 +78,21 @@ impl Args {
7378
enum Emission {
7479
SigTerm,
7580
Block(bdk_bitcoind_rpc::BlockEvent<Block>),
76-
Mempool(Vec<(Transaction, u64)>),
81+
Mempool(MempoolEvent),
7782
}
7883

7984
fn main() -> anyhow::Result<()> {
8085
let args = Args::parse();
8186

82-
let rpc_client = args.client()?;
87+
let rpc_client = Arc::new(args.client()?);
8388
println!(
8489
"Connected to Bitcoin Core RPC at {:?}",
8590
rpc_client.get_blockchain_info().unwrap()
8691
);
8792

8893
let start_load_wallet = Instant::now();
89-
let mut db =
90-
Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), args.db_path)?;
94+
let (mut db, _) =
95+
Store::<bdk_wallet::ChangeSet>::load_or_create(DB_MAGIC.as_bytes(), args.db_path)?;
9196
let wallet_opt = Wallet::load()
9297
.descriptor(KeychainKind::External, Some(args.descriptor.clone()))
9398
.descriptor(KeychainKind::Internal, args.change_descriptor.clone())
@@ -129,9 +134,15 @@ fn main() -> anyhow::Result<()> {
129134
.expect("failed to send sigterm")
130135
});
131136

132-
let emitter_tip = wallet_tip.clone();
137+
let mut emitter = Emitter::new(
138+
rpc_client,
139+
wallet_tip,
140+
args.start_height,
141+
wallet
142+
.transactions()
143+
.filter(|tx| tx.chain_position.is_unconfirmed()),
144+
);
133145
spawn(move || -> Result<(), anyhow::Error> {
134-
let mut emitter = Emitter::new(&rpc_client, emitter_tip, args.start_height);
135146
while let Some(emission) = emitter.next_block()? {
136147
sender.send(Emission::Block(emission))?;
137148
}
@@ -160,9 +171,10 @@ fn main() -> anyhow::Result<()> {
160171
hash, height, elapsed
161172
);
162173
}
163-
Emission::Mempool(mempool_emission) => {
174+
Emission::Mempool(event) => {
164175
let start_apply_mempool = Instant::now();
165-
wallet.apply_unconfirmed_txs(mempool_emission);
176+
wallet.apply_evicted_txs(event.evicted_ats());
177+
wallet.apply_unconfirmed_txs(event.new_txs);
166178
wallet.persist(&mut db)?;
167179
println!(
168180
"Applied unconfirmed transactions in {}s",

wallet/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ miniscript = { version = "12.3.1", features = [ "serde" ], default-features = fa
2121
bitcoin = { version = "0.32.4", features = [ "serde", "base64" ], default-features = false }
2222
serde = { version = "^1.0", features = ["derive"] }
2323
serde_json = { version = "^1.0" }
24-
bdk_chain = { version = "0.21.1", features = [ "miniscript", "serde" ], default-features = false }
25-
bdk_file_store = { version = "0.18.1", optional = true }
24+
bdk_chain = { version = "0.22.0", features = [ "miniscript", "serde" ], default-features = false }
2625

2726
# Optional dependencies
2827
bip39 = { version = "2.0", optional = true }
28+
bdk_file_store = { version = "0.20.0", optional = true }
2929

3030
[features]
3131
default = ["std"]
@@ -40,9 +40,8 @@ test-utils = ["std"]
4040
[dev-dependencies]
4141
assert_matches = "1.5.0"
4242
tempfile = "3"
43-
bdk_chain = { version = "0.21.1", features = ["rusqlite"] }
43+
bdk_chain = { version = "0.22.0", features = ["rusqlite"] }
4444
bdk_wallet = { path = ".", features = ["rusqlite", "file_store", "test-utils"] }
45-
bdk_file_store = { version = "0.18.1" }
4645
anyhow = "1"
4746
rand = "^0.8"
4847

wallet/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ To persist `Wallet` state data use a data store crate that reads and writes [`Ch
6565

6666
**Example**
6767

68-
<!-- compile_fail because outpoint and txout are fake variables -->
6968
```rust,no_run
7069
use bdk_wallet::{bitcoin::Network, KeychainKind, ChangeSet, Wallet};
7170
7271
// Open or create a new file store for wallet data.
73-
let mut db =
74-
bdk_file_store::Store::<ChangeSet>::open_or_create_new(b"magic_bytes", "/tmp/my_wallet.db")
72+
let (mut db, _changeset) =
73+
bdk_file_store::Store::<ChangeSet>::load_or_create(b"magic_bytes", "/tmp/my_wallet.db")
7574
.expect("create store");
7675
7776
// Create a wallet with initial wallet data read from the file store.

wallet/src/test_utils.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloc::string::ToString;
44
use alloc::sync::Arc;
55
use core::str::FromStr;
66

7-
use bdk_chain::{tx_graph, BlockId, ConfirmationBlockTime};
7+
use bdk_chain::{BlockId, ConfirmationBlockTime, TxUpdate};
88
use bitcoin::{
99
absolute, hashes::Hash, transaction, Address, Amount, BlockHash, FeeRate, Network, OutPoint,
1010
Transaction, TxIn, TxOut, Txid,
@@ -312,43 +312,45 @@ pub fn insert_checkpoint(wallet: &mut Wallet, block: BlockId) {
312312
.unwrap();
313313
}
314314

315-
/// Insert transaction
315+
/// Inserts a transaction into the local view, assuming it is currently present in the mempool.
316+
///
317+
/// This can be used, for example, to track a transaction immediately after it is broadcast.
316318
pub fn insert_tx(wallet: &mut Wallet, tx: Transaction) {
319+
let txid = tx.compute_txid();
320+
let seen_at = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
321+
let mut tx_update = TxUpdate::default();
322+
tx_update.txs = vec![Arc::new(tx)];
323+
tx_update.seen_ats = [(txid, seen_at)].into();
317324
wallet
318325
.apply_update(Update {
319-
tx_update: bdk_chain::TxUpdate {
320-
txs: vec![Arc::new(tx)],
321-
..Default::default()
322-
},
326+
tx_update,
323327
..Default::default()
324328
})
325-
.unwrap();
329+
.expect("failed to apply update");
326330
}
327331

328332
/// Simulates confirming a tx with `txid` by applying an update to the wallet containing
329333
/// the given `anchor`. Note: to be considered confirmed the anchor block must exist in
330334
/// the current active chain.
331335
pub fn insert_anchor(wallet: &mut Wallet, txid: Txid, anchor: ConfirmationBlockTime) {
336+
let mut tx_update = TxUpdate::default();
337+
tx_update.anchors = [(anchor, txid)].into();
332338
wallet
333339
.apply_update(Update {
334-
tx_update: tx_graph::TxUpdate {
335-
anchors: [(anchor, txid)].into(),
336-
..Default::default()
337-
},
340+
tx_update,
338341
..Default::default()
339342
})
340-
.unwrap();
343+
.expect("failed to apply update");
341344
}
342345

343346
/// Marks the given `txid` seen as unconfirmed at `seen_at`
344347
pub fn insert_seen_at(wallet: &mut Wallet, txid: Txid, seen_at: u64) {
348+
let mut tx_update = TxUpdate::default();
349+
tx_update.seen_ats = [(txid, seen_at)].into();
345350
wallet
346-
.apply_update(crate::Update {
347-
tx_update: tx_graph::TxUpdate {
348-
seen_ats: [(txid, seen_at)].into_iter().collect(),
349-
..Default::default()
350-
},
351+
.apply_update(Update {
352+
tx_update,
351353
..Default::default()
352354
})
353-
.unwrap();
355+
.expect("failed to apply update");
354356
}

0 commit comments

Comments
 (0)