@@ -6077,9 +6077,9 @@ mod tests {
6077
6077
// ChainWatchInterface and pass the preimage backward accordingly. So here we test that ChannelManager is
6078
6078
// broadcasting the right event to other nodes in payment path.
6079
6079
// A --------------------> B ----------------------> C (preimage)
6080
- // A's commitment tx C's commitment tx
6081
- // \ \
6082
- // B's preimage tx C's HTLC Success tx
6080
+ // C's commitment tx
6081
+ // \
6082
+ // C's HTLC Success tx
6083
6083
6084
6084
let nodes = create_network ( 3 ) ;
6085
6085
@@ -6097,6 +6097,7 @@ mod tests {
6097
6097
// Broadcast legit commitment tx from C on B's chain
6098
6098
// Broadcast HTLC Success transation by C on received output from C's commitment tx on B's chain
6099
6099
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6100
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
6100
6101
nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
6101
6102
{
6102
6103
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6122,7 +6123,14 @@ mod tests {
6122
6123
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6123
6124
_ => panic ! ( "Unexpected event" ) ,
6124
6125
}
6125
- let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6126
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Success tx), ChannelMonitor : 1 (HTLC-Success tx)
6127
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6128
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6129
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6130
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6131
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6132
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6133
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6126
6134
6127
6135
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
6128
6136
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn} , 1 ) ;
@@ -6147,18 +6155,42 @@ mod tests {
6147
6155
} ,
6148
6156
_ => panic ! ( "Unexpected event" ) ,
6149
6157
} ;
6158
+ {
6159
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ; ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 1 (timeout tx) * 2 (block-rescan)
6160
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6161
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6162
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6163
+ check_spends ! ( node_txn[ 3 ] , commitment_tx[ 0 ] . clone( ) ) ;
6164
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6165
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6166
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6167
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6168
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6169
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6170
+ node_txn. clear ( )
6171
+ }
6150
6172
6151
6173
// Broadcast legit commitment tx from A on B's chain
6152
6174
// Broadcast preimage tx by B on offered output from A commitment tx on A's chain
6153
6175
let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6176
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6154
6177
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6155
6178
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6156
6179
assert_eq ! ( events. len( ) , 1 ) ;
6157
6180
match events[ 0 ] {
6158
6181
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6159
6182
_ => panic ! ( "Unexpected event" ) ,
6160
6183
}
6161
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6184
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx), ChannelMonitor : 1 (HTLC-Success) * 2 (block-rescan)
6185
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6186
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
6187
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6188
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6189
+ check_spends ! ( node_txn[ 2 ] , commitment_tx[ 0 ] . clone( ) ) ;
6190
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6191
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6192
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6193
+ let commitment_tx = node_txn[ 1 ] . clone ( ) ;
6162
6194
6163
6195
// Verify that A's ChannelManager is able to extract preimage from preimage tx and pass it backward
6164
6196
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
@@ -6168,6 +6200,17 @@ mod tests {
6168
6200
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6169
6201
_ => panic ! ( "Unexpected event" ) ,
6170
6202
}
6203
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 1 (timeout tx) * 2 (block-rescan)
6204
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6205
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6206
+ check_spends ! ( node_txn[ 0 ] , commitment_tx. clone( ) ) ;
6207
+ check_spends ! ( node_txn[ 3 ] , commitment_tx. clone( ) ) ;
6208
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6209
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6210
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6211
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6212
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6213
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6171
6214
}
6172
6215
6173
6216
#[ test]
@@ -6176,7 +6219,7 @@ mod tests {
6176
6219
// ChainWatchInterface and timeout the HTLC bacward accordingly. So here we test that ChannelManager is
6177
6220
// broadcasting the right event to other nodes in payment path.
6178
6221
// A ------------------> B ----------------------> C (timeout)
6179
- // A 's commitment tx C's commitment tx
6222
+ // B 's commitment tx C's commitment tx
6180
6223
// \ \
6181
6224
// B's HTLC timeout tx B's timeout tx
6182
6225
@@ -6195,6 +6238,7 @@ mod tests {
6195
6238
6196
6239
// Brodacast legit commitment tx from C on B's chain
6197
6240
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6241
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
6198
6242
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash, PaymentFailReason :: PreimageUnknown ) ;
6199
6243
{
6200
6244
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6220,23 +6264,36 @@ mod tests {
6220
6264
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6221
6265
_ => panic ! ( "Unexpected event" ) ,
6222
6266
}
6223
- let mut funding_tx_map = HashMap :: new ( ) ;
6224
- funding_tx_map. insert ( chan_2. 3 . txid ( ) , chan_2. 3 . clone ( ) ) ;
6225
- commitment_tx[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
6267
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx)
6268
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
6269
+ check_spends ! ( node_txn[ 0 ] , chan_2. 3 . clone( ) ) ;
6270
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6226
6271
6227
6272
// Broadcast timeout transaction by B on received output fron C's commitment tx on B's chain
6228
6273
// Verify that B's ChannelManager is able to detect that HTLC is timeout by its own tx and react backward in consequence
6229
6274
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6230
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6231
- assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout), ChannelMonitor : 6 (commitment tx, HTLC-Timeout, timeout tx) * 2 (block-rescan)
6232
- assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
6233
- assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6234
-
6235
- let mut commitment_tx_map = HashMap :: new ( ) ;
6236
- commitment_tx_map. insert ( commitment_tx[ 0 ] . txid ( ) , commitment_tx[ 0 ] . clone ( ) ) ;
6237
- node_txn[ 0 ] . verify ( & commitment_tx_map) . unwrap ( ) ;
6238
-
6239
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
6275
+ let timeout_tx;
6276
+ {
6277
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6278
+ assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 6 (HTLC-Timeout tx, commitment tx, timeout tx) * 2 (block-rescan)
6279
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 5 ] ) ;
6280
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 6 ] ) ;
6281
+ assert_eq ! ( node_txn[ 2 ] , node_txn[ 7 ] ) ;
6282
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6283
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6284
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6285
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6286
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6287
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6288
+ check_spends ! ( node_txn[ 3 ] , chan_2. 3 . clone( ) ) ;
6289
+ check_spends ! ( node_txn[ 4 ] , node_txn[ 3 ] . clone( ) ) ;
6290
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6291
+ assert_eq ! ( node_txn[ 4 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6292
+ timeout_tx = node_txn[ 0 ] . clone ( ) ;
6293
+ node_txn. clear ( ) ;
6294
+ }
6295
+
6296
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ timeout_tx] } , 1 ) ;
6240
6297
{
6241
6298
let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
6242
6299
assert_eq ! ( added_monitors. len( ) , 1 ) ;
@@ -6258,27 +6315,29 @@ mod tests {
6258
6315
} ,
6259
6316
_ => panic ! ( "Unexpected event" ) ,
6260
6317
} ;
6318
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // Well... here we detect our own htlc_timeout_tx so no tx to be generated
6319
+ assert_eq ! ( node_txn. len( ) , 0 ) ;
6261
6320
6262
- // Broadcast legit commitment tx from A on B's chain
6263
- // Broadcast HTLC Timeout tx by B on offered output from A commitment tx on A's chain
6264
- let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6265
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6266
- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6267
- assert_eq ! ( events. len( ) , 1 ) ;
6268
- match events[ 0 ] {
6269
- MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6270
- _ => panic ! ( "Unexpected event" ) ,
6271
- }
6272
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6321
+ // Broadcast legit commitment tx from B on A's chain
6322
+ let commitment_tx = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6323
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6273
6324
6274
- // Verify that A's ChannelManager is able to detect that HTLC is timeout by a HTLC Timeout tx and react backward in consequence
6275
- nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
6325
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6276
6326
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6277
6327
assert_eq ! ( events. len( ) , 1 ) ;
6278
6328
match events[ 0 ] {
6279
6329
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6280
6330
_ => panic ! ( "Unexpected event" ) ,
6281
6331
}
6332
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout tx), ChannelMonitor : 2 (timeout tx) * 2 block-rescan
6333
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6334
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6335
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6336
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6337
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6338
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6339
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6340
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6282
6341
}
6283
6342
6284
6343
#[ test]
0 commit comments