@@ -3,54 +3,20 @@ use bdk_chain::{keychain_txout::KeychainTxOutIndex, local_chain::LocalChain, Ind
33use bdk_core:: { BlockId , CheckPoint } ;
44use bdk_core:: { ConfirmationBlockTime , TxUpdate } ;
55use bdk_testenv:: hash;
6- use bitcoin:: {
7- absolute, constants, hashes:: Hash , key:: Secp256k1 , transaction, Amount , BlockHash , Network ,
8- OutPoint , ScriptBuf , Transaction , TxIn , TxOut ,
9- } ;
6+ use bdk_testenv:: utils:: { genesis_block_id, new_standard_tx, spk_at_index, tip_block_id} ;
7+ use bitcoin:: { key:: Secp256k1 , Amount , OutPoint , Transaction , TxIn , TxOut } ;
108use criterion:: { criterion_group, criterion_main, Criterion } ;
119use miniscript:: { Descriptor , DescriptorPublicKey } ;
1210use std:: sync:: Arc ;
1311
1412type Keychain = ( ) ;
1513type KeychainTxGraph = IndexedTxGraph < ConfirmationBlockTime , KeychainTxOutIndex < Keychain > > ;
1614
17- /// New tx guaranteed to have at least one output
18- fn new_tx ( lt : u32 ) -> Transaction {
19- Transaction {
20- version : transaction:: Version :: TWO ,
21- lock_time : absolute:: LockTime :: from_consensus ( lt) ,
22- input : vec ! [ ] ,
23- output : vec ! [ TxOut :: NULL ] ,
24- }
25- }
26-
27- fn spk_at_index ( txout_index : & KeychainTxOutIndex < Keychain > , index : u32 ) -> ScriptBuf {
28- txout_index
29- . get_descriptor ( ( ) )
30- . unwrap ( )
31- . at_derivation_index ( index)
32- . unwrap ( )
33- . script_pubkey ( )
34- }
35-
36- fn genesis_block_id ( ) -> BlockId {
37- BlockId {
38- height : 0 ,
39- hash : constants:: genesis_block ( Network :: Regtest ) . block_hash ( ) ,
40- }
41- }
42-
43- fn tip_block_id ( ) -> BlockId {
44- BlockId {
45- height : 100 ,
46- hash : BlockHash :: all_zeros ( ) ,
47- }
48- }
49-
5015/// Add ancestor tx confirmed at `block_id` with `locktime` (used for uniqueness).
5116/// The transaction always pays 1 BTC to SPK 0.
5217fn add_ancestor_tx ( graph : & mut KeychainTxGraph , block_id : BlockId , locktime : u32 ) -> OutPoint {
53- let spk_0 = spk_at_index ( & graph. index , 0 ) ;
18+ let descriptor = graph. index . get_descriptor ( ( ) ) . unwrap ( ) ;
19+ let spk_0 = spk_at_index ( descriptor, 0 ) ;
5420 let tx = Transaction {
5521 input : vec ! [ TxIn {
5622 previous_output: OutPoint :: new( hash!( "bogus" ) , locktime) ,
@@ -60,7 +26,7 @@ fn add_ancestor_tx(graph: &mut KeychainTxGraph, block_id: BlockId, locktime: u32
6026 value: Amount :: ONE_BTC ,
6127 script_pubkey: spk_0,
6228 } ] ,
63- ..new_tx ( locktime)
29+ ..new_standard_tx ( locktime)
6430 } ;
6531 let txid = tx. compute_txid ( ) ;
6632 let _ = graph. insert_tx ( tx) ;
@@ -77,7 +43,7 @@ fn add_ancestor_tx(graph: &mut KeychainTxGraph, block_id: BlockId, locktime: u32
7743fn setup < F : Fn ( & mut KeychainTxGraph , & LocalChain ) > ( f : F ) -> ( KeychainTxGraph , LocalChain ) {
7844 const DESC : & str = "tr([ab28dc00/86h/1h/0h]tpubDCdDtzAMZZrkwKBxwNcGCqe4FRydeD9rfMisoi7qLdraG79YohRfPW4YgdKQhpgASdvh612xXNY5xYzoqnyCgPbkpK4LSVcH5Xv4cK7johH/0/*)" ;
7945 let cp = CheckPoint :: from_blocks (
80- [ genesis_block_id ( ) , tip_block_id ( ) ]
46+ [ genesis_block_id ( ) , tip_block_id ( 100 ) ]
8147 . into_iter ( )
8248 . map ( |block_id| ( block_id. height , block_id. hash ) ) ,
8349 )
@@ -127,9 +93,10 @@ fn run_filter_chain_unspents(tx_graph: &KeychainTxGraph, chain: &LocalChain, exp
12793pub fn many_conflicting_unconfirmed ( c : & mut Criterion ) {
12894 const CONFLICTING_TX_COUNT : u32 = 2100 ;
12995 let ( tx_graph, chain) = std:: hint:: black_box ( setup ( |tx_graph, _chain| {
130- let previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( ) , 0 ) ;
96+ let previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( 100 ) , 0 ) ;
97+ let descriptor = tx_graph. index . get_descriptor ( ( ) ) . unwrap ( ) ;
13198 // Create conflicting txs that spend from `previous_output`.
132- let spk_1 = spk_at_index ( & tx_graph . index , 1 ) ;
99+ let spk_1 = spk_at_index ( descriptor , 1 ) ;
133100 for i in 1 ..=CONFLICTING_TX_COUNT {
134101 let tx = Transaction {
135102 input : vec ! [ TxIn {
@@ -140,7 +107,7 @@ pub fn many_conflicting_unconfirmed(c: &mut Criterion) {
140107 value: Amount :: ONE_BTC - Amount :: from_sat( i as u64 * 10 ) ,
141108 script_pubkey: spk_1. clone( ) ,
142109 } ] ,
143- ..new_tx ( i)
110+ ..new_standard_tx ( i)
144111 } ;
145112 let mut update = TxUpdate :: default ( ) ;
146113 update. seen_ats = [ ( tx. compute_txid ( ) , i as u64 ) ] . into ( ) ;
@@ -165,7 +132,7 @@ pub fn many_conflicting_unconfirmed(c: &mut Criterion) {
165132pub fn many_chained_unconfirmed ( c : & mut Criterion ) {
166133 const TX_CHAIN_COUNT : u32 = 2100 ;
167134 let ( tx_graph, chain) = std:: hint:: black_box ( setup ( |tx_graph, _chain| {
168- let mut previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( ) , 0 ) ;
135+ let mut previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( 100 ) , 0 ) ;
169136 // Create a chain of unconfirmed txs where each subsequent tx spends the output of the
170137 // previous one.
171138 for i in 0 ..TX_CHAIN_COUNT {
@@ -175,7 +142,7 @@ pub fn many_chained_unconfirmed(c: &mut Criterion) {
175142 previous_output,
176143 ..Default :: default ( )
177144 } ] ,
178- ..new_tx ( i)
145+ ..new_standard_tx ( i)
179146 } ;
180147 let txid = tx. compute_txid ( ) ;
181148 let mut update = TxUpdate :: default ( ) ;
@@ -204,7 +171,7 @@ pub fn nested_conflicts(c: &mut Criterion) {
204171 const CONFLICTS_PER_OUTPUT : usize = 3 ;
205172 const GRAPH_DEPTH : usize = 7 ;
206173 let ( tx_graph, chain) = std:: hint:: black_box ( setup ( |tx_graph, _chain| {
207- let mut prev_ops = core:: iter:: once ( add_ancestor_tx ( tx_graph, tip_block_id ( ) , 0 ) )
174+ let mut prev_ops = core:: iter:: once ( add_ancestor_tx ( tx_graph, tip_block_id ( 100 ) , 0 ) )
208175 . collect :: < Vec < OutPoint > > ( ) ;
209176 for depth in 1 ..GRAPH_DEPTH {
210177 for previous_output in core:: mem:: take ( & mut prev_ops) {
@@ -225,7 +192,7 @@ pub fn nested_conflicts(c: &mut Criterion) {
225192 value,
226193 script_pubkey,
227194 } ] ,
228- ..new_tx ( conflict_i as _ )
195+ ..new_standard_tx ( conflict_i as _ )
229196 } ;
230197 let txid = tx. compute_txid ( ) ;
231198 prev_ops. push ( OutPoint :: new ( txid, 0 ) ) ;
0 commit comments