Skip to content

Commit cc97418

Browse files
committed
Reduce hold time resolution
In the spec process, it was agreed to report hold time in multiples of 100 ms.
1 parent 1027929 commit cc97418

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ use crate::ln::interactivetxs::{
6262
};
6363
use crate::ln::msgs;
6464
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
65-
use crate::ln::onion_utils::{AttributionData, HTLCFailReason, LocalHTLCFailureReason};
65+
use crate::ln::onion_utils::{
66+
AttributionData, HTLCFailReason, LocalHTLCFailureReason, HOLD_TIME_UNIT_MILLIS,
67+
};
6668
use crate::ln::script::{self, ShutdownScript};
6769
use crate::ln::types::ChannelId;
6870
use crate::routing::gossip::NodeId;
@@ -7168,9 +7170,9 @@ where
71687170
// We really want take() here, but, again, non-mut ref :(
71697171
if let OutboundHTLCOutcome::Failure(mut reason) = outcome.clone() {
71707172
if let (Some(timestamp), Some(now)) = (htlc.send_timestamp, now) {
7171-
let hold_time =
7172-
u32::try_from(now.saturating_sub(timestamp).as_millis())
7173-
.unwrap_or(u32::MAX);
7173+
let elapsed_millis = now.saturating_sub(timestamp).as_millis();
7174+
let elapsed_units = elapsed_millis / HOLD_TIME_UNIT_MILLIS;
7175+
let hold_time = u32::try_from(elapsed_units).unwrap_or(u32::MAX);
71747176
reason.set_hold_time(hold_time);
71757177
}
71767178

lightning/src/ln/onion_utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ use crate::prelude::*;
4444

4545
const DEFAULT_MIN_FAILURE_PACKET_LEN: usize = 256;
4646

47+
/// The unit size of the hold time. This is used to reduce the hold time resolution to improve privacy.
48+
pub(crate) const HOLD_TIME_UNIT_MILLIS: u128 = 100;
49+
4750
pub(crate) struct OnionKeys {
4851
#[cfg(test)]
4952
pub(crate) shared_secret: SharedSecret,
@@ -1223,7 +1226,7 @@ where
12231226
logger,
12241227
"Htlc hold time at pos {}: {} ms",
12251228
route_hop_idx,
1226-
hold_time
1229+
hold_time * HOLD_TIME_UNIT_MILLIS as u32
12271230
);
12281231

12291232
// Shift attribution data to prepare for processing the next hop.

0 commit comments

Comments
 (0)