routing/payment_session: remove prebuilt payment session

Since we no longer use payment sessions for send to route, we remove the
prebuilt one.
This commit is contained in:
Johan T. Halseth 2020-04-01 00:13:25 +02:00
parent 4509c4f3a9
commit 49efbefb43
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
4 changed files with 9 additions and 35 deletions

@ -391,7 +391,7 @@ func errorToPaymentFailure(err error) channeldb.FailureReason {
errNoTlvPayload, errNoTlvPayload,
errNoPaymentAddr, errNoPaymentAddr,
errNoPathFound, errNoPathFound,
errPrebuiltRouteTried: errEmptyPaySession:
return channeldb.FailureReasonNoRoute return channeldb.FailureReasonNoRoute

@ -13,9 +13,9 @@ import (
const BlockPadding uint16 = 3 const BlockPadding uint16 = 3
var ( var (
// errPrebuiltRouteTried is returned when the single pre-built route // errEmptyPaySession is returned when the empty payment session is
// failed and there is nothing more we can do. // queried for a route.
errPrebuiltRouteTried = errors.New("pre-built route already tried") errEmptyPaySession = errors.New("empty payment session")
) )
// PaymentSession is used during SendPayment attempts to provide routes to // PaymentSession is used during SendPayment attempts to provide routes to
@ -50,8 +50,7 @@ type paymentSession struct {
payment *LightningPayment payment *LightningPayment
preBuiltRoute *route.Route empty bool
preBuiltRouteTried bool
pathFinder pathFinder pathFinder pathFinder
} }
@ -68,18 +67,8 @@ type paymentSession struct {
func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi, func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
activeShards, height uint32) (*route.Route, error) { activeShards, height uint32) (*route.Route, error) {
switch { if p.empty {
return nil, errEmptyPaySession
// If we have a pre-built route, use that directly.
case p.preBuiltRoute != nil && !p.preBuiltRouteTried:
p.preBuiltRouteTried = true
return p.preBuiltRoute, nil
// If the pre-built route has been tried already, the payment session is
// over.
case p.preBuiltRoute != nil:
return nil, errPrebuiltRouteTried
} }
// Add BlockPadding to the finalCltvDelta so that the receiving node // Add BlockPadding to the finalCltvDelta so that the receiving node

@ -75,23 +75,13 @@ func (m *SessionSource) NewPaymentSession(p *LightningPayment) (
}, nil }, nil
} }
// NewPaymentSessionForRoute creates a new paymentSession instance that is just
// used for failure reporting to missioncontrol.
func (m *SessionSource) NewPaymentSessionForRoute(preBuiltRoute *route.Route) PaymentSession {
return &paymentSession{
sessionSource: m,
preBuiltRoute: preBuiltRoute,
}
}
// NewPaymentSessionEmpty creates a new paymentSession instance that is empty, // NewPaymentSessionEmpty creates a new paymentSession instance that is empty,
// and will be exhausted immediately. Used for failure reporting to // and will be exhausted immediately. Used for failure reporting to
// missioncontrol for resumed payment we don't want to make more attempts for. // missioncontrol for resumed payment we don't want to make more attempts for.
func (m *SessionSource) NewPaymentSessionEmpty() PaymentSession { func (m *SessionSource) NewPaymentSessionEmpty() PaymentSession {
return &paymentSession{ return &paymentSession{
sessionSource: m, sessionSource: m,
preBuiltRoute: &route.Route{}, empty: true,
preBuiltRouteTried: true,
} }
} }

@ -161,11 +161,6 @@ type PaymentSessionSource interface {
// finding a path to the payment's destination. // finding a path to the payment's destination.
NewPaymentSession(p *LightningPayment) (PaymentSession, error) NewPaymentSession(p *LightningPayment) (PaymentSession, error)
// NewPaymentSessionForRoute creates a new paymentSession instance that
// is just used for failure reporting to missioncontrol, and will only
// attempt the given route.
NewPaymentSessionForRoute(preBuiltRoute *route.Route) PaymentSession
// NewPaymentSessionEmpty creates a new paymentSession instance that is // NewPaymentSessionEmpty creates a new paymentSession instance that is
// empty, and will be exhausted immediately. Used for failure reporting // empty, and will be exhausted immediately. Used for failure reporting
// to missioncontrol for resumed payment we don't want to make more // to missioncontrol for resumed payment we don't want to make more