Skip to content

Commit 2f798f6

Browse files
committed
Remove the PaymentSecret field from HTLCSource::OutboundRoute
Many of the fields in `HTLCSource::OutboundRoute` are used to rebuild the pending-outbound-payment map on reload if the `ChannelManager` was not serialized though `ChannelMonitor`(s) were after an HTLC was sent. As of 0.0.114, however, such payments are not retryable without allowing them to fail and doing a full, fresh, send. Thus, some of the fields can be safely removed - we only really care about having enough information to provide the user a failure event, not being able to retry. Here we drop one such field - the `payment_secret`, making our `ChannelMonitorUpdate`s another handful of bytes smaller.
1 parent 3b8bf93 commit 2f798f6

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

lightning/src/ln/channel.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7158,7 +7158,6 @@ mod tests {
71587158
session_priv: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
71597159
first_hop_htlc_msat: 548,
71607160
payment_id: PaymentId([42; 32]),
7161-
payment_secret: None,
71627161
}
71637162
});
71647163

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ pub(crate) enum HTLCSource {
286286
/// doing a double-pass on route when we get a failure back
287287
first_hop_htlc_msat: u64,
288288
payment_id: PaymentId,
289-
payment_secret: Option<PaymentSecret>,
290289
},
291290
}
292291
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
@@ -297,12 +296,11 @@ impl core::hash::Hash for HTLCSource {
297296
0u8.hash(hasher);
298297
prev_hop_data.hash(hasher);
299298
},
300-
HTLCSource::OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat } => {
299+
HTLCSource::OutboundRoute { path, session_priv, payment_id, first_hop_htlc_msat } => {
301300
1u8.hash(hasher);
302301
path.hash(hasher);
303302
session_priv[..].hash(hasher);
304303
payment_id.hash(hasher);
305-
payment_secret.hash(hasher);
306304
first_hop_htlc_msat.hash(hasher);
307305
},
308306
}
@@ -317,7 +315,6 @@ impl HTLCSource {
317315
session_priv: SecretKey::from_slice(&[1; 32]).unwrap(),
318316
first_hop_htlc_msat: 0,
319317
payment_id: PaymentId([2; 32]),
320-
payment_secret: None,
321318
}
322319
}
323320
}
@@ -2556,7 +2553,6 @@ where
25562553
session_priv: session_priv.clone(),
25572554
first_hop_htlc_msat: htlc_msat,
25582555
payment_id,
2559-
payment_secret: payment_secret.clone(),
25602556
}, onion_packet, &self.logger);
25612557
match break_chan_entry!(self, send_res, chan) {
25622558
Some(monitor_update) => {
@@ -6900,13 +6896,11 @@ impl Readable for HTLCSource {
69006896
let mut first_hop_htlc_msat: u64 = 0;
69016897
let mut path: Option<Vec<RouteHop>> = Some(Vec::new());
69026898
let mut payment_id = None;
6903-
let mut payment_secret = None;
69046899
let mut payment_params: Option<PaymentParameters> = None;
69056900
read_tlv_fields!(reader, {
69066901
(0, session_priv, required),
69076902
(1, payment_id, option),
69086903
(2, first_hop_htlc_msat, required),
6909-
(3, payment_secret, option),
69106904
(4, path, vec_type),
69116905
(5, payment_params, (option: ReadableArgs, 0)),
69126906
});
@@ -6929,7 +6923,6 @@ impl Readable for HTLCSource {
69296923
first_hop_htlc_msat,
69306924
path,
69316925
payment_id: payment_id.unwrap(),
6932-
payment_secret,
69336926
})
69346927
}
69356928
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -6941,14 +6934,14 @@ impl Readable for HTLCSource {
69416934
impl Writeable for HTLCSource {
69426935
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), crate::io::Error> {
69436936
match self {
6944-
HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret } => {
6937+
HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id } => {
69456938
0u8.write(writer)?;
69466939
let payment_id_opt = Some(payment_id);
69476940
write_tlv_fields!(writer, {
69486941
(0, session_priv, required),
69496942
(1, payment_id_opt, option),
69506943
(2, first_hop_htlc_msat, required),
6951-
(3, payment_secret, option),
6944+
// 3 was previously used to write a PaymentSecret for the payment.
69526945
(4, *path, vec_type),
69536946
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
69546947
});
@@ -7611,7 +7604,7 @@ where
76117604
for (_, monitor) in args.channel_monitors.iter() {
76127605
if id_to_peer.get(&monitor.get_funding_txo().0.to_channel_id()).is_none() {
76137606
for (htlc_source, (htlc, _)) in monitor.get_pending_or_resolved_outbound_htlcs() {
7614-
if let HTLCSource::OutboundRoute { payment_id, session_priv, path, payment_secret, .. } = htlc_source {
7607+
if let HTLCSource::OutboundRoute { payment_id, session_priv, path, .. } = htlc_source {
76157608
if path.is_empty() {
76167609
log_error!(args.logger, "Got an empty path for a pending payment");
76177610
return Err(DecodeError::InvalidValue);
@@ -7634,7 +7627,7 @@ where
76347627
payment_params: None,
76357628
session_privs: [session_priv_bytes].iter().map(|a| *a).collect(),
76367629
payment_hash: htlc.payment_hash,
7637-
payment_secret,
7630+
payment_secret: None, // only used for retries, and we'll never retry on startup
76387631
keysend_preimage: None, // only used for retries, and we'll never retry on startup
76397632
pending_amt_msat: path_amt,
76407633
pending_fee_msat: Some(path_fee),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Backwards Compatibility
2+
* Payments sent with the legacy `*_with_route` methods on LDK 0.0.115+ will no
3+
longer be retryable via the LDK 0.0.114- `retry_payment` method (#XXXX).

0 commit comments

Comments
 (0)