Skip to content

Commit 92da523

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 248a970 commit 92da523

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
@@ -758,6 +758,10 @@ mod fuzzy_channelmanager {
758758
/// we can provide proof-of-payment details in payment claim events even after a restart
759759
/// with a stale ChannelManager state.
760760
bolt12_invoice: Option<PaidBolt12Invoice>,
761+
/// Whether we want our next-hop channel peer to hold onto this HTLC until they receive an
762+
/// onion message from the often-offline recipient indicating that the recipient is online and
763+
/// ready to receive the HTLC.
764+
hold_htlc: Option<()>,
761765
},
762766
}
763767

@@ -801,13 +805,15 @@ impl core::hash::Hash for HTLCSource {
801805
payment_id,
802806
first_hop_htlc_msat,
803807
bolt12_invoice,
808+
hold_htlc,
804809
} => {
805810
1u8.hash(hasher);
806811
path.hash(hasher);
807812
session_priv[..].hash(hasher);
808813
payment_id.hash(hasher);
809814
first_hop_htlc_msat.hash(hasher);
810815
bolt12_invoice.hash(hasher);
816+
hold_htlc.hash(hasher);
811817
},
812818
}
813819
}
@@ -821,6 +827,7 @@ impl HTLCSource {
821827
first_hop_htlc_msat: 0,
822828
payment_id: PaymentId([2; 32]),
823829
bolt12_invoice: None,
830+
hold_htlc: None,
824831
}
825832
}
826833

@@ -5043,6 +5050,7 @@ where
50435050
first_hop_htlc_msat: htlc_msat,
50445051
payment_id,
50455052
bolt12_invoice: bolt12_invoice.cloned(),
5053+
hold_htlc: None,
50465054
};
50475055
let send_res = chan.send_htlc_and_commit(
50485056
htlc_msat,
@@ -15298,6 +15306,7 @@ impl Readable for HTLCSource {
1529815306
let mut payment_params: Option<PaymentParameters> = None;
1529915307
let mut blinded_tail: Option<BlindedTail> = None;
1530015308
let mut bolt12_invoice: Option<PaidBolt12Invoice> = None;
15309+
let mut hold_htlc: Option<()> = None;
1530115310
read_tlv_fields!(reader, {
1530215311
(0, session_priv, required),
1530315312
(1, payment_id, option),
@@ -15306,6 +15315,7 @@ impl Readable for HTLCSource {
1530615315
(5, payment_params, (option: ReadableArgs, 0)),
1530715316
(6, blinded_tail, option),
1530815317
(7, bolt12_invoice, option),
15318+
(9, hold_htlc, option),
1530915319
});
1531015320
if payment_id.is_none() {
1531115321
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -15329,6 +15339,7 @@ impl Readable for HTLCSource {
1532915339
path,
1533015340
payment_id: payment_id.unwrap(),
1533115341
bolt12_invoice,
15342+
hold_htlc,
1533215343
})
1533315344
}
1533415345
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -15346,6 +15357,7 @@ impl Writeable for HTLCSource {
1534615357
ref path,
1534715358
payment_id,
1534815359
bolt12_invoice,
15360+
hold_htlc,
1534915361
} => {
1535015362
0u8.write(writer)?;
1535115363
let payment_id_opt = Some(payment_id);
@@ -15358,6 +15370,7 @@ impl Writeable for HTLCSource {
1535815370
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
1535915371
(6, path.blinded_tail, option),
1536015372
(7, bolt12_invoice, option),
15373+
(9, hold_htlc, option),
1536115374
});
1536215375
},
1536315376
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)