@@ -157,28 +157,6 @@ impl TestEnv {
157157    } 
158158} 
159159
160- fn  block_to_chain_update ( block :  & bitcoin:: Block ,  height :  u32 )  -> local_chain:: Update  { 
161-     let  this_id = BlockId  { 
162-         height, 
163-         hash :  block. block_hash ( ) , 
164-     } ; 
165-     let  tip = if  block. header . prev_blockhash  == BlockHash :: all_zeros ( )  { 
166-         CheckPoint :: new ( this_id) 
167-     }  else  { 
168-         CheckPoint :: new ( BlockId  { 
169-             height :  height - 1 , 
170-             hash :  block. header . prev_blockhash , 
171-         } ) 
172-         . extend ( core:: iter:: once ( this_id) ) 
173-         . expect ( "must construct checkpoint" ) 
174-     } ; 
175- 
176-     local_chain:: Update  { 
177-         tip, 
178-         introduce_older_blocks :  false , 
179-     } 
180- } 
181- 
182160/// Ensure that blocks are emitted in order even after reorg. 
183161/// 
184162/// 1. Mine 101 blocks. 
@@ -200,17 +178,21 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
200178
201179    // see if the emitter outputs the right blocks 
202180    println ! ( "first sync:" ) ; 
203-     while  let  Some ( ( height,  block) )  = emitter. next_block ( ) ? { 
181+     while  let  Some ( emission)  = emitter. next_block ( ) ? { 
182+         let  height = emission. block_height ( ) ; 
183+         let  hash = emission. block_hash ( ) ; 
204184        assert_eq ! ( 
205-             block . block_hash( ) , 
185+             emission . block_hash( ) , 
206186            exp_hashes[ height as  usize ] , 
207187            "emitted block hash is unexpected" 
208188        ) ; 
209189
210-         let  chain_update = block_to_chain_update ( & block,  height) ; 
211190        assert_eq ! ( 
212-             local_chain. apply_update( chain_update) ?, 
213-             BTreeMap :: from( [ ( height,  Some ( block. block_hash( ) ) ) ] ) , 
191+             local_chain. apply_update( local_chain:: Update  { 
192+                 tip:  emission. checkpoint, 
193+                 introduce_older_blocks:  false , 
194+             } ) ?, 
195+             BTreeMap :: from( [ ( height,  Some ( hash) ) ] ) , 
214196            "chain update changeset is unexpected" , 
215197        ) ; 
216198    } 
@@ -237,27 +219,30 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
237219    // see if the emitter outputs the right blocks 
238220    println ! ( "after reorg:" ) ; 
239221    let  mut  exp_height = exp_hashes. len ( )  - reorged_blocks. len ( ) ; 
240-     while  let  Some ( ( height,  block) )  = emitter. next_block ( ) ? { 
222+     while  let  Some ( emission)  = emitter. next_block ( ) ? { 
223+         let  height = emission. block_height ( ) ; 
224+         let  hash = emission. block_hash ( ) ; 
241225        assert_eq ! ( 
242226            height,  exp_height as  u32 , 
243227            "emitted block has unexpected height" 
244228        ) ; 
245229
246230        assert_eq ! ( 
247-             block. block_hash( ) , 
248-             exp_hashes[ height as  usize ] , 
231+             hash,  exp_hashes[ height as  usize ] , 
249232            "emitted block is unexpected" 
250233        ) ; 
251234
252-         let  chain_update = block_to_chain_update ( & block,  height) ; 
253235        assert_eq ! ( 
254-             local_chain. apply_update( chain_update) ?, 
236+             local_chain. apply_update( local_chain:: Update  { 
237+                 tip:  emission. checkpoint, 
238+                 introduce_older_blocks:  false , 
239+             } ) ?, 
255240            if  exp_height == exp_hashes. len( )  - reorged_blocks. len( )  { 
256-                 core:: iter:: once( ( height,  Some ( block . block_hash ( ) ) ) ) 
241+                 core:: iter:: once( ( height,  Some ( hash ) ) ) 
257242                    . chain( ( height + 1 ..exp_hashes. len( )  as  u32 ) . map( |h| ( h,  None ) ) ) 
258243                    . collect:: <bdk_chain:: local_chain:: ChangeSet >( ) 
259244            }  else { 
260-                 BTreeMap :: from( [ ( height,  Some ( block . block_hash ( ) ) ) ] ) 
245+                 BTreeMap :: from( [ ( height,  Some ( hash ) ) ] ) 
261246            } , 
262247            "chain update changeset is unexpected" , 
263248        ) ; 
@@ -307,9 +292,13 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
307292
308293    let  emitter = & mut  Emitter :: new ( & env. client ,  chain. tip ( ) ,  0 ) ; 
309294
310-     while  let  Some ( ( height,  block) )  = emitter. next_block ( ) ? { 
311-         let  _ = chain. apply_update ( block_to_chain_update ( & block,  height) ) ?; 
312-         let  indexed_additions = indexed_tx_graph. apply_block_relevant ( block,  height) ; 
295+     while  let  Some ( emission)  = emitter. next_block ( ) ? { 
296+         let  height = emission. block_height ( ) ; 
297+         let  _ = chain. apply_update ( local_chain:: Update  { 
298+             tip :  emission. checkpoint , 
299+             introduce_older_blocks :  false , 
300+         } ) ?; 
301+         let  indexed_additions = indexed_tx_graph. apply_block_relevant ( emission. block ,  height) ; 
313302        assert ! ( indexed_additions. is_empty( ) ) ; 
314303    } 
315304
@@ -367,10 +356,13 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
367356
368357    // must receive mined block which will confirm the transactions. 
369358    { 
370-         let  ( height,  block)  = emitter. next_block ( ) ?. expect ( "must get mined block" ) ; 
371-         let  _ = chain
372-             . apply_update ( CheckPoint :: from_header ( & block. header ,  height) . into_update ( false ) ) ?; 
373-         let  indexed_additions = indexed_tx_graph. apply_block_relevant ( block,  height) ; 
359+         let  emission = emitter. next_block ( ) ?. expect ( "must get mined block" ) ; 
360+         let  height = emission. block_height ( ) ; 
361+         let  _ = chain. apply_update ( local_chain:: Update  { 
362+             tip :  emission. checkpoint , 
363+             introduce_older_blocks :  false , 
364+         } ) ?; 
365+         let  indexed_additions = indexed_tx_graph. apply_block_relevant ( emission. block ,  height) ; 
374366        assert ! ( indexed_additions. graph. txs. is_empty( ) ) ; 
375367        assert ! ( indexed_additions. graph. txouts. is_empty( ) ) ; 
376368        assert_eq ! ( indexed_additions. graph. anchors,  exp_anchors) ; 
@@ -407,9 +399,12 @@ fn ensure_block_emitted_after_reorg_is_at_reorg_height() -> anyhow::Result<()> {
407399
408400    for  reorg_count in  1 ..=10  { 
409401        let  replaced_blocks = env. reorg_empty_blocks ( reorg_count) ?; 
410-         let  ( height ,  next_header )  = emitter. next_header ( ) ?. expect ( "must emit block after reorg" ) ; 
402+         let  next_emission  = emitter. next_header ( ) ?. expect ( "must emit block after reorg" ) ; 
411403        assert_eq ! ( 
412-             ( height as  usize ,  next_header. block_hash( ) ) , 
404+             ( 
405+                 next_emission. block_height( )  as  usize , 
406+                 next_emission. block_hash( ) 
407+             ) , 
413408            replaced_blocks[ 0 ] , 
414409            "block emitted after reorg should be at the reorg height" 
415410        ) ; 
@@ -439,8 +434,9 @@ fn sync_from_emitter<C>(
439434where 
440435    C :  bitcoincore_rpc:: RpcApi , 
441436{ 
442-     while  let  Some ( ( height,  block) )  = emitter. next_block ( ) ? { 
443-         process_block ( recv_chain,  recv_graph,  block,  height) ?; 
437+     while  let  Some ( emission)  = emitter. next_block ( ) ? { 
438+         let  height = emission. block_height ( ) ; 
439+         process_block ( recv_chain,  recv_graph,  emission. block ,  height) ?; 
444440    } 
445441    Ok ( ( ) ) 
446442} 
@@ -660,7 +656,8 @@ fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()
660656
661657    // At this point, the emitter has seen all mempool transactions. It should only re-emit those 
662658    // that have introduction heights less than the emitter's last-emitted block tip. 
663-     while  let  Some ( ( height,  _) )  = emitter. next_header ( ) ? { 
659+     while  let  Some ( emission)  = emitter. next_header ( ) ? { 
660+         let  height = emission. block_height ( ) ; 
664661        // We call `mempool()` twice. 
665662        // The second call (at height `h`) should skip the tx introduced at height `h`. 
666663        for  try_index in  0 ..2  { 
@@ -754,7 +751,8 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
754751            . collect:: <BTreeMap <_,  _>>( ) ) ; 
755752
756753        // `next_header` emits the replacement block of the reorg 
757-         if  let  Some ( ( height,  _) )  = emitter. next_header ( ) ? { 
754+         if  let  Some ( emission)  = emitter. next_header ( ) ? { 
755+             let  height = emission. block_height ( ) ; 
758756            println ! ( "\t - replacement height: {}" ,  height) ; 
759757
760758            // the mempool emission (that follows the first block emission after reorg) should only 
@@ -835,12 +833,12 @@ fn no_agreement_point() -> anyhow::Result<()> {
835833    env. mine_blocks ( PREMINE_COUNT ,  None ) ?; 
836834
837835    // emit block 99a 
838-     let  ( _ ,   block_header_99a)  = emitter. next_header ( ) ?. expect ( "block 99a header" ) ; 
836+     let  block_header_99a = emitter. next_header ( ) ?. expect ( "block 99a header" ) . block ; 
839837    let  block_hash_99a = block_header_99a. block_hash ( ) ; 
840838    let  block_hash_98a = block_header_99a. prev_blockhash ; 
841839
842840    // emit block 100a 
843-     let  ( _ ,   block_header_100a)  = emitter. next_header ( ) ?. expect ( "block 100a header" ) ; 
841+     let  block_header_100a = emitter. next_header ( ) ?. expect ( "block 100a header" ) . block ; 
844842    let  block_hash_100a = block_header_100a. block_hash ( ) ; 
845843
846844    // get hash for block 101a 
@@ -855,7 +853,7 @@ fn no_agreement_point() -> anyhow::Result<()> {
855853    env. mine_blocks ( 3 ,  None ) ?; 
856854
857855    // emit block header 99b 
858-     let  ( _ ,   block_header_99b)  = emitter. next_header ( ) ?. expect ( "block 99b header" ) ; 
856+     let  block_header_99b = emitter. next_header ( ) ?. expect ( "block 99b header" ) . block ; 
859857    let  block_hash_99b = block_header_99b. block_hash ( ) ; 
860858    let  block_hash_98b = block_header_99b. prev_blockhash ; 
861859
0 commit comments