Skip to content

Commit ad2ae08

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 437e9ed commit ad2ae08

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

lightning/src/ln/channel.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7117,7 +7117,6 @@ mod tests {
71177117
session_priv: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
71187118
first_hop_htlc_msat: 548,
71197119
payment_id: PaymentId([42; 32]),
7120-
payment_secret: None,
71217120
}
71227121
});
71237122

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ pub(crate) enum HTLCSource {
274274
/// doing a double-pass on route when we get a failure back
275275
first_hop_htlc_msat: u64,
276276
payment_id: PaymentId,
277-
payment_secret: Option<PaymentSecret>,
278277
},
279278
}
280279
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
@@ -285,12 +284,11 @@ impl core::hash::Hash for HTLCSource {
285284
0u8.hash(hasher);
286285
prev_hop_data.hash(hasher);
287286
},
288-
HTLCSource::OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat } => {
287+
HTLCSource::OutboundRoute { path, session_priv, payment_id, first_hop_htlc_msat } => {
289288
1u8.hash(hasher);
290289
path.hash(hasher);
291290
session_priv[..].hash(hasher);
292291
payment_id.hash(hasher);
293-
payment_secret.hash(hasher);
294292
first_hop_htlc_msat.hash(hasher);
295293
},
296294
}
@@ -305,7 +303,6 @@ impl HTLCSource {
305303
session_priv: SecretKey::from_slice(&[1; 32]).unwrap(),
306304
first_hop_htlc_msat: 0,
307305
payment_id: PaymentId([2; 32]),
308-
payment_secret: None,
309306
}
310307
}
311308
}
@@ -2531,7 +2528,6 @@ where
25312528
session_priv: session_priv.clone(),
25322529
first_hop_htlc_msat: htlc_msat,
25332530
payment_id,
2534-
payment_secret: payment_secret.clone(),
25352531
}, onion_packet, &self.logger);
25362532
match break_chan_entry!(self, send_res, chan) {
25372533
Some(monitor_update) => {
@@ -6855,13 +6851,11 @@ impl Readable for HTLCSource {
68556851
let mut first_hop_htlc_msat: u64 = 0;
68566852
let mut path: Option<Vec<RouteHop>> = Some(Vec::new());
68576853
let mut payment_id = None;
6858-
let mut payment_secret = None;
68596854
let mut payment_params: Option<PaymentParameters> = None;
68606855
read_tlv_fields!(reader, {
68616856
(0, session_priv, required),
68626857
(1, payment_id, option),
68636858
(2, first_hop_htlc_msat, required),
6864-
(3, payment_secret, option),
68656859
(4, path, vec_type),
68666860
(5, payment_params, (option: ReadableArgs, 0)),
68676861
});
@@ -6884,7 +6878,6 @@ impl Readable for HTLCSource {
68846878
first_hop_htlc_msat,
68856879
path,
68866880
payment_id: payment_id.unwrap(),
6887-
payment_secret,
68886881
})
68896882
}
68906883
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -6896,14 +6889,13 @@ impl Readable for HTLCSource {
68966889
impl Writeable for HTLCSource {
68976890
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), crate::io::Error> {
68986891
match self {
6899-
HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret } => {
6892+
HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id } => {
69006893
0u8.write(writer)?;
69016894
let payment_id_opt = Some(payment_id);
69026895
write_tlv_fields!(writer, {
69036896
(0, session_priv, required),
69046897
(1, payment_id_opt, option),
69056898
(2, first_hop_htlc_msat, required),
6906-
(3, payment_secret, option),
69076899
(4, *path, vec_type),
69086900
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
69096901
});
@@ -7553,7 +7545,7 @@ where
75537545
for (_, monitor) in args.channel_monitors.iter() {
75547546
if id_to_peer.get(&monitor.get_funding_txo().0.to_channel_id()).is_none() {
75557547
for (htlc_source, (htlc, _)) in monitor.get_pending_or_resolved_outbound_htlcs() {
7556-
if let HTLCSource::OutboundRoute { payment_id, session_priv, path, payment_secret, .. } = htlc_source {
7548+
if let HTLCSource::OutboundRoute { payment_id, session_priv, path, .. } = htlc_source {
75577549
if path.is_empty() {
75587550
log_error!(args.logger, "Got an empty path for a pending payment");
75597551
return Err(DecodeError::InvalidValue);
@@ -7576,7 +7568,7 @@ where
75767568
payment_params: None,
75777569
session_privs: [session_priv_bytes].iter().map(|a| *a).collect(),
75787570
payment_hash: htlc.payment_hash,
7579-
payment_secret,
7571+
payment_secret: None, // only used for retries, and we'll never retry on startup
75807572
keysend_preimage: None, // only used for retries, and we'll never retry on startup
75817573
pending_amt_msat: path_amt,
75827574
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)