@@ -6083,9 +6083,9 @@ mod tests {
6083
6083
// ChainWatchInterface and pass the preimage backward accordingly. So here we test that ChannelManager is
6084
6084
// broadcasting the right event to other nodes in payment path.
6085
6085
// A --------------------> B ----------------------> C (preimage)
6086
- // A's commitment tx C's commitment tx
6087
- // \ \
6088
- // B's preimage tx C's HTLC Success tx
6086
+ // C's commitment tx
6087
+ // \
6088
+ // C's HTLC Success tx
6089
6089
6090
6090
let nodes = create_network ( 3 ) ;
6091
6091
@@ -6103,6 +6103,7 @@ mod tests {
6103
6103
// Broadcast legit commitment tx from C on B's chain
6104
6104
// Broadcast HTLC Success transation by C on received output from C's commitment tx on B's chain
6105
6105
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6106
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
6106
6107
nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
6107
6108
{
6108
6109
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6128,7 +6129,14 @@ mod tests {
6128
6129
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6129
6130
_ => panic ! ( "Unexpected event" ) ,
6130
6131
}
6131
- let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6132
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Success tx), ChannelMonitor : 1 (HTLC-Success tx)
6133
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6134
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6135
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6136
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6137
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6138
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6139
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6132
6140
6133
6141
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
6134
6142
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn} , 1 ) ;
@@ -6153,18 +6161,42 @@ mod tests {
6153
6161
} ,
6154
6162
_ => panic ! ( "Unexpected event" ) ,
6155
6163
} ;
6164
+ {
6165
+ 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)
6166
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6167
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6168
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6169
+ check_spends ! ( node_txn[ 3 ] , commitment_tx[ 0 ] . clone( ) ) ;
6170
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6171
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6172
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6173
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6174
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6175
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6176
+ node_txn. clear ( )
6177
+ }
6156
6178
6157
6179
// Broadcast legit commitment tx from A on B's chain
6158
6180
// Broadcast preimage tx by B on offered output from A commitment tx on A's chain
6159
6181
let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6182
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6160
6183
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6161
6184
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6162
6185
assert_eq ! ( events. len( ) , 1 ) ;
6163
6186
match events[ 0 ] {
6164
6187
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6165
6188
_ => panic ! ( "Unexpected event" ) ,
6166
6189
}
6167
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6190
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx), ChannelMonitor : 1 (HTLC-Success) * 2 (block-rescan)
6191
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6192
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
6193
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6194
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6195
+ check_spends ! ( node_txn[ 2 ] , commitment_tx[ 0 ] . clone( ) ) ;
6196
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6197
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6198
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6199
+ let commitment_tx = node_txn[ 1 ] . clone ( ) ;
6168
6200
6169
6201
// Verify that A's ChannelManager is able to extract preimage from preimage tx and pass it backward
6170
6202
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
@@ -6174,6 +6206,17 @@ mod tests {
6174
6206
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6175
6207
_ => panic ! ( "Unexpected event" ) ,
6176
6208
}
6209
+ 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)
6210
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6211
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6212
+ check_spends ! ( node_txn[ 0 ] , commitment_tx. clone( ) ) ;
6213
+ check_spends ! ( node_txn[ 3 ] , commitment_tx. clone( ) ) ;
6214
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6215
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6216
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6217
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6218
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6219
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6177
6220
}
6178
6221
6179
6222
#[ test]
@@ -6182,7 +6225,7 @@ mod tests {
6182
6225
// ChainWatchInterface and timeout the HTLC bacward accordingly. So here we test that ChannelManager is
6183
6226
// broadcasting the right event to other nodes in payment path.
6184
6227
// A ------------------> B ----------------------> C (timeout)
6185
- // A 's commitment tx C's commitment tx
6228
+ // B 's commitment tx C's commitment tx
6186
6229
// \ \
6187
6230
// B's HTLC timeout tx B's timeout tx
6188
6231
@@ -6201,6 +6244,7 @@ mod tests {
6201
6244
6202
6245
// Brodacast legit commitment tx from C on B's chain
6203
6246
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6247
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
6204
6248
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash, PaymentFailReason :: PreimageUnknown ) ;
6205
6249
{
6206
6250
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6226,23 +6270,36 @@ mod tests {
6226
6270
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6227
6271
_ => panic ! ( "Unexpected event" ) ,
6228
6272
}
6229
- let mut funding_tx_map = HashMap :: new ( ) ;
6230
- funding_tx_map. insert ( chan_2. 3 . txid ( ) , chan_2. 3 . clone ( ) ) ;
6231
- commitment_tx[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
6273
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx)
6274
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
6275
+ check_spends ! ( node_txn[ 0 ] , chan_2. 3 . clone( ) ) ;
6276
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6232
6277
6233
6278
// Broadcast timeout transaction by B on received output fron C's commitment tx on B's chain
6234
6279
// Verify that B's ChannelManager is able to detect that HTLC is timeout by its own tx and react backward in consequence
6235
6280
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6236
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6237
- assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout), ChannelMonitor : 6 (commitment tx, HTLC-Timeout, timeout tx) * 2 (block-rescan)
6238
- assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
6239
- assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6240
-
6241
- let mut commitment_tx_map = HashMap :: new ( ) ;
6242
- commitment_tx_map. insert ( commitment_tx[ 0 ] . txid ( ) , commitment_tx[ 0 ] . clone ( ) ) ;
6243
- node_txn[ 0 ] . verify ( & commitment_tx_map) . unwrap ( ) ;
6244
-
6245
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
6281
+ let timeout_tx;
6282
+ {
6283
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6284
+ 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)
6285
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 5 ] ) ;
6286
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 6 ] ) ;
6287
+ assert_eq ! ( node_txn[ 2 ] , node_txn[ 7 ] ) ;
6288
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6289
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6290
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6291
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6292
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6293
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6294
+ check_spends ! ( node_txn[ 3 ] , chan_2. 3 . clone( ) ) ;
6295
+ check_spends ! ( node_txn[ 4 ] , node_txn[ 3 ] . clone( ) ) ;
6296
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6297
+ assert_eq ! ( node_txn[ 4 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6298
+ timeout_tx = node_txn[ 0 ] . clone ( ) ;
6299
+ node_txn. clear ( ) ;
6300
+ }
6301
+
6302
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ timeout_tx] } , 1 ) ;
6246
6303
{
6247
6304
let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
6248
6305
assert_eq ! ( added_monitors. len( ) , 1 ) ;
@@ -6264,27 +6321,29 @@ mod tests {
6264
6321
} ,
6265
6322
_ => panic ! ( "Unexpected event" ) ,
6266
6323
} ;
6324
+ 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
6325
+ assert_eq ! ( node_txn. len( ) , 0 ) ;
6267
6326
6268
- // Broadcast legit commitment tx from A on B's chain
6269
- // Broadcast HTLC Timeout tx by B on offered output from A commitment tx on A's chain
6270
- let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6271
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6272
- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6273
- assert_eq ! ( events. len( ) , 1 ) ;
6274
- match events[ 0 ] {
6275
- MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6276
- _ => panic ! ( "Unexpected event" ) ,
6277
- }
6278
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6327
+ // Broadcast legit commitment tx from B on A's chain
6328
+ let commitment_tx = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6329
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6279
6330
6280
- // Verify that A's ChannelManager is able to detect that HTLC is timeout by a HTLC Timeout tx and react backward in consequence
6281
- nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
6331
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6282
6332
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6283
6333
assert_eq ! ( events. len( ) , 1 ) ;
6284
6334
match events[ 0 ] {
6285
6335
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6286
6336
_ => panic ! ( "Unexpected event" ) ,
6287
6337
}
6338
+ 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
6339
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6340
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6341
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6342
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6343
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6344
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6345
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6346
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6288
6347
}
6289
6348
6290
6349
#[ test]
0 commit comments