File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -7478,12 +7478,9 @@ where
7478
7478
);
7479
7479
// We really want take() here, but, again, non-mut ref :(
7480
7480
if let OutboundHTLCOutcome::Failure(mut reason) = outcome.clone() {
7481
- if let (Some(timestamp), Some(now)) = (htlc.send_timestamp, now) {
7482
- let elapsed_millis = now.saturating_sub(timestamp).as_millis();
7483
- let elapsed_units = elapsed_millis / HOLD_TIME_UNIT_MILLIS;
7484
- let hold_time = u32::try_from(elapsed_units).unwrap_or(u32::MAX);
7481
+ hold_time(htlc.send_timestamp, now).map(|hold_time| {
7485
7482
reason.set_hold_time(hold_time);
7486
- }
7483
+ });
7487
7484
7488
7485
revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7489
7486
} else {
@@ -13540,6 +13537,17 @@ fn duration_since_epoch() -> Option<Duration> {
13540
13537
now
13541
13538
}
13542
13539
13540
+ /// Returns the time expressed in hold time units (1 unit = 100 ms) that has elapsed between send_timestamp and now. If
13541
+ /// any of the arguments are `None`, returns `None`.
13542
+ fn hold_time(send_timestamp: Option<Duration>, now: Option<Duration>) -> Option<u32> {
13543
+ send_timestamp.and_then(|t| {
13544
+ now.map(|now| {
13545
+ let elapsed = now.saturating_sub(t).as_millis() / HOLD_TIME_UNIT_MILLIS;
13546
+ u32::try_from(elapsed).unwrap_or(u32::MAX)
13547
+ })
13548
+ })
13549
+ }
13550
+
13543
13551
#[cfg(test)]
13544
13552
mod tests {
13545
13553
use crate::chain::chaininterface::LowerBoundedFeeEstimator;
You can’t perform that action at this time.
0 commit comments