channeldb: return error when payment is not found in duplicate payments

We also update the legacy code to return an error when the payment is
not found.
This commit is contained in:
yyforyongyu authored and Olaoluwa Osuntokun committed 2023-10-06 16:34:47 -07:00
1 parent b7d1c6666f
commit 21cecc40e1
1 file changed
+11 -8
+11 -8
View File
@@ -59,22 +59,22 @@ type duplicateHTLCAttemptInfo struct {
route route.Route route route.Route
} }
// fetchDuplicatePaymentStatus fetches the payment status of the payment. If the // fetchDuplicatePaymentStatus fetches the payment status of the payment. If
// payment isn't found, it will default to "StatusUnknown". // the payment isn't found, it will return error `ErrPaymentNotInitiated`.
func fetchDuplicatePaymentStatus(bucket kvdb.RBucket) PaymentStatus { func fetchDuplicatePaymentStatus(bucket kvdb.RBucket) (PaymentStatus, error) {
if bucket.Get(duplicatePaymentSettleInfoKey) != nil { if bucket.Get(duplicatePaymentSettleInfoKey) != nil {
return StatusSucceeded return StatusSucceeded, nil
} }
if bucket.Get(duplicatePaymentFailInfoKey) != nil { if bucket.Get(duplicatePaymentFailInfoKey) != nil {
return StatusFailed return StatusFailed, nil
} }
if bucket.Get(duplicatePaymentCreationInfoKey) != nil { if bucket.Get(duplicatePaymentCreationInfoKey) != nil {
return StatusInFlight return StatusInFlight, nil
} }
return StatusUnknown return 0, ErrPaymentNotInitiated
} }
func deserializeDuplicateHTLCAttemptInfo(r io.Reader) ( func deserializeDuplicateHTLCAttemptInfo(r io.Reader) (
@@ -138,7 +138,10 @@ func fetchDuplicatePayment(bucket kvdb.RBucket) (*MPPayment, error) {
sequenceNum := binary.BigEndian.Uint64(seqBytes) sequenceNum := binary.BigEndian.Uint64(seqBytes)
// Get the payment status. // Get the payment status.
paymentStatus := fetchDuplicatePaymentStatus(bucket) paymentStatus, err := fetchDuplicatePaymentStatus(bucket)
if err != nil {
return nil, err
}
// Get the PaymentCreationInfo. // Get the PaymentCreationInfo.
b := bucket.Get(duplicatePaymentCreationInfoKey) b := bucket.Get(duplicatePaymentCreationInfoKey)