@@ -16,7 +16,7 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
16
16
use bitcoin:: blockdata:: constants:: genesis_block;
17
17
use bitcoin:: hash_types:: BlockHash ;
18
18
use bitcoin:: network:: constants:: Network ;
19
- use chain:: channelmonitor:: ChannelMonitor ;
19
+ use chain:: channelmonitor:: { ANTI_REORG_DELAY , ChannelMonitor } ;
20
20
use chain:: transaction:: OutPoint ;
21
21
use chain:: { ChannelMonitorUpdateErr , Listen , Watch } ;
22
22
use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure } ;
@@ -2058,6 +2058,50 @@ fn test_pending_update_fee_ack_on_reconnect() {
2058
2058
claim_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , payment_preimage) ;
2059
2059
}
2060
2060
2061
+ #[ test]
2062
+ fn test_fail_htlc_on_broadcast_after_claim ( ) {
2063
+ // In an earlier version of 7e78fa660cec8a73286c94c1073ee588140e7a01 we'd also fail the inbound
2064
+ // channel backwards if we received an HTLC failure after a HTLC fulfillment. Here we test a
2065
+ // specific case of that by having the HTLC failure come from the ChannelMonitor after a dust
2066
+ // HTLC was not included in a confirmed commitment transaction.
2067
+ //
2068
+ // We first forward a payment, then claim it with an update_fulfill_htlc message, closing the
2069
+ // channel immediately before commitment occurs. After the commitment transaction reaches
2070
+ // ANTI_REORG_DELAY confirmations, will will try to fail the HTLC which was already fulfilled.
2071
+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
2072
+ let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
2073
+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
2074
+ let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
2075
+
2076
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
2077
+ let chan_id_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 2 ;
2078
+
2079
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 2000 ) . 0 ;
2080
+
2081
+ let bs_txn = get_local_commitment_txn ! ( nodes[ 2 ] , chan_id_2) ;
2082
+ assert_eq ! ( bs_txn. len( ) , 1 ) ;
2083
+
2084
+ nodes[ 2 ] . node . claim_funds ( payment_preimage) ;
2085
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
2086
+ let cs_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2087
+ nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & cs_updates. update_fulfill_htlcs [ 0 ] ) ;
2088
+ let bs_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
2089
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2090
+ expect_payment_forwarded ! ( nodes[ 1 ] , Some ( 1000 ) , false ) ;
2091
+
2092
+ mine_transaction ( & nodes[ 1 ] , & bs_txn[ 0 ] ) ;
2093
+ check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: CommitmentTxConfirmed ) ;
2094
+ check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
2095
+ connect_blocks ( & nodes[ 1 ] , ANTI_REORG_DELAY - 1 ) ;
2096
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2097
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
2098
+
2099
+ nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. update_fulfill_htlcs [ 0 ] ) ;
2100
+ expect_payment_sent_without_paths ! ( nodes[ 0 ] , payment_preimage) ;
2101
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , bs_updates. commitment_signed, true , true ) ;
2102
+ expect_payment_path_successful ! ( nodes[ 0 ] ) ;
2103
+ }
2104
+
2061
2105
fn do_update_fee_resend_test ( deliver_update : bool , parallel_updates : bool ) {
2062
2106
// In early versions we did not handle resending of update_fee on reconnect correctly. The
2063
2107
// chanmon_consistency fuzz target, of course, immediately found it, but we test a few cases
0 commit comments