Skip to content

Commit 04f9ac4

Browse files
committed
wip
1 parent ff279d6 commit 04f9ac4

File tree

8 files changed

+35
-3
lines changed

8 files changed

+35
-3
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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ struct OutboundHTLCOutput {
425425
blinding_point: Option<PublicKey>,
426426
skimmed_fee_msat: Option<u64>,
427427
send_timestamp: Option<Duration>,
428+
hold_htlc: bool,
428429
}
429430

430431
impl OutboundHTLCOutput {
@@ -459,6 +460,7 @@ enum HTLCUpdateAwaitingACK {
459460
// The extra fee we're skimming off the top of this HTLC.
460461
skimmed_fee_msat: Option<u64>,
461462
blinding_point: Option<PublicKey>,
463+
hold_htlc: bool,
462464
},
463465
ClaimHTLC {
464466
payment_preimage: PaymentPreimage,
@@ -7231,6 +7233,7 @@ where
72317233
ref onion_routing_packet,
72327234
skimmed_fee_msat,
72337235
blinding_point,
7236+
hold_htlc,
72347237
..
72357238
} => {
72367239
match self.send_htlc(
@@ -7242,6 +7245,7 @@ where
72427245
false,
72437246
skimmed_fee_msat,
72447247
blinding_point,
7248+
hold_htlc,
72457249
fee_estimator,
72467250
logger,
72477251
) {
@@ -8362,6 +8366,7 @@ where
83628366
onion_routing_packet: (**onion_packet).clone(),
83638367
skimmed_fee_msat: htlc.skimmed_fee_msat,
83648368
blinding_point: htlc.blinding_point,
8369+
hold_htlc: htlc.hold_htlc.then(|| ()),
83658370
});
83668371
}
83678372
}
@@ -10586,7 +10591,8 @@ where
1058610591
pub fn queue_add_htlc<F: Deref, L: Deref>(
1058710592
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1058810593
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10589-
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10594+
hold_htlc: bool, blinding_point: Option<PublicKey>,
10595+
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1059010596
) -> Result<(), (LocalHTLCFailureReason, String)>
1059110597
where
1059210598
F::Target: FeeEstimator,
@@ -10601,6 +10607,7 @@ where
1060110607
true,
1060210608
skimmed_fee_msat,
1060310609
blinding_point,
10610+
hold_htlc,
1060410611
fee_estimator,
1060510612
logger,
1060610613
)
@@ -10631,7 +10638,7 @@ where
1063110638
fn send_htlc<F: Deref, L: Deref>(
1063210639
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1063310640
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
10634-
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
10641+
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>, hold_htlc: bool,
1063510642
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1063610643
) -> Result<bool, (LocalHTLCFailureReason, String)>
1063710644
where
@@ -10713,6 +10720,7 @@ where
1071310720
onion_routing_packet,
1071410721
skimmed_fee_msat,
1071510722
blinding_point,
10723+
hold_htlc,
1071610724
});
1071710725
return Ok(false);
1071810726
}
@@ -10734,6 +10742,7 @@ where
1073410742
blinding_point,
1073510743
skimmed_fee_msat,
1073610744
send_timestamp,
10745+
hold_htlc,
1073710746
});
1073810747
self.context.next_holder_htlc_id += 1;
1073910748

@@ -10977,7 +10986,7 @@ where
1097710986
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
1097810987
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1097910988
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10980-
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10989+
hold_htlc: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1098110990
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
1098210991
where
1098310992
F::Target: FeeEstimator,
@@ -10992,6 +11001,7 @@ where
1099211001
false,
1099311002
skimmed_fee_msat,
1099411003
None,
11004+
hold_htlc,
1099511005
fee_estimator,
1099611006
logger,
1099711007
);
@@ -12629,6 +12639,7 @@ where
1262912639
ref onion_routing_packet,
1263012640
blinding_point,
1263112641
skimmed_fee_msat,
12642+
..
1263212643
} => {
1263312644
0u8.write(writer)?;
1263412645
amount_msat.write(writer)?;
@@ -13032,6 +13043,7 @@ where
1303213043
skimmed_fee_msat: None,
1303313044
blinding_point: None,
1303413045
send_timestamp: None,
13046+
hold_htlc: false, // TODO: Persistence
1303513047
});
1303613048
}
1303713049

