@@ -5976,9 +5976,9 @@ mod tests {
5976
5976
// ChainWatchInterface and pass the preimage backward accordingly. So here we test that ChannelManager is
5977
5977
// broadcasting the right event to other nodes in payment path.
5978
5978
// A --------------------> B ----------------------> C (preimage)
5979
- // A's commitment tx C's commitment tx
5980
- // \ \
5981
- // B's preimage tx C's HTLC Success tx
5979
+ // C's commitment tx
5980
+ // \
5981
+ // C's HTLC Success tx
5982
5982
5983
5983
let nodes = create_network ( 3 ) ;
5984
5984
@@ -5996,6 +5996,7 @@ mod tests {
5996
5996
// Broadcast legit commitment tx from C on B's chain
5997
5997
// Broadcast HTLC Success transation by C on received output from C's commitment tx on B's chain
5998
5998
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
5999
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
5999
6000
nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
6000
6001
{
6001
6002
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6021,7 +6022,14 @@ mod tests {
6021
6022
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6022
6023
_ => panic ! ( "Unexpected event" ) ,
6023
6024
}
6024
- let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6025
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 2 (commitment tx, HTLC-Success tx), ChannelMonitor : 1 (HTLC-Success tx)
6026
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6027
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6028
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6029
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6030
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6031
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6032
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6025
6033
6026
6034
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
6027
6035
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn} , 1 ) ;
@@ -6046,18 +6054,42 @@ mod tests {
6046
6054
} ,
6047
6055
_ => panic ! ( "Unexpected event" ) ,
6048
6056
} ;
6057
+ {
6058
+ 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)
6059
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6060
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6061
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6062
+ check_spends ! ( node_txn[ 3 ] , commitment_tx[ 0 ] . clone( ) ) ;
6063
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6064
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6065
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6066
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6067
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6068
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6069
+ node_txn. clear ( )
6070
+ }
6049
6071
6050
6072
// Broadcast legit commitment tx from A on B's chain
6051
6073
// Broadcast preimage tx by B on offered output from A commitment tx on A's chain
6052
6074
let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6075
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6053
6076
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6054
6077
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6055
6078
assert_eq ! ( events. len( ) , 1 ) ;
6056
6079
match events[ 0 ] {
6057
6080
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6058
6081
_ => panic ! ( "Unexpected event" ) ,
6059
6082
}
6060
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6083
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx), ChannelMonitor : 1 (HTLC-Success) * 2 (block-rescan)
6084
+ assert_eq ! ( node_txn. len( ) , 3 ) ;
6085
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 2 ] ) ;
6086
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6087
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6088
+ check_spends ! ( node_txn[ 2 ] , commitment_tx[ 0 ] . clone( ) ) ;
6089
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6090
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6091
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6092
+ let commitment_tx = node_txn[ 1 ] . clone ( ) ;
6061
6093
6062
6094
// Verify that A's ChannelManager is able to extract preimage from preimage tx and pass it backward
6063
6095
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
@@ -6067,6 +6099,17 @@ mod tests {
6067
6099
MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
6068
6100
_ => panic ! ( "Unexpected event" ) ,
6069
6101
}
6102
+ 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)
6103
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6104
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6105
+ check_spends ! ( node_txn[ 0 ] , commitment_tx. clone( ) ) ;
6106
+ check_spends ! ( node_txn[ 3 ] , commitment_tx. clone( ) ) ;
6107
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6108
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 138 ) ;
6109
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6110
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6111
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6112
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6070
6113
}
6071
6114
6072
6115
#[ test]
@@ -6075,7 +6118,7 @@ mod tests {
6075
6118
// ChainWatchInterface and timeout the HTLC bacward accordingly. So here we test that ChannelManager is
6076
6119
// broadcasting the right event to other nodes in payment path.
6077
6120
// A ------------------> B ----------------------> C (timeout)
6078
- // A 's commitment tx C's commitment tx
6121
+ // B 's commitment tx C's commitment tx
6079
6122
// \ \
6080
6123
// B's HTLC timeout tx B's timeout tx
6081
6124
@@ -6094,6 +6137,7 @@ mod tests {
6094
6137
6095
6138
// Brodacast legit commitment tx from C on B's chain
6096
6139
let commitment_tx = nodes[ 2 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_2. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6140
+ check_spends ! ( commitment_tx[ 0 ] , chan_2. 3 . clone( ) ) ;
6097
6141
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash, PaymentFailReason :: PreimageUnknown ) ;
6098
6142
{
6099
6143
let mut added_monitors = nodes[ 2 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
@@ -6119,23 +6163,36 @@ mod tests {
6119
6163
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6120
6164
_ => panic ! ( "Unexpected event" ) ,
6121
6165
}
6122
- let mut funding_tx_map = HashMap :: new ( ) ;
6123
- funding_tx_map. insert ( chan_2. 3 . txid ( ) , chan_2. 3 . clone ( ) ) ;
6124
- commitment_tx[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
6166
+ let node_txn = nodes[ 2 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ; // ChannelManager : 1 (commitment tx)
6167
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
6168
+ check_spends ! ( node_txn[ 0 ] , chan_2. 3 . clone( ) ) ;
6169
+ assert_eq ! ( node_txn[ 0 ] . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6125
6170
6126
6171
// Broadcast timeout transaction by B on received output fron C's commitment tx on B's chain
6127
6172
// Verify that B's ChannelManager is able to detect that HTLC is timeout by its own tx and react backward in consequence
6128
6173
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6129
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6130
- assert_eq ! ( node_txn. len( ) , 8 ) ; // ChannelManager : 2 (commitment tx, HTLC-Timeout), ChannelMonitor : 6 (commitment tx, HTLC-Timeout, timeout tx) * 2 (block-rescan)
6131
- assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
6132
- assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6133
-
6134
- let mut commitment_tx_map = HashMap :: new ( ) ;
6135
- commitment_tx_map. insert ( commitment_tx[ 0 ] . txid ( ) , commitment_tx[ 0 ] . clone ( ) ) ;
6136
- node_txn[ 0 ] . verify ( & commitment_tx_map) . unwrap ( ) ;
6137
-
6138
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 1 ) ;
6174
+ let timeout_tx;
6175
+ {
6176
+ let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6177
+ 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)
6178
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 5 ] ) ;
6179
+ assert_eq ! ( node_txn[ 1 ] , node_txn[ 6 ] ) ;
6180
+ assert_eq ! ( node_txn[ 2 ] , node_txn[ 7 ] ) ;
6181
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6182
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6183
+ check_spends ! ( node_txn[ 1 ] , chan_2. 3 . clone( ) ) ;
6184
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6185
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6186
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6187
+ check_spends ! ( node_txn[ 3 ] , chan_2. 3 . clone( ) ) ;
6188
+ check_spends ! ( node_txn[ 4 ] , node_txn[ 3 ] . clone( ) ) ;
6189
+ assert_eq ! ( node_txn[ 3 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 71 ) ;
6190
+ assert_eq ! ( node_txn[ 4 ] . input[ 0 ] . witness. clone( ) . last( ) . unwrap( ) . len( ) , 133 ) ;
6191
+ timeout_tx = node_txn[ 0 ] . clone ( ) ;
6192
+ node_txn. clear ( ) ;
6193
+ }
6194
+
6195
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ timeout_tx] } , 1 ) ;
6139
6196
{
6140
6197
let mut added_monitors = nodes[ 1 ] . chan_monitor . added_monitors . lock ( ) . unwrap ( ) ;
6141
6198
assert_eq ! ( added_monitors. len( ) , 1 ) ;
@@ -6157,27 +6214,29 @@ mod tests {
6157
6214
} ,
6158
6215
_ => panic ! ( "Unexpected event" ) ,
6159
6216
} ;
6217
+ 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
6218
+ assert_eq ! ( node_txn. len( ) , 0 ) ;
6160
6219
6161
- // Broadcast legit commitment tx from A on B's chain
6162
- // Broadcast HTLC Timeout tx by B on offered output from A commitment tx on A's chain
6163
- let commitment_tx = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6164
- nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 1 ) ;
6165
- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
6166
- assert_eq ! ( events. len( ) , 1 ) ;
6167
- match events[ 0 ] {
6168
- MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6169
- _ => panic ! ( "Unexpected event" ) ,
6170
- }
6171
- let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
6220
+ // Broadcast legit commitment tx from B on A's chain
6221
+ let commitment_tx = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
6222
+ check_spends ! ( commitment_tx[ 0 ] , chan_1. 3 . clone( ) ) ;
6172
6223
6173
- // Verify that A's ChannelManager is able to detect that HTLC is timeout by a HTLC Timeout tx and react backward in consequence
6174
- nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : node_txn } , 1 ) ;
6224
+ nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ commitment_tx[ 0 ] . clone( ) ] } , 200 ) ;
6175
6225
let events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6176
6226
assert_eq ! ( events. len( ) , 1 ) ;
6177
6227
match events[ 0 ] {
6178
6228
MessageSendEvent :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { .. } } => { } ,
6179
6229
_ => panic ! ( "Unexpected event" ) ,
6180
6230
}
6231
+ 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
6232
+ assert_eq ! ( node_txn. len( ) , 4 ) ;
6233
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ;
6234
+ check_spends ! ( node_txn[ 0 ] , commitment_tx[ 0 ] . clone( ) ) ;
6235
+ assert_eq ! ( node_txn[ 0 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 138 ) ;
6236
+ check_spends ! ( node_txn[ 1 ] , chan_1. 3 . clone( ) ) ;
6237
+ check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] . clone( ) ) ;
6238
+ assert_eq ! ( node_txn[ 1 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 71 ) ;
6239
+ assert_eq ! ( node_txn[ 2 ] . clone( ) . input[ 0 ] . witness. last( ) . unwrap( ) . len( ) , 133 ) ;
6181
6240
}
6182
6241
6183
6242
#[ test]
0 commit comments