channeldb+routing: apply method Terminated to decide a payment's terminal state

This commit applies the new method `Terminated`. A side effect from
using this method is, we can now save one query `fetchPayment` inside
`FetchInFlightPayments`.
This commit is contained in:
yyforyongyu
2022-11-17 10:28:22 +08:00
committed by Olaoluwa Osuntokun
parent fac6044501
commit c175386c4d
4 changed files with 26 additions and 19 deletions

View File

@@ -722,21 +722,16 @@ func (p *PaymentControl) FetchInFlightPayments() ([]*MPPayment, error) {
return fmt.Errorf("non bucket element")
}
// If the status is not InFlight, we can return early.
paymentStatus, err := fetchPaymentStatus(bucket)
if err != nil {
return err
}
if paymentStatus != StatusInFlight {
return nil
}
p, err := fetchPayment(bucket)
if err != nil {
return err
}
// Skip the payment if it's terminated.
if p.Terminated() {
return nil
}
inFlights = append(inFlights, p)
return nil
})