@@ -7525,19 +7525,18 @@ where
75257525 &htlc.payment_hash
75267526 );
75277527 // We really want take() here, but, again, non-mut ref :(
7528- if let OutboundHTLCOutcome::Failure(mut reason) = outcome.clone() {
7529- if let (Some(timestamp), Some(now)) = (htlc.send_timestamp, now) {
7530- let elapsed_millis = now.saturating_sub(timestamp).as_millis();
7531- let elapsed_units = elapsed_millis / HOLD_TIME_UNIT_MILLIS;
7532- let hold_time = u32::try_from(elapsed_units).unwrap_or(u32::MAX);
7533- reason.set_hold_time(hold_time);
7534- }
7535-
7536- revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7537- } else {
7538- finalized_claimed_htlcs.push(htlc.source.clone());
7539- // They fulfilled, so we sent them money
7540- value_to_self_msat_diff -= htlc.amount_msat as i64;
7528+ match outcome.clone() {
7529+ OutboundHTLCOutcome::Failure(mut reason) => {
7530+ get_hold_time(htlc.send_timestamp, now).map(|hold_time| {
7531+ reason.set_hold_time(hold_time);
7532+ });
7533+ revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7534+ },
7535+ OutboundHTLCOutcome::Success(_) => {
7536+ finalized_claimed_htlcs.push(htlc.source.clone());
7537+ // They fulfilled, so we sent them money
7538+ value_to_self_msat_diff -= htlc.amount_msat as i64;
7539+ },
75417540 }
75427541 false
75437542 } else {
@@ -13580,6 +13579,15 @@ fn duration_since_epoch() -> Option<Duration> {
1358013579 now
1358113580}
1358213581
13582+ fn get_hold_time(send_timestamp: Option<Duration>, now: Option<Duration>) -> Option<u32> {
13583+ send_timestamp.and_then(|t| {
13584+ now.map(|now| {
13585+ let elapsed = now.saturating_sub(t).as_millis() / HOLD_TIME_UNIT_MILLIS;
13586+ u32::try_from(elapsed).unwrap_or(u32::MAX)
13587+ })
13588+ })
13589+ }
13590+
1358313591#[cfg(test)]
1358413592mod tests {
1358513593 use crate::chain::chaininterface::LowerBoundedFeeEstimator;
0 commit comments