@@ -484,6 +484,11 @@ type RestrictParams struct {
484484 // FirstHopCustomRecords includes any records that should be included in
485485 // the update_add_htlc message towards our peer.
486486 FirstHopCustomRecords lnwire.CustomRecords
487+
488+ // ImputedCostControl provides access to imputed cost configurations
489+ // that influence routing decisions by applying virtual costs to
490+ // specific node pairs during pathfinding.
491+ ImputedCostControl * ImputedCostControl
487492}
488493
489494// PathFindingConfig defines global parameters that control the trade-off in
@@ -915,6 +920,48 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
915920 absoluteAttemptCost ,
916921 )
917922
923+ // Apply imputed costs if enabled. Imputed costs allow the
924+ // application of virtual costs to specific node pairs to
925+ // influence routing decisions without modifying actual network
926+ // fees.
927+ distInfo := toNodeDist .imputedDistInfo
928+ if r .ImputedCostControl != nil {
929+ // Calculate the imputed costs for this routing step and
930+ // validate that total costs (fees + imputed costs) do
931+ // not exceed configured limits. Returns an error if the
932+ // limit is exceeded, otherwise returns updated imputed
933+ // cost info.
934+ distInfo , err = r .ImputedCostControl .expandDistInfo (
935+ fromVertex , toNodeDist .node , netAmountToReceive ,
936+ totalFee , distInfo ,
937+ )
938+ if err != nil {
939+ return
940+ }
941+
942+ // Add the imputed distance to the total pathfinding
943+ // distance.
944+ //
945+ // Note: This addition is valid within the Dijkstra
946+ // algorithm implementation because the current design
947+ // ensures that the imputed cost delta to the toNode is
948+ // always non-negative.
949+ imputedDist := distInfo .getDist (probability )
950+ tempDist += imputedDist
951+
952+ log .Trace (lnutils .NewLogClosure (func () string {
953+ toDistInfo := toNodeDist .imputedDistInfo
954+ l := toDistInfo .getDist (toNodeDist .probability )
955+
956+ return fmt .Sprintf ("imputed cost distance: " +
957+ "fromnode=%v, tonode=%v, amt=%v, " +
958+ "dist=%v, distlast=%v, distdelta=%v" ,
959+ fromVertex , toNodeDist .node ,
960+ netAmountToReceive , imputedDist , l ,
961+ imputedDist - l )
962+ }))
963+ }
964+
918965 // If there is already a best route stored, compare this
919966 // candidate route with the best route so far.
920967 current , ok := distance [fromVertex ]
@@ -988,6 +1035,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
9881035 probability : probability ,
9891036 nextHop : edge ,
9901037 routingInfoSize : routingInfoSize ,
1038+ imputedDistInfo : distInfo ,
9911039 }
9921040 distance [fromVertex ] = withDist
9931041
0 commit comments