Skip to content

Commit e6bae89

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 1ab7b8b commit e6bae89

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
@@ -15387,6 +15387,7 @@ mod tests {
1538715387
first_hop_htlc_msat: 548,
1538815388
payment_id: PaymentId([42; 32]),
1538915389
bolt12_invoice: None,
15390+
hold_htlc: None,
1539015391
},
1539115392
skimmed_fee_msat: None,
1539215393
blinding_point: None,
@@ -15834,6 +15835,7 @@ mod tests {
1583415835
first_hop_htlc_msat: 0,
1583515836
payment_id: PaymentId([42; 32]),
1583615837
bolt12_invoice: None,
15838+
hold_htlc: None,
1583715839
};
1583815840
let dummy_outbound_output = OutboundHTLCOutput {
1583915841
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,
@@ -15181,6 +15189,7 @@ impl Readable for HTLCSource {
1518115189
let mut payment_params: Option<PaymentParameters> = None;
1518215190
let mut blinded_tail: Option<BlindedTail> = None;
1518315191
let mut bolt12_invoice: Option<PaidBolt12Invoice> = None;
15192+
let mut hold_htlc: Option<()> = None;
1518415193
read_tlv_fields!(reader, {
1518515194
(0, session_priv, required),
1518615195
(1, payment_id, option),
@@ -15189,6 +15198,7 @@ impl Readable for HTLCSource {
1518915198
(5, payment_params, (option: ReadableArgs, 0)),
1519015199
(6, blinded_tail, option),
1519115200
(7, bolt12_invoice, option),
15201+
(9, hold_htlc, option),
1519215202
});
1519315203
if payment_id.is_none() {
1519415204
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -15212,6 +15222,7 @@ impl Readable for HTLCSource {
1521215222
path,
1521315223
payment_id: payment_id.unwrap(),
1521415224
bolt12_invoice,
15225+
hold_htlc,
1521515226
})
1521615227
}
1521715228
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -15229,6 +15240,7 @@ impl Writeable for HTLCSource {
1522915240
ref path,
1523015241
payment_id,
1523115242
bolt12_invoice,
15243+
hold_htlc,
1523215244
} => {
1523315245
0u8.write(writer)?;
1523415246
let payment_id_opt = Some(payment_id);
@@ -15241,6 +15253,7 @@ impl Writeable for HTLCSource {
1524115253
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
1524215254
(6, path.blinded_tail, option),
1524315255
(7, bolt12_invoice, option),
15256+
(9, hold_htlc, option),
1524415257
});
1524515258
},
1524615259
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)