Skip to content

Commit 6951480

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 70d4369 commit 6951480

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
@@ -751,6 +751,10 @@ mod fuzzy_channelmanager {
751751
/// we can provide proof-of-payment details in payment claim events even after a restart
752752
/// with a stale ChannelManager state.
753753
bolt12_invoice: Option<PaidBolt12Invoice>,
754+
/// Whether we want our next-hop channel peer to hold onto this HTLC until they receive an
755+
/// onion message from the often-offline recipient indicating that the recipient is online and
756+
/// ready to receive the HTLC.
757+
hold_htlc: Option<()>,
754758
},
755759
}
756760

@@ -794,13 +798,15 @@ impl core::hash::Hash for HTLCSource {
794798
payment_id,
795799
first_hop_htlc_msat,
796800
bolt12_invoice,
801+
hold_htlc,
797802
} => {
798803
1u8.hash(hasher);
799804
path.hash(hasher);
800805
session_priv[..].hash(hasher);
801806
payment_id.hash(hasher);
802807
first_hop_htlc_msat.hash(hasher);
803808
bolt12_invoice.hash(hasher);
809+
hold_htlc.hash(hasher);
804810
},
805811
}
806812
}
@@ -814,6 +820,7 @@ impl HTLCSource {
814820
first_hop_htlc_msat: 0,
815821
payment_id: PaymentId([2; 32]),
816822
bolt12_invoice: None,
823+
hold_htlc: None,
817824
}
818825
}
819826

@@ -5036,6 +5043,7 @@ where
50365043
first_hop_htlc_msat: htlc_msat,
50375044
payment_id,
50385045
bolt12_invoice: bolt12_invoice.cloned(),
5046+
hold_htlc: None,
50395047
};
50405048
let send_res = chan.send_htlc_and_commit(
50415049
htlc_msat,
@@ -15291,6 +15299,7 @@ impl Readable for HTLCSource {
1529115299
let mut payment_params: Option<PaymentParameters> = None;
1529215300
let mut blinded_tail: Option<BlindedTail> = None;
1529315301
let mut bolt12_invoice: Option<PaidBolt12Invoice> = None;
15302+
let mut hold_htlc: Option<()> = None;
1529415303
read_tlv_fields!(reader, {
1529515304
(0, session_priv, required),
1529615305
(1, payment_id, option),
@@ -15299,6 +15308,7 @@ impl Readable for HTLCSource {
1529915308
(5, payment_params, (option: ReadableArgs, 0)),
1530015309
(6, blinded_tail, option),
1530115310
(7, bolt12_invoice, option),
15311+
(9, hold_htlc, option),
1530215312
});
1530315313
if payment_id.is_none() {
1530415314
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -15322,6 +15332,7 @@ impl Readable for HTLCSource {
1532215332
path,
1532315333
payment_id: payment_id.unwrap(),
1532415334
bolt12_invoice,
15335+
hold_htlc,
1532515336
})
1532615337
}
1532715338
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -15339,6 +15350,7 @@ impl Writeable for HTLCSource {
1533915350
ref path,
1534015351
payment_id,
1534115352
bolt12_invoice,
15353+
hold_htlc,
1534215354
} => {
1534315355
0u8.write(writer)?;
1534415356
let payment_id_opt = Some(payment_id);
@@ -15351,6 +15363,7 @@ impl Writeable for HTLCSource {
1535115363
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
1535215364
(6, path.blinded_tail, option),
1535315365
(7, bolt12_invoice, option),
15366+
(9, hold_htlc, option),
1535415367
});
1535515368
},
1535615369
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)