routing: query bandwidth hints before each payment attempt

Previously the bandwidth hints were only queried once per payment. This
did not allow for concurrent payments changing channel balances.
This commit is contained in:
Joost Jager 2019-08-17 09:58:36 +02:00
parent 67e40d4433
commit e7a457f1ce
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
3 changed files with 27 additions and 15 deletions

@ -33,7 +33,7 @@ type PaymentSession interface {
type paymentSession struct {
additionalEdges map[route.Vertex][]*channeldb.ChannelEdgePolicy
bandwidthHints map[uint64]lnwire.MilliSatoshi
getBandwidthHints func() (map[uint64]lnwire.MilliSatoshi, error)
sessionSource *SessionSource
@ -97,11 +97,22 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment,
CltvLimit: cltvLimit,
}
// We'll also obtain a set of bandwidthHints from the lower layer for
// each of our outbound channels. This will allow the path finding to
// skip any links that aren't active or just don't have enough bandwidth
// to carry the payment. New bandwidth hints are queried for every new
// path finding attempt, because concurrent payments may change
// balances.
bandwidthHints, err := p.getBandwidthHints()
if err != nil {
return nil, err
}
path, err := p.pathFinder(
&graphParams{
graph: ss.Graph,
additionalEdges: p.additionalEdges,
bandwidthHints: p.bandwidthHints,
bandwidthHints: bandwidthHints,
},
restrictions, &ss.PathFindingConfig,
ss.SelfNode.PubKeyBytes, payment.Target,

@ -97,24 +97,20 @@ func (m *SessionSource) NewPaymentSession(routeHints [][]zpay32.HopHint,
}
}
// We'll also obtain a set of bandwidthHints from the lower layer for
// each of our outbound channels. This will allow the path finding to
// skip any links that aren't active or just don't have enough
// bandwidth to carry the payment.
sourceNode, err := m.Graph.SourceNode()
if err != nil {
return nil, err
}
bandwidthHints, err := generateBandwidthHints(
sourceNode, m.QueryBandwidth,
)
if err != nil {
return nil, err
getBandwidthHints := func() (map[uint64]lnwire.MilliSatoshi,
error) {
return generateBandwidthHints(sourceNode, m.QueryBandwidth)
}
return &paymentSession{
additionalEdges: edges,
bandwidthHints: bandwidthHints,
getBandwidthHints: getBandwidthHints,
sessionSource: m,
pathFinder: findPath,
}, nil

@ -41,6 +41,11 @@ func TestRequestRoute(t *testing.T) {
}
session := &paymentSession{
getBandwidthHints: func() (map[uint64]lnwire.MilliSatoshi,
error) {
return nil, nil
},
sessionSource: sessionSource,
pathFinder: findPath,
}