mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-15 07:32:39 +02:00
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:
committed by
Olaoluwa Osuntokun
parent
a6f4f0dfc9
commit
105c275b91
@ -451,7 +451,7 @@ func (p *PaymentControl) updateHtlcKey(paymentHash lntypes.Hash,
|
|||||||
// We can only update keys of in-flight payments. We allow
|
// We can only update keys of in-flight payments. We allow
|
||||||
// updating keys even if the payment has reached a terminal
|
// updating keys even if the payment has reached a terminal
|
||||||
// condition, since the HTLC outcomes must still be updated.
|
// condition, since the HTLC outcomes must still be updated.
|
||||||
if err := ensureInFlight(p); err != nil {
|
if err := p.Status.updatable(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,3 +103,27 @@ func (ps PaymentStatus) removable() error {
|
|||||||
return fmt.Errorf("%w: %v", ErrUnknownPaymentStatus, ps)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user