Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routing: probability based path finding #2802

Merged
merged 10 commits into from
Jun 5, 2019
59 changes: 59 additions & 0 deletions cmd/lncli/cmd_query_mission_control.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// +build routerrpc

package main

import (
"context"
"encoding/hex"

"github.com/lightningnetwork/lnd/lnrpc/routerrpc"

"github.com/urfave/cli"
)

var queryMissionControlCommand = cli.Command{
Name: "querymc",
Category: "Payments",
Action: actionDecorator(queryMissionControl),
}

func queryMissionControl(ctx *cli.Context) error {
conn := getClientConn(ctx, false)
defer conn.Close()

client := routerrpc.NewRouterClient(conn)

req := &routerrpc.QueryMissionControlRequest{}
rpcCtx := context.Background()
snapshot, err := client.QueryMissionControl(rpcCtx, req)
if err != nil {
return err
}

type displayNodeHistory struct {
Pubkey string
LastFailTime int64
OtherChanSuccessProb float32
Channels []*routerrpc.ChannelHistory
}

displayResp := struct {
joostjager marked this conversation as resolved.
Show resolved Hide resolved
Nodes []displayNodeHistory
}{}

for _, n := range snapshot.Nodes {
displayResp.Nodes = append(
displayResp.Nodes,
displayNodeHistory{
Pubkey: hex.EncodeToString(n.Pubkey),
LastFailTime: n.LastFailTime,
OtherChanSuccessProb: n.OtherChanSuccessProb,
Channels: n.Channels,
},
)
}

printJSON(displayResp)

return nil
}
1 change: 1 addition & 0 deletions cmd/lncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func main() {
// Add any extra autopilot commands determined by build flags.
app.Commands = append(app.Commands, autopilotCommands()...)
app.Commands = append(app.Commands, invoicesCommands()...)
app.Commands = append(app.Commands, routerCommands()...)

if err := app.Run(os.Args); err != nil {
fatal(err)
Expand Down
10 changes: 10 additions & 0 deletions cmd/lncli/routerrpc_active.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build routerrpc

package main

import "github.com/urfave/cli"

// routerCommands will return nil for non-routerrpc builds.
func routerCommands() []cli.Command {
return []cli.Command{queryMissionControlCommand}
}
10 changes: 10 additions & 0 deletions cmd/lncli/routerrpc_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build !routerrpc

package main

import "github.com/urfave/cli"

// routerCommands will return nil for non-routerrpc builds.
func routerCommands() []cli.Command {
return nil
}
4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing"
Expand Down Expand Up @@ -369,7 +370,8 @@ func loadConfig() (*config, error) {
MinBackoff: defaultMinBackoff,
MaxBackoff: defaultMaxBackoff,
SubRPCServers: &subRPCServerConfigs{
SignRPC: &signrpc.Config{},
SignRPC: &signrpc.Config{},
RouterRPC: routerrpc.DefaultConfig(),
},
Autopilot: &autoPilotConfig{
MaxChannels: 5,
Expand Down
47 changes: 47 additions & 0 deletions lnrpc/routerrpc/config_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
package routerrpc

import (
"time"

"github.com/lightningnetwork/lnd/lnwire"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/routing"
)
Expand All @@ -19,6 +24,23 @@ type Config struct {
// 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
Expand All @@ -45,3 +67,28 @@ type Config struct {
// main rpc server.
RouterBackend *RouterBackend
}

// DefaultConfig defines the config defaults.
func DefaultConfig() *Config {
return &Config{
AprioriHopProbability: routing.DefaultAprioriHopProbability,
MinRouteProbability: routing.DefaultMinRouteProbability,
PenaltyHalfLife: routing.DefaultPenaltyHalfLife,
AttemptCost: int64(
routing.DefaultPaymentAttemptPenalty.ToSatoshis(),
),
}
}

// GetMissionControlConfig returns the mission control config based on this sub
// server config.
func GetMissionControlConfig(cfg *Config) *routing.MissionControlConfig {
return &routing.MissionControlConfig{
AprioriHopProbability: cfg.AprioriHopProbability,
MinRouteProbability: cfg.MinRouteProbability,
PaymentAttemptPenalty: lnwire.NewMSatFromSatoshis(
btcutil.Amount(cfg.AttemptCost),
),
PenaltyHalfLife: cfg.PenaltyHalfLife,
}
}
21 changes: 20 additions & 1 deletion lnrpc/routerrpc/config_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

package routerrpc

// Config is the default config for the package. When the build tag isn't
import "github.com/lightningnetwork/lnd/routing"

// Config is the default config struct for the package. When the build tag isn't
// specified, then we output a blank config.
type Config struct{}

// DefaultConfig defines the config defaults. Without the sub server enabled,
// there are no defaults to set.
func DefaultConfig() *Config {
return &Config{}
}

// GetMissionControlConfig returns the mission control config based on this sub
// server config.
func GetMissionControlConfig(cfg *Config) *routing.MissionControlConfig {
return &routing.MissionControlConfig{
AprioriHopProbability: routing.DefaultAprioriHopProbability,
MinRouteProbability: routing.DefaultMinRouteProbability,
PaymentAttemptPenalty: routing.DefaultPaymentAttemptPenalty,
PenaltyHalfLife: routing.DefaultPenaltyHalfLife,
}
}
Loading