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