@@ -6692,30 +6692,46 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
66926692
66936693 // Connect three more block to see if bumped penalty are issued for HTLC txn
66946694 let header_132 = connect_blocks ( & nodes[ 0 ] . block_notifier , 3 , 129 , true , header_129. bitcoin_hash ( ) ) ;
6695- let node_txn = {
6695+ let penalty_local_tx;
6696+ {
66966697 let mut node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6697- assert_eq ! ( node_txn. len( ) , 5 ) ; // 2 bumped penalty txn on offered/received HTLC outputs of revoked commitment tx + 1 penalty tx on to_local of revoked commitment tx + 2 bumped penalty tx on revoked HTLC txn
6698+ assert_eq ! ( node_txn. len( ) , 3 ) ; // 2 bumped penalty txn on offered/received HTLC outputs of revoked commitment tx + 1 penalty tx on to_local of revoked commitment tx + 2 bumped penalty tx on revoked HTLC txn
66986699
66996700 check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
67006701 check_spends ! ( node_txn[ 1 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
67016702
6702- let mut penalty_local = :: std:: usize:: MAX ;
6703+ check_spends ! ( node_txn[ 2 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
6704+
6705+ penalty_local_tx = node_txn[ 2 ] . clone ( ) ;
6706+ node_txn. clear ( ) ;
6707+ } ;
6708+ // Few more blocks to broadcast and confirm penalty_local_tx
6709+ let header_133 = BlockHeader { version : 0x20000000 , prev_blockhash : header_132, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6710+ nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_133, txdata : vec ! [ penalty_local_tx] } , 133 ) ;
6711+ let header_135 = connect_blocks ( & nodes[ 0 ] . block_notifier , 2 , 133 , true , header_133. bitcoin_hash ( ) ) ;
6712+ {
6713+ let mut node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6714+ assert_eq ! ( node_txn. len( ) , 1 ) ;
6715+ check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] . clone( ) ) ;
6716+ node_txn. clear ( ) ;
6717+ }
6718+ let header_144 = connect_blocks ( & nodes[ 0 ] . block_notifier , 9 , 135 , true , header_135) ;
6719+ let node_txn = {
6720+ let mut node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6721+ assert_eq ! ( node_txn. len( ) , 2 ) ;
6722+
67036723 let mut penalty_offered = :: std:: usize:: MAX ;
67046724 let mut penalty_received = :: std:: usize:: MAX ;
67056725
67066726 {
6707- let iter_txn = node_txn[ 2 ..] . iter ( ) ;
6708- for ( i, tx) in iter_txn. enumerate ( ) {
6709- if tx. input [ 0 ] . previous_output . txid == revoked_local_txn[ 0 ] . txid ( ) {
6710- penalty_local = 2 + i;
6711- } else if tx. input [ 0 ] . previous_output . txid == revoked_htlc_txn[ offered] . txid ( ) {
6712- penalty_offered = 2 + i;
6727+ for ( i, tx) in node_txn. iter ( ) . enumerate ( ) {
6728+ if tx. input [ 0 ] . previous_output . txid == revoked_htlc_txn[ offered] . txid ( ) {
6729+ penalty_offered = i;
67136730 } else if tx. input [ 0 ] . previous_output . txid == revoked_htlc_txn[ received] . txid ( ) {
6714- penalty_received = 2 + i;
6731+ penalty_received = i;
67156732 }
67166733 }
67176734 }
6718- check_spends ! ( node_txn[ penalty_local] , revoked_local_txn[ 0 ] . clone( ) ) ;
67196735
67206736 assert_eq ! ( node_txn[ penalty_received] . input. len( ) , 1 ) ;
67216737 assert_eq ! ( node_txn[ penalty_received] . output. len( ) , 1 ) ;
@@ -6733,24 +6749,17 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
67336749 let fee = revoked_htlc_txn[ received] . output [ 0 ] . value - node_txn[ penalty_received] . output [ 0 ] . value ;
67346750 let new_feerate = fee * 1000 / node_txn[ penalty_received] . get_weight ( ) as u64 ;
67356751 assert ! ( new_feerate * 100 > feerate_2 * 125 ) ;
6736- let txn = vec ! [ node_txn[ 2 ] . clone( ) , node_txn[ 3 ] . clone ( ) , node_txn [ 4 ] . clone( ) ] ;
6752+ let txn = vec ! [ node_txn[ 0 ] . clone( ) , node_txn[ 1 ] . clone( ) ] ;
67376753 node_txn. clear ( ) ;
67386754 txn
67396755 } ;
67406756 // Broadcast claim txn and confirm blocks to avoid further bumps on this outputs
6741- let header_133 = BlockHeader { version : 0x20000000 , prev_blockhash : header_132, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6742- nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_133, txdata : node_txn } , 133 ) ;
6743- let header_140 = connect_blocks ( & nodes[ 0 ] . block_notifier , 6 , 134 , true , header_133. bitcoin_hash ( ) ) ;
6744- {
6745- let mut node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6746- node_txn. clear ( ) ;
6747- }
6748-
6749- // Connect few more blocks and check only penalty transaction for to_local output have been issued
6750- connect_blocks ( & nodes[ 0 ] . block_notifier , 7 , 140 , true , header_140) ;
6757+ let header_145 = BlockHeader { version : 0x20000000 , prev_blockhash : header_144, merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6758+ nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_145, txdata : node_txn } , 145 ) ;
6759+ connect_blocks ( & nodes[ 0 ] . block_notifier , 20 , 145 , true , header_145. bitcoin_hash ( ) ) ;
67516760 {
67526761 let mut node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6753- assert_eq ! ( node_txn. len( ) , 2 ) ; //TODO: should be zero when we fix check_spend_remote_htlc
6762+ assert_eq ! ( node_txn. len( ) , 2 ) ; //TODO: fix check_spend_remote_htlc lack of watch output
67546763 node_txn. clear ( ) ;
67556764 }
67566765 check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
0 commit comments