@@ -6013,9 +6013,9 @@ mod tests {
6013
6013
// ChainWatchInterface and pass the preimage backward accordingly. So here we test that ChannelManager is
6014
6014
// broadcasting the right event to other nodes in payment path.
6015
6015
// A --------------------> B ----------------------> C (preimage)
6016
- // A's commitment tx C's commitment tx
6017
- // \ \
6018
- // B's preimage tx C's HTLC Success tx
6016
+ // C's commitment tx
6017
+ // \
6018
+ // C's HTLC Success tx
6019
6019
6020
6020
let nodes = create_network ( 3 ) ;
6021
6021
@@ -6033,6 +6033,7 @@ mod tests {
6033
6033
// Broadcast legit commitment tx from C on B's chain
6034
6034
// Broadcast HTLC Success transation by C on received output from C's commitment tx on B's chain
6035
6035
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6036
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
6036
6037
nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
6037
6038
{
6038
6039
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6058,7 +6059,14 @@ mod tests {
6058
6059
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6059
6060
_ => panic ! ( "Unexpected event" ) ,
6060
6061
}
6061
- let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6062
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Success tx), ChannelMonitor : 1 (HTLC-Success tx)
6063
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6064
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6065
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6066
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6067
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6068
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6069
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6062
6070
6063
6071
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
6064
6072
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn} , 1 ) ;
@@ -6083,18 +6091,42 @@ mod tests {
6083
6091
} ,
6084
6092
_ => panic ! ( "Unexpected event" ) ,
6085
6093
} ;
6094
+ {
6095
+ 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)
6096
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6097
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6098
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6099
+ check_spends ! ( node_txn[ 3 ] , commitment_tx[ 0 ] . clone( ) ) ;
6100
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6101
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6102
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6103
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6104
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6105
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6106
+ node_txn. clear ( )
6107
+ }
6086
6108
6087
6109
// Broadcast legit commitment tx from A on B's chain
6088
6110
// Broadcast preimage tx by B on offered output from A commitment tx on A's chain
6089
6111
let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6112
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6090
6113
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6091
6114
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6092
6115
assert_eq ! ( events. len( ) , 1 ) ;
6093
6116
match events[ 0 ] {
6094
6117
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6095
6118
_ => panic ! ( "Unexpected event" ) ,
6096
6119
}
6097
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6120
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx), ChannelMonitor : 1 (HTLC-Success) * 2 (block-rescan)
6121
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6122
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
6123
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6124
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6125
+ check_spends ! ( node_txn[ 2 ] , commitment_tx[ 0 ] . clone( ) ) ;
6126
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6127
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6128
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6129
+ let commitment_tx = node_txn[ 1 ] . clone ( ) ;
6098
6130
6099
6131
// Verify that A's ChannelManager is able to extract preimage from preimage tx and pass it backward
6100
6132
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
@@ -6104,6 +6136,17 @@ mod tests {
6104
6136
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6105
6137
_ => panic ! ( "Unexpected event" ) ,
6106
6138
}
6139
+ 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)
6140
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6141
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6142
+ check_spends ! ( node_txn[ 0 ] , commitment_tx. clone( ) ) ;
6143
+ check_spends ! ( node_txn[ 3 ] , commitment_tx. clone( ) ) ;
6144
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6145
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6146
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6147
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6148
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6149
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6107
6150
}
6108
6151
6109
6152
#[ test]
@@ -6112,7 +6155,7 @@ mod tests {
6112
6155
// ChainWatchInterface and timeout the HTLC bacward accordingly. So here we test that ChannelManager is
6113
6156
// broadcasting the right event to other nodes in payment path.
6114
6157
// A ------------------> B ----------------------> C (timeout)
6115
- // A 's commitment tx C's commitment tx
6158
+ // B 's commitment tx C's commitment tx
6116
6159
// \ \
6117
6160
// B's HTLC timeout tx B's timeout tx
6118
6161
@@ -6131,6 +6174,7 @@ mod tests {
6131
6174
6132
6175
// Brodacast legit commitment tx from C on B's chain
6133
6176
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6177
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
6134
6178
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash, PaymentFailReason :: PreimageUnknown ) ;
6135
6179
{
6136
6180
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6156,23 +6200,36 @@ mod tests {
6156
6200
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6157
6201
_ => panic ! ( "Unexpected event" ) ,
6158
6202
}
6159
- let mut funding_tx_map = HashMap :: new ( ) ;
6160
- funding_tx_map. insert ( chan_2. 3 . txid ( ) , chan_2. 3 . clone ( ) ) ;
6161
- commitment_tx[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
6203
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx)
6204
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
6205
+ check_spends ! ( node_txn[ 0 ] , chan_2. 3 . clone( ) ) ;
6206
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6162
6207
6163
6208
// Broadcast timeout transaction by B on received output fron C's commitment tx on B's chain
6164
6209
// Verify that B's ChannelManager is able to detect that HTLC is timeout by its own tx and react backward in consequence
6165
6210
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6166
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6167
- assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout), ChannelMonitor : 6 (commitment tx, HTLC-Timeout, timeout tx) * 2 (block-rescan)
6168
- assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
6169
- assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6170
-
6171
- let mut commitment_tx_map = HashMap :: new ( ) ;
6172
- commitment_tx_map. insert ( commitment_tx[ 0 ] . txid ( ) , commitment_tx[ 0 ] . clone ( ) ) ;
6173
- node_txn[ 0 ] . verify ( & commitment_tx_map) . unwrap ( ) ;
6174
-
6175
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
6211
+ let timeout_tx;
6212
+ {
6213
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6214
+ 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)
6215
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 5 ] ) ;
6216
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 6 ] ) ;
6217
+ assert_eq ! ( node_txn[ 2 ] , node_txn[ 7 ] ) ;
6218
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6219
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6220
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6221
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6222
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6223
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6224
+ check_spends ! ( node_txn[ 3 ] , chan_2. 3 . clone( ) ) ;
6225
+ check_spends ! ( node_txn[ 4 ] , node_txn[ 3 ] . clone( ) ) ;
6226
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6227
+ assert_eq ! ( node_txn[ 4 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6228
+ timeout_tx = node_txn[ 0 ] . clone ( ) ;
6229
+ node_txn. clear ( ) ;
6230
+ }
6231
+
6232
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ timeout_tx] } , 1 ) ;
6176
6233
{
6177
6234
let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
6178
6235
assert_eq ! ( added_monitors. len( ) , 1 ) ;
@@ -6194,27 +6251,29 @@ mod tests {
6194
6251
} ,
6195
6252
_ => panic ! ( "Unexpected event" ) ,
6196
6253
} ;
6254
+ 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
6255
+ assert_eq ! ( node_txn. len( ) , 0 ) ;
6197
6256
6198
- // Broadcast legit commitment tx from A on B's chain
6199
- // Broadcast HTLC Timeout tx by B on offered output from A commitment tx on A's chain
6200
- let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6201
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6202
- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6203
- assert_eq ! ( events. len( ) , 1 ) ;
6204
- match events[ 0 ] {
6205
- MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6206
- _ => panic ! ( "Unexpected event" ) ,
6207
- }
6208
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6257
+ // Broadcast legit commitment tx from B on A's chain
6258
+ let commitment_tx = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6259
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6209
6260
6210
- // Verify that A's ChannelManager is able to detect that HTLC is timeout by a HTLC Timeout tx and react backward in consequence
6211
- nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
6261
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6212
6262
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6213
6263
assert_eq ! ( events. len( ) , 1 ) ;
6214
6264
match events[ 0 ] {
6215
6265
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6216
6266
_ => panic ! ( "Unexpected event" ) ,
6217
6267
}
6268
+ 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
6269
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6270
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6271
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6272
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6273
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6274
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6275
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6276
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6218
6277
}
6219
6278
6220
6279
#[ test]
0 commit comments