|
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,18 @@ 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(u64), |
| 297 | +} |
| 298 | + |
| 299 | +impl_writeable_tlv_based_enum!(InterceptNextHop, ; |
| 300 | + (0, FakeScid) |
| 301 | +); |
| 302 | + |
291 | 303 | /// An Event which you should probably take some action in response to.
|
292 | 304 | ///
|
293 | 305 | /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
|
@@ -566,6 +578,20 @@ pub enum Event {
|
566 | 578 | /// now + 5*time_forwardable).
|
567 | 579 | time_forwardable: Duration,
|
568 | 580 | },
|
| 581 | + /// Used to indicate that we've intercepted an HTLC forward. |
| 582 | + HTLCIntercepted { |
| 583 | + /// The fake scid that was programmed as the next hop's scid. |
| 584 | + requested_next_hop_scid: u64, |
| 585 | + /// The payment hash used for this HTLC. |
| 586 | + payment_hash: PaymentHash, |
| 587 | + /// How many msats are to be received on the inbound edge of this HTLC. |
| 588 | + inbound_amount_msat: u64, |
| 589 | + /// How many msats the payer intended to route to the next node. Depending on the reason you are |
| 590 | + /// intercepting this payment, you might take a fee by forwarding less than this amount. |
| 591 | + expected_outbound_amount_msat: u64, |
| 592 | + /// A id to help LDK identify which HTLC is being forwarded or failed. |
| 593 | + intercept_id: InterceptId |
| 594 | + }, |
569 | 595 | /// Used to indicate that an output which you should know how to spend was confirmed on chain
|
570 | 596 | /// and is now spendable.
|
571 | 597 | /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
|
@@ -896,6 +922,17 @@ impl Writeable for Event {
|
896 | 922 | (6, channel_type, required),
|
897 | 923 | });
|
898 | 924 | },
|
| 925 | + &Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat: inbound_amount_msats, expected_outbound_amount_msat: expected_outbound_amount_msats, intercept_id } => { |
| 926 | + 31u8.write(writer)?; |
| 927 | + let intercept_scid = InterceptNextHop::FakeScid(requested_next_hop_scid); |
| 928 | + write_tlv_fields!(writer, { |
| 929 | + (0, intercept_scid, required), |
| 930 | + (2, payment_hash, required), |
| 931 | + (4, inbound_amount_msats, required), |
| 932 | + (6, expected_outbound_amount_msats, required), |
| 933 | + (8, intercept_id, required) |
| 934 | + }); |
| 935 | + } |
899 | 936 | // Note that, going forward, all new events must only write data inside of
|
900 | 937 | // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
|
901 | 938 | // data via `write_tlv_fields`.
|
@@ -1199,6 +1236,30 @@ impl MaybeReadable for Event {
|
1199 | 1236 | };
|
1200 | 1237 | f()
|
1201 | 1238 | },
|
| 1239 | + 31u8 => { |
| 1240 | + let mut payment_hash = PaymentHash([0; 32]); |
| 1241 | + let mut intercept_id = InterceptId([0; 32]); |
| 1242 | + let mut requested_next_hop_scid = InterceptNextHop::FakeScid(0); |
| 1243 | + let mut inbound_amount_msats = 0; |
| 1244 | + let mut expected_outbound_amount_msats = 0; |
| 1245 | + read_tlv_fields!(reader, { |
| 1246 | + (0, requested_next_hop_scid, required), |
| 1247 | + (2, payment_hash, required), |
| 1248 | + (4, inbound_amount_msats, required), |
| 1249 | + (6, expected_outbound_amount_msats, required), |
| 1250 | + (8, intercept_id, required) |
| 1251 | + }); |
| 1252 | + let next_scid = match requested_next_hop_scid { |
| 1253 | + InterceptNextHop::FakeScid(scid) => scid |
| 1254 | + }; |
| 1255 | + Ok(Some(Event::HTLCIntercepted { |
| 1256 | + payment_hash, |
| 1257 | + requested_next_hop_scid: next_scid, |
| 1258 | + inbound_amount_msat: inbound_amount_msats, |
| 1259 | + expected_outbound_amount_msat: expected_outbound_amount_msats, |
| 1260 | + intercept_id, |
| 1261 | + })) |
| 1262 | + }, |
1202 | 1263 | // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
|
1203 | 1264 | // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
|
1204 | 1265 | // reads.
|
|
0 commit comments