|
17 | 17 | use crate::chain::keysinterface::SpendableOutputDescriptor;
|
18 | 18 | #[cfg(anchors)]
|
19 | 19 | use crate::ln::chan_utils::HTLCOutputInCommitment;
|
20 |
| -use crate::ln::channelmanager::PaymentId; |
| 20 | +use crate::ln::channelmanager::{InterceptId, PaymentId}; |
21 | 21 | use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
|
22 | 22 | use crate::ln::features::ChannelTypeFeatures;
|
23 | 23 | use crate::ln::msgs;
|
@@ -288,6 +288,22 @@ pub enum BumpTransactionEvent {
|
288 | 288 | },
|
289 | 289 | }
|
290 | 290 |
|
| 291 | +/// Will be used in [`Event::HTLCIntercepted`] to identify the next hop in the HTLC's path. |
| 292 | +/// Currently only used in serialization for the sake of maintaining compatibility. More variants |
| 293 | +/// will be added for general-purpose HTLC forward intercepts as well as trampoline forward |
| 294 | +/// intercepts in upcoming work. |
| 295 | +enum InterceptNextHop { |
| 296 | + FakeScid { |
| 297 | + requested_next_hop_scid: u64, |
| 298 | + }, |
| 299 | +} |
| 300 | + |
| 301 | +impl_writeable_tlv_based_enum!(InterceptNextHop, |
| 302 | + (0, FakeScid) => { |
| 303 | + (0, requested_next_hop_scid, required), |
| 304 | + }; |
| 305 | +); |
| 306 | + |
291 | 307 | /// An Event which you should probably take some action in response to.
|
292 | 308 | ///
|
293 | 309 | /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
|
@@ -585,6 +601,24 @@ pub enum Event {
|
585 | 601 | /// now + 5*time_forwardable).
|
586 | 602 | time_forwardable: Duration,
|
587 | 603 | },
|
| 604 | + /// Used to indicate that we've intercepted an HTLC forward. |
| 605 | + HTLCIntercepted { |
| 606 | + /// An id to help LDK identify which HTLC is being forwarded or failed. |
| 607 | + intercept_id: InterceptId, |
| 608 | + /// The fake scid that was programmed as the next hop's scid. |
| 609 | + requested_next_hop_scid: u64, |
| 610 | + /// The payment hash used for this HTLC. |
| 611 | + payment_hash: PaymentHash, |
| 612 | + /// How many msats were received on the inbound edge of this HTLC. |
| 613 | + inbound_amount_msat: u64, |
| 614 | + /// How many msats the payer intended to route to the next node. Depending on the reason you are |
| 615 | + /// intercepting this payment, you might take a fee by forwarding less than this amount. |
| 616 | + /// |
| 617 | + /// Note that LDK will NOT check that expected fees were factored into this value. You MUST |
| 618 | + /// check that whatever fee you want has been included here or subtract it as required. Further, |
| 619 | + /// LDK will not stop you from forwarding more than you received. |
| 620 | + expected_outbound_amount_msat: u64, |
| 621 | + }, |
588 | 622 | /// Used to indicate that an output which you should know how to spend was confirmed on chain
|
589 | 623 | /// and is now spendable.
|
590 | 624 | /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
|
@@ -825,6 +859,17 @@ impl Writeable for Event {
|
825 | 859 | (0, WithoutLength(outputs), required),
|
826 | 860 | });
|
827 | 861 | },
|
| 862 | + &Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, intercept_id } => { |
| 863 | + 6u8.write(writer)?; |
| 864 | + let intercept_scid = InterceptNextHop::FakeScid { requested_next_hop_scid }; |
| 865 | + write_tlv_fields!(writer, { |
| 866 | + (0, intercept_id, required), |
| 867 | + (2, intercept_scid, required), |
| 868 | + (4, payment_hash, required), |
| 869 | + (6, inbound_amount_msat, required), |
| 870 | + (8, expected_outbound_amount_msat, required), |
| 871 | + }); |
| 872 | + } |
828 | 873 | &Event::PaymentForwarded { fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id } => {
|
829 | 874 | 7u8.write(writer)?;
|
830 | 875 | write_tlv_fields!(writer, {
|
@@ -1054,6 +1099,30 @@ impl MaybeReadable for Event {
|
1054 | 1099 | };
|
1055 | 1100 | f()
|
1056 | 1101 | },
|
| 1102 | + 6u8 => { |
| 1103 | + let mut payment_hash = PaymentHash([0; 32]); |
| 1104 | + let mut intercept_id = InterceptId([0; 32]); |
| 1105 | + let mut requested_next_hop_scid = InterceptNextHop::FakeScid { requested_next_hop_scid: 0 }; |
| 1106 | + let mut inbound_amount_msat = 0; |
| 1107 | + let mut expected_outbound_amount_msat = 0; |
| 1108 | + read_tlv_fields!(reader, { |
| 1109 | + (0, intercept_id, required), |
| 1110 | + (2, requested_next_hop_scid, required), |
| 1111 | + (4, payment_hash, required), |
| 1112 | + (6, inbound_amount_msat, required), |
| 1113 | + (8, expected_outbound_amount_msat, required), |
| 1114 | + }); |
| 1115 | + let next_scid = match requested_next_hop_scid { |
| 1116 | + InterceptNextHop::FakeScid { requested_next_hop_scid: scid } => scid |
| 1117 | + }; |
| 1118 | + Ok(Some(Event::HTLCIntercepted { |
| 1119 | + payment_hash, |
| 1120 | + requested_next_hop_scid: next_scid, |
| 1121 | + inbound_amount_msat, |
| 1122 | + expected_outbound_amount_msat, |
| 1123 | + intercept_id, |
| 1124 | + })) |
| 1125 | + }, |
1057 | 1126 | 7u8 => {
|
1058 | 1127 | let f = || {
|
1059 | 1128 | let mut fee_earned_msat = None;
|
|
0 commit comments