1- use std:: collections:: { BTreeMap , BTreeSet } ;
1+ use std:: collections:: { BTreeMap , BTreeSet , HashSet } ;
22
33use bdk_bitcoind_rpc:: Emitter ;
44use bdk_chain:: {
@@ -22,7 +22,7 @@ pub fn test_sync_local_chain() -> anyhow::Result<()> {
2222 let env = TestEnv :: new ( ) ?;
2323 let network_tip = env. rpc_client ( ) . get_block_count ( ) ?;
2424 let ( mut local_chain, _) = LocalChain :: from_genesis_hash ( env. rpc_client ( ) . get_block_hash ( 0 ) ?) ;
25- let mut emitter = Emitter :: new ( env. rpc_client ( ) , local_chain. tip ( ) , 0 ) ;
25+ let mut emitter = Emitter :: new ( env. rpc_client ( ) , local_chain. tip ( ) , 0 , HashSet :: new ( ) ) ;
2626
2727 // Mine some blocks and return the actual block hashes.
2828 // Because initializing `ElectrsD` already mines some blocks, we must include those too when
@@ -156,7 +156,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
156156 index
157157 } ) ;
158158
159- let emitter = & mut Emitter :: new ( env. rpc_client ( ) , chain. tip ( ) , 0 ) ;
159+ let emitter = & mut Emitter :: new ( env. rpc_client ( ) , chain. tip ( ) , 0 , HashSet :: new ( ) ) ;
160160
161161 while let Some ( emission) = emitter. next_block ( ) ? {
162162 let height = emission. block_height ( ) ;
@@ -189,7 +189,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
189189 assert ! ( emitter. next_block( ) ?. is_none( ) ) ;
190190
191191 let mempool_txs = emitter. mempool ( ) ?;
192- let indexed_additions = indexed_tx_graph. batch_insert_unconfirmed ( mempool_txs) ;
192+ let indexed_additions = indexed_tx_graph. batch_insert_unconfirmed ( mempool_txs. new_txs ) ;
193193 assert_eq ! (
194194 indexed_additions
195195 . tx_graph
@@ -252,6 +252,7 @@ fn ensure_block_emitted_after_reorg_is_at_reorg_height() -> anyhow::Result<()> {
252252 hash : env. rpc_client ( ) . get_block_hash ( 0 ) ?,
253253 } ) ,
254254 EMITTER_START_HEIGHT as _ ,
255+ HashSet :: new ( ) ,
255256 ) ;
256257
257258 env. mine_blocks ( CHAIN_TIP_HEIGHT , None ) ?;
@@ -328,6 +329,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
328329 hash : env. rpc_client ( ) . get_block_hash ( 0 ) ?,
329330 } ) ,
330331 0 ,
332+ HashSet :: new ( ) ,
331333 ) ;
332334
333335 // setup addresses
@@ -419,6 +421,7 @@ fn mempool_avoids_re_emission() -> anyhow::Result<()> {
419421 hash : env. rpc_client ( ) . get_block_hash ( 0 ) ?,
420422 } ) ,
421423 0 ,
424+ HashSet :: new ( ) ,
422425 ) ;
423426
424427 // mine blocks and sync up emitter
@@ -437,6 +440,7 @@ fn mempool_avoids_re_emission() -> anyhow::Result<()> {
437440 // the first emission should include all transactions
438441 let emitted_txids = emitter
439442 . mempool ( ) ?
443+ . new_txs
440444 . into_iter ( )
441445 . map ( |( tx, _) | tx. compute_txid ( ) )
442446 . collect :: < BTreeSet < Txid > > ( ) ;
@@ -447,7 +451,7 @@ fn mempool_avoids_re_emission() -> anyhow::Result<()> {
447451
448452 // second emission should be empty
449453 assert ! (
450- emitter. mempool( ) ?. is_empty( ) ,
454+ emitter. mempool( ) ?. new_txs . is_empty( ) ,
451455 "second emission should be empty"
452456 ) ;
453457
@@ -457,7 +461,7 @@ fn mempool_avoids_re_emission() -> anyhow::Result<()> {
457461 }
458462 while emitter. next_header ( ) ?. is_some ( ) { }
459463 assert ! (
460- emitter. mempool( ) ?. is_empty( ) ,
464+ emitter. mempool( ) ?. new_txs . is_empty( ) ,
461465 "third emission, after chain tip is extended, should also be empty"
462466 ) ;
463467
@@ -484,6 +488,7 @@ fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()
484488 hash : env. rpc_client ( ) . get_block_hash ( 0 ) ?,
485489 } ) ,
486490 0 ,
491+ HashSet :: new ( ) ,
487492 ) ;
488493
489494 // mine blocks to get initial balance, sync emitter up to tip
@@ -506,6 +511,7 @@ fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()
506511 assert_eq ! (
507512 emitter
508513 . mempool( ) ?
514+ . new_txs
509515 . into_iter( )
510516 . map( |( tx, _) | tx. compute_txid( ) )
511517 . collect:: <BTreeSet <_>>( ) ,
@@ -515,6 +521,7 @@ fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()
515521 assert_eq ! (
516522 emitter
517523 . mempool( ) ?
524+ . new_txs
518525 . into_iter( )
519526 . map( |( tx, _) | tx. compute_txid( ) )
520527 . collect:: <BTreeSet <_>>( ) ,
@@ -535,6 +542,7 @@ fn mempool_re_emits_if_tx_introduction_height_not_reached() -> anyhow::Result<()
535542 . collect :: < BTreeSet < _ > > ( ) ;
536543 let emitted_txids = emitter
537544 . mempool ( ) ?
545+ . new_txs
538546 . into_iter ( )
539547 . map ( |( tx, _) | tx. compute_txid ( ) )
540548 . collect :: < BTreeSet < _ > > ( ) ;
@@ -572,6 +580,7 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
572580 hash : env. rpc_client ( ) . get_block_hash ( 0 ) ?,
573581 } ) ,
574582 0 ,
583+ HashSet :: new ( ) ,
575584 ) ;
576585
577586 // mine blocks to get initial balance
@@ -593,6 +602,7 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
593602 assert_eq ! (
594603 emitter
595604 . mempool( ) ?
605+ . new_txs
596606 . into_iter( )
597607 . map( |( tx, _) | tx. compute_txid( ) )
598608 . collect:: <BTreeSet <_>>( ) ,
@@ -628,6 +638,7 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
628638 // include mempool txs introduced at reorg height or greater
629639 let mempool = emitter
630640 . mempool ( ) ?
641+ . new_txs
631642 . into_iter ( )
632643 . map ( |( tx, _) | tx. compute_txid ( ) )
633644 . collect :: < BTreeSet < _ > > ( ) ;
@@ -643,6 +654,7 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
643654
644655 let mempool = emitter
645656 . mempool ( ) ?
657+ . new_txs
646658 . into_iter ( )
647659 . map ( |( tx, _) | tx. compute_txid ( ) )
648660 . collect :: < BTreeSet < _ > > ( ) ;
@@ -696,6 +708,7 @@ fn no_agreement_point() -> anyhow::Result<()> {
696708 hash : env. rpc_client ( ) . get_block_hash ( 0 ) ?,
697709 } ) ,
698710 ( PREMINE_COUNT - 2 ) as u32 ,
711+ HashSet :: new ( ) ,
699712 ) ;
700713
701714 // mine 101 blocks
@@ -821,10 +834,10 @@ fn test_expect_tx_evicted() -> anyhow::Result<()> {
821834 assert ! ( mempool_event. evicted_txids. contains( & txid_1) ) ;
822835
823836 // Update graph with evicted tx.
824- let exp_txids = exp_spk_txids . into_iter ( ) . map ( | ( _ , txid ) | txid ) ;
825- let evicted_txids = mempool_event . evicted_txids ( exp_txids ) ;
826- for txid in evicted_txids {
827- let _ = graph . insert_evicted_at ( txid , seen_at ) ;
837+ for txid in mempool_event . evicted_txids {
838+ if graph . graph ( ) . get_tx_node ( txid ) . is_some ( ) {
839+ let _ = graph . insert_evicted_at ( txid , seen_at ) ;
840+ }
828841 }
829842
830843 let canonical_txids = graph
0 commit comments