From 21cecc40e1139950697b455d56943c9914388e78 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 24 Nov 2022 12:31:31 +0800 Subject: [PATCH] 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. --- channeldb/duplicate_payments.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/channeldb/duplicate_payments.go b/channeldb/duplicate_payments.go index 2f6a0a278..cae3e956a 100644 --- a/channeldb/duplicate_payments.go +++ b/channeldb/duplicate_payments.go @@ -59,22 +59,22 @@ type duplicateHTLCAttemptInfo struct { route route.Route } -// fetchDuplicatePaymentStatus fetches the payment status of the payment. If the -// payment isn't found, it will default to "StatusUnknown". -func fetchDuplicatePaymentStatus(bucket kvdb.RBucket) PaymentStatus { +// fetchDuplicatePaymentStatus fetches the payment status of the payment. If +// the payment isn't found, it will return error `ErrPaymentNotInitiated`. +func fetchDuplicatePaymentStatus(bucket kvdb.RBucket) (PaymentStatus, error) { if bucket.Get(duplicatePaymentSettleInfoKey) != nil { - return StatusSucceeded + return StatusSucceeded, nil } if bucket.Get(duplicatePaymentFailInfoKey) != nil { - return StatusFailed + return StatusFailed, nil } if bucket.Get(duplicatePaymentCreationInfoKey) != nil { - return StatusInFlight + return StatusInFlight, nil } - return StatusUnknown + return 0, ErrPaymentNotInitiated } func deserializeDuplicateHTLCAttemptInfo(r io.Reader) ( @@ -138,7 +138,10 @@ func fetchDuplicatePayment(bucket kvdb.RBucket) (*MPPayment, error) { sequenceNum := binary.BigEndian.Uint64(seqBytes) // Get the payment status. - paymentStatus := fetchDuplicatePaymentStatus(bucket) + paymentStatus, err := fetchDuplicatePaymentStatus(bucket) + if err != nil { + return nil, err + } // Get the PaymentCreationInfo. b := bucket.Get(duplicatePaymentCreationInfoKey)