@@ -10,6 +10,7 @@ use core::task::{Poll, Waker};
1010use std:: collections:: VecDeque ;
1111use std:: ops:: Deref ;
1212use std:: sync:: { Arc , Mutex } ;
13+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
1314
1415use bitcoin:: blockdata:: locktime:: absolute:: LockTime ;
1516use bitcoin:: secp256k1:: PublicKey ;
@@ -45,10 +46,13 @@ use crate::logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger
4546use crate :: payment:: asynchronous:: om_mailbox:: OnionMessageMailbox ;
4647use crate :: payment:: asynchronous:: static_invoice_store:: StaticInvoiceStore ;
4748use crate :: payment:: store:: {
48- PaymentDetails , PaymentDetailsUpdate , PaymentDirection , PaymentKind , PaymentStatus ,
49+ ForwardedPaymentDetails , ForwardedPaymentId , PaymentDetails , PaymentDetailsUpdate ,
50+ PaymentDirection , PaymentKind , PaymentStatus ,
4951} ;
5052use crate :: runtime:: Runtime ;
51- use crate :: types:: { CustomTlvRecord , DynStore , OnionMessenger , PaymentStore , Sweeper , Wallet } ;
53+ use crate :: types:: {
54+ CustomTlvRecord , DynStore , ForwardedPaymentStore , OnionMessenger , PaymentStore , Sweeper , Wallet ,
55+ } ;
5256use crate :: {
5357 hex_utils, BumpTransactionEventHandler , ChannelManager , Error , Graph , PeerInfo , PeerStore ,
5458 UserChannelId ,
@@ -487,6 +491,7 @@ where
487491 network_graph : Arc < Graph > ,
488492 liquidity_source : Option < Arc < LiquiditySource < Arc < Logger > > > > ,
489493 payment_store : Arc < PaymentStore > ,
494+ forwarded_payment_store : Arc < ForwardedPaymentStore > ,
490495 peer_store : Arc < PeerStore < L > > ,
491496 runtime : Arc < Runtime > ,
492497 logger : L ,
@@ -506,10 +511,10 @@ where
506511 channel_manager : Arc < ChannelManager > , connection_manager : Arc < ConnectionManager < L > > ,
507512 output_sweeper : Arc < Sweeper > , network_graph : Arc < Graph > ,
508513 liquidity_source : Option < Arc < LiquiditySource < Arc < Logger > > > > ,
509- payment_store : Arc < PaymentStore > , peer_store : Arc < PeerStore < L > > ,
510- static_invoice_store : Option < StaticInvoiceStore > , onion_messenger : Arc < OnionMessenger > ,
511- om_mailbox : Option < Arc < OnionMessageMailbox > > , runtime : Arc < Runtime > , logger : L ,
512- config : Arc < Config > ,
514+ payment_store : Arc < PaymentStore > , forwarded_payment_store : Arc < ForwardedPaymentStore > ,
515+ peer_store : Arc < PeerStore < L > > , static_invoice_store : Option < StaticInvoiceStore > ,
516+ onion_messenger : Arc < OnionMessenger > , om_mailbox : Option < Arc < OnionMessageMailbox > > ,
517+ runtime : Arc < Runtime > , logger : L , config : Arc < Config > ,
513518 ) -> Self {
514519 Self {
515520 event_queue,
@@ -521,6 +526,7 @@ where
521526 network_graph,
522527 liquidity_source,
523528 payment_store,
529+ forwarded_payment_store,
524530 peer_store,
525531 logger,
526532 runtime,
@@ -1364,9 +1370,44 @@ where
13641370 . await ;
13651371 }
13661372
1373+ // Store the forwarded payment details
1374+ let prev_channel_id_value = prev_channel_id
1375+ . expect ( "prev_channel_id expected for events generated by LDK versions greater than 0.0.107." ) ;
1376+ let next_channel_id_value = next_channel_id
1377+ . expect ( "next_channel_id expected for events generated by LDK versions greater than 0.0.107." ) ;
1378+
1379+ // PaymentForwarded does not have a unique id, so we generate a random one here.
1380+ let mut id_bytes = [ 0u8 ; 32 ] ;
1381+ rng ( ) . fill ( & mut id_bytes) ;
1382+
1383+ let forwarded_at_timestamp = SystemTime :: now ( )
1384+ . duration_since ( UNIX_EPOCH )
1385+ . expect ( "SystemTime::now() should come after SystemTime::UNIX_EPOCH" )
1386+ . as_secs ( ) ;
1387+
1388+ let forwarded_payment = ForwardedPaymentDetails {
1389+ id : ForwardedPaymentId ( id_bytes) ,
1390+ prev_channel_id : prev_channel_id_value,
1391+ next_channel_id : next_channel_id_value,
1392+ prev_user_channel_id : prev_user_channel_id. map ( UserChannelId ) ,
1393+ next_user_channel_id : next_user_channel_id. map ( UserChannelId ) ,
1394+ prev_node_id,
1395+ next_node_id,
1396+ total_fee_earned_msat,
1397+ skimmed_fee_msat,
1398+ claim_from_onchain_tx,
1399+ outbound_amount_forwarded_msat,
1400+ forwarded_at_timestamp,
1401+ } ;
1402+
1403+ self . forwarded_payment_store . insert ( forwarded_payment) . map_err ( |e| {
1404+ log_error ! ( self . logger, "Failed to store forwarded payment: {e}" ) ;
1405+ ReplayEvent ( )
1406+ } ) ?;
1407+
13671408 let event = Event :: PaymentForwarded {
1368- prev_channel_id : prev_channel_id . expect ( "prev_channel_id expected for events generated by LDK versions greater than 0.0.107." ) ,
1369- next_channel_id : next_channel_id . expect ( "next_channel_id expected for events generated by LDK versions greater than 0.0.107." ) ,
1409+ prev_channel_id : prev_channel_id_value ,
1410+ next_channel_id : next_channel_id_value ,
13701411 prev_user_channel_id : prev_user_channel_id. map ( UserChannelId ) ,
13711412 next_user_channel_id : next_user_channel_id. map ( UserChannelId ) ,
13721413 prev_node_id,
0 commit comments