From 3dc83d1b6bf22e6535727de49c982c73c11dbcdc Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Sat, 13 Jul 2019 23:26:26 +0200 Subject: [PATCH] routerrpc: embed routing config --- lnrpc/routerrpc/config.go | 29 +++++++++++----------- lnrpc/routerrpc/config_active.go | 40 +++++++++---------------------- lnrpc/routerrpc/config_default.go | 5 ++-- server.go | 8 ++++--- 4 files changed, 33 insertions(+), 49 deletions(-) diff --git a/lnrpc/routerrpc/config.go b/lnrpc/routerrpc/config.go index 15dd6c40..2f82c5ae 100644 --- a/lnrpc/routerrpc/config.go +++ b/lnrpc/routerrpc/config.go @@ -3,26 +3,25 @@ package routerrpc import ( "time" - "github.com/lightningnetwork/lnd/lnwire" + "github.com/btcsuite/btcutil" ) // RoutingConfig contains the configurable parameters that control routing. type RoutingConfig struct { - // PenaltyHalfLife defines after how much time a penalized node or - // channel is back at 50% probability. - PenaltyHalfLife time.Duration - - // PaymentAttemptPenalty is the virtual cost in path finding weight - // units of executing a payment attempt that fails. It is used to trade - // off potentially better routes against their probability of - // succeeding. - PaymentAttemptPenalty lnwire.MilliSatoshi - - // MinProbability defines the minimum success probability of the - // returned route. - MinRouteProbability float64 + // MinRouteProbability is the minimum required route success probability + // to attempt the payment. + MinRouteProbability float64 `long:"minrtprob" description:"Minimum required route success probability to attempt the payment"` // AprioriHopProbability is the assumed success probability of a hop in // a route when no other information is available. - AprioriHopProbability float64 + AprioriHopProbability float64 `long:"apriorihopprob" description:"Assumed success probability of a hop in a route when no other information is available."` + + // PenaltyHalfLife defines after how much time a penalized node or + // channel is back at 50% probability. + PenaltyHalfLife time.Duration `long:"penaltyhalflife" description:"Defines the duration after which a penalized node or channel is back at 50% probability"` + + // AttemptCost is the virtual cost in path finding weight units of + // executing a payment attempt that fails. It is used to trade off + // potentially better routes against their probability of succeeding. + AttemptCost btcutil.Amount `long:"attemptcost" description:"The (virtual) cost in sats of a failed payment attempt"` } diff --git a/lnrpc/routerrpc/config_active.go b/lnrpc/routerrpc/config_active.go index b919364e..832c86d7 100644 --- a/lnrpc/routerrpc/config_active.go +++ b/lnrpc/routerrpc/config_active.go @@ -3,10 +3,6 @@ package routerrpc import ( - "time" - - "github.com/btcsuite/btcutil" - "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/macaroons" "github.com/lightningnetwork/lnd/routing" ) @@ -17,28 +13,13 @@ import ( // options, while if able to be populated, the latter fields MUST also be // specified. type Config struct { + RoutingConfig + // RouterMacPath is the path for the router macaroon. If unspecified // then we assume that the macaroon will be found under the network // directory, named DefaultRouterMacFilename. RouterMacPath string `long:"routermacaroonpath" description:"Path to the router macaroon"` - // MinProbability is the minimum required route success probability to - // attempt the payment. - MinRouteProbability float64 `long:"minrtprob" description:"Minimum required route success probability to attempt the payment"` - - // AprioriHopProbability is the assumed success probability of a hop in - // a route when no other information is available. - AprioriHopProbability float64 `long:"apriorihopprob" description:"Assumed success probability of a hop in a route when no other information is available."` - - // PenaltyHalfLife defines after how much time a penalized node or - // channel is back at 50% probability. - PenaltyHalfLife time.Duration `long:"penaltyhalflife" description:"Defines the duration after which a penalized node or channel is back at 50% probability"` - - // AttemptCost is the virtual cost in path finding weight units of - // executing a payment attempt that fails. It is used to trade off - // potentially better routes against their probability of succeeding. - AttemptCost int64 `long:"attemptcost" description:"The (virtual) cost in sats of a failed payment attempt"` - // NetworkDir is the main network directory wherein the router rpc // server will find the macaroon named DefaultRouterMacFilename. NetworkDir string @@ -62,13 +43,16 @@ type Config struct { // DefaultConfig defines the config defaults. func DefaultConfig() *Config { - return &Config{ + defaultRoutingConfig := RoutingConfig{ AprioriHopProbability: routing.DefaultAprioriHopProbability, MinRouteProbability: routing.DefaultMinRouteProbability, PenaltyHalfLife: routing.DefaultPenaltyHalfLife, - AttemptCost: int64( - routing.DefaultPaymentAttemptPenalty.ToSatoshis(), - ), + AttemptCost: routing.DefaultPaymentAttemptPenalty. + ToSatoshis(), + } + + return &Config{ + RoutingConfig: defaultRoutingConfig, } } @@ -77,9 +61,7 @@ func GetRoutingConfig(cfg *Config) *RoutingConfig { return &RoutingConfig{ AprioriHopProbability: cfg.AprioriHopProbability, MinRouteProbability: cfg.MinRouteProbability, - PaymentAttemptPenalty: lnwire.NewMSatFromSatoshis( - btcutil.Amount(cfg.AttemptCost), - ), - PenaltyHalfLife: cfg.PenaltyHalfLife, + AttemptCost: cfg.AttemptCost, + PenaltyHalfLife: cfg.PenaltyHalfLife, } } diff --git a/lnrpc/routerrpc/config_default.go b/lnrpc/routerrpc/config_default.go index a3a95021..6308ca54 100644 --- a/lnrpc/routerrpc/config_default.go +++ b/lnrpc/routerrpc/config_default.go @@ -19,7 +19,8 @@ func GetRoutingConfig(cfg *Config) *RoutingConfig { return &RoutingConfig{ AprioriHopProbability: routing.DefaultAprioriHopProbability, MinRouteProbability: routing.DefaultMinRouteProbability, - PaymentAttemptPenalty: routing.DefaultPaymentAttemptPenalty, - PenaltyHalfLife: routing.DefaultPenaltyHalfLife, + AttemptCost: routing.DefaultPaymentAttemptPenalty. + ToSatoshis(), + PenaltyHalfLife: routing.DefaultPenaltyHalfLife, } } diff --git a/server.go b/server.go index 11f32cb8..658b47f9 100644 --- a/server.go +++ b/server.go @@ -662,12 +662,14 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, srvrLog.Debugf("Instantiating payment session source with config: "+ "PaymentAttemptPenalty=%v, MinRouteProbability=%v", - int64(routingConfig.PaymentAttemptPenalty.ToSatoshis()), + int64(routingConfig.AttemptCost), routingConfig.MinRouteProbability) pathFindingConfig := routing.PathFindingConfig{ - PaymentAttemptPenalty: routingConfig.PaymentAttemptPenalty, - MinProbability: routingConfig.MinRouteProbability, + PaymentAttemptPenalty: lnwire.NewMSatFromSatoshis( + routingConfig.AttemptCost, + ), + MinProbability: routingConfig.MinRouteProbability, } paymentSessionSource := &routing.SessionSource{