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:
parent
67e40d4433
commit
e7a457f1ce
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user