@@ -1129,7 +1129,7 @@ mod tests {
1129
1129
SCORER_PERSISTENCE_SECONDARY_NAMESPACE ,
1130
1130
} ;
1131
1131
use lightning:: util:: ser:: Writeable ;
1132
- use lightning:: util:: sweep:: { OutputSpendStatus , OutputSweeperSync , PRUNE_DELAY_BLOCKS } ;
1132
+ use lightning:: util:: sweep:: { OutputSpendStatus , OutputSweeperSync , TrackedSpendableOutput , PRUNE_DELAY_BLOCKS } ;
1133
1133
use lightning:: util:: test_utils;
1134
1134
use lightning:: { get_event, get_event_msg} ;
1135
1135
use lightning_persister:: fs_store:: FilesystemStore ;
@@ -2258,10 +2258,22 @@ mod tests {
2258
2258
2259
2259
advance_chain ( & mut nodes[ 0 ] , 3 ) ;
2260
2260
2261
+ let tx_broadcaster = nodes[ 0 ] . tx_broadcaster . clone ( ) ;
2262
+ let wait_for_sweep_tx = || -> Transaction {
2263
+ loop {
2264
+ let sweep_tx = tx_broadcaster. txn_broadcasted . lock ( ) . unwrap ( ) . pop ( ) ;
2265
+ if let Some ( sweep_tx) = sweep_tx {
2266
+ return sweep_tx;
2267
+ }
2268
+
2269
+ std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
2270
+ }
2271
+ } ;
2272
+
2261
2273
// Check we generate an initial sweeping tx.
2262
2274
assert_eq ! ( nodes[ 0 ] . sweeper. tracked_spendable_outputs( ) . len( ) , 1 ) ;
2275
+ let sweep_tx_0 = wait_for_sweep_tx ( ) ;
2263
2276
let tracked_output = nodes[ 0 ] . sweeper . tracked_spendable_outputs ( ) . first ( ) . unwrap ( ) . clone ( ) ;
2264
- let sweep_tx_0 = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
2265
2277
match tracked_output. status {
2266
2278
OutputSpendStatus :: PendingFirstConfirmation { latest_spending_tx, .. } => {
2267
2279
assert_eq ! ( sweep_tx_0. compute_txid( ) , latest_spending_tx. compute_txid( ) ) ;
@@ -2272,8 +2284,8 @@ mod tests {
2272
2284
// Check we regenerate and rebroadcast the sweeping tx each block.
2273
2285
advance_chain ( & mut nodes[ 0 ] , 1 ) ;
2274
2286
assert_eq ! ( nodes[ 0 ] . sweeper. tracked_spendable_outputs( ) . len( ) , 1 ) ;
2287
+ let sweep_tx_1 = wait_for_sweep_tx ( ) ;
2275
2288
let tracked_output = nodes[ 0 ] . sweeper . tracked_spendable_outputs ( ) . first ( ) . unwrap ( ) . clone ( ) ;
2276
- let sweep_tx_1 = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
2277
2289
match tracked_output. status {
2278
2290
OutputSpendStatus :: PendingFirstConfirmation { latest_spending_tx, .. } => {
2279
2291
assert_eq ! ( sweep_tx_1. compute_txid( ) , latest_spending_tx. compute_txid( ) ) ;
@@ -2284,8 +2296,8 @@ mod tests {
2284
2296
2285
2297
advance_chain ( & mut nodes[ 0 ] , 1 ) ;
2286
2298
assert_eq ! ( nodes[ 0 ] . sweeper. tracked_spendable_outputs( ) . len( ) , 1 ) ;
2299
+ let sweep_tx_2 = wait_for_sweep_tx ( ) ;
2287
2300
let tracked_output = nodes[ 0 ] . sweeper . tracked_spendable_outputs ( ) . first ( ) . unwrap ( ) . clone ( ) ;
2288
- let sweep_tx_2 = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
2289
2301
match tracked_output. status {
2290
2302
OutputSpendStatus :: PendingFirstConfirmation { latest_spending_tx, .. } => {
2291
2303
assert_eq ! ( sweep_tx_2. compute_txid( ) , latest_spending_tx. compute_txid( ) ) ;
0 commit comments