@@ -8190,6 +8190,43 @@ fn test_bump_txn_sanitize_tracking_maps() {
8190
8190
}
8191
8191
}
8192
8192
8193
+ #[ test]
8194
+ fn test_pending_claimed_htlc_no_balance_underflow ( ) {
8195
+ // Tests that if we have a pending outbound HTLC as well as a claimed-but-not-fully-removed
8196
+ // HTLC we will not underflow when we call `Channel::get_balance_msat()`.
8197
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
8198
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
8199
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
8200
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
8201
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , 0 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
8202
+
8203
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_010_000 ) . 0 ;
8204
+ nodes[ 1 ] . node . claim_funds ( payment_preimage) ;
8205
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
8206
+ let fulfill_ev = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
8207
+
8208
+ nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & fulfill_ev. update_fulfill_htlcs [ 0 ] ) ;
8209
+ expect_payment_sent_without_paths ! ( nodes[ 0 ] , payment_preimage) ;
8210
+ nodes[ 0 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & fulfill_ev. commitment_signed ) ;
8211
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
8212
+ let ( _raa, _cs) = get_revoke_commit_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
8213
+
8214
+ // At this point nodes[1] has received 1,010k msat (10k msat more than their reserve) and can
8215
+ // send an HTLC back (though it will go in the holding cell). Send an HTLC back and check we
8216
+ // can get our balance.
8217
+
8218
+ // Get a route from nodes[1] to nodes[0] by getting a route going the other way and then flip
8219
+ // the public key of the only hop. This works around ChannelDetails not showing the
8220
+ // almost-claimed HTLC as available balance.
8221
+ let ( mut route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 10_000 ) ;
8222
+ route. payment_params = None ; // This is all wrong, but unnecessary
8223
+ route. paths [ 0 ] [ 0 ] . pubkey = nodes[ 0 ] . node . get_our_node_id ( ) ;
8224
+ let ( _, payment_hash_2, payment_secret_2) = get_payment_preimage_hash ! ( nodes[ 0 ] ) ;
8225
+ nodes[ 1 ] . node . send_payment ( & route, payment_hash_2, & Some ( payment_secret_2) ) . unwrap ( ) ;
8226
+
8227
+ assert_eq ! ( nodes[ 1 ] . node. list_channels( ) [ 0 ] . balance_msat, 1_000_000 ) ;
8228
+ }
8229
+
8193
8230
#[ test]
8194
8231
fn test_channel_conf_timeout ( ) {
8195
8232
// Tests that, for inbound channels, we give up on them if the funding transaction does not
0 commit comments