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:
1 parent
fac6044501
commit
c175386c4d
4 files changed
+26
-19
No files matched your search
@@ -177,6 +177,13 @@ type MPPayment struct {
|
||||
Status PaymentStatus
|
||||
}
|
||||
|
||||
// Terminated returns a bool to specify whether the payment is in a terminal
|
||||
// state.
|
||||
func (m *MPPayment) Terminated() bool {
|
||||
// If the payment is in terminal state, it cannot be updated.
|
||||
return m.Status.updatable() != nil
|
||||
}
|
||||
|
||||
// TerminalInfo returns any HTLC settle info recorded. If no settle info is
|
||||
// recorded, any payment level failure will be returned. If neither a settle
|
||||
// nor a failure is recorded, both return values will be nil.
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user