|
13 | 13 | use chain::keysinterface::BaseSign;
|
14 | 14 | use ln::PaymentPreimage;
|
15 | 15 | use ln::channel::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC};
|
16 |
| -use ln::channelmanager::{ChannelManager, RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA}; |
17 |
| -use ln::channel::{Channel, ChannelError}; |
| 16 | +use ln::channelmanager::{RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT}; |
| 17 | +use ln::channel::Channel; |
18 | 18 | use ln::onion_utils;
|
19 | 19 | use ln::features::InitFeatures;
|
20 | 20 | use ln::msgs;
|
21 | 21 | use ln::msgs::{ChannelMessageHandler, ErrorAction};
|
22 | 22 | use util::enforcing_trait_impls::EnforcingSigner;
|
23 | 23 | use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason};
|
24 | 24 | use util::errors::APIError;
|
25 |
| -use util::ser::Writeable; |
26 | 25 | use util::config::UserConfig;
|
27 | 26 |
|
28 | 27 | use bitcoin::blockdata::constants::genesis_block;
|
@@ -895,6 +894,43 @@ fn test_counterparty_raa_skip_no_crash() {
|
895 | 894 | check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError { err: "Received an unexpected revoke_and_ack".to_string() });
|
896 | 895 | }
|
897 | 896 |
|
| 897 | +#[test] |
| 898 | +fn test_pending_claimed_htlc_no_balance_underflow() { |
| 899 | + // Tests that if we have a pending outbound HTLC as well as a claimed-but-not-fully-removed |
| 900 | + // HTLC we will not underflow when we call `Channel::get_balance_msat()`. |
| 901 | + let chanmon_cfgs = create_chanmon_cfgs(2); |
| 902 | + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); |
| 903 | + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); |
| 904 | + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); |
| 905 | + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 0, InitFeatures::known(), InitFeatures::known()); |
| 906 | + |
| 907 | + let payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 1_010_000).0; |
| 908 | + nodes[1].node.claim_funds(payment_preimage); |
| 909 | + check_added_monitors!(nodes[1], 1); |
| 910 | + let fulfill_ev = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); |
| 911 | + |
| 912 | + nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &fulfill_ev.update_fulfill_htlcs[0]); |
| 913 | + expect_payment_sent_without_paths!(nodes[0], payment_preimage); |
| 914 | + nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &fulfill_ev.commitment_signed); |
| 915 | + check_added_monitors!(nodes[0], 1); |
| 916 | + let (_raa, _cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); |
| 917 | + |
| 918 | + // At this point nodes[1] has received 1,010k msat (10k msat more than their reserve) and can |
| 919 | + // send an HTLC back (though it will go in the holding cell). Send an HTLC back and check we |
| 920 | + // can get our balance. |
| 921 | + |
| 922 | + // Get a route from nodes[1] to nodes[0] by getting a route going the other way and then flip |
| 923 | + // the public key of the only hop. This works around ChannelDetails not showing the |
| 924 | + // almost-claimed HTLC as available balance. |
| 925 | + let (mut route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 10_000); |
| 926 | + route.payment_params = None; // This is all wrong, but unnecessary |
| 927 | + route.paths[0][0].pubkey = nodes[0].node.get_our_node_id(); |
| 928 | + let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[0]); |
| 929 | + nodes[1].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap(); |
| 930 | + |
| 931 | + assert_eq!(nodes[1].node.list_channels()[0].balance_msat, 1_000_000); |
| 932 | +} |
| 933 | + |
898 | 934 | #[test]
|
899 | 935 | fn test_channel_conf_timeout() {
|
900 | 936 | // Tests that, for inbound channels, we give up on them if the funding transaction does not
|
|
0 commit comments