diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index b2ea102d..f1f28dc4 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -420,12 +420,11 @@ func (m *MissionControl) GetHistorySnapshot() *MissionControlSnapshot { // ReportPaymentFail reports a failed payment to mission control as input for // future probability estimates. The failureSourceIdx argument indicates the // failure source. If it is nil, the failure source is unknown. This function -// returns a bool indicating whether this error is a final error. If it is -// final, a failure reason is returned and no further payment attempts need to -// be made. +// returns a reason if this failure is a final failure. In that case no further +// payment attempts need to be made. func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route, - failureSourceIdx *int, failure lnwire.FailureMessage) (bool, - channeldb.FailureReason, error) { + failureSourceIdx *int, failure lnwire.FailureMessage) ( + *channeldb.FailureReason, error) { timestamp := m.now() @@ -442,13 +441,18 @@ func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route, // Store complete result in database. if err := m.store.AddResult(result); err != nil { - return false, 0, err + return nil, err } // Apply result to update mission control state. final, reason := m.applyPaymentResult(result) - return final, reason, nil + // Convert final bool and reason to nillable reason. + if final { + return &reason, nil + } + + return nil, nil } // applyPaymentResult applies a payment result as input for future probability diff --git a/routing/mock_test.go b/routing/mock_test.go index b58ba3d5..96da1448 100644 --- a/routing/mock_test.go +++ b/routing/mock_test.go @@ -98,11 +98,11 @@ type mockMissionControl struct { var _ MissionController = (*mockMissionControl)(nil) -func (m *mockMissionControl) ReportPaymentFail(paymentID uint64, - rt *route.Route, failureSourceIdx *int, failure lnwire.FailureMessage) ( - bool, channeldb.FailureReason, error) { +func (m *mockMissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route, + failureSourceIdx *int, failure lnwire.FailureMessage) ( + *channeldb.FailureReason, error) { - return false, 0, nil + return nil, nil } func (m *mockMissionControl) GetProbability(fromNode, toNode route.Vertex, diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index db9b9803..18edfc0a 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -342,10 +342,10 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID, // whether we should make another payment attempt. func (p *paymentLifecycle) handleSendError(sendErr error) error { - final, reason := p.router.processSendError( + reason := p.router.processSendError( p.attempt.PaymentID, &p.attempt.Route, sendErr, ) - if !final { + if reason == nil { // Save the forwarding error so it can be returned if // this turns out to be the last attempt. p.lastError = sendErr @@ -354,14 +354,14 @@ func (p *paymentLifecycle) handleSendError(sendErr error) error { } log.Debugf("Payment %x failed: final_outcome=%v, raw_err=%v", - p.payment.PaymentHash, reason, sendErr) + p.payment.PaymentHash, *reason, sendErr) // Mark the payment failed with no route. // // TODO(halseth): make payment codes for the actual reason we don't // continue path finding. err := p.router.cfg.Control.Fail( - p.payment.PaymentHash, reason, + p.payment.PaymentHash, *reason, ) if err != nil { return err diff --git a/routing/router.go b/routing/router.go index 6a8c0308..65b28f51 100644 --- a/routing/router.go +++ b/routing/router.go @@ -179,8 +179,8 @@ type MissionController interface { // whether this error is a final error and no further payment attempts // need to be made. ReportPaymentFail(paymentID uint64, rt *route.Route, - failureSourceIdx *int, failure lnwire.FailureMessage) (bool, - channeldb.FailureReason, error) + failureSourceIdx *int, failure lnwire.FailureMessage) ( + *channeldb.FailureReason, error) // GetProbability is expected to return the success probability of a // payment from fromNode along edge. @@ -1887,23 +1887,25 @@ func (r *ChannelRouter) tryApplyChannelUpdate(rt *route.Route, // to continue with an alternative route. This is indicated by the boolean // return value. func (r *ChannelRouter) processSendError(paymentID uint64, rt *route.Route, - sendErr error) (bool, channeldb.FailureReason) { + sendErr error) *channeldb.FailureReason { - reportFail := func(srcIdx *int, msg lnwire.FailureMessage) (bool, - channeldb.FailureReason) { + internalErrorReason := channeldb.FailureReasonError + + reportFail := func(srcIdx *int, + msg lnwire.FailureMessage) *channeldb.FailureReason { // Report outcome to mission control. - final, reason, err := r.cfg.MissionControl.ReportPaymentFail( + reason, err := r.cfg.MissionControl.ReportPaymentFail( paymentID, rt, srcIdx, msg, ) if err != nil { log.Errorf("Error reporting payment result to mc: %v", err) - return true, channeldb.FailureReasonError + return &internalErrorReason } - return final, reason + return reason } if sendErr == htlcswitch.ErrUnreadableFailureMessage { @@ -1915,7 +1917,7 @@ func (r *ChannelRouter) processSendError(paymentID uint64, rt *route.Route, // trying. fErr, ok := sendErr.(*htlcswitch.ForwardingError) if !ok { - return true, channeldb.FailureReasonError + return &internalErrorReason } failureMessage := fErr.FailureMessage @@ -1928,7 +1930,7 @@ func (r *ChannelRouter) processSendError(paymentID uint64, rt *route.Route, rt, failureSourceIdx, failureMessage, ) if err != nil { - return true, channeldb.FailureReasonError + return &internalErrorReason } }