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 @@ -7496,12 +7496,9 @@ where
7496
7496
);
7497
7497
// We really want take() here, but, again, non-mut ref :(
7498
7498
if let OutboundHTLCOutcome::Failure(mut reason) = outcome.clone() {
7499
- if let (Some(timestamp), Some(now)) = (htlc.send_timestamp, now) {
7500
- let elapsed_millis = now.saturating_sub(timestamp).as_millis();
7501
- let elapsed_units = elapsed_millis / HOLD_TIME_UNIT_MILLIS;
7502
- let hold_time = u32::try_from(elapsed_units).unwrap_or(u32::MAX);
7499
+ hold_time(htlc.send_timestamp, now).map(|hold_time| {
7503
7500
reason.set_hold_time(hold_time);
7504
- }
7501
+ });
7505
7502
7506
7503
revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7507
7504
} else {
@@ -13565,6 +13562,17 @@ fn duration_since_epoch() -> Option<Duration> {
13565
13562
now
13566
13563
}
13567
13564
13565
+ /// Returns the time expressed in hold time units (1 unit = 100 ms) that has elapsed between send_timestamp and now. If
13566
+ /// any of the arguments are `None`, returns `None`.
13567
+ fn hold_time(send_timestamp: Option<Duration>, now: Option<Duration>) -> Option<u32> {
13568
+ send_timestamp.and_then(|t| {
13569
+ now.map(|now| {
13570
+ let elapsed = now.saturating_sub(t).as_millis() / HOLD_TIME_UNIT_MILLIS;
13571
+ u32::try_from(elapsed).unwrap_or(u32::MAX)
13572
+ })
13573
+ })
13574
+ }
13575
+
13568
13576
#[cfg(test)]
13569
13577
mod tests {
13570
13578
use crate::chain::chaininterface::LowerBoundedFeeEstimator;
You can’t perform that action at this time.
0 commit comments