Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bitcoind_rpc/examples/filter_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn main() -> anyhow::Result<()> {
println!("Local tip: {}", chain.tip().height());

let canonical_view =
chain.canonical_view(graph.graph(), chain.tip().block_id(), Default::default());
chain.canonicalize(graph.graph(), chain.tip().block_id(), Default::default());

let unspent: Vec<_> = canonical_view
.filter_unspent_outpoints(graph.index.outpoints().clone())
Expand Down
8 changes: 4 additions & 4 deletions crates/bitcoind_rpc/tests/test_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn get_balance(
) -> anyhow::Result<Balance> {
let outpoints = recv_graph.index.outpoints().clone();
let balance = recv_chain
.canonical_view(
.canonicalize(
recv_graph.graph(),
recv_chain.tip().block_id(),
Default::default(),
Expand All @@ -331,7 +331,7 @@ fn get_balance(
outpoints.into_iter().map(|(_, op)| op),
bdk_chain::taints_unowned(&recv_graph.index),
|pos| pos.is_confirmed(),
|_txout| false,
|_txout| Default::default(),
);
Ok(balance)
}
Expand Down Expand Up @@ -642,7 +642,7 @@ fn test_expect_tx_evicted() -> anyhow::Result<()> {

// Retrieve the expected unconfirmed txids and spks from the graph.
let exp_spk_txids = chain
.canonical_view(graph.graph(), chain_tip, Default::default())
.canonicalize(graph.graph(), chain_tip, Default::default())
.list_expected_spk_txids(&graph.index, ..)
.collect::<Vec<_>>();
assert_eq!(exp_spk_txids, vec![(spk, txid_1)]);
Expand All @@ -658,7 +658,7 @@ fn test_expect_tx_evicted() -> anyhow::Result<()> {
let _ = graph.batch_insert_relevant_evicted_at(mempool_event.evicted);

let canonical_txids = chain
.canonical_view(graph.graph(), chain_tip, Default::default())
.canonicalize(graph.graph(), chain_tip, Default::default())
.txs()
.map(|tx| tx.txid)
.collect::<Vec<_>>();
Expand Down
6 changes: 3 additions & 3 deletions crates/chain/benches/canonicalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ fn setup<F: Fn(&mut KeychainTxGraph, &LocalChain)>(f: F) -> (KeychainTxGraph, Lo
}

fn run_list_canonical_txs(tx_graph: &KeychainTxGraph, chain: &LocalChain, exp_txs: usize) {
let view = chain.canonical_view(tx_graph.graph(), chain.tip().block_id(), Default::default());
let view = chain.canonicalize(tx_graph.graph(), chain.tip().block_id(), Default::default());
let txs = view.txs();
assert_eq!(txs.count(), exp_txs);
}

fn run_filter_chain_txouts(tx_graph: &KeychainTxGraph, chain: &LocalChain, exp_txos: usize) {
let view = chain.canonical_view(tx_graph.graph(), chain.tip().block_id(), Default::default());
let view = chain.canonicalize(tx_graph.graph(), chain.tip().block_id(), Default::default());
let utxos = view.filter_outpoints(tx_graph.index.outpoints().clone());
assert_eq!(utxos.count(), exp_txos);
}

fn run_filter_chain_unspents(tx_graph: &KeychainTxGraph, chain: &LocalChain, exp_utxos: usize) {
let view = chain.canonical_view(tx_graph.graph(), chain.tip().block_id(), Default::default());
let view = chain.canonicalize(tx_graph.graph(), chain.tip().block_id(), Default::default());
let utxos = view.filter_unspent_outpoints(tx_graph.index.outpoints().clone());
assert_eq!(utxos.count(), exp_utxos);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/chain/benches/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ fn do_bench(indexed_tx_graph: &KeychainTxGraph, chain: &LocalChain) {
// Check balance
let op = graph.index.outpoints().clone();
let bal = chain
.canonical_view(graph.graph(), chain.tip().block_id(), Default::default())
.canonicalize(graph.graph(), chain.tip().block_id(), Default::default())
.balance(
op.into_iter().map(|(_, o)| o),
bdk_chain::taints_unowned(&graph.index),
|pos| pos.is_confirmed(),
|_txout| false,
|_txout| Default::default(),
);
assert_eq!(bal.total(), AMOUNT * TX_CT as u64);
}
Expand Down
28 changes: 15 additions & 13 deletions crates/chain/benches/trust_classification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use std::collections::BTreeMap;

use bdk_chain::{
local_chain::LocalChain, CanonicalView, ChainPosition, ConfirmationBlockTime, TxGraph,
local_chain::LocalChain, CanonicalView, ChainPosition, ConfirmationBlockTime, Timelocks,
TxGraph,
};
use bdk_testenv::{hash, utils::new_tx};
use bitcoin::{Amount, BlockHash, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut, Txid};
Expand All @@ -23,15 +24,15 @@ fn make_chain() -> LocalChain {

// The three predicates `classify_outpoints` takes, faking what a wallet would pass:
// `does_taint` = the tx pulls in coins that aren't ours; `is_settled` = the tx is confirmed;
// `is_locked` = the tx has timelocked outputs.
// `timelocks` = no output is timelocked.
#[allow(clippy::type_complexity)]
fn classify_outpoints_predicates<'a>(
view: &'a CanonicalView<ConfirmationBlockTime>,
owned: &ScriptBuf,
) -> (
impl FnMut(&bdk_chain::CanonicalTx<ChainPosition<ConfirmationBlockTime>>) -> bool + 'a,
impl Fn(&ChainPosition<ConfirmationBlockTime>) -> bool,
impl Fn(&bdk_chain::CanonicalTxOut<ChainPosition<ConfirmationBlockTime>>) -> bool,
impl Fn(&bdk_chain::CanonicalTxOut<ChainPosition<ConfirmationBlockTime>>) -> Timelocks,
) {
let owned = owned.clone();
let is_mine = move |spk: &Script| spk == owned.as_script();
Expand All @@ -50,10 +51,11 @@ fn classify_outpoints_predicates<'a>(
let is_settled =
|pos: &ChainPosition<ConfirmationBlockTime>| matches!(pos, ChainPosition::Confirmed { .. });

let is_locked =
|_txout: &bdk_chain::CanonicalTxOut<ChainPosition<ConfirmationBlockTime>>| false;
let timelocks = |_txout: &bdk_chain::CanonicalTxOut<ChainPosition<ConfirmationBlockTime>>| {
Timelocks::default()
};

(does_taint, is_settled, is_locked)
(does_taint, is_settled, timelocks)
}

// Per-UTXO memoized classification (`classify_outpoints`).
Expand All @@ -63,8 +65,8 @@ fn run_classify(
owned: &ScriptBuf,
) {
let outpoints = utxo_txids.iter().map(|&txid| OutPoint::new(txid, 0));
let (does_taint, is_settled, is_locked) = classify_outpoints_predicates(view, owned);
for item in view.classify_outpoints(outpoints, does_taint, is_settled, is_locked) {
let (does_taint, is_settled, timelocks) = classify_outpoints_predicates(view, owned);
for item in view.classify_outpoints(outpoints, does_taint, is_settled, timelocks) {
std::hint::black_box(item);
}
}
Expand Down Expand Up @@ -420,7 +422,7 @@ fn bench_fan_in(c: &mut Criterion) {
for (width, depth) in [(10, 3), (50, 5), (100, 10), (500, 20)] {
let label = format!("{width}w×{depth}d");
let (chain, tx_graph, utxo_txids, owned) = setup_fan_in(width, depth);
let view = chain.canonical_view(&tx_graph, chain.tip().block_id(), Default::default());
let view = chain.canonicalize(&tx_graph, chain.tip().block_id(), Default::default());
group.bench_with_input(BenchmarkId::new("classify", &label), &(), |b, _| {
b.iter(|| run_classify(&utxo_txids, &view, &owned));
});
Expand All @@ -433,7 +435,7 @@ fn bench_disjoint(c: &mut Criterion) {
for (width, depth) in [(10, 3), (50, 5), (100, 10), (500, 20)] {
let label = format!("{width}w×{depth}d");
let (chain, tx_graph, utxo_txids, owned) = setup_disjoint(width, depth);
let view = chain.canonical_view(&tx_graph, chain.tip().block_id(), Default::default());
let view = chain.canonicalize(&tx_graph, chain.tip().block_id(), Default::default());
group.bench_with_input(BenchmarkId::new("classify", &label), &(), |b, _| {
b.iter(|| run_classify(&utxo_txids, &view, &owned));
});
Expand All @@ -446,7 +448,7 @@ fn bench_untrusted_fan_in(c: &mut Criterion) {
for (width, depth) in [(10, 3), (50, 5), (100, 10), (500, 20)] {
let label = format!("{width}w×{depth}d");
let (chain, tx_graph, utxo_txids, owned) = setup_untrusted_fan_in(width, depth);
let view = chain.canonical_view(&tx_graph, chain.tip().block_id(), Default::default());
let view = chain.canonicalize(&tx_graph, chain.tip().block_id(), Default::default());
group.bench_with_input(BenchmarkId::new("classify", &label), &(), |b, _| {
b.iter(|| run_classify(&utxo_txids, &view, &owned));
});
Expand All @@ -459,7 +461,7 @@ fn bench_diamond(c: &mut Criterion) {
for (shared, utxos) in [(5, 20), (10, 50), (20, 100), (50, 500)] {
let label = format!("{shared}s×{utxos}u");
let (chain, tx_graph, utxo_txids, owned) = setup_diamond(shared, utxos);
let view = chain.canonical_view(&tx_graph, chain.tip().block_id(), Default::default());
let view = chain.canonicalize(&tx_graph, chain.tip().block_id(), Default::default());
group.bench_with_input(BenchmarkId::new("classify", &label), &(), |b, _| {
b.iter(|| run_classify(&utxo_txids, &view, &owned));
});
Expand All @@ -472,7 +474,7 @@ fn bench_tainted_midchain(c: &mut Criterion) {
for (width, depth) in [(10, 3), (50, 5), (100, 10), (500, 20)] {
let label = format!("{width}w×{depth}d");
let (chain, tx_graph, utxo_txids, owned) = setup_tainted_midchain(width, depth);
let view = chain.canonical_view(&tx_graph, chain.tip().block_id(), Default::default());
let view = chain.canonicalize(&tx_graph, chain.tip().block_id(), Default::default());
group.bench_with_input(BenchmarkId::new("classify", &label), &(), |b, _| {
b.iter(|| run_classify(&utxo_txids, &view, &owned));
});
Expand Down
Loading
Loading