Skip to content

Commit

Permalink
Merge 024b4fb into 6e3b92b
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed May 25, 2019
2 parents 6e3b92b + 024b4fb commit f8eec09
Show file tree
Hide file tree
Showing 26 changed files with 1,632 additions and 446 deletions.
58 changes: 58 additions & 0 deletions cmd/lncli/cmd_query_mission_control.go
@@ -0,0 +1,58 @@
// +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 {
Nodes []displayNodeHistory
}{
make([]displayNodeHistory, len(snapshot.Nodes)),
}

for i, n := range snapshot.Nodes {
displayResp.Nodes[i] = 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
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
@@ -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
@@ -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
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 @@ -365,7 +366,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
11 changes: 9 additions & 2 deletions lnd_test.go
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/chanbackup"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lnwire"
"golang.org/x/net/context"
Expand Down Expand Up @@ -8325,8 +8326,14 @@ out:
// failed payment.
shutdownAndAssert(net, t, carol)

// TODO(roasbeef): mission control
time.Sleep(time.Second * 5)
// Reset mission control to forget the temporary channel failure above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
_, err = net.Alice.RouterClient.ResetMissionControl(
ctxt, &routerrpc.ResetMissionControlRequest{},
)
if err != nil {
t.Fatalf("unable to reset mission control: %v", err)
}

sendReq = &lnrpc.SendRequest{
PaymentRequest: carolInvoice.PaymentRequest,
Expand Down
47 changes: 47 additions & 0 deletions lnrpc/routerrpc/config_active.go
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
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,
}
}

0 comments on commit f8eec09

Please sign in to comment.