@@ -21,7 +21,6 @@ use crate::fiber::history::SentNode;
2121use crate :: fiber:: key:: KeyPair ;
2222use crate :: fiber:: path:: NodeHeapElement ;
2323use crate :: fiber:: payment:: { Attempt , PaymentSession , PaymentStatus } ;
24- use crate :: fiber:: serde_utils:: EntityHex ;
2524use crate :: fiber:: serde_utils:: { U128Hex , U64Hex } ;
2625use crate :: fiber:: types:: PaymentHopData ;
2726use crate :: fiber:: types:: Privkey ;
@@ -453,6 +452,53 @@ impl GraphChannelStat {
453452 }
454453}
455454
455+ /// A wrapper that combines `SendPaymentData` (the user's payment request) with
456+ /// `GraphChannelStat` (runtime channel usage state for path-finding).
457+ ///
458+ /// Graph methods accept `&SendPaymentState` instead of `&SendPaymentData`.
459+ /// Thanks to `Deref<Target = SendPaymentData>`, all payment data fields
460+ /// are accessible directly (e.g., `state.target_pubkey`), while the
461+ /// runtime-only `channel_stats` field lives on this wrapper.
462+ #[ derive( Clone , Debug ) ]
463+ pub struct SendPaymentState {
464+ /// The underlying payment request data.
465+ pub request : SendPaymentData ,
466+ /// Runtime channel usage statistics for path-finding (overlay on global stats).
467+ pub channel_stats : GraphChannelStat ,
468+ }
469+
470+ impl SendPaymentState {
471+ /// Create a new `SendPaymentState` with default (empty) channel stats.
472+ pub fn new ( request : SendPaymentData ) -> Self {
473+ Self {
474+ request,
475+ channel_stats : Default :: default ( ) ,
476+ }
477+ }
478+
479+ /// Create a new `SendPaymentState` with specific channel stats.
480+ pub fn with_channel_stats ( request : SendPaymentData , channel_stats : GraphChannelStat ) -> Self {
481+ Self {
482+ request,
483+ channel_stats,
484+ }
485+ }
486+ }
487+
488+ impl std:: ops:: Deref for SendPaymentState {
489+ type Target = SendPaymentData ;
490+
491+ fn deref ( & self ) -> & Self :: Target {
492+ & self . request
493+ }
494+ }
495+
496+ impl From < SendPaymentData > for SendPaymentState {
497+ fn from ( request : SendPaymentData ) -> Self {
498+ Self :: new ( request)
499+ }
500+ }
501+
456502#[ derive( Clone , Debug ) ]
457503pub struct NetworkGraph < S > {
458504 // Whether to always process gossip messages for our own channels.
@@ -517,27 +563,8 @@ pub enum PathFindError {
517563 Other ( String ) ,
518564}
519565
520- /// A router hop information for a payment, a paymenter router is an array of RouterHop,
521- /// a router hop generally implies hop `target` will receive `amount_received` with `channel_outpoint` of channel.
522- /// Improper hop hint may make payment fail, for example the specified channel do not have enough capacity.
523- #[ serde_as]
524- #[ derive( Clone , Debug , Eq , PartialEq , Serialize , Deserialize ) ]
525- pub struct RouterHop {
526- /// The node that is sending the TLC to the next node.
527- pub ( crate ) target : Pubkey ,
528- /// The channel of this hop used to receive TLC
529- #[ serde_as( as = "EntityHex" ) ]
530- pub ( crate ) channel_outpoint : OutPoint ,
531- /// The amount that the source node will transfer to the target node.
532- /// We have already added up all the fees along the path, so this amount can be used directly for the TLC.
533- #[ serde_as( as = "U128Hex" ) ]
534- pub ( crate ) amount_received : u128 ,
535- /// The expiry for the TLC that the source node sends to the target node.
536- /// We have already added up all the expiry deltas along the path,
537- /// the only thing missing is current time. So the expiry is the current time plus the expiry delta.
538- #[ serde_as( as = "U64Hex" ) ]
539- pub ( crate ) incoming_tlc_expiry : u64 ,
540- }
566+ // RouterHop is defined in fiber-types and re-exported here for backward compatibility
567+ pub use fiber_types:: RouterHop ;
541568
542569#[ derive( Debug ) ]
543570struct ResolvedRoute {
@@ -1245,7 +1272,7 @@ where
12451272 amount : u128 ,
12461273 amount_low_bound : Option < u128 > ,
12471274 max_fee_amount : Option < u128 > ,
1248- payment_data : & SendPaymentData ,
1275+ payment_data : & SendPaymentState ,
12491276 ) -> Result < Vec < PaymentHopData > , PathFindError > {
12501277 info ! (
12511278 "entered build_route: amount: {}, amount_low_bound: {:?}, max_fee_amount: {:?}" ,
@@ -1325,7 +1352,7 @@ where
13251352 amount : u128 ,
13261353 amount_low_bound : Option < u128 > ,
13271354 max_fee_amount : Option < u128 > ,
1328- payment_data : & SendPaymentData ,
1355+ payment_data : & SendPaymentState ,
13291356 ) -> Result < ResolvedRoute , PathFindError > {
13301357 if !payment_data. router . is_empty ( ) {
13311358 // If a router is explicitly provided, use it.
@@ -1383,7 +1410,7 @@ where
13831410 source : Pubkey ,
13841411 final_amount : u128 ,
13851412 max_fee_amount : Option < u128 > ,
1386- payment_data : & SendPaymentData ,
1413+ payment_data : & SendPaymentState ,
13871414 ) -> Result < ResolvedRoute , PathFindError > {
13881415 let target = payment_data. target_pubkey ;
13891416 let max_fee_amount = max_fee_amount. or ( payment_data. max_fee_amount ) ;
@@ -1598,7 +1625,7 @@ where
15981625 source : Pubkey ,
15991626 amount : u128 ,
16001627 max_fee_amount : Option < u128 > ,
1601- payment_data : & SendPaymentData ,
1628+ payment_data : & SendPaymentState ,
16021629 ) -> Result < Vec < RouterHop > , PathFindError > {
16031630 #[ cfg( any( feature = "metrics" , test) ) ]
16041631 {
@@ -1623,7 +1650,7 @@ where
16231650
16241651 pub fn find_path_max_capacity (
16251652 & self ,
1626- payment_data : & SendPaymentData ,
1653+ payment_data : & SendPaymentState ,
16271654 ) -> Result < u128 , PathFindError > {
16281655 #[ cfg( any( feature = "metrics" , test) ) ]
16291656 {
@@ -1657,7 +1684,7 @@ where
16571684 amount : u128 ,
16581685 amount_low_bound : u128 ,
16591686 max_fee_amount : Option < u128 > ,
1660- payment_data : & SendPaymentData ,
1687+ payment_data : & SendPaymentState ,
16611688 ) -> Result < ( Vec < RouterHop > , u128 ) , PathFindError > {
16621689 debug ! (
16631690 "find_path_in_range (max capacity) for amount: {} low_bound: {} max_fee_amount: {:?}" ,
@@ -1741,7 +1768,7 @@ where
17411768 source : Pubkey ,
17421769 lower_bound : u128 ,
17431770 upper_bound : u128 ,
1744- payment_data : & SendPaymentData ,
1771+ payment_data : & SendPaymentState ,
17451772 ) -> ( Vec < RouterHop > , u128 ) {
17461773 if let Ok ( res) = self . probe_max_capacity_for_route ( source, upper_bound, route, payment_data)
17471774 {
@@ -1772,7 +1799,7 @@ where
17721799 source : Pubkey ,
17731800 amount : u128 ,
17741801 route : & [ RouterHop ] ,
1775- payment_data : & SendPaymentData ,
1802+ payment_data : & SendPaymentState ,
17761803 ) -> Result < std:: vec:: Vec < RouterHop > , PathFindError > {
17771804 self . inner_find_path (
17781805 source,
@@ -1794,7 +1821,7 @@ where
17941821 & self ,
17951822 route : & Vec < RouterHop > ,
17961823 amount : u128 ,
1797- payment_data : & SendPaymentData ,
1824+ payment_data : & SendPaymentState ,
17981825 trampoline_payload : Option < Vec < u8 > > ,
17991826 final_hop_expiry_delta_override : Option < u64 > ,
18001827 ) -> Vec < PaymentHopData > {
0 commit comments