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