Skip to content

Commit a24746f

Browse files
Add UpdateAddHTLC::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 update_add struct. See-also <lightning/bolts#989>
1 parent ecce859 commit a24746f

File tree

7 files changed

+20
-1
lines changed

7 files changed

+20
-1
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ fn update_add_msg(
15221522
onion_routing_packet,
15231523
skimmed_fee_msat: None,
15241524
blinding_point,
1525+
hold_htlc: None,
15251526
}
15261527
}
15271528

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9045,6 +9045,7 @@ where
90459045
onion_routing_packet: (**onion_packet).clone(),
90469046
skimmed_fee_msat: htlc.skimmed_fee_msat,
90479047
blinding_point: htlc.blinding_point,
9048+
hold_htlc: None, // Will be set by the async sender when support is added
90489049
});
90499050
}
90509051
}

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,7 @@ pub fn fail_backward_pending_htlc_upon_channel_failure() {
22882288
onion_routing_packet,
22892289
skimmed_fee_msat: None,
22902290
blinding_point: None,
2291+
hold_htlc: None,
22912292
};
22922293
nodes[0].node.handle_update_add_htlc(node_b_id, &update_add_htlc);
22932294
}

lightning/src/ln/htlc_reserve_unit_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ pub fn do_test_fee_spike_buffer(cfg: Option<UserConfig>, htlc_fails: bool) {
835835
onion_routing_packet: onion_packet,
836836
skimmed_fee_msat: None,
837837
blinding_point: None,
838+
hold_htlc: None,
838839
};
839840

840841
nodes[1].node.handle_update_add_htlc(node_a_id, &msg);
@@ -1072,6 +1073,7 @@ pub fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
10721073
onion_routing_packet: onion_packet,
10731074
skimmed_fee_msat: None,
10741075
blinding_point: None,
1076+
hold_htlc: None,
10751077
};
10761078

10771079
nodes[0].node.handle_update_add_htlc(node_b_id, &msg);
@@ -1255,6 +1257,7 @@ pub fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
12551257
onion_routing_packet: onion_packet,
12561258
skimmed_fee_msat: None,
12571259
blinding_point: None,
1260+
hold_htlc: None,
12581261
};
12591262

12601263
nodes[1].node.handle_update_add_htlc(node_a_id, &msg);
@@ -1637,6 +1640,7 @@ pub fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
16371640
onion_routing_packet: onion_packet.clone(),
16381641
skimmed_fee_msat: None,
16391642
blinding_point: None,
1643+
hold_htlc: None,
16401644
};
16411645

16421646
for i in 0..50 {
@@ -2242,6 +2246,7 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) {
22422246
onion_routing_packet,
22432247
skimmed_fee_msat: None,
22442248
blinding_point: None,
2249+
hold_htlc: None,
22452250
};
22462251

22472252
nodes[1].node.handle_update_add_htlc(node_a_id, &msg);

lightning/src/ln/msgs.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ pub struct UpdateAddHTLC {
765765
/// Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion
766766
/// routing packet and the recipient-provided encrypted payload within.
767767
pub blinding_point: Option<PublicKey>,
768+
/// Set to `Some` if the sender wants the receiver of this message to hold onto this HTLC until
769+
/// receipt of a [`ReleaseHeldHtlc`] onion message from the payment recipient.
770+
///
771+
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
772+
pub hold_htlc: Option<()>,
768773
}
769774

770775
/// An onion message to be sent to or received from a peer.
@@ -3350,7 +3355,10 @@ impl_writeable_msg!(UpdateAddHTLC, {
33503355
onion_routing_packet,
33513356
}, {
33523357
(0, blinding_point, option),
3353-
(65537, skimmed_fee_msat, option)
3358+
(65537, skimmed_fee_msat, option),
3359+
// TODO: currently we may fail to read the `ChannelManager` if we write a new even TLV in this message
3360+
// and then downgrade. Once this is fixed, update the type here to match BOLTs PR 989.
3361+
(75537, hold_htlc, option),
33543362
});
33553363

33563364
impl LengthReadable for OnionMessage {
@@ -5847,6 +5855,7 @@ mod tests {
58475855
onion_routing_packet,
58485856
skimmed_fee_msat: None,
58495857
blinding_point: None,
5858+
hold_htlc: None,
58505859
};
58515860
let encoded_value = update_add_htlc.encode();
58525861
let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034d32144668701144760101010101010101010101010101010101010101010101010101010101010101000c89d4ff031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap();

lightning/src/ln/onion_payment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ mod tests {
753753
onion_routing_packet,
754754
skimmed_fee_msat: None,
755755
blinding_point: None,
756+
hold_htlc: None,
756757
}
757758
}
758759

lightning/src/ln/payment_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5017,6 +5017,7 @@ fn peel_payment_onion_custom_tlvs() {
50175017
skimmed_fee_msat: None,
50185018
onion_routing_packet,
50195019
blinding_point: None,
5020+
hold_htlc: None,
50205021
};
50215022
let peeled_onion = crate::ln::onion_payment::peel_payment_onion(
50225023
&update_add,

0 commit comments

Comments
 (0)