@@ -2,54 +2,20 @@ use bdk_chain::{keychain_txout::KeychainTxOutIndex, local_chain::LocalChain, Ind
22use bdk_core:: { BlockId , CheckPoint } ;
33use bdk_core:: { ConfirmationBlockTime , TxUpdate } ;
44use bdk_testenv:: hash;
5- use bitcoin:: {
6- absolute, constants, hashes:: Hash , key:: Secp256k1 , transaction, Amount , BlockHash , Network ,
7- OutPoint , ScriptBuf , Transaction , TxIn , TxOut ,
8- } ;
5+ use bdk_testenv:: utils:: { genesis_block_id, new_standard_tx, spk_at_index, tip_block_id} ;
6+ use bitcoin:: { key:: Secp256k1 , Amount , OutPoint , Transaction , TxIn , TxOut } ;
97use criterion:: { criterion_group, criterion_main, Criterion } ;
108use miniscript:: { Descriptor , DescriptorPublicKey } ;
119use std:: sync:: Arc ;
1210
1311type Keychain = ( ) ;
1412type KeychainTxGraph = IndexedTxGraph < ConfirmationBlockTime , KeychainTxOutIndex < Keychain > > ;
1513
16- /// New tx guaranteed to have at least one output
17- fn new_tx ( lt : u32 ) -> Transaction {
18- Transaction {
19- version : transaction:: Version :: TWO ,
20- lock_time : absolute:: LockTime :: from_consensus ( lt) ,
21- input : vec ! [ ] ,
22- output : vec ! [ TxOut :: NULL ] ,
23- }
24- }
25-
26- fn spk_at_index ( txout_index : & KeychainTxOutIndex < Keychain > , index : u32 ) -> ScriptBuf {
27- txout_index
28- . get_descriptor ( ( ) )
29- . unwrap ( )
30- . at_derivation_index ( index)
31- . unwrap ( )
32- . script_pubkey ( )
33- }
34-
35- fn genesis_block_id ( ) -> BlockId {
36- BlockId {
37- height : 0 ,
38- hash : constants:: genesis_block ( Network :: Regtest ) . block_hash ( ) ,
39- }
40- }
41-
42- fn tip_block_id ( ) -> BlockId {
43- BlockId {
44- height : 100 ,
45- hash : BlockHash :: all_zeros ( ) ,
46- }
47- }
48-
4914/// Add ancestor tx confirmed at `block_id` with `locktime` (used for uniqueness).
5015/// The transaction always pays 1 BTC to SPK 0.
5116fn add_ancestor_tx ( graph : & mut KeychainTxGraph , block_id : BlockId , locktime : u32 ) -> OutPoint {
52- let spk_0 = spk_at_index ( & graph. index , 0 ) ;
17+ let descriptor = graph. index . get_descriptor ( ( ) ) . unwrap ( ) ;
18+ let spk_0 = spk_at_index ( descriptor, 0 ) ;
5319 let tx = Transaction {
5420 input : vec ! [ TxIn {
5521 previous_output: OutPoint :: new( hash!( "bogus" ) , locktime) ,
@@ -59,7 +25,7 @@ fn add_ancestor_tx(graph: &mut KeychainTxGraph, block_id: BlockId, locktime: u32
5925 value: Amount :: ONE_BTC ,
6026 script_pubkey: spk_0,
6127 } ] ,
62- ..new_tx ( locktime)
28+ ..new_standard_tx ( locktime)
6329 } ;
6430 let txid = tx. compute_txid ( ) ;
6531 let _ = graph. insert_tx ( tx) ;
@@ -76,7 +42,7 @@ fn add_ancestor_tx(graph: &mut KeychainTxGraph, block_id: BlockId, locktime: u32
7642fn setup < F : Fn ( & mut KeychainTxGraph , & LocalChain ) > ( f : F ) -> ( KeychainTxGraph , LocalChain ) {
7743 const DESC : & str = "tr([ab28dc00/86h/1h/0h]tpubDCdDtzAMZZrkwKBxwNcGCqe4FRydeD9rfMisoi7qLdraG79YohRfPW4YgdKQhpgASdvh612xXNY5xYzoqnyCgPbkpK4LSVcH5Xv4cK7johH/0/*)" ;
7844 let cp = CheckPoint :: from_blocks (
79- [ genesis_block_id ( ) , tip_block_id ( ) ]
45+ [ genesis_block_id ( ) , tip_block_id ( 100 ) ]
8046 . into_iter ( )
8147 . map ( |block_id| ( block_id. height , block_id. hash ) ) ,
8248 )
@@ -114,9 +80,10 @@ fn run_filter_chain_unspents(tx_graph: &KeychainTxGraph, chain: &LocalChain, exp
11480pub fn many_conflicting_unconfirmed ( c : & mut Criterion ) {
11581 const CONFLICTING_TX_COUNT : u32 = 2100 ;
11682 let ( tx_graph, chain) = std:: hint:: black_box ( setup ( |tx_graph, _chain| {
117- let previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( ) , 0 ) ;
83+ let previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( 100 ) , 0 ) ;
84+ let descriptor = tx_graph. index . get_descriptor ( ( ) ) . unwrap ( ) ;
11885 // Create conflicting txs that spend from `previous_output`.
119- let spk_1 = spk_at_index ( & tx_graph . index , 1 ) ;
86+ let spk_1 = spk_at_index ( descriptor , 1 ) ;
12087 for i in 1 ..=CONFLICTING_TX_COUNT {
12188 let tx = Transaction {
12289 input : vec ! [ TxIn {
@@ -127,7 +94,7 @@ pub fn many_conflicting_unconfirmed(c: &mut Criterion) {
12794 value: Amount :: ONE_BTC - Amount :: from_sat( i as u64 * 10 ) ,
12895 script_pubkey: spk_1. clone( ) ,
12996 } ] ,
130- ..new_tx ( i)
97+ ..new_standard_tx ( i)
13198 } ;
13299 let mut update = TxUpdate :: default ( ) ;
133100 update. seen_ats = [ ( tx. compute_txid ( ) , i as u64 ) ] . into ( ) ;
@@ -152,7 +119,7 @@ pub fn many_conflicting_unconfirmed(c: &mut Criterion) {
152119pub fn many_chained_unconfirmed ( c : & mut Criterion ) {
153120 const TX_CHAIN_COUNT : u32 = 2100 ;
154121 let ( tx_graph, chain) = std:: hint:: black_box ( setup ( |tx_graph, _chain| {
155- let mut previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( ) , 0 ) ;
122+ let mut previous_output = add_ancestor_tx ( tx_graph, tip_block_id ( 100 ) , 0 ) ;
156123 // Create a chain of unconfirmed txs where each subsequent tx spends the output of the
157124 // previous one.
158125 for i in 0 ..TX_CHAIN_COUNT {
@@ -162,7 +129,7 @@ pub fn many_chained_unconfirmed(c: &mut Criterion) {
162129 previous_output,
163130 ..Default :: default ( )
164131 } ] ,
165- ..new_tx ( i)
132+ ..new_standard_tx ( i)
166133 } ;
167134 let txid = tx. compute_txid ( ) ;
168135 let mut update = TxUpdate :: default ( ) ;
@@ -191,7 +158,7 @@ pub fn nested_conflicts(c: &mut Criterion) {
191158 const CONFLICTS_PER_OUTPUT : usize = 3 ;
192159 const GRAPH_DEPTH : usize = 7 ;
193160 let ( tx_graph, chain) = std:: hint:: black_box ( setup ( |tx_graph, _chain| {
194- let mut prev_ops = core:: iter:: once ( add_ancestor_tx ( tx_graph, tip_block_id ( ) , 0 ) )
161+ let mut prev_ops = core:: iter:: once ( add_ancestor_tx ( tx_graph, tip_block_id ( 100 ) , 0 ) )
195162 . collect :: < Vec < OutPoint > > ( ) ;
196163 for depth in 1 ..GRAPH_DEPTH {
197164 for previous_output in core:: mem:: take ( & mut prev_ops) {
@@ -212,7 +179,7 @@ pub fn nested_conflicts(c: &mut Criterion) {
212179 value,
213180 script_pubkey,
214181 } ] ,
215- ..new_tx ( conflict_i as _ )
182+ ..new_standard_tx ( conflict_i as _ )
216183 } ;
217184 let txid = tx. compute_txid ( ) ;
218185 prev_ops. push ( OutPoint :: new ( txid, 0 ) ) ;
0 commit comments