Skip to content

Commit 5f1b366

Browse files
committed
Split get_pending_htlc_stats
to get_inbound_pending_htlc_stats and get_outbound_pending_htlc_stats
1 parent ff6ea71 commit 5f1b366

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/ln/channel.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,17 +1476,9 @@ impl Channel {
14761476
Ok(())
14771477
}
14781478

1479-
/// Returns (inbound_htlc_count, outbound_htlc_count, htlc_outbound_value_msat, htlc_inbound_value_msat)
1480-
/// If its for a remote update check, we need to be more lax about checking against messages we
1481-
/// sent but they may not have received/processed before they sent this message. Further, for
1482-
/// our own sends, we're more conservative and even consider things they've removed against
1483-
/// totals, though there is little reason to outside of further avoiding any race condition
1484-
/// issues.
1485-
fn get_pending_htlc_stats(&self, for_remote_update_check: bool) -> (u32, u32, u64, u64) {
1486-
//TODO: Can probably split this into inbound/outbound
1479+
/// Returns (inbound_htlc_count, htlc_inbound_value_msat)
1480+
fn get_inbound_pending_htlc_stats(&self) -> (u32, u64) {
14871481
let mut inbound_htlc_count: u32 = 0;
1488-
let mut outbound_htlc_count: u32 = 0;
1489-
let mut htlc_outbound_value_msat = 0;
14901482
let mut htlc_inbound_value_msat = 0;
14911483
for ref htlc in self.pending_inbound_htlcs.iter() {
14921484
match htlc.state {
@@ -1499,6 +1491,18 @@ impl Channel {
14991491
inbound_htlc_count += 1;
15001492
htlc_inbound_value_msat += htlc.amount_msat;
15011493
}
1494+
(inbound_htlc_count, htlc_inbound_value_msat)
1495+
}
1496+
1497+
/// Returns (outbound_htlc_count, htlc_outbound_value_msat)
1498+
/// If its for a remote update check, we need to be more lax about checking against messages we
1499+
/// sent but they may not have received/processed before they sent this message. Further, for
1500+
/// our own sends, we're more conservative and even consider things they've removed against
1501+
/// totals, though there is little reason to outside of further avoiding any race condition
1502+
/// issues.
1503+
fn get_outbound_pending_htlc_stats(&self, for_remote_update_check: bool) -> (u32, u64) {
1504+
let mut outbound_htlc_count: u32 = 0;
1505+
let mut htlc_outbound_value_msat = 0;
15021506
for ref htlc in self.pending_outbound_htlcs.iter() {
15031507
match htlc.state {
15041508
OutboundHTLCState::LocalAnnounced => { if for_remote_update_check { continue; } },
@@ -1511,7 +1515,7 @@ impl Channel {
15111515
htlc_outbound_value_msat += htlc.amount_msat;
15121516
}
15131517

1514-
(inbound_htlc_count, outbound_htlc_count, htlc_outbound_value_msat, htlc_inbound_value_msat)
1518+
(outbound_htlc_count, htlc_outbound_value_msat)
15151519
}
15161520

15171521
pub fn update_add_htlc(&mut self, msg: &msgs::UpdateAddHTLC, pending_forward_state: PendingHTLCStatus) -> Result<(), HandleError> {
@@ -1528,7 +1532,7 @@ impl Channel {
15281532
return Err(HandleError{err: "Remote side tried to send less than our minimum HTLC value", action: None});
15291533
}
15301534

1531-
let (inbound_htlc_count, _, _, htlc_inbound_value_msat) = self.get_pending_htlc_stats(true);
1535+
let (inbound_htlc_count, htlc_inbound_value_msat) = self.get_inbound_pending_htlc_stats();
15321536
if inbound_htlc_count + 1 > OUR_MAX_HTLCS as u32 {
15331537
return Err(HandleError{err: "Remote tried to push more than our max accepted HTLCs", action: None});
15341538
}
@@ -2803,7 +2807,7 @@ impl Channel {
28032807
return Err(HandleError{err: "Cannot send an HTLC while disconnected", action: Some(ErrorAction::IgnoreError)});
28042808
}
28052809

2806-
let (_, outbound_htlc_count, htlc_outbound_value_msat, _) = self.get_pending_htlc_stats(false);
2810+
let (outbound_htlc_count, htlc_outbound_value_msat) = self.get_outbound_pending_htlc_stats(false);
28072811
if outbound_htlc_count + 1 > self.their_max_accepted_htlcs as u32 {
28082812
return Err(HandleError{err: "Cannot push more than their max accepted HTLCs", action: None});
28092813
}

0 commit comments

Comments
 (0)