@@ -3689,7 +3689,7 @@ fn test_funding_peer_disconnect() {
3689
3689
nodes[ 0 ] . net_graph_msg_handler . handle_channel_update ( & as_update) . unwrap ( ) ;
3690
3690
3691
3691
let ( route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 1000000 ) ;
3692
- let ( payment_preimage, _ , _ ) = send_along_route ( & nodes[ 0 ] , route, & [ & nodes[ 1 ] ] , 1000000 ) ;
3692
+ let payment_preimage = send_along_route ( & nodes[ 0 ] , route, & [ & nodes[ 1 ] ] , 1000000 ) . 0 ;
3693
3693
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage) ;
3694
3694
3695
3695
// Check that after deserialization and reconnection we can still generate an identical
@@ -4100,7 +4100,7 @@ fn test_no_txn_manager_serialize_deserialize() {
4100
4100
send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1000000 ) ;
4101
4101
}
4102
4102
4103
- fn do_test_dup_htlc_onchain_fails_on_reload ( persist_manager_post_event : bool ) {
4103
+ fn do_test_dup_htlc_onchain_fails_on_reload ( persist_manager_post_event : bool , confirm_commitment_tx : bool , payment_timeout : bool ) {
4104
4104
// When a Channel is closed, any outbound HTLCs which were relayed through it are simply
4105
4105
// dropped when the Channel is. From there, the ChannelManager relies on the ChannelMonitor
4106
4106
// having a copy of the relevant fail-/claim-back data and processes the HTLC fail/claim when
@@ -4121,7 +4121,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool) {
4121
4121
4122
4122
// Route a payment, but force-close the channel before the HTLC fulfill message arrives at
4123
4123
// nodes[0].
4124
- let ( payment_preimage, _ , _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 10000000 ) ;
4124
+ let ( payment_preimage, payment_hash , _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 10000000 ) ;
4125
4125
nodes[ 0 ] . node . force_close_channel ( & nodes[ 0 ] . node . list_channels ( ) [ 0 ] . channel_id ) . unwrap ( ) ;
4126
4126
check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
4127
4127
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
@@ -4137,6 +4137,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool) {
4137
4137
assert_eq ! ( node_txn[ 0 ] , node_txn[ 1 ] ) ;
4138
4138
check_spends ! ( node_txn[ 1 ] , funding_tx) ;
4139
4139
check_spends ! ( node_txn[ 2 ] , node_txn[ 1 ] ) ;
4140
+ let timeout_txn = vec ! [ node_txn[ 2 ] . clone( ) ] ;
4140
4141
4141
4142
assert ! ( nodes[ 1 ] . node. claim_funds( payment_preimage) ) ;
4142
4143
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
@@ -4151,15 +4152,30 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool) {
4151
4152
header. prev_blockhash = nodes[ 0 ] . best_block_hash ( ) ;
4152
4153
connect_block ( & nodes[ 0 ] , & Block { header, txdata : vec ! [ node_txn[ 1 ] . clone( ) ] } ) ;
4153
4154
4155
+ if confirm_commitment_tx {
4156
+ connect_blocks ( & nodes[ 0 ] , BREAKDOWN_TIMEOUT as u32 - 1 ) ;
4157
+ }
4158
+
4159
+ header. prev_blockhash = nodes[ 0 ] . best_block_hash ( ) ;
4160
+ let claim_block = Block { header, txdata : if payment_timeout { timeout_txn } else { claim_txn } } ;
4161
+
4162
+ if payment_timeout {
4163
+ assert ! ( confirm_commitment_tx) ; // Otherwise we're spending below our CSV!
4164
+ connect_block ( & nodes[ 0 ] , & claim_block) ;
4165
+ connect_blocks ( & nodes[ 0 ] , ANTI_REORG_DELAY - 2 ) ;
4166
+ }
4167
+
4154
4168
// Now connect the HTLC claim transaction with the ChainMonitor-generated ChannelMonitor update
4155
4169
// returning TemporaryFailure. This should cause the claim event to never make its way to the
4156
4170
// ChannelManager.
4157
4171
chanmon_cfgs[ 0 ] . persister . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . clear ( ) ;
4158
4172
chanmon_cfgs[ 0 ] . persister . set_update_ret ( Err ( ChannelMonitorUpdateErr :: TemporaryFailure ) ) ;
4159
4173
4160
- header. prev_blockhash = nodes[ 0 ] . best_block_hash ( ) ;
4161
- let claim_block = Block { header, txdata : claim_txn } ;
4162
- connect_block ( & nodes[ 0 ] , & claim_block) ;
4174
+ if payment_timeout {
4175
+ connect_blocks ( & nodes[ 0 ] , 1 ) ;
4176
+ } else {
4177
+ connect_block ( & nodes[ 0 ] , & claim_block) ;
4178
+ }
4163
4179
4164
4180
let funding_txo = OutPoint { txid : funding_tx. txid ( ) , index : 0 } ;
4165
4181
let mon_updates: Vec < _ > = chanmon_cfgs[ 0 ] . persister . chain_sync_monitor_persistences . lock ( ) . unwrap ( )
@@ -4181,7 +4197,11 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool) {
4181
4197
let mut chan_0_monitor_serialized = test_utils:: TestVecWriter ( Vec :: new ( ) ) ;
4182
4198
get_monitor ! ( nodes[ 0 ] , chan_id) . write ( & mut chan_0_monitor_serialized) . unwrap ( ) ;
4183
4199
nodes[ 0 ] . chain_monitor . chain_monitor . channel_monitor_updated ( funding_txo, mon_updates[ 0 ] ) . unwrap ( ) ;
4184
- expect_payment_sent ! ( nodes[ 0 ] , payment_preimage) ;
4200
+ if payment_timeout {
4201
+ expect_payment_failed ! ( nodes[ 0 ] , payment_hash, true ) ;
4202
+ } else {
4203
+ expect_payment_sent ! ( nodes[ 0 ] , payment_preimage) ;
4204
+ }
4185
4205
4186
4206
// If we persist the ChannelManager after we get the PaymentSent event, we shouldn't get it
4187
4207
// twice.
@@ -4221,6 +4241,8 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool) {
4221
4241
4222
4242
if persist_manager_post_event {
4223
4243
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
4244
+ } else if payment_timeout {
4245
+ expect_payment_failed ! ( nodes[ 0 ] , payment_hash, true ) ;
4224
4246
} else {
4225
4247
expect_payment_sent ! ( nodes[ 0 ] , payment_preimage) ;
4226
4248
}
@@ -4235,8 +4257,12 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool) {
4235
4257
4236
4258
#[ test]
4237
4259
fn test_dup_htlc_onchain_fails_on_reload ( ) {
4238
- do_test_dup_htlc_onchain_fails_on_reload ( true ) ;
4239
- do_test_dup_htlc_onchain_fails_on_reload ( false ) ;
4260
+ do_test_dup_htlc_onchain_fails_on_reload ( true , true , true ) ;
4261
+ do_test_dup_htlc_onchain_fails_on_reload ( true , true , false ) ;
4262
+ do_test_dup_htlc_onchain_fails_on_reload ( true , false , false ) ;
4263
+ do_test_dup_htlc_onchain_fails_on_reload ( false , true , true ) ;
4264
+ do_test_dup_htlc_onchain_fails_on_reload ( false , true , false ) ;
4265
+ do_test_dup_htlc_onchain_fails_on_reload ( false , false , false ) ;
4240
4266
}
4241
4267
4242
4268
#[ test]
0 commit comments