Skip to content

Commit 1f7ff08

Browse files
Add HTLCSource::OutboundRoute::hold_htlc
As part of supporting sending payments as an often-offline sender, the sender needs to be able to set a flag in their update_add_htlc message indicating that the HTLC should be held until receipt of a release_held_htlc onion message from the often-offline payment recipient. We don't yet ever set this flag, but lay the groundwork by including the field in the HTLCSource::OutboundRoute enum variant. See-also <lightning/bolts#989>
1 parent 2790f46 commit 1f7ff08

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

fuzz/src/process_onion_failure.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
120120
first_hop_htlc_msat: 0,
121121
payment_id,
122122
bolt12_invoice: None,
123+
hold_htlc: None,
123124
};
124125

125126
let failure_len = get_u16!();

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15423,6 +15423,7 @@ mod tests {
1542315423
first_hop_htlc_msat: 548,
1542415424
payment_id: PaymentId([42; 32]),
1542515425
bolt12_invoice: None,
15426+
hold_htlc: None,
1542615427
},
1542715428
skimmed_fee_msat: None,
1542815429
blinding_point: None,
@@ -15870,6 +15871,7 @@ mod tests {
1587015871
first_hop_htlc_msat: 0,
1587115872
payment_id: PaymentId([42; 32]),
1587215873
bolt12_invoice: None,
15874+
hold_htlc: None,
1587315875
};
1587415876
let dummy_outbound_output = OutboundHTLCOutput {
1587515877
htlc_id: 0,

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ mod fuzzy_channelmanager {
750750
/// we can provide proof-of-payment details in payment claim events even after a restart
751751
/// with a stale ChannelManager state.
752752
bolt12_invoice: Option<PaidBolt12Invoice>,
753+
/// Whether we want our next-hop channel peer to hold onto this HTLC until they receive an
754+
/// onion message from the often-offline recipient indicating that the recipient is online and
755+
/// ready to receive the HTLC.
756+
hold_htlc: Option<()>,
753757
},
754758
}
755759

@@ -793,13 +797,15 @@ impl core::hash::Hash for HTLCSource {
793797
payment_id,
794798
first_hop_htlc_msat,
795799
bolt12_invoice,
800+
hold_htlc,
796801
} => {
797802
1u8.hash(hasher);
798803
path.hash(hasher);
799804
session_priv[..].hash(hasher);
800805
payment_id.hash(hasher);
801806
first_hop_htlc_msat.hash(hasher);
802807
bolt12_invoice.hash(hasher);
808+
hold_htlc.hash(hasher);
803809
},
804810
}
805811
}
@@ -813,6 +819,7 @@ impl HTLCSource {
813819
first_hop_htlc_msat: 0,
814820
payment_id: PaymentId([2; 32]),
815821
bolt12_invoice: None,
822+
hold_htlc: None,
816823
}
817824
}
818825

@@ -5032,6 +5039,7 @@ where
50325039
first_hop_htlc_msat: htlc_msat,
50335040
payment_id,
50345041
bolt12_invoice: bolt12_invoice.cloned(),
5042+
hold_htlc: None,
50355043
};
50365044
let send_res = chan.send_htlc_and_commit(
50375045
htlc_msat,
@@ -15190,6 +15198,7 @@ impl Readable for HTLCSource {
1519015198
let mut payment_params: Option<PaymentParameters> = None;
1519115199
let mut blinded_tail: Option<BlindedTail> = None;
1519215200
let mut bolt12_invoice: Option<PaidBolt12Invoice> = None;
15201+
let mut hold_htlc: Option<()> = None;
1519315202
read_tlv_fields!(reader, {
1519415203
(0, session_priv, required),
1519515204
(1, payment_id, option),
@@ -15198,6 +15207,7 @@ impl Readable for HTLCSource {
1519815207
(5, payment_params, (option: ReadableArgs, 0)),
1519915208
(6, blinded_tail, option),
1520015209
(7, bolt12_invoice, option),
15210+
(9, hold_htlc, option),
1520115211
});
1520215212
if payment_id.is_none() {
1520315213
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -15221,6 +15231,7 @@ impl Readable for HTLCSource {
1522115231
path,
1522215232
payment_id: payment_id.unwrap(),
1522315233
bolt12_invoice,
15234+
hold_htlc,
1522415235
})
1522515236
}
1522615237
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -15238,6 +15249,7 @@ impl Writeable for HTLCSource {
1523815249
ref path,
1523915250
payment_id,
1524015251
bolt12_invoice,
15252+
hold_htlc,
1524115253
} => {
1524215254
0u8.write(writer)?;
1524315255
let payment_id_opt = Some(payment_id);
@@ -15250,6 +15262,7 @@ impl Writeable for HTLCSource {
1525015262
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
1525115263
(6, path.blinded_tail, option),
1525215264
(7, bolt12_invoice, option),
15265+
(9, hold_htlc, option),
1525315266
});
1525415267
},
1525515268
HTLCSource::PreviousHopData(ref field) => {

lightning/src/ln/onion_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,7 @@ mod tests {
34133413
first_hop_htlc_msat: 0,
34143414
payment_id: PaymentId([1; 32]),
34153415
bolt12_invoice: None,
3416+
hold_htlc: None,
34163417
};
34173418

34183419
process_onion_failure(&ctx_full, &logger, &htlc_source, onion_error)
@@ -3603,6 +3604,7 @@ mod tests {
36033604
first_hop_htlc_msat: dummy_amt_msat,
36043605
payment_id: PaymentId([1; 32]),
36053606
bolt12_invoice: None,
3607+
hold_htlc: None,
36063608
};
36073609

36083610
{
@@ -3791,6 +3793,7 @@ mod tests {
37913793
first_hop_htlc_msat: 0,
37923794
payment_id: PaymentId([1; 32]),
37933795
bolt12_invoice: None,
3796+
hold_htlc: None,
37943797
};
37953798

37963799
// Iterate over all possible failure positions and check that the cases that can be attributed are.
@@ -3900,6 +3903,7 @@ mod tests {
39003903
first_hop_htlc_msat: 0,
39013904
payment_id: PaymentId([1; 32]),
39023905
bolt12_invoice: None,
3906+
hold_htlc: None,
39033907
};
39043908

39053909
let decrypted_failure = process_onion_failure(&ctx_full, &logger, &htlc_source, packet);

0 commit comments

Comments
 (0)