@@ -13050,6 +13062,7 @@ where
1305013062
onion_routing_packet: Readable::read(reader)?,
1305113063
skimmed_fee_msat: None,
1305213064
blinding_point: None,
13065+
hold_htlc: false, // TODO: Persistence
1305313066
},
1305413067
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1305513068
payment_preimage: Readable::read(reader)?,
@@ -13944,6 +13957,7 @@ mod tests {
1394413957
skimmed_fee_msat: None,
1394513958
blinding_point: None,
1394613959
send_timestamp: None,
13960+
hold_htlc: false,
1394713961
});
1394813962

1394913963
// Make sure when Node A calculates their local commitment transaction, none of the HTLCs pass
@@ -14398,6 +14412,7 @@ mod tests {
1439814412
skimmed_fee_msat: None,
1439914413
blinding_point: None,
1440014414
send_timestamp: None,
14415+
hold_htlc: false,
1440114416
};
1440214417
let mut pending_outbound_htlcs = vec![dummy_outbound_output.clone(); 10];
1440314418
for (idx, htlc) in pending_outbound_htlcs.iter_mut().enumerate() {
@@ -14423,6 +14438,7 @@ mod tests {
1442314438
},
1442414439
skimmed_fee_msat: None,
1442514440
blinding_point: None,
14441+
hold_htlc: false,
1442614442
};
1442714443
let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
1442814444
payment_preimage: PaymentPreimage([42; 32]),

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6644,6 +6644,7 @@ where
66446644
htlc_source.clone(),
66456645
onion_packet.clone(),
66466646
skimmed_fee_msat,
6647+
false, // Never signal hold on forwarded HTLCs.
66476648
next_blinding_point,
66486649
&self.fee_estimator,
66496650
&&logger,

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,7 @@ pub fn fail_backward_pending_htlc_upon_channel_failure() {
26832683
onion_routing_packet,
26842684
skimmed_fee_msat: None,
26852685
blinding_point: None,
2686+
hold_htlc: None,
26862687
};
26872688
nodes[0].node.handle_update_add_htlc(node_b_id, &update_add_htlc);
26882689
}

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ pub struct UpdateAddHTLC {
766766
/// Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion
767767
/// routing packet and the recipient-provided encrypted payload within.
768768
pub blinding_point: Option<PublicKey>,
769+
/// When set, this HTLC is held and a [`HeldHtlcAvailable`] message will be sent out.
770+
///
771+
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
772+
pub hold_htlc: Option<()>,
769773
}
770774

771775
/// An onion message to be sent to or received from a peer.
@@ -3227,6 +3231,7 @@ impl_writeable_msg!(UpdateAddHTLC, {
32273231
onion_routing_packet,
32283232
}, {
32293233
(0, blinding_point, option),
3234+
(2, hold_htlc, option),
32303235
(65537, skimmed_fee_msat, option)
32313236
});
32323237

@@ -5663,6 +5668,7 @@ mod tests {
56635668
onion_routing_packet,
56645669
skimmed_fee_msat: None,
56655670
blinding_point: None,
5671+
hold_htlc: None,
56665672
};
56675673
let encoded_value = update_add_htlc.encode();
56685674
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
@@ -5015,6 +5015,7 @@ fn peel_payment_onion_custom_tlvs() {
50155015
skimmed_fee_msat: None,
50165016
onion_routing_packet,
50175017
blinding_point: None,
5018+
hold_htlc: None,
50185019
};
50195020
let peeled_onion = crate::ln::onion_payment::peel_payment_onion(
50205021
&update_add,

0 commit comments

Comments
 (0)