channeldb: rename PaymentAttemptInfo to HTLCAttemptInfo
To better distinguish payments from HTLCs, we rename the attempt info struct to HTLCAttemptInfo. We also embed it into the HTLCAttempt struct, to avoid having to duplicate this information. The paymentID term is renamed to attemptID.
This commit is contained in:
parent
967b4b2dc3
commit
bee2380441
@ -8,16 +8,15 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTLCAttempt contains information about a specific HTLC attempt for a given
|
// HTLCAttemptInfo contains static information about a specific HTLC attempt
|
||||||
// payment. This information is used by the router to handle any errors coming
|
// for a payment. This information is used by the router to handle any errors
|
||||||
// back after an attempt is made, and to query the switch about the status of a
|
// coming back after an attempt is made, and to query the switch about the
|
||||||
// payment. For settled payment this will be the information for the succeeding
|
// status of the attempt.
|
||||||
// payment attempt.
|
type HTLCAttemptInfo struct {
|
||||||
type HTLCAttempt struct {
|
// AttemptID is the unique ID used for this attempt.
|
||||||
// PaymentID is the unique ID used for this attempt.
|
AttemptID uint64
|
||||||
PaymentID uint64
|
|
||||||
|
|
||||||
// SessionKey is the ephemeral key used for this payment attempt.
|
// SessionKey is the ephemeral key used for this attempt.
|
||||||
SessionKey *btcec.PrivateKey
|
SessionKey *btcec.PrivateKey
|
||||||
|
|
||||||
// Route is the route attempted to send the HTLC.
|
// Route is the route attempted to send the HTLC.
|
||||||
@ -25,6 +24,13 @@ type HTLCAttempt struct {
|
|||||||
|
|
||||||
// AttemptTime is the time at which this HTLC was attempted.
|
// AttemptTime is the time at which this HTLC was attempted.
|
||||||
AttemptTime time.Time
|
AttemptTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTLCAttempt contains information about a specific HTLC attempt for a given
|
||||||
|
// payment. It contains the HTLCAttemptInfo used to send the HTLC, as well
|
||||||
|
// as a timestamp and any known outcome of the attempt.
|
||||||
|
type HTLCAttempt struct {
|
||||||
|
HTLCAttemptInfo
|
||||||
|
|
||||||
// Settle is the preimage of a successful payment. This serves as a
|
// Settle is the preimage of a successful payment. This serves as a
|
||||||
// proof of payment. It will only be non-nil for settled payments.
|
// proof of payment. It will only be non-nil for settled payments.
|
||||||
|
@ -143,14 +143,14 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
|
|||||||
return updateErr
|
return updateErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterAttempt atomically records the provided PaymentAttemptInfo to the
|
// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
|
||||||
// DB.
|
// DB.
|
||||||
func (p *PaymentControl) RegisterAttempt(paymentHash lntypes.Hash,
|
func (p *PaymentControl) RegisterAttempt(paymentHash lntypes.Hash,
|
||||||
attempt *PaymentAttemptInfo) error {
|
attempt *HTLCAttemptInfo) error {
|
||||||
|
|
||||||
// Serialize the information before opening the db transaction.
|
// Serialize the information before opening the db transaction.
|
||||||
var a bytes.Buffer
|
var a bytes.Buffer
|
||||||
if err := serializePaymentAttemptInfo(&a, attempt); err != nil {
|
if err := serializeHTLCAttemptInfo(&a, attempt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
attemptBytes := a.Bytes()
|
attemptBytes := a.Bytes()
|
||||||
@ -405,14 +405,14 @@ func ensureInFlight(bucket *bbolt.Bucket) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetchPaymentAttempt fetches the payment attempt from the bucket.
|
// fetchPaymentAttempt fetches the payment attempt from the bucket.
|
||||||
func fetchPaymentAttempt(bucket *bbolt.Bucket) (*PaymentAttemptInfo, error) {
|
func fetchPaymentAttempt(bucket *bbolt.Bucket) (*HTLCAttemptInfo, error) {
|
||||||
attemptData := bucket.Get(paymentAttemptInfoKey)
|
attemptData := bucket.Get(paymentAttemptInfoKey)
|
||||||
if attemptData == nil {
|
if attemptData == nil {
|
||||||
return nil, errNoAttemptInfo
|
return nil, errNoAttemptInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
r := bytes.NewReader(attemptData)
|
r := bytes.NewReader(attemptData)
|
||||||
return deserializePaymentAttemptInfo(r)
|
return deserializeHTLCAttemptInfo(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InFlightPayment is a wrapper around a payment that has status InFlight.
|
// InFlightPayment is a wrapper around a payment that has status InFlight.
|
||||||
@ -424,7 +424,7 @@ type InFlightPayment struct {
|
|||||||
// made to this payment hash.
|
// made to this payment hash.
|
||||||
//
|
//
|
||||||
// NOTE: Might be nil.
|
// NOTE: Might be nil.
|
||||||
Attempt *PaymentAttemptInfo
|
Attempt *HTLCAttemptInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchInFlightPayments returns all payments with status InFlight.
|
// FetchInFlightPayments returns all payments with status InFlight.
|
||||||
|
@ -38,7 +38,7 @@ func genPreimage() ([32]byte, error) {
|
|||||||
return preimage, nil
|
return preimage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genInfo() (*PaymentCreationInfo, *PaymentAttemptInfo,
|
func genInfo() (*PaymentCreationInfo, *HTLCAttemptInfo,
|
||||||
lntypes.Preimage, error) {
|
lntypes.Preimage, error) {
|
||||||
|
|
||||||
preimage, err := genPreimage()
|
preimage, err := genPreimage()
|
||||||
@ -54,8 +54,8 @@ func genInfo() (*PaymentCreationInfo, *PaymentAttemptInfo,
|
|||||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||||
PaymentRequest: []byte("hola"),
|
PaymentRequest: []byte("hola"),
|
||||||
},
|
},
|
||||||
&PaymentAttemptInfo{
|
&HTLCAttemptInfo{
|
||||||
PaymentID: 1,
|
AttemptID: 1,
|
||||||
SessionKey: priv,
|
SessionKey: priv,
|
||||||
Route: testRoute,
|
Route: testRoute,
|
||||||
}, preimage, nil
|
}, preimage, nil
|
||||||
@ -119,7 +119,7 @@ func TestPaymentControlSwitchFail(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Record a new attempt.
|
// Record a new attempt.
|
||||||
attempt.PaymentID = 2
|
attempt.AttemptID = 2
|
||||||
err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to send htlc message: %v", err)
|
t.Fatalf("unable to send htlc message: %v", err)
|
||||||
@ -445,7 +445,7 @@ func checkPaymentCreationInfo(bucket *bbolt.Bucket, c *PaymentCreationInfo) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkPaymentAttemptInfo(bucket *bbolt.Bucket, a *PaymentAttemptInfo) error {
|
func checkHTLCAttemptInfo(bucket *bbolt.Bucket, a *HTLCAttemptInfo) error {
|
||||||
b := bucket.Get(paymentAttemptInfoKey)
|
b := bucket.Get(paymentAttemptInfoKey)
|
||||||
switch {
|
switch {
|
||||||
case b == nil && a == nil:
|
case b == nil && a == nil:
|
||||||
@ -457,7 +457,7 @@ func checkPaymentAttemptInfo(bucket *bbolt.Bucket, a *PaymentAttemptInfo) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
r := bytes.NewReader(b)
|
r := bytes.NewReader(b)
|
||||||
a2, err := deserializePaymentAttemptInfo(r)
|
a2, err := deserializeHTLCAttemptInfo(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -508,7 +508,7 @@ func checkFailInfo(bucket *bbolt.Bucket, failReason *FailureReason) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertPaymentInfo(t *testing.T, db *DB, hash lntypes.Hash,
|
func assertPaymentInfo(t *testing.T, db *DB, hash lntypes.Hash,
|
||||||
c *PaymentCreationInfo, a *PaymentAttemptInfo, s lntypes.Preimage,
|
c *PaymentCreationInfo, a *HTLCAttemptInfo, s lntypes.Preimage,
|
||||||
f *FailureReason) {
|
f *FailureReason) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@ -535,7 +535,7 @@ func assertPaymentInfo(t *testing.T, db *DB, hash lntypes.Hash,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := checkPaymentAttemptInfo(bucket, a); err != nil {
|
if err := checkHTLCAttemptInfo(bucket, a); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/coreos/bbolt"
|
"github.com/coreos/bbolt"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
@ -185,25 +184,9 @@ type PaymentCreationInfo struct {
|
|||||||
PaymentRequest []byte
|
PaymentRequest []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// PaymentAttemptInfo contains information about a specific payment attempt for
|
|
||||||
// a given 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
|
|
||||||
// status of a payment. For settled payment this will be the information for
|
|
||||||
// the succeeding payment attempt.
|
|
||||||
type PaymentAttemptInfo struct {
|
|
||||||
// PaymentID is the unique ID used for this attempt.
|
|
||||||
PaymentID uint64
|
|
||||||
|
|
||||||
// SessionKey is the ephemeral key used for this payment attempt.
|
|
||||||
SessionKey *btcec.PrivateKey
|
|
||||||
|
|
||||||
// Route is the route attempted to send the HTLC.
|
|
||||||
Route route.Route
|
|
||||||
}
|
|
||||||
|
|
||||||
// Payment is a wrapper around a payment's PaymentCreationInfo,
|
// Payment is a wrapper around a payment's PaymentCreationInfo,
|
||||||
// PaymentAttemptInfo, and preimage. All payments will have the
|
// HTLCAttemptInfo, and preimage. All payments will have the
|
||||||
// PaymentCreationInfo set, the PaymentAttemptInfo will be set only if at least
|
// PaymentCreationInfo set, the HTLCAttemptInfo will be set only if at least
|
||||||
// one payment attempt has been made, while only completed payments will have a
|
// one payment attempt has been made, while only completed payments will have a
|
||||||
// non-zero payment preimage.
|
// non-zero payment preimage.
|
||||||
type Payment struct {
|
type Payment struct {
|
||||||
@ -221,7 +204,7 @@ type Payment struct {
|
|||||||
// Attempt is the information about the last payment attempt made.
|
// Attempt is the information about the last payment attempt made.
|
||||||
//
|
//
|
||||||
// NOTE: Can be nil if no attempt is yet made.
|
// NOTE: Can be nil if no attempt is yet made.
|
||||||
Attempt *PaymentAttemptInfo
|
Attempt *HTLCAttemptInfo
|
||||||
|
|
||||||
// Preimage is the preimage of a successful payment. This serves as a
|
// Preimage is the preimage of a successful payment. This serves as a
|
||||||
// proof of payment. It will only be non-nil for settled payments.
|
// proof of payment. It will only be non-nil for settled payments.
|
||||||
@ -272,9 +255,7 @@ func (p *Payment) ToMPPayment() *MPPayment {
|
|||||||
// NOTE: AttemptTime is not set for legacy payments.
|
// NOTE: AttemptTime is not set for legacy payments.
|
||||||
htlcs = []HTLCAttempt{
|
htlcs = []HTLCAttempt{
|
||||||
{
|
{
|
||||||
PaymentID: p.Attempt.PaymentID,
|
HTLCAttemptInfo: *p.Attempt,
|
||||||
SessionKey: p.Attempt.SessionKey,
|
|
||||||
Route: p.Attempt.Route,
|
|
||||||
Settle: settle,
|
Settle: settle,
|
||||||
Failure: failure,
|
Failure: failure,
|
||||||
},
|
},
|
||||||
@ -392,11 +373,11 @@ func fetchPayment(bucket *bbolt.Bucket) (*MPPayment, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the PaymentAttemptInfo. This can be unset.
|
// Get the HTLCAttemptInfo. This can be unset.
|
||||||
b = bucket.Get(paymentAttemptInfoKey)
|
b = bucket.Get(paymentAttemptInfoKey)
|
||||||
if b != nil {
|
if b != nil {
|
||||||
r = bytes.NewReader(b)
|
r = bytes.NewReader(b)
|
||||||
p.Attempt, err = deserializePaymentAttemptInfo(r)
|
p.Attempt, err = deserializeHTLCAttemptInfo(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -527,8 +508,8 @@ func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func serializePaymentAttemptInfo(w io.Writer, a *PaymentAttemptInfo) error {
|
func serializeHTLCAttemptInfo(w io.Writer, a *HTLCAttemptInfo) error {
|
||||||
if err := WriteElements(w, a.PaymentID, a.SessionKey); err != nil {
|
if err := WriteElements(w, a.AttemptID, a.SessionKey); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,9 +520,9 @@ func serializePaymentAttemptInfo(w io.Writer, a *PaymentAttemptInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deserializePaymentAttemptInfo(r io.Reader) (*PaymentAttemptInfo, error) {
|
func deserializeHTLCAttemptInfo(r io.Reader) (*HTLCAttemptInfo, error) {
|
||||||
a := &PaymentAttemptInfo{}
|
a := &HTLCAttemptInfo{}
|
||||||
err := ReadElements(r, &a.PaymentID, &a.SessionKey)
|
err := ReadElements(r, &a.AttemptID, &a.SessionKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeFakeInfo() (*PaymentCreationInfo, *PaymentAttemptInfo) {
|
func makeFakeInfo() (*PaymentCreationInfo, *HTLCAttemptInfo) {
|
||||||
var preimg lntypes.Preimage
|
var preimg lntypes.Preimage
|
||||||
copy(preimg[:], rev[:])
|
copy(preimg[:], rev[:])
|
||||||
|
|
||||||
@ -66,8 +66,8 @@ func makeFakeInfo() (*PaymentCreationInfo, *PaymentAttemptInfo) {
|
|||||||
PaymentRequest: []byte(""),
|
PaymentRequest: []byte(""),
|
||||||
}
|
}
|
||||||
|
|
||||||
a := &PaymentAttemptInfo{
|
a := &HTLCAttemptInfo{
|
||||||
PaymentID: 44,
|
AttemptID: 44,
|
||||||
SessionKey: priv,
|
SessionKey: priv,
|
||||||
Route: testRoute,
|
Route: testRoute,
|
||||||
}
|
}
|
||||||
@ -109,11 +109,11 @@ func TestSentPaymentSerialization(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.Reset()
|
b.Reset()
|
||||||
if err := serializePaymentAttemptInfo(&b, s); err != nil {
|
if err := serializeHTLCAttemptInfo(&b, s); err != nil {
|
||||||
t.Fatalf("unable to serialize info: %v", err)
|
t.Fatalf("unable to serialize info: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newAttemptInfo, err := deserializePaymentAttemptInfo(&b)
|
newAttemptInfo, err := deserializeHTLCAttemptInfo(&b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to deserialize info: %v", err)
|
t.Fatalf("unable to deserialize info: %v", err)
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ func TestSentPaymentSerialization(t *testing.T) {
|
|||||||
// they are not equal.
|
// they are not equal.
|
||||||
func assertRouteEqual(a, b *route.Route) error {
|
func assertRouteEqual(a, b *route.Route) error {
|
||||||
if !reflect.DeepEqual(a, b) {
|
if !reflect.DeepEqual(a, b) {
|
||||||
return fmt.Errorf("PaymentAttemptInfos don't match: %v vs %v",
|
return fmt.Errorf("HTLCAttemptInfos don't match: %v vs %v",
|
||||||
spew.Sdump(a), spew.Sdump(b))
|
spew.Sdump(a), spew.Sdump(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ type ControlTower interface {
|
|||||||
// hash.
|
// hash.
|
||||||
InitPayment(lntypes.Hash, *channeldb.PaymentCreationInfo) error
|
InitPayment(lntypes.Hash, *channeldb.PaymentCreationInfo) error
|
||||||
|
|
||||||
// RegisterAttempt atomically records the provided PaymentAttemptInfo.
|
// RegisterAttempt atomically records the provided HTLCAttemptInfo.
|
||||||
RegisterAttempt(lntypes.Hash, *channeldb.PaymentAttemptInfo) error
|
RegisterAttempt(lntypes.Hash, *channeldb.HTLCAttemptInfo) error
|
||||||
|
|
||||||
// Success transitions a payment into the Succeeded state. After
|
// Success transitions a payment into the Succeeded state. After
|
||||||
// invoking this method, InitPayment should always return an error to
|
// invoking this method, InitPayment should always return an error to
|
||||||
@ -91,10 +91,10 @@ func (p *controlTower) InitPayment(paymentHash lntypes.Hash,
|
|||||||
return p.db.InitPayment(paymentHash, info)
|
return p.db.InitPayment(paymentHash, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterAttempt atomically records the provided PaymentAttemptInfo to the
|
// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
|
||||||
// DB.
|
// DB.
|
||||||
func (p *controlTower) RegisterAttempt(paymentHash lntypes.Hash,
|
func (p *controlTower) RegisterAttempt(paymentHash lntypes.Hash,
|
||||||
attempt *channeldb.PaymentAttemptInfo) error {
|
attempt *channeldb.HTLCAttemptInfo) error {
|
||||||
|
|
||||||
return p.db.RegisterAttempt(paymentHash, attempt)
|
return p.db.RegisterAttempt(paymentHash, attempt)
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ func initDB() (*channeldb.DB, error) {
|
|||||||
return db, err
|
return db, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.PaymentAttemptInfo,
|
func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.HTLCAttemptInfo,
|
||||||
lntypes.Preimage, error) {
|
lntypes.Preimage, error) {
|
||||||
|
|
||||||
preimage, err := genPreimage()
|
preimage, err := genPreimage()
|
||||||
@ -314,8 +314,8 @@ func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.PaymentAttemptInfo,
|
|||||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||||
PaymentRequest: []byte("hola"),
|
PaymentRequest: []byte("hola"),
|
||||||
},
|
},
|
||||||
&channeldb.PaymentAttemptInfo{
|
&channeldb.HTLCAttemptInfo{
|
||||||
PaymentID: 1,
|
AttemptID: 1,
|
||||||
SessionKey: priv,
|
SessionKey: priv,
|
||||||
Route: testRoute,
|
Route: testRoute,
|
||||||
}, preimage, nil
|
}, preimage, nil
|
||||||
|
@ -178,7 +178,7 @@ type initArgs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type registerArgs struct {
|
type registerArgs struct {
|
||||||
a *channeldb.PaymentAttemptInfo
|
a *channeldb.HTLCAttemptInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type successArgs struct {
|
type successArgs struct {
|
||||||
@ -238,7 +238,7 @@ func (m *mockControlTower) InitPayment(phash lntypes.Hash,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
|
func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
|
||||||
a *channeldb.PaymentAttemptInfo) error {
|
a *channeldb.HTLCAttemptInfo) error {
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
@ -35,7 +35,7 @@ type paymentLifecycle struct {
|
|||||||
timeoutChan <-chan time.Time
|
timeoutChan <-chan time.Time
|
||||||
currentHeight int32
|
currentHeight int32
|
||||||
finalCLTVDelta uint16
|
finalCLTVDelta uint16
|
||||||
attempt *channeldb.PaymentAttemptInfo
|
attempt *channeldb.HTLCAttemptInfo
|
||||||
circuit *sphinx.Circuit
|
circuit *sphinx.Circuit
|
||||||
lastError error
|
lastError error
|
||||||
}
|
}
|
||||||
@ -97,17 +97,17 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
// Now ask the switch to return the result of the payment when
|
// Now ask the switch to return the result of the payment when
|
||||||
// available.
|
// available.
|
||||||
resultChan, err := p.router.cfg.Payer.GetPaymentResult(
|
resultChan, err := p.router.cfg.Payer.GetPaymentResult(
|
||||||
p.attempt.PaymentID, p.payment.PaymentHash, errorDecryptor,
|
p.attempt.AttemptID, p.payment.PaymentHash, errorDecryptor,
|
||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
// If this payment ID is unknown to the Switch, it means it was
|
// If this attempt ID is unknown to the Switch, it means it was
|
||||||
// never checkpointed and forwarded by the switch before a
|
// never checkpointed and forwarded by the switch before a
|
||||||
// restart. In this case we can safely send a new payment
|
// restart. In this case we can safely send a new payment
|
||||||
// attempt, and wait for its result to be available.
|
// attempt, and wait for its result to be available.
|
||||||
case err == htlcswitch.ErrPaymentIDNotFound:
|
case err == htlcswitch.ErrPaymentIDNotFound:
|
||||||
log.Debugf("Payment ID %v for hash %x not found in "+
|
log.Debugf("Payment ID %v for hash %x not found in "+
|
||||||
"the Switch, retrying.", p.attempt.PaymentID,
|
"the Switch, retrying.", p.attempt.AttemptID,
|
||||||
p.payment.PaymentHash)
|
p.payment.PaymentHash)
|
||||||
|
|
||||||
// Reset the attempt to indicate we want to make a new
|
// Reset the attempt to indicate we want to make a new
|
||||||
@ -117,8 +117,8 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
|
|
||||||
// A critical, unexpected error was encountered.
|
// A critical, unexpected error was encountered.
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Errorf("Failed getting result for paymentID %d "+
|
log.Errorf("Failed getting result for attemptID %d "+
|
||||||
"from switch: %v", p.attempt.PaymentID, err)
|
"from switch: %v", p.attempt.AttemptID, err)
|
||||||
|
|
||||||
return [32]byte{}, nil, err
|
return [32]byte{}, nil, err
|
||||||
}
|
}
|
||||||
@ -161,11 +161,11 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
|
|
||||||
// We successfully got a payment result back from the switch.
|
// We successfully got a payment result back from the switch.
|
||||||
log.Debugf("Payment %x succeeded with pid=%v",
|
log.Debugf("Payment %x succeeded with pid=%v",
|
||||||
p.payment.PaymentHash, p.attempt.PaymentID)
|
p.payment.PaymentHash, p.attempt.AttemptID)
|
||||||
|
|
||||||
// Report success to mission control.
|
// Report success to mission control.
|
||||||
err = p.router.cfg.MissionControl.ReportPaymentSuccess(
|
err = p.router.cfg.MissionControl.ReportPaymentSuccess(
|
||||||
p.attempt.PaymentID, &p.attempt.Route,
|
p.attempt.AttemptID, &p.attempt.Route,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error reporting payment success to mc: %v",
|
log.Errorf("Error reporting payment success to mc: %v",
|
||||||
@ -331,21 +331,21 @@ func (p *paymentLifecycle) createNewPaymentAttempt() (lnwire.ShortChannelID,
|
|||||||
|
|
||||||
// We generate a new, unique payment ID that we will use for
|
// We generate a new, unique payment ID that we will use for
|
||||||
// this HTLC.
|
// this HTLC.
|
||||||
paymentID, err := p.router.cfg.NextPaymentID()
|
attemptID, err := p.router.cfg.NextPaymentID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return lnwire.ShortChannelID{}, nil, err
|
return lnwire.ShortChannelID{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We now have all the information needed to populate
|
// We now have all the information needed to populate
|
||||||
// the current attempt information.
|
// the current attempt information.
|
||||||
p.attempt = &channeldb.PaymentAttemptInfo{
|
p.attempt = &channeldb.HTLCAttemptInfo{
|
||||||
PaymentID: paymentID,
|
AttemptID: attemptID,
|
||||||
SessionKey: sessionKey,
|
SessionKey: sessionKey,
|
||||||
Route: *rt,
|
Route: *rt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before sending this HTLC to the switch, we checkpoint the
|
// Before sending this HTLC to the switch, we checkpoint the
|
||||||
// fresh paymentID and route to the DB. This lets us know on
|
// fresh attemptID and route to the DB. This lets us know on
|
||||||
// startup the ID of the payment that we attempted to send,
|
// startup the ID of the payment that we attempted to send,
|
||||||
// such that we can query the Switch for its whereabouts. The
|
// such that we can query the Switch for its whereabouts. The
|
||||||
// route is needed to handle the result when it eventually
|
// route is needed to handle the result when it eventually
|
||||||
@ -363,7 +363,7 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID,
|
|||||||
htlcAdd *lnwire.UpdateAddHTLC) error {
|
htlcAdd *lnwire.UpdateAddHTLC) error {
|
||||||
|
|
||||||
log.Tracef("Attempting to send payment %x (pid=%v), "+
|
log.Tracef("Attempting to send payment %x (pid=%v), "+
|
||||||
"using route: %v", p.payment.PaymentHash, p.attempt.PaymentID,
|
"using route: %v", p.payment.PaymentHash, p.attempt.AttemptID,
|
||||||
newLogClosure(func() string {
|
newLogClosure(func() string {
|
||||||
return spew.Sdump(p.attempt.Route)
|
return spew.Sdump(p.attempt.Route)
|
||||||
}),
|
}),
|
||||||
@ -374,17 +374,17 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID,
|
|||||||
// such that we can resume waiting for the result after a
|
// such that we can resume waiting for the result after a
|
||||||
// restart.
|
// restart.
|
||||||
err := p.router.cfg.Payer.SendHTLC(
|
err := p.router.cfg.Payer.SendHTLC(
|
||||||
firstHop, p.attempt.PaymentID, htlcAdd,
|
firstHop, p.attempt.AttemptID, htlcAdd,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed sending attempt %d for payment "+
|
log.Errorf("Failed sending attempt %d for payment "+
|
||||||
"%x to switch: %v", p.attempt.PaymentID,
|
"%x to switch: %v", p.attempt.AttemptID,
|
||||||
p.payment.PaymentHash, err)
|
p.payment.PaymentHash, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Payment %x (pid=%v) successfully sent to switch, route: %v",
|
log.Debugf("Payment %x (pid=%v) successfully sent to switch, route: %v",
|
||||||
p.payment.PaymentHash, p.attempt.PaymentID, &p.attempt.Route)
|
p.payment.PaymentHash, p.attempt.AttemptID, &p.attempt.Route)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -394,7 +394,7 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID,
|
|||||||
func (p *paymentLifecycle) handleSendError(sendErr error) error {
|
func (p *paymentLifecycle) handleSendError(sendErr error) error {
|
||||||
|
|
||||||
reason := p.router.processSendError(
|
reason := p.router.processSendError(
|
||||||
p.attempt.PaymentID, &p.attempt.Route, sendErr,
|
p.attempt.AttemptID, &p.attempt.Route, sendErr,
|
||||||
)
|
)
|
||||||
if reason == nil {
|
if reason == nil {
|
||||||
// Save the forwarding error so it can be returned if
|
// Save the forwarding error so it can be returned if
|
||||||
|
@ -1768,7 +1768,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
|
|||||||
// router will call this method for every payment still in-flight according to
|
// router will call this method for every payment still in-flight according to
|
||||||
// the ControlTower.
|
// the ControlTower.
|
||||||
func (r *ChannelRouter) sendPayment(
|
func (r *ChannelRouter) sendPayment(
|
||||||
existingAttempt *channeldb.PaymentAttemptInfo,
|
existingAttempt *channeldb.HTLCAttemptInfo,
|
||||||
payment *LightningPayment, paySession PaymentSession) (
|
payment *LightningPayment, paySession PaymentSession) (
|
||||||
[32]byte, *route.Route, error) {
|
[32]byte, *route.Route, error) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user