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
74787478 );
74797479 // We really want take() here, but, again, non-mut ref :(
74807480 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| {
74857482 reason.set_hold_time(hold_time);
7486- }
7483+ });
74877484
74887485 revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
74897486 } else {
@@ -13540,6 +13537,17 @@ fn duration_since_epoch() -> Option<Duration> {
1354013537 now
1354113538}
1354213539
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+
1354313551#[cfg(test)]
1354413552mod tests {
1354513553 use crate::chain::chaininterface::LowerBoundedFeeEstimator;
You can’t perform that action at this time.
0 commit comments