mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
multi: move DBMPPayment to paymentsdb package
This commit is contained in:
@@ -89,3 +89,35 @@ type PaymentControl interface {
|
||||
// completed, and the payment has reached a final terminal state.
|
||||
DeleteFailedAttempts(lntypes.Hash) error
|
||||
}
|
||||
|
||||
// DBMPPayment is an interface that represents the payment state during a
|
||||
// payment lifecycle.
|
||||
type DBMPPayment interface {
|
||||
// GetState returns the current state of the payment.
|
||||
GetState() *MPPaymentState
|
||||
|
||||
// Terminated returns true if the payment is in a final state.
|
||||
Terminated() bool
|
||||
|
||||
// GetStatus returns the current status of the payment.
|
||||
GetStatus() PaymentStatus
|
||||
|
||||
// NeedWaitAttempts specifies whether the payment needs to wait for the
|
||||
// outcome of an attempt.
|
||||
NeedWaitAttempts() (bool, error)
|
||||
|
||||
// GetHTLCs returns all HTLCs of this payment.
|
||||
GetHTLCs() []HTLCAttempt
|
||||
|
||||
// InFlightHTLCs returns all HTLCs that are in flight.
|
||||
InFlightHTLCs() []HTLCAttempt
|
||||
|
||||
// AllowMoreAttempts is used to decide whether we can safely attempt
|
||||
// more HTLCs for a given payment state. Return an error if the payment
|
||||
// is in an unexpected state.
|
||||
AllowMoreAttempts() (bool, error)
|
||||
|
||||
// TerminalInfo returns the settled HTLC attempt or the payment's
|
||||
// failure reason.
|
||||
TerminalInfo() (*HTLCAttempt, *FailureReason)
|
||||
}
|
||||
|
||||
@@ -9,38 +9,6 @@ import (
|
||||
"github.com/lightningnetwork/lnd/queue"
|
||||
)
|
||||
|
||||
// DBMPPayment is an interface derived from channeldb.MPPayment that is used by
|
||||
// the payment lifecycle.
|
||||
type DBMPPayment interface {
|
||||
// GetState returns the current state of the payment.
|
||||
GetState() *paymentsdb.MPPaymentState
|
||||
|
||||
// Terminated returns true if the payment is in a final state.
|
||||
Terminated() bool
|
||||
|
||||
// GetStatus returns the current status of the payment.
|
||||
GetStatus() paymentsdb.PaymentStatus
|
||||
|
||||
// NeedWaitAttempts specifies whether the payment needs to wait for the
|
||||
// outcome of an attempt.
|
||||
NeedWaitAttempts() (bool, error)
|
||||
|
||||
// GetHTLCs returns all HTLCs of this payment.
|
||||
GetHTLCs() []paymentsdb.HTLCAttempt
|
||||
|
||||
// InFlightHTLCs returns all HTLCs that are in flight.
|
||||
InFlightHTLCs() []paymentsdb.HTLCAttempt
|
||||
|
||||
// AllowMoreAttempts is used to decide whether we can safely attempt
|
||||
// more HTLCs for a given payment state. Return an error if the payment
|
||||
// is in an unexpected state.
|
||||
AllowMoreAttempts() (bool, error)
|
||||
|
||||
// TerminalInfo returns the settled HTLC attempt or the payment's
|
||||
// failure reason.
|
||||
TerminalInfo() (*paymentsdb.HTLCAttempt, *paymentsdb.FailureReason)
|
||||
}
|
||||
|
||||
// ControlTower tracks all outgoing payments made, whose primary purpose is to
|
||||
// prevent duplicate payments to the same payment hash. In production, a
|
||||
// persistent implementation is preferred so that tracking can survive across
|
||||
@@ -76,7 +44,7 @@ type ControlTower interface {
|
||||
|
||||
// FetchPayment fetches the payment corresponding to the given payment
|
||||
// hash.
|
||||
FetchPayment(paymentHash lntypes.Hash) (DBMPPayment, error)
|
||||
FetchPayment(paymentHash lntypes.Hash) (paymentsdb.DBMPPayment, error)
|
||||
|
||||
// FailPayment transitions a payment into the Failed state, and records
|
||||
// the ultimate reason the payment failed. Note that this should only
|
||||
@@ -273,7 +241,7 @@ func (p *controlTower) FailAttempt(paymentHash lntypes.Hash,
|
||||
|
||||
// FetchPayment fetches the payment corresponding to the given payment hash.
|
||||
func (p *controlTower) FetchPayment(paymentHash lntypes.Hash) (
|
||||
DBMPPayment, error) {
|
||||
paymentsdb.DBMPPayment, error) {
|
||||
|
||||
return p.db.FetchPayment(paymentHash)
|
||||
}
|
||||
|
||||
@@ -510,7 +510,7 @@ func (m *mockControlTowerOld) FailPayment(phash lntypes.Hash,
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) FetchPayment(phash lntypes.Hash) (
|
||||
DBMPPayment, error) {
|
||||
paymentsdb.DBMPPayment, error) {
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
@@ -787,7 +787,7 @@ func (m *mockControlTower) FailPayment(phash lntypes.Hash,
|
||||
}
|
||||
|
||||
func (m *mockControlTower) FetchPayment(phash lntypes.Hash) (
|
||||
DBMPPayment, error) {
|
||||
paymentsdb.DBMPPayment, error) {
|
||||
|
||||
args := m.Called(phash)
|
||||
|
||||
@@ -825,7 +825,7 @@ type mockMPPayment struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
var _ DBMPPayment = (*mockMPPayment)(nil)
|
||||
var _ paymentsdb.DBMPPayment = (*mockMPPayment)(nil)
|
||||
|
||||
func (m *mockMPPayment) GetState() *paymentsdb.MPPaymentState {
|
||||
args := m.Called()
|
||||
|
||||
@@ -130,7 +130,7 @@ const (
|
||||
// wait for results, the method will exit with `stepExit` such that the payment
|
||||
// lifecycle loop will terminate.
|
||||
func (p *paymentLifecycle) decideNextStep(
|
||||
payment DBMPPayment) (stateStep, error) {
|
||||
payment paymentsdb.DBMPPayment) (stateStep, error) {
|
||||
|
||||
// Check whether we could make new HTLC attempts.
|
||||
allow, err := payment.AllowMoreAttempts()
|
||||
@@ -1110,7 +1110,9 @@ func (p *paymentLifecycle) patchLegacyPaymentHash(
|
||||
// reloadInflightAttempts is called when the payment lifecycle is resumed after
|
||||
// a restart. It reloads all inflight attempts from the control tower and
|
||||
// collects the results of the attempts that have been sent before.
|
||||
func (p *paymentLifecycle) reloadInflightAttempts() (DBMPPayment, error) {
|
||||
func (p *paymentLifecycle) reloadInflightAttempts() (paymentsdb.DBMPPayment,
|
||||
error) {
|
||||
|
||||
payment, err := p.router.cfg.Control.FetchPayment(p.identifier)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1133,7 +1135,7 @@ func (p *paymentLifecycle) reloadInflightAttempts() (DBMPPayment, error) {
|
||||
}
|
||||
|
||||
// reloadPayment returns the latest payment found in the db (control tower).
|
||||
func (p *paymentLifecycle) reloadPayment() (DBMPPayment,
|
||||
func (p *paymentLifecycle) reloadPayment() (paymentsdb.DBMPPayment,
|
||||
*paymentsdb.MPPaymentState, error) {
|
||||
|
||||
// Read the db to get the latest state of the payment.
|
||||
|
||||
Reference in New Issue
Block a user