@@ -137,6 +137,20 @@ pub enum ConnectStyle {
137
137
}
138
138
139
139
impl 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
+
140
154
fn random_style ( ) -> ConnectStyle {
141
155
#[ cfg( feature = "std" ) ] {
142
156
use core:: hash:: { BuildHasher , Hasher } ;
@@ -164,12 +178,7 @@ impl ConnectStyle {
164
178
}
165
179
166
180
pub 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 ( ) ;
173
182
174
183
let height = node. best_block_info ( ) . 1 + 1 ;
175
184
let mut block = Block {
@@ -2535,6 +2544,8 @@ pub enum HTLCType { NONE, TIMEOUT, SUCCESS }
2535
2544
/// also fail.
2536
2545
pub 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 > {
2537
2546
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 ( ) ) ) ;
2538
2549
assert ! ( node_txn. len( ) >= if commitment_tx. is_some( ) { 0 } else { 1 } + if has_htlc_tx == HTLCType :: NONE { 0 } else { 1 } ) ;
2539
2550
2540
2551
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>
2598
2609
2599
2610
pub fn check_preimage_claim < ' a , ' b , ' c > ( node : & Node < ' a , ' b , ' c > , prev_txn : & Vec < Transaction > ) -> Vec < Transaction > {
2600
2611
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 ( ) ) ) ;
2601
2614
2602
- assert ! ( node_txn. len( ) >= 1 ) ;
2603
- assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
2604
2615
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
+ }
2617
2629
}
2618
2630
}
2619
2631
assert ! ( found_prev) ;
0 commit comments