Skip to content

Commit 99b162f

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 b6cc8c2 commit 99b162f

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
@@ -15238,6 +15238,7 @@ mod tests {
1523815238
first_hop_htlc_msat: 548,
1523915239
payment_id: PaymentId([42; 32]),
1524015240
bolt12_invoice: None,
15241+
hold_htlc: None,
1524115242
},
1524215243
skimmed_fee_msat: None,
1524315244
blinding_point: None,
@@ -15685,6 +15686,7 @@ mod tests {
1568515686
first_hop_htlc_msat: 0,
1568615687
payment_id: PaymentId([42; 32]),
1568715688
bolt12_invoice: None,
15689+
hold_htlc: None,
1568815690
};
1568915691
let dummy_outbound_output = OutboundHTLCOutput {
1569015692
htlc_id: 0,

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ mod fuzzy_channelmanager {
759759
/// we can provide proof-of-payment details in payment claim events even after a restart
760760
/// with a stale ChannelManager state.
761761
bolt12_invoice: Option<PaidBolt12Invoice>,
762+
/// Whether we want our next-hop channel peer to hold onto this HTLC until they receive an
763+
/// onion message from the often-offline recipient indicating that the recipient is online and
764+
/// ready to receive the HTLC.
765+
hold_htlc: Option<()>,
762766
},
763767
}
764768

@@ -802,13 +806,15 @@ impl core::hash::Hash for HTLCSource {
802806
payment_id,
803807
first_hop_htlc_msat,
804808
bolt12_invoice,
809+
hold_htlc,
805810
} => {
806811
1u8.hash(hasher);
807812
path.hash(hasher);
808813
session_priv[..].hash(hasher);
809814
payment_id.hash(hasher);
810815
first_hop_htlc_msat.hash(hasher);
811816
bolt12_invoice.hash(hasher);
817+
hold_htlc.hash(hasher);
812818
},
813819
}
814820
}
@@ -822,6 +828,7 @@ impl HTLCSource {
822828
first_hop_htlc_msat: 0,
823829
payment_id: PaymentId([2; 32]),
824830
bolt12_invoice: None,
831+
hold_htlc: None,
825832
}
826833
}
827834

@@ -5044,6 +5051,7 @@ where
50445051
first_hop_htlc_msat: htlc_msat,
50455052
payment_id,
50465053
bolt12_invoice: bolt12_invoice.cloned(),
5054+
hold_htlc: None,
50475055
};
50485056
let send_res = chan.send_htlc_and_commit(
50495057
htlc_msat,
@@ -15308,6 +15316,7 @@ impl Readable for HTLCSource {
1530815316
let mut payment_params: Option<PaymentParameters> = None;
1530915317
let mut blinded_tail: Option<BlindedTail> = None;
1531015318
let mut bolt12_invoice: Option<PaidBolt12Invoice> = None;
15319+
let mut hold_htlc: Option<()> = None;
1531115320
read_tlv_fields!(reader, {
1531215321
(0, session_priv, required),
1531315322
(1, payment_id, option),
@@ -15316,6 +15325,7 @@ impl Readable for HTLCSource {
1531615325
(5, payment_params, (option: ReadableArgs, 0)),
1531715326
(6, blinded_tail, option),
1531815327
(7, bolt12_invoice, option),
15328+
(9, hold_htlc, option),
1531915329
});
1532015330
if payment_id.is_none() {
1532115331
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -15339,6 +15349,7 @@ impl Readable for HTLCSource {
1533915349
path,
1534015350
payment_id: payment_id.unwrap(),
1534115351
bolt12_invoice,
15352+
hold_htlc,
1534215353
})
1534315354
}
1534415355
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -15356,6 +15367,7 @@ impl Writeable for HTLCSource {
1535615367
ref path,
1535715368
payment_id,
1535815369
bolt12_invoice,
15370+
hold_htlc,
1535915371
} => {
1536015372
0u8.write(writer)?;
1536115373
let payment_id_opt = Some(payment_id);
@@ -15368,6 +15380,7 @@ impl Writeable for HTLCSource {
1536815380
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
1536915381
(6, path.blinded_tail, option),
1537015382
(7, bolt12_invoice, option),
15383+
(9, hold_htlc, option),
1537115384
});
1537215385
},
1537315386
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)