Skip to content

Commit 3d03c26

Browse files
Add PaymentIntercepted event
Used in upcoming commit(s) so users can intercept forwarded payments Co-authored-by: John Cantrell <johncantrell97@gmail.com> Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
1 parent bcac847 commit 3d03c26

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

lightning/src/util/events.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use crate::chain::keysinterface::SpendableOutputDescriptor;
1818
#[cfg(anchors)]
1919
use crate::ln::chan_utils::HTLCOutputInCommitment;
20-
use crate::ln::channelmanager::PaymentId;
20+
use crate::ln::channelmanager::{InterceptId, PaymentId};
2121
use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
2222
use crate::ln::features::ChannelTypeFeatures;
2323
use crate::ln::msgs;
@@ -566,6 +566,20 @@ pub enum Event {
566566
/// now + 5*time_forwardable).
567567
time_forwardable: Duration,
568568
},
569+
/// Used to indicate that we've received a forwardable payment that should be intercepted.
570+
PaymentIntercepted {
571+
/// The scid that indicated this payment should be intercepted
572+
short_channel_id: u64,
573+
/// The payment hash used for this payment
574+
payment_hash: PaymentHash,
575+
/// How many msats are to be received on the inbound edge of this payment
576+
inbound_amount_msat: u64,
577+
/// How many msats the payer intended to route to the next node. Depending on the reason you are
578+
/// intercepting this payment, you might take a fee by forwarding less than this amount
579+
expected_outbound_amount_msat: u64,
580+
/// A id to help LDK identify which payment is being forwarded or failed
581+
intercept_id: InterceptId
582+
},
569583
/// Used to indicate that an output which you should know how to spend was confirmed on chain
570584
/// and is now spendable.
571585
/// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
@@ -896,6 +910,16 @@ impl Writeable for Event {
896910
(6, channel_type, required),
897911
});
898912
},
913+
&Event::PaymentIntercepted { short_channel_id, payment_hash, inbound_amount_msat: inbound_amount_msats, expected_outbound_amount_msat: expected_outbound_amount_msats, intercept_id } => {
914+
31u8.write(writer)?;
915+
write_tlv_fields!(writer, {
916+
(0, short_channel_id, required),
917+
(2, payment_hash, required),
918+
(4, inbound_amount_msats, required),
919+
(6, expected_outbound_amount_msats, required),
920+
(8, intercept_id, required)
921+
});
922+
}
899923
// Note that, going forward, all new events must only write data inside of
900924
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
901925
// data via `write_tlv_fields`.
@@ -1199,6 +1223,27 @@ impl MaybeReadable for Event {
11991223
};
12001224
f()
12011225
},
1226+
31u8 => {
1227+
let mut payment_hash = PaymentHash([0; 32]);
1228+
let mut intercept_id = InterceptId([0; 32]);
1229+
let mut short_channel_id = 0;
1230+
let mut inbound_amount_msats = 0;
1231+
let mut expected_outbound_amount_msats = 0;
1232+
read_tlv_fields!(reader, {
1233+
(0, short_channel_id, required),
1234+
(2, payment_hash, required),
1235+
(4, inbound_amount_msats, required),
1236+
(6, expected_outbound_amount_msats, required),
1237+
(8, intercept_id, required)
1238+
});
1239+
Ok(Some(Event::PaymentIntercepted {
1240+
payment_hash,
1241+
short_channel_id,
1242+
inbound_amount_msat: inbound_amount_msats,
1243+
expected_outbound_amount_msat: expected_outbound_amount_msats,
1244+
intercept_id,
1245+
}))
1246+
},
12021247
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
12031248
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
12041249
// reads.

0 commit comments

Comments
 (0)