@@ -18,10 +18,9 @@ use lightning::events::bump_transaction::BumpTransactionEvent;
1818#[ cfg( not( feature = "uniffi" ) ) ]
1919use lightning:: events:: PaidBolt12Invoice ;
2020use lightning:: events:: {
21- ClosureReason , Event as LdkEvent , FundingInfo , PaymentFailureReason , PaymentPurpose ,
22- ReplayEvent ,
21+ ClosureReason , Event as LdkEvent , FundingInfo , HTLCLocator as LdkHtlcLocator ,
22+ PaymentFailureReason , PaymentPurpose , ReplayEvent ,
2323} ;
24- use lightning:: impl_writeable_tlv_based_enum;
2524use lightning:: ln:: channelmanager:: PaymentId ;
2625use lightning:: ln:: types:: ChannelId ;
2726use lightning:: routing:: gossip:: NodeId ;
@@ -32,6 +31,7 @@ use lightning::util::config::{
3231use lightning:: util:: errors:: APIError ;
3332use lightning:: util:: persist:: KVStore ;
3433use lightning:: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
34+ use lightning:: { impl_writeable_tlv_based, impl_writeable_tlv_based_enum} ;
3535use lightning_liquidity:: lsps2:: utils:: compute_opening_fee;
3636use lightning_types:: payment:: { PaymentHash , PaymentPreimage } ;
3737
@@ -61,6 +61,40 @@ use crate::{
6161 UserChannelId ,
6262} ;
6363
64+ /// Identifies the channel and counterparty that a HTLC was processed with.
65+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
66+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
67+ pub struct HTLCLocator {
68+ /// The channel that the HTLC was sent or received on.
69+ pub channel_id : ChannelId ,
70+ /// The `user_channel_id` for the channel.
71+ ///
72+ /// Will only be `None` for events serialized with LDK Node v0.3.0 or prior, or if the
73+ /// payment was settled via an on-chain transaction.
74+ pub user_channel_id : Option < UserChannelId > ,
75+ /// The node id of the counterparty for this HTLC.
76+ ///
77+ /// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
78+ /// versions prior to v0.5.
79+ pub node_id : Option < PublicKey > ,
80+ }
81+
82+ impl_writeable_tlv_based ! ( HTLCLocator , {
83+ ( 1 , channel_id, required) ,
84+ ( 3 , user_channel_id, option) ,
85+ ( 5 , node_id, option) ,
86+ } ) ;
87+
88+ impl From < LdkHtlcLocator > for HTLCLocator {
89+ fn from ( value : LdkHtlcLocator ) -> Self {
90+ HTLCLocator {
91+ channel_id : value. channel_id ,
92+ user_channel_id : value. user_channel_id . map ( |u| UserChannelId ( u) ) ,
93+ node_id : value. node_id ,
94+ }
95+ }
96+ }
97+
6498/// An event emitted by [`Node`], which should be handled by the user.
6599///
66100/// [`Node`]: [`crate::Node`]
@@ -128,29 +162,14 @@ pub enum Event {
128162 } ,
129163 /// A payment has been forwarded.
130164 PaymentForwarded {
131- /// The channel id of the incoming channel between the previous node and us.
132- prev_channel_id : ChannelId ,
133- /// The channel id of the outgoing channel between the next node and us.
134- next_channel_id : ChannelId ,
135- /// The `user_channel_id` of the incoming channel between the previous node and us.
136- ///
137- /// Will only be `None` for events serialized with LDK Node v0.3.0 or prior.
138- prev_user_channel_id : Option < UserChannelId > ,
139- /// The `user_channel_id` of the outgoing channel between the next node and us.
140- ///
141- /// This will be `None` if the payment was settled via an on-chain transaction. See the
142- /// caveat described for the `total_fee_earned_msat` field.
143- next_user_channel_id : Option < UserChannelId > ,
144- /// The node id of the previous node.
145- ///
146- /// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
147- /// versions prior to v0.5.
148- prev_node_id : Option < PublicKey > ,
149- /// The node id of the next node.
150- ///
151- /// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
152- /// versions prior to v0.5.
153- next_node_id : Option < PublicKey > ,
165+ /// The set of incoming HTLCs that were forwarded to our node. Contains a single HTLC for
166+ /// source-routed payments, and may contain multiple HTLCs when we acted as a trampoline
167+ /// router.
168+ prev_htlcs : Vec < HTLCLocator > ,
169+ /// The set of outgoing HTLCs forwarded by our node. Contains a single HTLC for regular
170+ /// source-routed payments, and may contain multiple HTLCs when we acted as a trampoline
171+ /// router.
172+ next_htlcs : Vec < HTLCLocator > ,
154173 /// The total fee, in milli-satoshis, which was earned as a result of the payment.
155174 ///
156175 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
@@ -323,16 +342,27 @@ impl_writeable_tlv_based_enum!(Event,
323342 ( 7 , custom_records, optional_vec) ,
324343 } ,
325344 ( 7 , PaymentForwarded ) => {
326- ( 0 , prev_channel_id, required) ,
327- ( 1 , prev_node_id, option) ,
328- ( 2 , next_channel_id, required) ,
329- ( 3 , next_node_id, option) ,
330- ( 4 , prev_user_channel_id, option) ,
331- ( 6 , next_user_channel_id, option) ,
345+ // Legacy fields: read from old data, never written.
346+ ( 0 , legacy_prev_channel_id, ( legacy, ChannelId , |_| Ok ( ( ) ) , |_: & Event | None :: <Option <ChannelId >>) ) ,
347+ ( 1 , legacy_prev_node_id, ( legacy, PublicKey , |_| Ok ( ( ) ) , |_: & Event | None :: <Option <PublicKey >>) ) ,
348+ ( 2 , legacy_next_channel_id, ( legacy, ChannelId , |_| Ok ( ( ) ) , |_: & Event | None :: <Option <ChannelId >>) ) ,
349+ ( 3 , legacy_next_node_id, ( legacy, PublicKey , |_| Ok ( ( ) ) , |_: & Event | None :: <Option <PublicKey >>) ) ,
350+ ( 4 , legacy_prev_user_channel_id, ( legacy, u128 , |_| Ok ( ( ) ) , |_: & Event | None :: <Option <u128 >>) ) ,
351+ ( 6 , legacy_next_user_channel_id, ( legacy, u128 , |_| Ok ( ( ) ) , |_: & Event | None :: <Option <u128 >>) ) ,
332352 ( 8 , total_fee_earned_msat, option) ,
333353 ( 10 , skimmed_fee_msat, option) ,
334354 ( 12 , claim_from_onchain_tx, required) ,
335355 ( 14 , outbound_amount_forwarded_msat, option) ,
356+ ( 15 , prev_htlcs, ( default_value_vec, vec![ HTLCLocator {
357+ channel_id: legacy_prev_channel_id. ok_or( lightning:: ln:: msgs:: DecodeError :: InvalidValue ) ?,
358+ user_channel_id: legacy_prev_user_channel_id. map( UserChannelId ) ,
359+ node_id: legacy_prev_node_id,
360+ } ] ) ) ,
361+ ( 17 , next_htlcs, ( default_value_vec, vec![ HTLCLocator {
362+ channel_id: legacy_next_channel_id. ok_or( lightning:: ln:: msgs:: DecodeError :: InvalidValue ) ?,
363+ user_channel_id: legacy_next_user_channel_id. map( UserChannelId ) ,
364+ node_id: legacy_next_node_id,
365+ } ] ) ) ,
336366 } ,
337367 ( 8 , SplicePending ) => {
338368 ( 1 , channel_id, required) ,
@@ -1400,9 +1430,6 @@ where
14001430 // reporting the first HTLC in each vec.
14011431 debug_assert_eq ! ( prev_htlcs. len( ) , 1 , "unexpected number of prev_htlcs" ) ;
14021432 debug_assert_eq ! ( next_htlcs. len( ) , 1 , "unexpected number of next_htlcs" ) ;
1403- let prev_htlc = prev_htlcs
1404- . first ( )
1405- . expect ( "we expect at least one prev_htlc for PaymentForwarded" ) ;
14061433 let next_htlc = next_htlcs
14071434 . first ( )
14081435 . expect ( "we expect at least one next_htlc for PaymentForwarded" ) ;
@@ -1415,12 +1442,8 @@ where
14151442 }
14161443
14171444 let event = Event :: PaymentForwarded {
1418- prev_channel_id : prev_htlc. channel_id ,
1419- next_channel_id : next_htlc. channel_id ,
1420- prev_user_channel_id : prev_htlc. user_channel_id . map ( UserChannelId ) ,
1421- next_user_channel_id : next_htlc. user_channel_id . map ( UserChannelId ) ,
1422- prev_node_id : prev_htlc. node_id ,
1423- next_node_id : next_htlc. node_id ,
1445+ prev_htlcs : prev_htlcs. into_iter ( ) . map ( HTLCLocator :: from) . collect ( ) ,
1446+ next_htlcs : next_htlcs. into_iter ( ) . map ( HTLCLocator :: from) . collect ( ) ,
14241447 total_fee_earned_msat,
14251448 skimmed_fee_msat,
14261449 claim_from_onchain_tx,
0 commit comments