-
Notifications
You must be signed in to change notification settings - Fork 9
/
mission_ctl.go
61 lines (51 loc) · 1.44 KB
/
mission_ctl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"encoding/hex"
"fmt"
"math"
"github.com/lightningnetwork/lnd/lnrpc"
)
func (r *regolancer) addFailedChan(fromStr string, toStr string, amount int64) {
r.mcCache[fromStr+toStr] = amount
}
func (r *regolancer) validateRoute(route *lnrpc.Route) error {
prevHopPK := r.myPK
for _, h := range route.Hops {
hopPK := h.PubKey
if fp, ok := r.mcCache[prevHopPK+hopPK]; ok && absoluteDeltaPPM(fp, h.AmtToForwardMsat) < params.FailTolerance {
from, err := hex.DecodeString(prevHopPK)
if err != nil {
return err
}
to, err := hex.DecodeString(hopPK)
if err != nil {
return err
}
r.failedPairs = append(r.failedPairs, &lnrpc.NodePair{From: from, To: to})
return fmt.Errorf("chan %d failed before with %d msat and will not be used anymore during this rebalance, payment attempt with %d msat cancelled", h.ChanId, fp, h.AmtToForwardMsat)
}
prevHopPK = hopPK
}
return nil
}
func (r *regolancer) maxAmountOnRoute(ctx context.Context, route *lnrpc.Route) (uint64, error) {
var capAmountMsat uint64 = math.MaxInt64
for _, h := range route.Hops {
edge, err := r.getChanInfo(ctx, h.ChanId)
if err != nil {
return 0, err
}
policyTo := edge.Node1Policy
if h.PubKey != edge.Node2Pub {
policyTo = edge.Node2Policy
}
if policyTo.MaxHtlcMsat <= 0 {
continue
}
if capAmountMsat > policyTo.MaxHtlcMsat {
capAmountMsat = policyTo.MaxHtlcMsat
}
}
return capAmountMsat, nil
}