@@ -24,7 +24,7 @@ use crate::ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, Pa
24
24
use crate::ln::channel::{Channel, ChannelError};
25
25
use crate::ln::{chan_utils, onion_utils};
26
26
use crate::ln::chan_utils::{OFFERED_HTLC_SCRIPT_WEIGHT, htlc_success_tx_weight, htlc_timeout_tx_weight, HTLCOutputInCommitment};
27
- use crate::routing::gossip::{NetworkGraph, NetworkUpdate};
27
+ use crate::routing::gossip::{NetworkGraph, NetworkUpdate, NodeId };
28
28
use crate::routing::router::{PaymentParameters, Route, RouteHop, RouteParameters, find_route, get_route};
29
29
use crate::ln::features::{ChannelFeatures, NodeFeatures};
30
30
use crate::ln::msgs;
@@ -10490,3 +10490,35 @@ fn test_non_final_funding_tx() {
10490
10490
assert!(nodes[0].node.funding_transaction_generated(&temp_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).is_ok());
10491
10491
get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
10492
10492
}
10493
+
10494
+
10495
+ #[test]
10496
+ fn test_trivial_inflight_htlc_tracking() {
10497
+ let chanmon_cfgs = create_chanmon_cfgs(2);
10498
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
10499
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
10500
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
10501
+
10502
+ let (_, _, chan_id, _) = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
10503
+
10504
+ // Send and claim the payment. Inflight HTLCs should be empty.
10505
+ send_payment(&nodes[0], &vec!(&nodes[1])[..], 500000);
10506
+ assert_eq!(node_chanmgrs[0].compute_inflight_htlcs().0.len(), 0);
10507
+
10508
+ // Send the payment, but do not claim it. Our inflight HTLCs should contain the pending payment
10509
+ route_payment(&nodes[0], &vec!(&nodes[1])[..], 500000);
10510
+ let inflight_htlcs = node_chanmgrs[0].compute_inflight_htlcs();
10511
+
10512
+ {
10513
+ let channel_lock = nodes[0].node.channel_state.lock().unwrap();
10514
+ let channel = channel_lock.by_id.get(&chan_id).unwrap();
10515
+
10516
+ let used_liquidity = inflight_htlcs.used_liquidity_msat(
10517
+ &NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) ,
10518
+ &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
10519
+ channel.get_short_channel_id().unwrap()
10520
+ );
10521
+
10522
+ assert_eq!(used_liquidity, Some(500000));
10523
+ }
10524
+ }
0 commit comments