Skip to content

Commit

Permalink
Merge pull request #3462 from joostjager/mc-extrapolate
Browse files Browse the repository at this point in the history
routing+routerrpc: improve prob. estimation for untried connections
  • Loading branch information
Roasbeef authored Oct 23, 2019
2 parents 254de64 + 1fac41d commit 8ed7583
Show file tree
Hide file tree
Showing 15 changed files with 630 additions and 425 deletions.
20 changes: 0 additions & 20 deletions cmd/lncli/cmd_query_mission_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,17 @@ func queryMissionControl(ctx *cli.Context) error {
return err
}

type displayNodeHistory struct {
Pubkey string
LastFailTime int64
OtherSuccessProb float32
}

type displayPairHistory struct {
NodeFrom, NodeTo string
LastAttemptSuccessful bool
Timestamp int64
SuccessProb float32
MinPenalizeAmtSat int64
}

displayResp := struct {
Nodes []displayNodeHistory
Pairs []displayPairHistory
}{}

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

for _, n := range snapshot.Pairs {
displayResp.Pairs = append(
displayResp.Pairs,
Expand All @@ -69,7 +50,6 @@ func queryMissionControl(ctx *cli.Context) error {
NodeTo: hex.EncodeToString(n.NodeTo),
LastAttemptSuccessful: n.LastAttemptSuccessful,
Timestamp: n.Timestamp,
SuccessProb: n.SuccessProb,
MinPenalizeAmtSat: n.MinPenalizeAmtSat,
},
)
Expand Down
9 changes: 9 additions & 0 deletions lnrpc/routerrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ type RoutingConfig struct {
// 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."`

// AprioriWeight is a value in the range [0, 1] that defines to what
// extent historical results should be extrapolated to untried
// connections. Setting it to one will completely ignore historical
// results and always assume the configured a priori probability for
// untried connections. A value of zero will ignore the a priori
// probability completely and only base the probability on historical
// results, unless there are none available.
AprioriWeight float64 `long:"aprioriweight" description:"Weight of the a priori probability in success probability estimation. Valid values are in [0, 1]."`

// 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"`
Expand Down
2 changes: 2 additions & 0 deletions lnrpc/routerrpc/config_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Config struct {
func DefaultConfig() *Config {
defaultRoutingConfig := RoutingConfig{
AprioriHopProbability: routing.DefaultAprioriHopProbability,
AprioriWeight: routing.DefaultAprioriWeight,
MinRouteProbability: routing.DefaultMinRouteProbability,
PenaltyHalfLife: routing.DefaultPenaltyHalfLife,
AttemptCost: routing.DefaultPaymentAttemptPenalty.
Expand All @@ -61,6 +62,7 @@ func DefaultConfig() *Config {
func GetRoutingConfig(cfg *Config) *RoutingConfig {
return &RoutingConfig{
AprioriHopProbability: cfg.AprioriHopProbability,
AprioriWeight: cfg.AprioriWeight,
MinRouteProbability: cfg.MinRouteProbability,
AttemptCost: cfg.AttemptCost,
PenaltyHalfLife: cfg.PenaltyHalfLife,
Expand Down
1 change: 1 addition & 0 deletions lnrpc/routerrpc/config_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func DefaultConfig() *Config {
func GetRoutingConfig(cfg *Config) *RoutingConfig {
return &RoutingConfig{
AprioriHopProbability: routing.DefaultAprioriHopProbability,
AprioriWeight: routing.DefaultAprioriWeight,
MinRouteProbability: routing.DefaultMinRouteProbability,
AttemptCost: routing.DefaultPaymentAttemptPenalty.
ToSatoshis(),
Expand Down
319 changes: 117 additions & 202 deletions lnrpc/routerrpc/router.pb.go

Large diffs are not rendered by default.

23 changes: 2 additions & 21 deletions lnrpc/routerrpc/router.proto
Original file line number Diff line number Diff line change
Expand Up @@ -337,30 +337,12 @@ message QueryMissionControlRequest {}

/// QueryMissionControlResponse contains mission control state.
message QueryMissionControlResponse {
/// Node-level mission control state.
repeated NodeHistory nodes = 1 [json_name = "nodes"];
reserved 1;

/// Node pair-level mission control state.
repeated PairHistory pairs = 2 [json_name = "pairs"];
}

/// NodeHistory contains the mission control state for a particular node.
message NodeHistory {
/// Node pubkey
bytes pubkey = 1 [json_name = "pubkey"];

/// Time stamp of last failure. Set to zero if no failure happened yet.
int64 last_fail_time = 2 [json_name = "last_fail_time"];

/**
Estimation of success probability of forwarding towards peers of this node
for which no specific history is available.
**/
float other_success_prob = 3 [json_name = "other_success_prob"];

reserved 4;
}

/// PairHistory contains the mission control state for a particular node pair.
message PairHistory {
/// The source node pubkey of the pair.
Expand All @@ -375,8 +357,7 @@ message PairHistory {
/// Minimum penalization amount (only applies to failed attempts).
int64 min_penalize_amt_sat = 4 [json_name = "min_penalize_amt_sat"];

/// Estimation of success probability for this pair.
float success_prob = 5 [json_name = "success_prob"];
reserved 5;

/// Whether the last payment attempt through this pair was successful.
bool last_attempt_successful = 6 [json_name = "last_attempt_successful"];
Expand Down
18 changes: 0 additions & 18 deletions lnrpc/routerrpc/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,6 @@ func (s *Server) QueryMissionControl(ctx context.Context,

snapshot := s.cfg.RouterBackend.MissionControl.GetHistorySnapshot()

rpcNodes := make([]*NodeHistory, 0, len(snapshot.Nodes))
for _, n := range snapshot.Nodes {
// Copy node struct to prevent loop variable binding bugs.
node := n

rpcNode := NodeHistory{
Pubkey: node.Node[:],
LastFailTime: node.LastFail.Unix(),
OtherSuccessProb: float32(
node.OtherSuccessProb,
),
}

rpcNodes = append(rpcNodes, &rpcNode)
}

rpcPairs := make([]*PairHistory, 0, len(snapshot.Pairs))
for _, p := range snapshot.Pairs {
// Prevent binding to loop variable.
Expand All @@ -494,15 +478,13 @@ func (s *Server) QueryMissionControl(ctx context.Context,
MinPenalizeAmtSat: int64(
pair.MinPenalizeAmt.ToSatoshis(),
),
SuccessProb: float32(pair.SuccessProb),
LastAttemptSuccessful: pair.LastAttemptSuccessful,
}

rpcPairs = append(rpcPairs, &rpcPair)
}

response := QueryMissionControlResponse{
Nodes: rpcNodes,
Pairs: rpcPairs,
}

Expand Down
Loading

0 comments on commit 8ed7583

Please sign in to comment.