channeldb: add method updatable to decide updating payments

This commit adds a new method, `updatable`, to help decide whether
updating a given payment is allowed.
This commit is contained in:
yyforyongyu authored and Olaoluwa Osuntokun committed 2023-10-06 16:34:47 -07:00
1 parent a6f4f0dfc9
commit 105c275b91
2 files changed
+25 -1

No files matched your search

+1 -1
View File
@@ -451,7 +451,7 @@ func (p *PaymentControl) updateHtlcKey(paymentHash lntypes.Hash,
// We can only update keys of in-flight payments. We allow
// updating keys even if the payment has reached a terminal
// condition, since the HTLC outcomes must still be updated.
if err := ensureInFlight(p); err != nil {
if err := p.Status.updatable(); err != nil {
return err
}
+24
View File
@@ -103,3 +103,27 @@ func (ps PaymentStatus) removable() error {
return fmt.Errorf("%w: %v", ErrUnknownPaymentStatus, ps)
}
}
// updatable returns an error to specify whether the payment's HTLCs can be
// updated. A payment can update its HTLCs when it has inflight HTLCs.
func (ps PaymentStatus) updatable() error {
switch ps {
// Newly created payments can be updated.
case StatusInitiated:
return nil
// Inflight payments can be updated.
case StatusInFlight:
return nil
// If the payment has a terminal condition, we won't allow any updates.
case StatusSucceeded:
return ErrPaymentAlreadySucceeded
case StatusFailed:
return ErrPaymentAlreadyFailed
default:
return fmt.Errorf("%w: %v", ErrUnknownPaymentStatus, ps)
}
}