@@ -5081,6 +5081,9 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
5081
5081
assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
5082
5082
assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ;
5083
5083
5084
+ // The to-be-revoked commitment tx should have one HTLC and one to_remote output
5085
+ assert_eq ! ( revoked_local_txn[ 0 ] . output. len( ) , 2 ) ;
5086
+
5084
5087
claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage, 3_000_000 ) ;
5085
5088
5086
5089
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
@@ -5095,28 +5098,45 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
5095
5098
assert_eq ! ( revoked_htlc_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , ACCEPTED_HTLC_SCRIPT_WEIGHT ) ;
5096
5099
check_spends ! ( revoked_htlc_txn[ 0 ] , revoked_local_txn[ 0 ] ) ;
5097
5100
5101
+ // Check that the unspent (of two) outputs on revoked_local_txn[0] is a P2WPKH:
5102
+ let unspent_local_txn_output = revoked_htlc_txn[ 0 ] . input [ 0 ] . previous_output . vout as usize ^ 1 ;
5103
+ assert_eq ! ( revoked_local_txn[ 0 ] . output[ unspent_local_txn_output] . script_pubkey. len( ) , 2 + 20 ) ; // P2WPKH
5104
+
5098
5105
// A will generate justice tx from B's revoked commitment/HTLC tx
5099
5106
nodes[ 0 ] . block_notifier . block_connected ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) , revoked_htlc_txn[ 0 ] . clone( ) ] } , 1 ) ;
5100
5107
check_closed_broadcast ! ( nodes[ 0 ] , false ) ;
5101
5108
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
5102
5109
5103
5110
let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
5104
5111
assert_eq ! ( node_txn. len( ) , 3 ) ; // ChannelMonitor: justice tx on revoked commitment, justice tx on revoked HTLC-success, ChannelManager: local commitment tx
5112
+
5113
+ // The first transaction generated is just in case of a reorg - it double-spends
5114
+ // revoked_htlc_txn[0], spending the HTLC output on revoked_local_txn[0] directly.
5115
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 1 ) ;
5116
+ check_spends ! ( node_txn[ 0 ] , revoked_local_txn[ 0 ] ) ;
5117
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . previous_output, revoked_htlc_txn[ 0 ] . input[ 0 ] . previous_output) ;
5118
+
5105
5119
assert_eq ! ( node_txn[ 2 ] . input. len( ) , 1 ) ;
5106
5120
check_spends ! ( node_txn[ 2 ] , revoked_htlc_txn[ 0 ] ) ;
5107
5121
5122
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 ) ;
5123
+
5108
5124
let header_1 = BlockHeader { version : 0x20000000 , prev_blockhash : header. block_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
5109
- nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_1, txdata : vec ! [ node_txn[ 0 ] . clone ( ) , node_txn [ 2 ] . clone( ) ] } , 1 ) ;
5125
+ nodes[ 0 ] . block_notifier . block_connected ( & Block { header : header_1, txdata : vec ! [ node_txn[ 2 ] . clone( ) ] } , 1 ) ;
5110
5126
connect_blocks ( & nodes[ 0 ] . block_notifier , ANTI_REORG_DELAY - 1 , 1 , true , header. block_hash ( ) ) ;
5111
5127
5128
+ // Note that nodes[0]'s tx_broadcaster is still locked, so if we get here the channelmonitor
5129
+ // didn't try to generate any new transactions.
5130
+
5112
5131
// Check A's ChannelMonitor was able to generate the right spendable output descriptor
5113
5132
let spend_txn = check_spendable_outputs ! ( nodes[ 0 ] , 1 , node_cfgs[ 0 ] . keys_manager, 100000 ) ;
5114
- assert_eq ! ( spend_txn. len( ) , 5 ) ; // Duplicated SpendableOutput due to block rescan after revoked htlc output tracking
5133
+ assert_eq ! ( spend_txn. len( ) , 4 ) ; // Duplicated SpendableOutput due to block rescan after revoked htlc output tracking
5115
5134
assert_eq ! ( spend_txn[ 0 ] , spend_txn[ 1 ] ) ;
5116
5135
assert_eq ! ( spend_txn[ 0 ] , spend_txn[ 2 ] ) ;
5136
+ assert_eq ! ( spend_txn[ 0 ] . input. len( ) , 1 ) ;
5117
5137
check_spends ! ( spend_txn[ 0 ] , revoked_local_txn[ 0 ] ) ; // spending to_remote output from revoked local tx
5118
- check_spends ! ( spend_txn[ 3 ] , node_txn [ 0 ] ) ; // spending justice tx output from revoked local tx htlc received output
5119
- check_spends ! ( spend_txn[ 4 ] , node_txn[ 2 ] ) ; // spending justice tx output on htlc success tx
5138
+ assert_ne ! ( spend_txn[ 0 ] . input [ 0 ] . previous_output , revoked_htlc_txn [ 0 ] . input [ 0 ] . previous_output ) ;
5139
+ check_spends ! ( spend_txn[ 3 ] , node_txn[ 2 ] ) ; // spending justice tx output on the htlc success tx
5120
5140
}
5121
5141
5122
5142
#[ test]
0 commit comments