multi: move FailureReason to payment package
This commit is contained in:
19 files changed
+134
-140
No files matched your search
@@ -8,63 +8,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FailureReason encodes the reason a payment ultimately failed.
|
|
||||||
type FailureReason byte
|
|
||||||
|
|
||||||
const (
|
|
||||||
// FailureReasonTimeout indicates that the payment did timeout before a
|
|
||||||
// successful payment attempt was made.
|
|
||||||
FailureReasonTimeout FailureReason = 0
|
|
||||||
|
|
||||||
// FailureReasonNoRoute indicates no successful route to the
|
|
||||||
// destination was found during path finding.
|
|
||||||
FailureReasonNoRoute FailureReason = 1
|
|
||||||
|
|
||||||
// FailureReasonError indicates that an unexpected error happened during
|
|
||||||
// payment.
|
|
||||||
FailureReasonError FailureReason = 2
|
|
||||||
|
|
||||||
// FailureReasonPaymentDetails indicates that either the hash is unknown
|
|
||||||
// or the final cltv delta or amount is incorrect.
|
|
||||||
FailureReasonPaymentDetails FailureReason = 3
|
|
||||||
|
|
||||||
// FailureReasonInsufficientBalance indicates that we didn't have enough
|
|
||||||
// balance to complete the payment.
|
|
||||||
FailureReasonInsufficientBalance FailureReason = 4
|
|
||||||
|
|
||||||
// FailureReasonCanceled indicates that the payment was canceled by the
|
|
||||||
// user.
|
|
||||||
FailureReasonCanceled FailureReason = 5
|
|
||||||
|
|
||||||
// TODO(joostjager): Add failure reasons for:
|
|
||||||
// LocalLiquidityInsufficient, RemoteCapacityInsufficient.
|
|
||||||
)
|
|
||||||
|
|
||||||
// Error returns a human-readable error string for the FailureReason.
|
|
||||||
func (r FailureReason) Error() string {
|
|
||||||
return r.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns a human-readable FailureReason.
|
|
||||||
func (r FailureReason) String() string {
|
|
||||||
switch r {
|
|
||||||
case FailureReasonTimeout:
|
|
||||||
return "timeout"
|
|
||||||
case FailureReasonNoRoute:
|
|
||||||
return "no_route"
|
|
||||||
case FailureReasonError:
|
|
||||||
return "error"
|
|
||||||
case FailureReasonPaymentDetails:
|
|
||||||
return "incorrect_payment_details"
|
|
||||||
case FailureReasonInsufficientBalance:
|
|
||||||
return "insufficient_balance"
|
|
||||||
case FailureReasonCanceled:
|
|
||||||
return "canceled"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
// PaymentCreationInfo is the information necessary to have ready when
|
// PaymentCreationInfo is the information necessary to have ready when
|
||||||
// initiating a payment, moving it into state InFlight.
|
// initiating a payment, moving it into state InFlight.
|
||||||
type PaymentCreationInfo struct {
|
type PaymentCreationInfo struct {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/clock"
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
"github.com/lightningnetwork/lnd/feature"
|
"github.com/lightningnetwork/lnd/feature"
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
"github.com/lightningnetwork/lnd/fn/v2"
|
||||||
@@ -1843,7 +1842,7 @@ func convertPaymentStatus(dbStatus paymentsdb.PaymentStatus, useInit bool) (
|
|||||||
|
|
||||||
// marshallPaymentFailureReason marshalls the failure reason to the corresponding rpc
|
// marshallPaymentFailureReason marshalls the failure reason to the corresponding rpc
|
||||||
// type.
|
// type.
|
||||||
func marshallPaymentFailureReason(reason *channeldb.FailureReason) (
|
func marshallPaymentFailureReason(reason *paymentsdb.FailureReason) (
|
||||||
lnrpc.PaymentFailureReason, error) {
|
lnrpc.PaymentFailureReason, error) {
|
||||||
|
|
||||||
if reason == nil {
|
if reason == nil {
|
||||||
@@ -1851,22 +1850,22 @@ func marshallPaymentFailureReason(reason *channeldb.FailureReason) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch *reason {
|
switch *reason {
|
||||||
case channeldb.FailureReasonTimeout:
|
case paymentsdb.FailureReasonTimeout:
|
||||||
return lnrpc.PaymentFailureReason_FAILURE_REASON_TIMEOUT, nil
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_TIMEOUT, nil
|
||||||
|
|
||||||
case channeldb.FailureReasonNoRoute:
|
case paymentsdb.FailureReasonNoRoute:
|
||||||
return lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE, nil
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE, nil
|
||||||
|
|
||||||
case channeldb.FailureReasonError:
|
case paymentsdb.FailureReasonError:
|
||||||
return lnrpc.PaymentFailureReason_FAILURE_REASON_ERROR, nil
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_ERROR, nil
|
||||||
|
|
||||||
case channeldb.FailureReasonPaymentDetails:
|
case paymentsdb.FailureReasonPaymentDetails:
|
||||||
return lnrpc.PaymentFailureReason_FAILURE_REASON_INCORRECT_PAYMENT_DETAILS, nil
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_INCORRECT_PAYMENT_DETAILS, nil
|
||||||
|
|
||||||
case channeldb.FailureReasonInsufficientBalance:
|
case paymentsdb.FailureReasonInsufficientBalance:
|
||||||
return lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE, nil
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE, nil
|
||||||
|
|
||||||
case channeldb.FailureReasonCanceled:
|
case paymentsdb.FailureReasonCanceled:
|
||||||
return lnrpc.PaymentFailureReason_FAILURE_REASON_CANCELED, nil
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_CANCELED, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,10 +157,10 @@ func fetchDuplicatePayment(bucket kvdb.RBucket) (*MPPayment, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get failure reason if available.
|
// Get failure reason if available.
|
||||||
var failureReason *channeldb.FailureReason
|
var failureReason *FailureReason
|
||||||
b = bucket.Get(duplicatePaymentFailInfoKey)
|
b = bucket.Get(duplicatePaymentFailInfoKey)
|
||||||
if b != nil {
|
if b != nil {
|
||||||
reason := channeldb.FailureReason(b[0])
|
reason := FailureReason(b[0])
|
||||||
failureReason = &reason
|
failureReason = &reason
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -605,7 +605,7 @@ func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
|
|||||||
// its next call for this payment hash, allowing the switch to make a
|
// its next call for this payment hash, allowing the switch to make a
|
||||||
// subsequent payment.
|
// subsequent payment.
|
||||||
func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
|
func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
|
||||||
reason channeldb.FailureReason) (*MPPayment, error) {
|
reason FailureReason) (*MPPayment, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
updateErr error
|
updateErr error
|
||||||
@@ -979,10 +979,10 @@ func fetchPayment(bucket kvdb.RBucket) (*MPPayment, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get failure reason if available.
|
// Get failure reason if available.
|
||||||
var failureReason *channeldb.FailureReason
|
var failureReason *FailureReason
|
||||||
b := bucket.Get(paymentFailInfoKey)
|
b := bucket.Get(paymentFailInfoKey)
|
||||||
if b != nil {
|
if b != nil {
|
||||||
reason := channeldb.FailureReason(b[0])
|
reason := FailureReason(b[0])
|
||||||
failureReason = &reason
|
failureReason = &reason
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func TestKVPaymentsDBSwitchFail(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Fail the payment, which should moved it to Failed.
|
// Fail the payment, which should moved it to Failed.
|
||||||
failReason := channeldb.FailureReasonNoRoute
|
failReason := FailureReasonNoRoute
|
||||||
_, err = paymentDB.Fail(info.PaymentIdentifier, failReason)
|
_, err = paymentDB.Fail(info.PaymentIdentifier, failReason)
|
||||||
require.NoError(t, err, "unable to fail payment hash")
|
require.NoError(t, err, "unable to fail payment hash")
|
||||||
|
|
||||||
@@ -301,7 +301,7 @@ func TestKVPaymentsDBFailsWithoutInFlight(t *testing.T) {
|
|||||||
|
|
||||||
// Calling Fail should return an error.
|
// Calling Fail should return an error.
|
||||||
_, err = paymentDB.Fail(
|
_, err = paymentDB.Fail(
|
||||||
info.PaymentIdentifier, channeldb.FailureReasonNoRoute,
|
info.PaymentIdentifier, FailureReasonNoRoute,
|
||||||
)
|
)
|
||||||
require.ErrorIs(t, err, ErrPaymentNotInitiated)
|
require.ErrorIs(t, err, ErrPaymentNotInitiated)
|
||||||
}
|
}
|
||||||
@@ -383,7 +383,7 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fail the payment, which should moved it to Failed.
|
// Fail the payment, which should moved it to Failed.
|
||||||
failReason := channeldb.FailureReasonNoRoute
|
failReason := FailureReasonNoRoute
|
||||||
_, err = paymentDB.Fail(
|
_, err = paymentDB.Fail(
|
||||||
info.PaymentIdentifier, failReason,
|
info.PaymentIdentifier, failReason,
|
||||||
)
|
)
|
||||||
@@ -787,7 +787,7 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
HTLCAttemptInfo: a,
|
HTLCAttemptInfo: a,
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstFailReason *channeldb.FailureReason
|
var firstFailReason *FailureReason
|
||||||
if test.settleFirst {
|
if test.settleFirst {
|
||||||
_, err := paymentDB.SettleAttempt(
|
_, err := paymentDB.SettleAttempt(
|
||||||
info.PaymentIdentifier, a.AttemptID,
|
info.PaymentIdentifier, a.AttemptID,
|
||||||
@@ -827,7 +827,7 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
|
|
||||||
// We also record a payment level fail, to move it into
|
// We also record a payment level fail, to move it into
|
||||||
// a terminal state.
|
// a terminal state.
|
||||||
failReason := channeldb.FailureReasonNoRoute
|
failReason := FailureReasonNoRoute
|
||||||
_, err = paymentDB.Fail(
|
_, err = paymentDB.Fail(
|
||||||
info.PaymentIdentifier, failReason,
|
info.PaymentIdentifier, failReason,
|
||||||
)
|
)
|
||||||
@@ -910,7 +910,7 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
// failure. This is to allow multiple concurrent shard
|
// failure. This is to allow multiple concurrent shard
|
||||||
// write a terminal failure to the database without
|
// write a terminal failure to the database without
|
||||||
// syncing.
|
// syncing.
|
||||||
failReason := channeldb.FailureReasonPaymentDetails
|
failReason := FailureReasonPaymentDetails
|
||||||
_, err = paymentDB.Fail(
|
_, err = paymentDB.Fail(
|
||||||
info.PaymentIdentifier, failReason,
|
info.PaymentIdentifier, failReason,
|
||||||
)
|
)
|
||||||
@@ -1156,7 +1156,7 @@ type htlcStatus struct {
|
|||||||
// assertPaymentInfo retrieves the payment referred to by hash and verifies the
|
// assertPaymentInfo retrieves the payment referred to by hash and verifies the
|
||||||
// expected values.
|
// expected values.
|
||||||
func assertPaymentInfo(t *testing.T, p *KVPaymentsDB, hash lntypes.Hash,
|
func assertPaymentInfo(t *testing.T, p *KVPaymentsDB, hash lntypes.Hash,
|
||||||
c *channeldb.PaymentCreationInfo, f *channeldb.FailureReason,
|
c *channeldb.PaymentCreationInfo, f *FailureReason,
|
||||||
a *htlcStatus) {
|
a *htlcStatus) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -1339,7 +1339,7 @@ func createTestPayments(t *testing.T, p *KVPaymentsDB, payments []*payment) {
|
|||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to fail htlc")
|
require.NoError(t, err, "unable to fail htlc")
|
||||||
|
|
||||||
failReason := channeldb.FailureReasonNoRoute
|
failReason := FailureReasonNoRoute
|
||||||
_, err = p.Fail(info.PaymentIdentifier,
|
_, err = p.Fail(info.PaymentIdentifier,
|
||||||
failReason)
|
failReason)
|
||||||
require.NoError(t, err, "unable to fail payment hash")
|
require.NoError(t, err, "unable to fail payment hash")
|
||||||
|
|||||||
+59
-2
@@ -19,6 +19,63 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FailureReason encodes the reason a payment ultimately failed.
|
||||||
|
type FailureReason byte
|
||||||
|
|
||||||
|
const (
|
||||||
|
// FailureReasonTimeout indicates that the payment did timeout before a
|
||||||
|
// successful payment attempt was made.
|
||||||
|
FailureReasonTimeout FailureReason = 0
|
||||||
|
|
||||||
|
// FailureReasonNoRoute indicates no successful route to the
|
||||||
|
// destination was found during path finding.
|
||||||
|
FailureReasonNoRoute FailureReason = 1
|
||||||
|
|
||||||
|
// FailureReasonError indicates that an unexpected error happened during
|
||||||
|
// payment.
|
||||||
|
FailureReasonError FailureReason = 2
|
||||||
|
|
||||||
|
// FailureReasonPaymentDetails indicates that either the hash is unknown
|
||||||
|
// or the final cltv delta or amount is incorrect.
|
||||||
|
FailureReasonPaymentDetails FailureReason = 3
|
||||||
|
|
||||||
|
// FailureReasonInsufficientBalance indicates that we didn't have enough
|
||||||
|
// balance to complete the payment.
|
||||||
|
FailureReasonInsufficientBalance FailureReason = 4
|
||||||
|
|
||||||
|
// FailureReasonCanceled indicates that the payment was canceled by the
|
||||||
|
// user.
|
||||||
|
FailureReasonCanceled FailureReason = 5
|
||||||
|
|
||||||
|
// TODO(joostjager): Add failure reasons for:
|
||||||
|
// LocalLiquidityInsufficient, RemoteCapacityInsufficient.
|
||||||
|
)
|
||||||
|
|
||||||
|
// Error returns a human-readable error string for the FailureReason.
|
||||||
|
func (r FailureReason) Error() string {
|
||||||
|
return r.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a human-readable FailureReason.
|
||||||
|
func (r FailureReason) String() string {
|
||||||
|
switch r {
|
||||||
|
case FailureReasonTimeout:
|
||||||
|
return "timeout"
|
||||||
|
case FailureReasonNoRoute:
|
||||||
|
return "no_route"
|
||||||
|
case FailureReasonError:
|
||||||
|
return "error"
|
||||||
|
case FailureReasonPaymentDetails:
|
||||||
|
return "incorrect_payment_details"
|
||||||
|
case FailureReasonInsufficientBalance:
|
||||||
|
return "insufficient_balance"
|
||||||
|
case FailureReasonCanceled:
|
||||||
|
return "canceled"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
// HTLCAttemptInfo contains static information about a specific HTLC attempt
|
// HTLCAttemptInfo contains static information about a specific HTLC attempt
|
||||||
// for a payment. This information is used by the router to handle any errors
|
// for a payment. This information is used by the router to handle any errors
|
||||||
// coming back after an attempt is made, and to query the switch about the
|
// coming back after an attempt is made, and to query the switch about the
|
||||||
@@ -252,7 +309,7 @@ type MPPayment struct {
|
|||||||
//
|
//
|
||||||
// NOTE: Will only be set once the daemon has given up on the payment
|
// NOTE: Will only be set once the daemon has given up on the payment
|
||||||
// altogether.
|
// altogether.
|
||||||
FailureReason *channeldb.FailureReason
|
FailureReason *FailureReason
|
||||||
|
|
||||||
// Status is the current PaymentStatus of this payment.
|
// Status is the current PaymentStatus of this payment.
|
||||||
Status PaymentStatus
|
Status PaymentStatus
|
||||||
@@ -273,7 +330,7 @@ func (m *MPPayment) Terminated() bool {
|
|||||||
// TerminalInfo returns any HTLC settle info recorded. If no settle info is
|
// TerminalInfo returns any HTLC settle info recorded. If no settle info is
|
||||||
// recorded, any payment level failure will be returned. If neither a settle
|
// recorded, any payment level failure will be returned. If neither a settle
|
||||||
// nor a failure is recorded, both return values will be nil.
|
// nor a failure is recorded, both return values will be nil.
|
||||||
func (m *MPPayment) TerminalInfo() (*HTLCAttempt, *channeldb.FailureReason) {
|
func (m *MPPayment) TerminalInfo() (*HTLCAttempt, *FailureReason) {
|
||||||
for _, h := range m.HTLCs {
|
for _, h := range m.HTLCs {
|
||||||
if h.Settle != nil {
|
if h.Settle != nil {
|
||||||
return &h, nil
|
return &h, nil
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package paymentsdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PaymentStatus represent current status of payment.
|
// PaymentStatus represent current status of payment.
|
||||||
@@ -173,7 +171,7 @@ func (ps PaymentStatus) updatable() error {
|
|||||||
// failed` is false, this indicates all the payment's HTLCs have occurred a
|
// failed` is false, this indicates all the payment's HTLCs have occurred a
|
||||||
// temporarily failure and the payment is still in-flight.
|
// temporarily failure and the payment is still in-flight.
|
||||||
func decidePaymentStatus(htlcs []HTLCAttempt,
|
func decidePaymentStatus(htlcs []HTLCAttempt,
|
||||||
reason *channeldb.FailureReason) (PaymentStatus, error) {
|
reason *FailureReason) (PaymentStatus, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
inflight bool
|
inflight bool
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -24,13 +23,13 @@ func TestDecidePaymentStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a test failure reason and get the pointer.
|
// Create a test failure reason and get the pointer.
|
||||||
reason := channeldb.FailureReasonNoRoute
|
reason := FailureReasonNoRoute
|
||||||
failure := &reason
|
failure := &reason
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
htlcs []HTLCAttempt
|
htlcs []HTLCAttempt
|
||||||
reason *channeldb.FailureReason
|
reason *FailureReason
|
||||||
expectedStatus PaymentStatus
|
expectedStatus PaymentStatus
|
||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
|
|||||||
@@ -598,7 +598,7 @@ func TestPaymentSetState(t *testing.T) {
|
|||||||
|
|
||||||
// Create a test preimage and failure reason.
|
// Create a test preimage and failure reason.
|
||||||
preimage := lntypes.Preimage{1}
|
preimage := lntypes.Preimage{1}
|
||||||
failureReasonError := channeldb.FailureReasonError
|
failureReasonError := FailureReasonError
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ type DBMPPayment interface {
|
|||||||
|
|
||||||
// TerminalInfo returns the settled HTLC attempt or the payment's
|
// TerminalInfo returns the settled HTLC attempt or the payment's
|
||||||
// failure reason.
|
// failure reason.
|
||||||
TerminalInfo() (*paymentsdb.HTLCAttempt, *channeldb.FailureReason)
|
TerminalInfo() (*paymentsdb.HTLCAttempt, *paymentsdb.FailureReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControlTower tracks all outgoing payments made, whose primary purpose is to
|
// ControlTower tracks all outgoing payments made, whose primary purpose is to
|
||||||
@@ -85,7 +85,7 @@ type ControlTower interface {
|
|||||||
// invoking this method, InitPayment should return nil on its next call
|
// invoking this method, InitPayment should return nil on its next call
|
||||||
// for this payment hash, allowing the user to make a subsequent
|
// for this payment hash, allowing the user to make a subsequent
|
||||||
// payment.
|
// payment.
|
||||||
FailPayment(lntypes.Hash, channeldb.FailureReason) error
|
FailPayment(lntypes.Hash, paymentsdb.FailureReason) error
|
||||||
|
|
||||||
// FetchInFlightPayments returns all payments with status InFlight.
|
// FetchInFlightPayments returns all payments with status InFlight.
|
||||||
FetchInFlightPayments() ([]*paymentsdb.MPPayment, error)
|
FetchInFlightPayments() ([]*paymentsdb.MPPayment, error)
|
||||||
@@ -287,7 +287,7 @@ func (p *controlTower) FetchPayment(paymentHash lntypes.Hash) (
|
|||||||
// NOTE: This method will overwrite the failure reason if the payment is already
|
// NOTE: This method will overwrite the failure reason if the payment is already
|
||||||
// failed.
|
// failed.
|
||||||
func (p *controlTower) FailPayment(paymentHash lntypes.Hash,
|
func (p *controlTower) FailPayment(paymentHash lntypes.Hash,
|
||||||
reason channeldb.FailureReason) error {
|
reason paymentsdb.FailureReason) error {
|
||||||
|
|
||||||
p.paymentsMtx.Lock(paymentHash)
|
p.paymentsMtx.Lock(paymentHash)
|
||||||
defer p.paymentsMtx.Unlock(paymentHash)
|
defer p.paymentsMtx.Unlock(paymentHash)
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
|
|||||||
|
|
||||||
// Mark the payment as failed.
|
// Mark the payment as failed.
|
||||||
err = pControl.FailPayment(
|
err = pControl.FailPayment(
|
||||||
info.PaymentIdentifier, channeldb.FailureReasonTimeout,
|
info.PaymentIdentifier, paymentsdb.FailureReasonTimeout,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -537,7 +537,7 @@ func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
|
|||||||
"subscriber %v failed, want %s, got %s", i,
|
"subscriber %v failed, want %s, got %s", i,
|
||||||
paymentsdb.StatusFailed, result.GetStatus())
|
paymentsdb.StatusFailed, result.GetStatus())
|
||||||
|
|
||||||
if *result.FailureReason != channeldb.FailureReasonTimeout {
|
if *result.FailureReason != paymentsdb.FailureReasonTimeout {
|
||||||
t.Fatal("unexpected failure reason")
|
t.Fatal("unexpected failure reason")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btclog/v2"
|
"github.com/btcsuite/btclog/v2"
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/clock"
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
"github.com/lightningnetwork/lnd/fn/v2"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
@@ -617,7 +617,7 @@ func (m *MissionControl) GetPairHistorySnapshot(
|
|||||||
// payment attempts need to be made.
|
// payment attempts need to be made.
|
||||||
func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route,
|
func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route,
|
||||||
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
||||||
*channeldb.FailureReason, error) {
|
*paymentsdb.FailureReason, error) {
|
||||||
|
|
||||||
timestamp := m.cfg.clock.Now()
|
timestamp := m.cfg.clock.Now()
|
||||||
|
|
||||||
@@ -649,7 +649,7 @@ func (m *MissionControl) ReportPaymentSuccess(paymentID uint64,
|
|||||||
// processPaymentResult stores a payment result in the mission control store and
|
// processPaymentResult stores a payment result in the mission control store and
|
||||||
// updates mission control's in-memory state.
|
// updates mission control's in-memory state.
|
||||||
func (m *MissionControl) processPaymentResult(result *paymentResult) (
|
func (m *MissionControl) processPaymentResult(result *paymentResult) (
|
||||||
*channeldb.FailureReason, error) {
|
*paymentsdb.FailureReason, error) {
|
||||||
|
|
||||||
// Store complete result in database.
|
// Store complete result in database.
|
||||||
m.store.AddResult(result)
|
m.store.AddResult(result)
|
||||||
@@ -667,7 +667,7 @@ func (m *MissionControl) processPaymentResult(result *paymentResult) (
|
|||||||
// estimates. It returns a bool indicating whether this error is a final error
|
// estimates. It returns a bool indicating whether this error is a final error
|
||||||
// and no further payment attempts need to be made.
|
// and no further payment attempts need to be made.
|
||||||
func (m *MissionControl) applyPaymentResult(
|
func (m *MissionControl) applyPaymentResult(
|
||||||
result *paymentResult) *channeldb.FailureReason {
|
result *paymentResult) *paymentsdb.FailureReason {
|
||||||
|
|
||||||
// Interpret result.
|
// Interpret result.
|
||||||
i := interpretResult(&result.route.Val, result.failure.ValOpt())
|
i := interpretResult(&result.route.Val, result.failure.ValOpt())
|
||||||
|
|||||||
+12
-12
@@ -134,12 +134,12 @@ var _ MissionControlQuerier = (*mockMissionControlOld)(nil)
|
|||||||
func (m *mockMissionControlOld) ReportPaymentFail(
|
func (m *mockMissionControlOld) ReportPaymentFail(
|
||||||
paymentID uint64, rt *route.Route,
|
paymentID uint64, rt *route.Route,
|
||||||
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
||||||
*channeldb.FailureReason, error) {
|
*paymentsdb.FailureReason, error) {
|
||||||
|
|
||||||
// Report a permanent failure if this is an error caused
|
// Report a permanent failure if this is an error caused
|
||||||
// by incorrect details.
|
// by incorrect details.
|
||||||
if failure.Code() == lnwire.CodeIncorrectOrUnknownPaymentDetails {
|
if failure.Code() == lnwire.CodeIncorrectOrUnknownPaymentDetails {
|
||||||
reason := channeldb.FailureReasonPaymentDetails
|
reason := paymentsdb.FailureReasonPaymentDetails
|
||||||
return &reason, nil
|
return &reason, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ type failAttemptArgs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type failPaymentArgs struct {
|
type failPaymentArgs struct {
|
||||||
reason channeldb.FailureReason
|
reason paymentsdb.FailureReason
|
||||||
}
|
}
|
||||||
|
|
||||||
type testPayment struct {
|
type testPayment struct {
|
||||||
@@ -275,7 +275,7 @@ type testPayment struct {
|
|||||||
type mockControlTowerOld struct {
|
type mockControlTowerOld struct {
|
||||||
payments map[lntypes.Hash]*testPayment
|
payments map[lntypes.Hash]*testPayment
|
||||||
successful map[lntypes.Hash]struct{}
|
successful map[lntypes.Hash]struct{}
|
||||||
failed map[lntypes.Hash]channeldb.FailureReason
|
failed map[lntypes.Hash]paymentsdb.FailureReason
|
||||||
|
|
||||||
init chan initArgs
|
init chan initArgs
|
||||||
registerAttempt chan registerAttemptArgs
|
registerAttempt chan registerAttemptArgs
|
||||||
@@ -293,7 +293,7 @@ func makeMockControlTower() *mockControlTowerOld {
|
|||||||
return &mockControlTowerOld{
|
return &mockControlTowerOld{
|
||||||
payments: make(map[lntypes.Hash]*testPayment),
|
payments: make(map[lntypes.Hash]*testPayment),
|
||||||
successful: make(map[lntypes.Hash]struct{}),
|
successful: make(map[lntypes.Hash]struct{}),
|
||||||
failed: make(map[lntypes.Hash]channeldb.FailureReason),
|
failed: make(map[lntypes.Hash]paymentsdb.FailureReason),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,7 +489,7 @@ func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockControlTowerOld) FailPayment(phash lntypes.Hash,
|
func (m *mockControlTowerOld) FailPayment(phash lntypes.Hash,
|
||||||
reason channeldb.FailureReason) error {
|
reason paymentsdb.FailureReason) error {
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
@@ -664,7 +664,7 @@ var _ MissionControlQuerier = (*mockMissionControl)(nil)
|
|||||||
func (m *mockMissionControl) ReportPaymentFail(
|
func (m *mockMissionControl) ReportPaymentFail(
|
||||||
paymentID uint64, rt *route.Route,
|
paymentID uint64, rt *route.Route,
|
||||||
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
||||||
*channeldb.FailureReason, error) {
|
*paymentsdb.FailureReason, error) {
|
||||||
|
|
||||||
args := m.Called(paymentID, rt, failureSourceIdx, failure)
|
args := m.Called(paymentID, rt, failureSourceIdx, failure)
|
||||||
|
|
||||||
@@ -673,7 +673,7 @@ func (m *mockMissionControl) ReportPaymentFail(
|
|||||||
return nil, args.Error(1)
|
return nil, args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return args.Get(0).(*channeldb.FailureReason), args.Error(1)
|
return args.Get(0).(*paymentsdb.FailureReason), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockMissionControl) ReportPaymentSuccess(paymentID uint64,
|
func (m *mockMissionControl) ReportPaymentSuccess(paymentID uint64,
|
||||||
@@ -779,7 +779,7 @@ func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockControlTower) FailPayment(phash lntypes.Hash,
|
func (m *mockControlTower) FailPayment(phash lntypes.Hash,
|
||||||
reason channeldb.FailureReason) error {
|
reason paymentsdb.FailureReason) error {
|
||||||
|
|
||||||
args := m.Called(phash, reason)
|
args := m.Called(phash, reason)
|
||||||
return args.Error(0)
|
return args.Error(0)
|
||||||
@@ -863,13 +863,13 @@ func (m *mockMPPayment) AllowMoreAttempts() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockMPPayment) TerminalInfo() (*paymentsdb.HTLCAttempt,
|
func (m *mockMPPayment) TerminalInfo() (*paymentsdb.HTLCAttempt,
|
||||||
*channeldb.FailureReason) {
|
*paymentsdb.FailureReason) {
|
||||||
|
|
||||||
args := m.Called()
|
args := m.Called()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
settleInfo *paymentsdb.HTLCAttempt
|
settleInfo *paymentsdb.HTLCAttempt
|
||||||
failureInfo *channeldb.FailureReason
|
failureInfo *paymentsdb.FailureReason
|
||||||
)
|
)
|
||||||
|
|
||||||
settle := args.Get(0)
|
settle := args.Get(0)
|
||||||
@@ -879,7 +879,7 @@ func (m *mockMPPayment) TerminalInfo() (*paymentsdb.HTLCAttempt,
|
|||||||
|
|
||||||
reason := args.Get(1)
|
reason := args.Get(1)
|
||||||
if reason != nil {
|
if reason != nil {
|
||||||
failureInfo = reason.(*channeldb.FailureReason)
|
failureInfo = reason.(*paymentsdb.FailureReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
return settleInfo, failureInfo
|
return settleInfo, failureInfo
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
"github.com/lightningnetwork/lnd/fn/v2"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
@@ -353,13 +352,13 @@ func (p *paymentLifecycle) checkContext(ctx context.Context) error {
|
|||||||
// user-provided timeout was reached, or the context was
|
// user-provided timeout was reached, or the context was
|
||||||
// canceled, either to a manual cancellation or due to an
|
// canceled, either to a manual cancellation or due to an
|
||||||
// unknown error.
|
// unknown error.
|
||||||
var reason channeldb.FailureReason
|
var reason paymentsdb.FailureReason
|
||||||
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
||||||
reason = channeldb.FailureReasonTimeout
|
reason = paymentsdb.FailureReasonTimeout
|
||||||
log.Warnf("Payment attempt not completed before "+
|
log.Warnf("Payment attempt not completed before "+
|
||||||
"context timeout, id=%s", p.identifier.String())
|
"context timeout, id=%s", p.identifier.String())
|
||||||
} else {
|
} else {
|
||||||
reason = channeldb.FailureReasonCanceled
|
reason = paymentsdb.FailureReasonCanceled
|
||||||
log.Warnf("Payment attempt context canceled, id=%s",
|
log.Warnf("Payment attempt context canceled, id=%s",
|
||||||
p.identifier.String())
|
p.identifier.String())
|
||||||
}
|
}
|
||||||
@@ -795,7 +794,7 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
|
|||||||
// failAttemptAndPayment fails both the payment and its attempt via the
|
// failAttemptAndPayment fails both the payment and its attempt via the
|
||||||
// router's control tower, which marks the payment as failed in db.
|
// router's control tower, which marks the payment as failed in db.
|
||||||
func (p *paymentLifecycle) failPaymentAndAttempt(
|
func (p *paymentLifecycle) failPaymentAndAttempt(
|
||||||
attemptID uint64, reason *channeldb.FailureReason,
|
attemptID uint64, reason *paymentsdb.FailureReason,
|
||||||
sendErr error) (*attemptResult, error) {
|
sendErr error) (*attemptResult, error) {
|
||||||
|
|
||||||
log.Errorf("Payment %v failed: final_outcome=%v, raw_err=%v",
|
log.Errorf("Payment %v failed: final_outcome=%v, raw_err=%v",
|
||||||
@@ -827,7 +826,7 @@ func (p *paymentLifecycle) failPaymentAndAttempt(
|
|||||||
func (p *paymentLifecycle) handleSwitchErr(attempt *paymentsdb.HTLCAttempt,
|
func (p *paymentLifecycle) handleSwitchErr(attempt *paymentsdb.HTLCAttempt,
|
||||||
sendErr error) (*attemptResult, error) {
|
sendErr error) (*attemptResult, error) {
|
||||||
|
|
||||||
internalErrorReason := channeldb.FailureReasonError
|
internalErrorReason := paymentsdb.FailureReasonError
|
||||||
attemptID := attempt.AttemptID
|
attemptID := attempt.AttemptID
|
||||||
|
|
||||||
// reportAndFail is a helper closure that reports the failure to the
|
// reportAndFail is a helper closure that reports the failure to the
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
"github.com/lightningnetwork/lnd/fn/v2"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnmock"
|
"github.com/lightningnetwork/lnd/lnmock"
|
||||||
@@ -303,7 +302,7 @@ func TestCheckTimeoutTimedOut(t *testing.T) {
|
|||||||
// Mock the control tower's `FailPayment` method.
|
// Mock the control tower's `FailPayment` method.
|
||||||
ct := &mockControlTower{}
|
ct := &mockControlTower{}
|
||||||
ct.On("FailPayment",
|
ct.On("FailPayment",
|
||||||
p.identifier, channeldb.FailureReasonTimeout).Return(nil)
|
p.identifier, paymentsdb.FailureReasonTimeout).Return(nil)
|
||||||
|
|
||||||
// Mount the mocked control tower.
|
// Mount the mocked control tower.
|
||||||
p.router.cfg.Control = ct
|
p.router.cfg.Control = ct
|
||||||
@@ -324,7 +323,7 @@ func TestCheckTimeoutTimedOut(t *testing.T) {
|
|||||||
// Mock `FailPayment` to return a dummy error.
|
// Mock `FailPayment` to return a dummy error.
|
||||||
ct = &mockControlTower{}
|
ct = &mockControlTower{}
|
||||||
ct.On("FailPayment",
|
ct.On("FailPayment",
|
||||||
p.identifier, channeldb.FailureReasonTimeout).Return(errDummy)
|
p.identifier, paymentsdb.FailureReasonTimeout).Return(errDummy)
|
||||||
|
|
||||||
// Mount the mocked control tower.
|
// Mount the mocked control tower.
|
||||||
p.router.cfg.Control = ct
|
p.router.cfg.Control = ct
|
||||||
@@ -468,7 +467,7 @@ func TestRequestRouteHandleNoRouteErr(t *testing.T) {
|
|||||||
|
|
||||||
// The payment should be failed with reason no route.
|
// The payment should be failed with reason no route.
|
||||||
m.control.On("FailPayment",
|
m.control.On("FailPayment",
|
||||||
p.identifier, channeldb.FailureReasonNoRoute,
|
p.identifier, paymentsdb.FailureReasonNoRoute,
|
||||||
).Return(nil).Once()
|
).Return(nil).Once()
|
||||||
|
|
||||||
result, err := p.requestRoute(ps)
|
result, err := p.requestRoute(ps)
|
||||||
@@ -838,7 +837,7 @@ func TestResumePaymentFailOnTimeout(t *testing.T) {
|
|||||||
|
|
||||||
// 4. the payment should be failed with reason timeout.
|
// 4. the payment should be failed with reason timeout.
|
||||||
m.control.On("FailPayment",
|
m.control.On("FailPayment",
|
||||||
p.identifier, channeldb.FailureReasonTimeout,
|
p.identifier, paymentsdb.FailureReasonTimeout,
|
||||||
).Return(nil).Once()
|
).Return(nil).Once()
|
||||||
|
|
||||||
// 5. decideNextStep now returns stepExit.
|
// 5. decideNextStep now returns stepExit.
|
||||||
@@ -849,7 +848,7 @@ func TestResumePaymentFailOnTimeout(t *testing.T) {
|
|||||||
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
|
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
|
||||||
|
|
||||||
// 7. the payment returns the failed reason.
|
// 7. the payment returns the failed reason.
|
||||||
reason := channeldb.FailureReasonTimeout
|
reason := paymentsdb.FailureReasonTimeout
|
||||||
m.payment.On("TerminalInfo").Return(nil, &reason)
|
m.payment.On("TerminalInfo").Return(nil, &reason)
|
||||||
|
|
||||||
// Send the payment and assert it failed with the timeout reason.
|
// Send the payment and assert it failed with the timeout reason.
|
||||||
@@ -925,7 +924,7 @@ func TestResumePaymentFailContextCancel(t *testing.T) {
|
|||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
m.control.On(
|
m.control.On(
|
||||||
"FailPayment", p.identifier, channeldb.FailureReasonCanceled,
|
"FailPayment", p.identifier, paymentsdb.FailureReasonCanceled,
|
||||||
).Return(nil).Once()
|
).Return(nil).Once()
|
||||||
|
|
||||||
// 4. decideNextStep now returns stepExit.
|
// 4. decideNextStep now returns stepExit.
|
||||||
@@ -936,7 +935,7 @@ func TestResumePaymentFailContextCancel(t *testing.T) {
|
|||||||
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
|
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
|
||||||
|
|
||||||
// 6. We will observe FailureReasonError if the context was cancelled.
|
// 6. We will observe FailureReasonError if the context was cancelled.
|
||||||
reason := channeldb.FailureReasonError
|
reason := paymentsdb.FailureReasonError
|
||||||
m.payment.On("TerminalInfo").Return(nil, &reason)
|
m.payment.On("TerminalInfo").Return(nil, &reason)
|
||||||
|
|
||||||
// Send the payment and assert it failed with the timeout reason.
|
// Send the payment and assert it failed with the timeout reason.
|
||||||
@@ -1162,7 +1161,7 @@ func TestResumePaymentFailOnSendAttemptErr(t *testing.T) {
|
|||||||
// which we'd fail the payment, cancel the shard and fail the attempt.
|
// which we'd fail the payment, cancel the shard and fail the attempt.
|
||||||
//
|
//
|
||||||
// `FailPayment` should be called with an internal reason.
|
// `FailPayment` should be called with an internal reason.
|
||||||
reason := channeldb.FailureReasonError
|
reason := paymentsdb.FailureReasonError
|
||||||
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
|
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
|
||||||
|
|
||||||
// `CancelShard` should be called with the attemptID.
|
// `CancelShard` should be called with the attemptID.
|
||||||
@@ -1453,7 +1452,7 @@ func TestCollectResultExitOnErr(t *testing.T) {
|
|||||||
// which we'd fail the payment, cancel the shard and fail the attempt.
|
// which we'd fail the payment, cancel the shard and fail the attempt.
|
||||||
//
|
//
|
||||||
// `FailPayment` should be called with an internal reason.
|
// `FailPayment` should be called with an internal reason.
|
||||||
reason := channeldb.FailureReasonError
|
reason := paymentsdb.FailureReasonError
|
||||||
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
|
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
|
||||||
|
|
||||||
// `CancelShard` should be called with the attemptID.
|
// `CancelShard` should be called with the attemptID.
|
||||||
@@ -1499,7 +1498,7 @@ func TestCollectResultExitOnResultErr(t *testing.T) {
|
|||||||
// which we'd fail the payment, cancel the shard and fail the attempt.
|
// which we'd fail the payment, cancel the shard and fail the attempt.
|
||||||
//
|
//
|
||||||
// `FailPayment` should be called with an internal reason.
|
// `FailPayment` should be called with an internal reason.
|
||||||
reason := channeldb.FailureReasonError
|
reason := paymentsdb.FailureReasonError
|
||||||
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
|
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
|
||||||
|
|
||||||
// `CancelShard` should be called with the attemptID.
|
// `CancelShard` should be called with the attemptID.
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btclog/v2"
|
"github.com/btcsuite/btclog/v2"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lnutils"
|
"github.com/lightningnetwork/lnd/lnutils"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/netann"
|
"github.com/lightningnetwork/lnd/netann"
|
||||||
|
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ func (e noRouteError) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FailureReason converts a path finding error into a payment-level failure.
|
// FailureReason converts a path finding error into a payment-level failure.
|
||||||
func (e noRouteError) FailureReason() channeldb.FailureReason {
|
func (e noRouteError) FailureReason() paymentsdb.FailureReason {
|
||||||
switch e {
|
switch e {
|
||||||
case
|
case
|
||||||
errNoTlvPayload,
|
errNoTlvPayload,
|
||||||
@@ -114,13 +114,13 @@ func (e noRouteError) FailureReason() channeldb.FailureReason {
|
|||||||
errUnknownRequiredFeature,
|
errUnknownRequiredFeature,
|
||||||
errMissingDependentFeature:
|
errMissingDependentFeature:
|
||||||
|
|
||||||
return channeldb.FailureReasonNoRoute
|
return paymentsdb.FailureReasonNoRoute
|
||||||
|
|
||||||
case errInsufficientBalance:
|
case errInsufficientBalance:
|
||||||
return channeldb.FailureReasonInsufficientBalance
|
return paymentsdb.FailureReasonInsufficientBalance
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return channeldb.FailureReasonError
|
return paymentsdb.FailureReasonError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,17 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
"github.com/lightningnetwork/lnd/fn/v2"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Instantiate variables to allow taking a reference from the failure reason.
|
// Instantiate variables to allow taking a reference from the failure reason.
|
||||||
var (
|
var (
|
||||||
reasonError = channeldb.FailureReasonError
|
reasonError = paymentsdb.FailureReasonError
|
||||||
reasonIncorrectDetails = channeldb.FailureReasonPaymentDetails
|
reasonIncorrectDetails = paymentsdb.FailureReasonPaymentDetails
|
||||||
)
|
)
|
||||||
|
|
||||||
// pairResult contains the result of the interpretation of a payment attempt for
|
// pairResult contains the result of the interpretation of a payment attempt for
|
||||||
@@ -70,7 +70,7 @@ type interpretedResult struct {
|
|||||||
// finalFailureReason is set to a non-nil value if it makes no more
|
// finalFailureReason is set to a non-nil value if it makes no more
|
||||||
// sense to start another payment attempt. It will contain the reason
|
// sense to start another payment attempt. It will contain the reason
|
||||||
// why.
|
// why.
|
||||||
finalFailureReason *channeldb.FailureReason
|
finalFailureReason *paymentsdb.FailureReason
|
||||||
|
|
||||||
// policyFailure is set to a node pair if there is a policy failure on
|
// policyFailure is set to a node pair if there is a policy failure on
|
||||||
// that connection. This is used to control the second chance logic for
|
// that connection. This is used to control the second chance logic for
|
||||||
|
|||||||
+3
-3
@@ -175,7 +175,7 @@ type MissionControlQuerier interface {
|
|||||||
// need to be made.
|
// need to be made.
|
||||||
ReportPaymentFail(attemptID uint64, rt *route.Route,
|
ReportPaymentFail(attemptID uint64, rt *route.Route,
|
||||||
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
||||||
*channeldb.FailureReason, error)
|
*paymentsdb.FailureReason, error)
|
||||||
|
|
||||||
// ReportPaymentSuccess reports a successful payment to mission control
|
// ReportPaymentSuccess reports a successful payment to mission control
|
||||||
// as input for future probability estimates.
|
// as input for future probability estimates.
|
||||||
@@ -1068,7 +1068,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
|||||||
// Helper function to fail a payment. It makes sure the payment is only
|
// Helper function to fail a payment. It makes sure the payment is only
|
||||||
// failed once so that the failure reason is not overwritten.
|
// failed once so that the failure reason is not overwritten.
|
||||||
failPayment := func(paymentIdentifier lntypes.Hash,
|
failPayment := func(paymentIdentifier lntypes.Hash,
|
||||||
reason channeldb.FailureReason) error {
|
reason paymentsdb.FailureReason) error {
|
||||||
|
|
||||||
payment, fetchErr := r.cfg.Control.FetchPayment(
|
payment, fetchErr := r.cfg.Control.FetchPayment(
|
||||||
paymentIdentifier,
|
paymentIdentifier,
|
||||||
@@ -1191,7 +1191,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
|||||||
// Since for SendToRoute we won't retry in case the shard fails, we'll
|
// Since for SendToRoute we won't retry in case the shard fails, we'll
|
||||||
// mark the payment failed with the control tower immediately if the
|
// mark the payment failed with the control tower immediately if the
|
||||||
// skipTempErr is false.
|
// skipTempErr is false.
|
||||||
reason := channeldb.FailureReasonError
|
reason := paymentsdb.FailureReasonError
|
||||||
|
|
||||||
// If we failed to send the HTLC, we need to further decide if we want
|
// If we failed to send the HTLC, we need to further decide if we want
|
||||||
// to fail the payment.
|
// to fail the payment.
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/lightningnetwork/lnd/clock"
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
"github.com/lightningnetwork/lnd/fn/v2"
|
||||||
"github.com/lightningnetwork/lnd/graph"
|
"github.com/lightningnetwork/lnd/graph"
|
||||||
@@ -32,6 +31,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
|
||||||
"github.com/lightningnetwork/lnd/record"
|
"github.com/lightningnetwork/lnd/record"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/zpay32"
|
"github.com/lightningnetwork/lnd/zpay32"
|
||||||
@@ -1091,7 +1091,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) {
|
|||||||
|
|
||||||
// The final error returned should also indicate that the peer wasn't
|
// The final error returned should also indicate that the peer wasn't
|
||||||
// online (the last error we returned).
|
// online (the last error we returned).
|
||||||
require.Equal(t, channeldb.FailureReasonNoRoute, err)
|
require.Equal(t, paymentsdb.FailureReasonNoRoute, err)
|
||||||
|
|
||||||
// Inspect the two attempts that were made before the payment failed.
|
// Inspect the two attempts that were made before the payment failed.
|
||||||
p, err := ctx.router.cfg.Control.FetchPayment(*payment.paymentHash)
|
p, err := ctx.router.cfg.Control.FetchPayment(*payment.paymentHash)
|
||||||
@@ -2429,7 +2429,7 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
|
|||||||
mock.Anything, mock.Anything, mock.Anything,
|
mock.Anything, mock.Anything, mock.Anything,
|
||||||
).Return(permErr)
|
).Return(permErr)
|
||||||
|
|
||||||
failureReason := channeldb.FailureReasonPaymentDetails
|
failureReason := paymentsdb.FailureReasonPaymentDetails
|
||||||
missionControl.On("ReportPaymentFail",
|
missionControl.On("ReportPaymentFail",
|
||||||
mock.Anything, rt, mock.Anything, mock.Anything,
|
mock.Anything, rt, mock.Anything, mock.Anything,
|
||||||
).Return(&failureReason, nil)
|
).Return(&failureReason, nil)
|
||||||
|
|||||||
Reference in new issue
Block a user