@@ -103,6 +103,50 @@ pub enum Event {
103103 /// The value, in thousandths of a satoshi, that has been received.
104104 amount_msat : u64 ,
105105 } ,
106+ /// A payment has been forwarded.
107+ PaymentForwarded {
108+ /// The channel id of the incoming channel between the previous node and us.
109+ prev_channel_id : ChannelId ,
110+ /// The channel id of the outgoing channel between the next node and us.
111+ next_channel_id : ChannelId ,
112+ /// The `user_channel_id` of the incoming channel between the previous node and us.
113+ ///
114+ /// Will only be `None` for events serialized with LDK Node v0.3.0 or prior.
115+ prev_user_channel_id : Option < UserChannelId > ,
116+ /// The `user_channel_id` of the outgoing channel between the next node and us.
117+ ///
118+ /// This will be `None` if the payment was settled via an on-chain transaction. See the
119+ /// caveat described for the `total_fee_earned_msat` field.
120+ next_user_channel_id : Option < UserChannelId > ,
121+ /// The total fee, in milli-satoshis, which was earned as a result of the payment.
122+ ///
123+ /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
124+ /// was pending, the amount the next hop claimed will have been rounded down to the nearest
125+ /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
126+ /// claimed the full value in millisatoshis from the source. In this case,
127+ /// `claim_from_onchain_tx` will be set.
128+ ///
129+ /// If the channel which sent us the payment has been force-closed, we will claim the funds
130+ /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
131+ /// fees which we will spend and will instead set this to `None`.
132+ total_fee_earned_msat : Option < u64 > ,
133+ /// The share of the total fee, in milli-satoshis, which was withheld in addition to the
134+ /// forwarding fee.
135+ ///
136+ /// This will only be `Some` if we forwarded an intercepted HTLC with less than the
137+ /// expected amount. This means our counterparty accepted to receive less than the invoice
138+ /// amount.
139+ ///
140+ /// The caveat described above the `total_fee_earned_msat` field applies here as well.
141+ skimmed_fee_msat : Option < u64 > ,
142+ /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
143+ /// transaction.
144+ claim_from_onchain_tx : bool ,
145+ /// The final amount forwarded, in milli-satoshis, after the fee is deducted.
146+ ///
147+ /// The caveat described above the `total_fee_earned_msat` field applies here as well.
148+ outbound_amount_forwarded_msat : Option < u64 > ,
149+ } ,
106150 /// A payment for a previously-registered payment hash has been received.
107151 ///
108152 /// This needs to be manually claimed by supplying the correct preimage to [`claim_for_hash`].
@@ -204,6 +248,16 @@ impl_writeable_tlv_based_enum!(Event,
204248 ( 2 , payment_id, required) ,
205249 ( 4 , claimable_amount_msat, required) ,
206250 ( 6 , claim_deadline, option) ,
251+ } ,
252+ ( 7 , PaymentForwarded ) => {
253+ ( 0 , prev_channel_id, required) ,
254+ ( 2 , next_channel_id, required) ,
255+ ( 4 , prev_user_channel_id, option) ,
256+ ( 6 , next_user_channel_id, option) ,
257+ ( 8 , total_fee_earned_msat, option) ,
258+ ( 10 , skimmed_fee_msat, option) ,
259+ ( 12 , claim_from_onchain_tx, required) ,
260+ ( 14 , outbound_amount_forwarded_msat, option) ,
207261 }
208262) ;
209263
@@ -1068,11 +1122,28 @@ where
10681122 LdkEvent :: PaymentForwarded {
10691123 prev_channel_id,
10701124 next_channel_id,
1125+ prev_user_channel_id,
1126+ next_user_channel_id,
10711127 total_fee_earned_msat,
1128+ skimmed_fee_msat,
10721129 claim_from_onchain_tx,
10731130 outbound_amount_forwarded_msat,
1074- ..
10751131 } => {
1132+ let event = Event :: PaymentForwarded {
1133+ prev_channel_id : prev_channel_id. expect ( "prev_channel_id expected for events generated by LDK versions greater than 0.0.107." ) ,
1134+ next_channel_id : next_channel_id. expect ( "next_channel_id expected for events generated by LDK versions greater than 0.0.107." ) ,
1135+ prev_user_channel_id : prev_user_channel_id. map ( UserChannelId ) ,
1136+ next_user_channel_id : next_user_channel_id. map ( UserChannelId ) ,
1137+ total_fee_earned_msat,
1138+ skimmed_fee_msat,
1139+ claim_from_onchain_tx,
1140+ outbound_amount_forwarded_msat,
1141+ } ;
1142+ self . event_queue . add_event ( event) . map_err ( |e| {
1143+ log_error ! ( self . logger, "Failed to push to event queue: {}" , e) ;
1144+ ReplayEvent ( )
1145+ } ) ?;
1146+
10761147 let read_only_network_graph = self . network_graph . read_only ( ) ;
10771148 let nodes = read_only_network_graph. nodes ( ) ;
10781149 let channels = self . channel_manager . list_channels ( ) ;
0 commit comments