@@ -137,6 +137,20 @@ pub enum ConnectStyle {
137137}
138138
139139impl ConnectStyle {
140+ pub fn skips_blocks ( & self ) -> bool {
141+ match self {
142+ ConnectStyle :: BestBlockFirst => false ,
143+ ConnectStyle :: BestBlockFirstSkippingBlocks => true ,
144+ ConnectStyle :: BestBlockFirstReorgsOnlyTip => true ,
145+ ConnectStyle :: TransactionsFirst => false ,
146+ ConnectStyle :: TransactionsFirstSkippingBlocks => true ,
147+ ConnectStyle :: TransactionsDuplicativelyFirstSkippingBlocks => true ,
148+ ConnectStyle :: HighlyRedundantTransactionsFirstSkippingBlocks => true ,
149+ ConnectStyle :: TransactionsFirstReorgsOnlyTip => true ,
150+ ConnectStyle :: FullBlockViaListen => false ,
151+ }
152+ }
153+
140154 fn random_style ( ) -> ConnectStyle {
141155 #[ cfg( feature = "std" ) ] {
142156 use core:: hash:: { BuildHasher , Hasher } ;
@@ -164,12 +178,7 @@ impl ConnectStyle {
164178}
165179
166180pub fn connect_blocks < ' a , ' b , ' c , ' d > ( node : & ' a Node < ' b , ' c , ' d > , depth : u32 ) -> BlockHash {
167- let skip_intermediaries = match * node. connect_style . borrow ( ) {
168- ConnectStyle :: BestBlockFirstSkippingBlocks |ConnectStyle :: TransactionsFirstSkippingBlocks |
169- ConnectStyle :: TransactionsDuplicativelyFirstSkippingBlocks |ConnectStyle :: HighlyRedundantTransactionsFirstSkippingBlocks |
170- ConnectStyle :: BestBlockFirstReorgsOnlyTip |ConnectStyle :: TransactionsFirstReorgsOnlyTip => true ,
171- _ => false ,
172- } ;
181+ let skip_intermediaries = node. connect_style . borrow ( ) . skips_blocks ( ) ;
173182
174183 let height = node. best_block_info ( ) . 1 + 1 ;
175184 let mut block = Block {
@@ -2535,6 +2544,8 @@ pub enum HTLCType { NONE, TIMEOUT, SUCCESS }
25352544/// also fail.
25362545pub fn test_txn_broadcast < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , chan : & ( msgs:: ChannelUpdate , msgs:: ChannelUpdate , [ u8 ; 32 ] , Transaction ) , commitment_tx : Option < Transaction > , has_htlc_tx : HTLCType ) -> Vec < Transaction > {
25372546 let mut node_txn = node. tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
2547+ let mut txn_seen = HashSet :: new ( ) ;
2548+ node_txn. retain ( |tx| txn_seen. insert ( tx. txid ( ) ) ) ;
25382549 assert ! ( node_txn. len( ) >= if commitment_tx. is_some( ) { 0 } else { 1 } + if has_htlc_tx == HTLCType :: NONE { 0 } else { 1 } ) ;
25392550
25402551 let mut res = Vec :: with_capacity ( 2 ) ;
@@ -2598,22 +2609,23 @@ pub fn test_revoked_htlc_claim_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>
25982609
25992610pub fn check_preimage_claim < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , prev_txn : & Vec < Transaction > ) -> Vec < Transaction > {
26002611 let mut node_txn = node. tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
2612+ let mut txn_seen = HashSet :: new ( ) ;
2613+ node_txn. retain ( |tx| txn_seen. insert ( tx. txid ( ) ) ) ;
26012614
2602- assert ! ( node_txn. len( ) >= 1 ) ;
2603- assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
26042615 let mut found_prev = false ;
2605-
2606- for tx in prev_txn {
2607- if node_txn[ 0 ] . input [ 0 ] . previous_output . txid == tx. txid ( ) {
2608- check_spends ! ( node_txn[ 0 ] , tx) ;
2609- let mut iter = node_txn[ 0 ] . input [ 0 ] . witness . iter ( ) ;
2610- iter. next ( ) . expect ( "expected 3 witness items" ) ;
2611- iter. next ( ) . expect ( "expected 3 witness items" ) ;
2612- assert ! ( iter. next( ) . expect( "expected 3 witness items" ) . len( ) > 106 ) ; // must spend an htlc output
2613- assert_eq ! ( tx. input. len( ) , 1 ) ; // must spend a commitment tx
2614-
2615- found_prev = true ;
2616- break ;
2616+ for prev_tx in prev_txn {
2617+ for tx in & * node_txn {
2618+ if tx. input [ 0 ] . previous_output . txid == prev_tx. txid ( ) {
2619+ check_spends ! ( tx, prev_tx) ;
2620+ let mut iter = tx. input [ 0 ] . witness . iter ( ) ;
2621+ iter. next ( ) . expect ( "expected 3 witness items" ) ;
2622+ iter. next ( ) . expect ( "expected 3 witness items" ) ;
2623+ assert ! ( iter. next( ) . expect( "expected 3 witness items" ) . len( ) > 106 ) ; // must spend an htlc output
2624+ assert_eq ! ( tx. input. len( ) , 1 ) ; // must spend a commitment tx
2625+
2626+ found_prev = true ;
2627+ break ;
2628+ }
26172629 }
26182630 }
26192631 assert ! ( found_prev) ;
0 commit comments