channeldb: add new payment status StatusInitiated

This commit adds a new payment status, `StatusInitiated`, to properly
represent the state where a payment is newly created without attempting
any HTLCs. Since the `PaymentStatus` is a memory representation of a
given payment's status, the enum used for the statuses are directly
updated.
This commit is contained in:
yyforyongyu authored and Olaoluwa Osuntokun committed 2023-10-06 16:34:47 -07:00
1 parent 6be3817eed
commit 30fd29371c
4 files changed
+35 -8

No files matched your search

+13 -1
View File
@@ -26,6 +26,10 @@ var (
// already "in flight" on the network.
ErrPaymentInFlight = errors.New("payment is in transition")
// ErrPaymentExists is returned when we try to initialize an already
// existing payment that is not failed.
ErrPaymentExists = errors.New("payment already exists")
// ErrPaymentNotInitiated is returned if the payment wasn't initiated.
ErrPaymentNotInitiated = errors.New("payment isn't initiated")
@@ -148,10 +152,15 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
// retrying the payment or return a specific error.
case err == nil:
switch paymentStatus {
// We allow retrying failed payments.
case StatusFailed:
// We already have payment creation info for this
// payment so we won't allow creating a duplicate one.
case StatusInitiated:
updateErr = ErrPaymentExists
return nil
// We already have an InFlight payment on the network.
// We will disallow any new payments.
case StatusInFlight:
@@ -727,6 +736,9 @@ func ensureInFlight(payment *MPPayment) error {
paymentStatus := payment.Status
switch {
// Newly created payment is also inflight.
case paymentStatus == StatusInitiated:
return nil
// The payment was indeed InFlight.
case paymentStatus == StatusInFlight:
+10 -3
View File
@@ -7,22 +7,29 @@ const (
// NOTE: PaymentStatus = 0 was previously used for status unknown and
// is now deprecated.
// StatusInitiated is the status where a payment has just been
// initiated.
StatusInitiated PaymentStatus = 1
// StatusInFlight is the status where a payment has been initiated, but
// a response has not been received.
StatusInFlight PaymentStatus = 1
StatusInFlight PaymentStatus = 2
// StatusSucceeded is the status where a payment has been initiated and
// the payment was completed successfully.
StatusSucceeded PaymentStatus = 2
StatusSucceeded PaymentStatus = 3
// StatusFailed is the status where a payment has been initiated and a
// failure result has come back.
StatusFailed PaymentStatus = 3
StatusFailed PaymentStatus = 4
)
// String returns readable representation of payment status.
func (ps PaymentStatus) String() string {
switch ps {
case StatusInitiated:
return "Initiated"
case StatusInFlight:
return "In Flight"