routing/payment_session: make NewPaymentSession take payment directly

This commit moves supplying of the information in the LightningPayment
to the initialization of the paymentSession, away from every call to
RequestRoute.

Instead the paymentSession will store this information internally, as it
doesn't change between payment attempts.

This is done to rid the RequestRoute call of the LightingPayment
argument, as for SendToRoute calls, it is not needed to supply the next
route.
This commit is contained in:
Johan T. Halseth
2020-04-01 00:13:22 +02:00
parent 77df8e3a43
commit c2301c14b2
6 changed files with 54 additions and 61 deletions

View File

@ -29,15 +29,14 @@ func (e errNoRoute) Error() string {
// paymentLifecycle holds all information about the current state of a payment
// needed to resume if from any point.
type paymentLifecycle struct {
router *ChannelRouter
payment *LightningPayment
paySession PaymentSession
timeoutChan <-chan time.Time
currentHeight int32
finalCLTVDelta uint16
attempt *channeldb.HTLCAttemptInfo
circuit *sphinx.Circuit
lastError error
router *ChannelRouter
payment *LightningPayment
paySession PaymentSession
timeoutChan <-chan time.Time
currentHeight int32
attempt *channeldb.HTLCAttemptInfo
circuit *sphinx.Circuit
lastError error
}
// resumePayment resumes the paymentLifecycle from the current state.
@ -267,9 +266,7 @@ func (p *paymentLifecycle) createNewPaymentAttempt() (lnwire.ShortChannelID,
}
// Create a new payment attempt from the given payment session.
rt, err := p.paySession.RequestRoute(
p.payment, uint32(p.currentHeight), p.finalCLTVDelta,
)
rt, err := p.paySession.RequestRoute(uint32(p.currentHeight))
if err != nil {
log.Warnf("Failed to find route for payment %x: %v",
p.payment.PaymentHash, err)