Skip to content

Commit 99e01b2

Browse files
committed
Further simplify get_{inbound,outbound}_pending_htlc_stats
1 parent 1f93a83 commit 99e01b2

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/ln/channel.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,44 +1471,21 @@ impl Channel {
14711471

14721472
/// Returns (inbound_htlc_count, htlc_inbound_value_msat)
14731473
fn get_inbound_pending_htlc_stats(&self) -> (u32, u64) {
1474-
let mut inbound_htlc_count: u32 = 0;
14751474
let mut htlc_inbound_value_msat = 0;
14761475
for ref htlc in self.pending_inbound_htlcs.iter() {
1477-
match htlc.state {
1478-
InboundHTLCState::RemoteAnnounced => {},
1479-
InboundHTLCState::AwaitingRemoteRevokeToAnnounce => {},
1480-
InboundHTLCState::AwaitingAnnouncedRemoteRevoke => {},
1481-
InboundHTLCState::Committed => {},
1482-
InboundHTLCState::LocalRemoved => {},
1483-
}
1484-
inbound_htlc_count += 1;
14851476
htlc_inbound_value_msat += htlc.amount_msat;
14861477
}
1487-
(inbound_htlc_count, htlc_inbound_value_msat)
1478+
(self.pending_inbound_htlcs.len() as u32, htlc_inbound_value_msat)
14881479
}
14891480

14901481
/// Returns (outbound_htlc_count, htlc_outbound_value_msat)
1491-
/// If its for a remote update check, we need to be more lax about checking against messages we
1492-
/// sent but they may not have received/processed before they sent this message. Further, for
1493-
/// our own sends, we're more conservative and even consider things they've removed against
1494-
/// totals, though there is little reason to outside of further avoiding any race condition
1495-
/// issues.
1496-
fn get_outbound_pending_htlc_stats(&self, for_remote_update_check: bool) -> (u32, u64) {
1497-
let mut outbound_htlc_count: u32 = 0;
1482+
fn get_outbound_pending_htlc_stats(&self) -> (u32, u64) {
14981483
let mut htlc_outbound_value_msat = 0;
14991484
for ref htlc in self.pending_outbound_htlcs.iter() {
1500-
match htlc.state {
1501-
OutboundHTLCState::LocalAnnounced => { if for_remote_update_check { continue; } },
1502-
OutboundHTLCState::Committed => {},
1503-
OutboundHTLCState::RemoteRemoved => { if for_remote_update_check { continue; } },
1504-
OutboundHTLCState::AwaitingRemoteRevokeToRemove => { if for_remote_update_check { continue; } },
1505-
OutboundHTLCState::AwaitingRemovedRemoteRevoke => { if for_remote_update_check { continue; } },
1506-
}
1507-
outbound_htlc_count += 1;
15081485
htlc_outbound_value_msat += htlc.amount_msat;
15091486
}
15101487

1511-
(outbound_htlc_count, htlc_outbound_value_msat)
1488+
(self.pending_outbound_htlcs.len() as u32, htlc_outbound_value_msat)
15121489
}
15131490

15141491
pub fn update_add_htlc(&mut self, msg: &msgs::UpdateAddHTLC, pending_forward_state: PendingHTLCStatus) -> Result<(), HandleError> {
@@ -2804,7 +2781,7 @@ impl Channel {
28042781
return Err(HandleError{err: "Cannot send an HTLC while disconnected", action: Some(ErrorAction::IgnoreError)});
28052782
}
28062783

2807-
let (outbound_htlc_count, htlc_outbound_value_msat) = self.get_outbound_pending_htlc_stats(false);
2784+
let (outbound_htlc_count, htlc_outbound_value_msat) = self.get_outbound_pending_htlc_stats();
28082785
if outbound_htlc_count + 1 > self.their_max_accepted_htlcs as u32 {
28092786
return Err(HandleError{err: "Cannot push more than their max accepted HTLCs", action: None});
28102787
}

0 commit comments

Comments
 (0)