routing: use Identifier in place of PaymentHash
Since we want to support AMP payment using a different unique payment identifier (AMP payments don't go to one specific hash), we change the nomenclature to be Identifier instead of PaymentHash.
This commit is contained in:
parent
6104d12cf8
commit
f07c9d002c
@ -99,7 +99,7 @@ func deserializeDuplicatePaymentCreationInfo(r io.Reader) (
|
||||
|
||||
c := &PaymentCreationInfo{}
|
||||
|
||||
if _, err := io.ReadFull(r, c.PaymentHash[:]); err != nil {
|
||||
if _, err := io.ReadFull(r, c.PaymentIdentifier[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -173,8 +173,10 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
|
||||
|
||||
// Once we have obtained a sequence number, we add an entry
|
||||
// to our index bucket which will map the sequence number to
|
||||
// our payment hash.
|
||||
err = createPaymentIndexEntry(tx, sequenceNum, info.PaymentHash)
|
||||
// our payment identifier.
|
||||
err = createPaymentIndexEntry(
|
||||
tx, sequenceNum, info.PaymentIdentifier,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -220,12 +222,12 @@ const paymentIndexTypeHash paymentIndexType = 0
|
||||
|
||||
// createPaymentIndexEntry creates a payment hash typed index for a payment. The
|
||||
// index produced contains a payment index type (which can be used in future to
|
||||
// signal different payment index types) and the payment hash.
|
||||
// signal different payment index types) and the payment identifier.
|
||||
func createPaymentIndexEntry(tx kvdb.RwTx, sequenceNumber []byte,
|
||||
hash lntypes.Hash) error {
|
||||
id lntypes.Hash) error {
|
||||
|
||||
var b bytes.Buffer
|
||||
if err := WriteElements(&b, paymentIndexTypeHash, hash[:]); err != nil {
|
||||
if err := WriteElements(&b, paymentIndexTypeHash, id[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -38,10 +38,10 @@ func genInfo() (*PaymentCreationInfo, *HTLCAttemptInfo,
|
||||
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
return &PaymentCreationInfo{
|
||||
PaymentHash: rhash,
|
||||
Value: testRoute.ReceiverAmt(),
|
||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||
PaymentRequest: []byte("hola"),
|
||||
PaymentIdentifier: rhash,
|
||||
Value: testRoute.ReceiverAmt(),
|
||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||
PaymentRequest: []byte("hola"),
|
||||
},
|
||||
&HTLCAttemptInfo{
|
||||
AttemptID: 0,
|
||||
@ -70,63 +70,63 @@ func TestPaymentControlSwitchFail(t *testing.T) {
|
||||
}
|
||||
|
||||
// Sends base htlc message which initiate StatusInFlight.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
|
||||
assertPaymentIndex(t, pControl, info.PaymentHash)
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentIndex(t, pControl, info.PaymentIdentifier)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, nil,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, nil,
|
||||
)
|
||||
|
||||
// Fail the payment, which should moved it to Failed.
|
||||
failReason := FailureReasonNoRoute
|
||||
_, err = pControl.Fail(info.PaymentHash, failReason)
|
||||
_, err = pControl.Fail(info.PaymentIdentifier, failReason)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail payment hash: %v", err)
|
||||
}
|
||||
|
||||
// Verify the status is indeed Failed.
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusFailed)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusFailed)
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, &failReason, nil,
|
||||
t, pControl, info.PaymentIdentifier, info, &failReason, nil,
|
||||
)
|
||||
|
||||
// Lookup the payment so we can get its old sequence number before it is
|
||||
// overwritten.
|
||||
payment, err := pControl.FetchPayment(info.PaymentHash)
|
||||
payment, err := pControl.FetchPayment(info.PaymentIdentifier)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Sends the htlc again, which should succeed since the prior payment
|
||||
// failed.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
|
||||
// Check that our index has been updated, and the old index has been
|
||||
// removed.
|
||||
assertPaymentIndex(t, pControl, info.PaymentHash)
|
||||
assertPaymentIndex(t, pControl, info.PaymentIdentifier)
|
||||
assertNoIndex(t, pControl, payment.SequenceNum)
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, nil,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, nil,
|
||||
)
|
||||
|
||||
// Record a new attempt. In this test scenario, the attempt fails.
|
||||
// However, this is not communicated to control tower in the current
|
||||
// implementation. It only registers the initiation of the attempt.
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register attempt: %v", err)
|
||||
}
|
||||
|
||||
htlcReason := HTLCFailUnreadable
|
||||
_, err = pControl.FailAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcReason,
|
||||
},
|
||||
@ -134,35 +134,35 @@ func TestPaymentControlSwitchFail(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
|
||||
htlc := &htlcStatus{
|
||||
HTLCAttemptInfo: attempt,
|
||||
failure: &htlcReason,
|
||||
}
|
||||
|
||||
assertPaymentInfo(t, pControl, info.PaymentHash, info, nil, htlc)
|
||||
assertPaymentInfo(t, pControl, info.PaymentIdentifier, info, nil, htlc)
|
||||
|
||||
// Record another attempt.
|
||||
attempt.AttemptID = 1
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
|
||||
htlc = &htlcStatus{
|
||||
HTLCAttemptInfo: attempt,
|
||||
}
|
||||
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
|
||||
// Settle the attempt and verify that status was changed to
|
||||
// StatusSucceeded.
|
||||
payment, err = pControl.SettleAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@ -183,16 +183,16 @@ func TestPaymentControlSwitchFail(t *testing.T) {
|
||||
spew.Sdump(payment.HTLCs[0].Route), err)
|
||||
}
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusSucceeded)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusSucceeded)
|
||||
|
||||
htlc.settle = &preimg
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
|
||||
// Attempt a final payment, which should now fail since the prior
|
||||
// payment succeed.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != ErrAlreadyPaid {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
@ -219,42 +219,42 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
|
||||
|
||||
// Sends base htlc message which initiate base status and move it to
|
||||
// StatusInFlight and verifies that it was changed.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
|
||||
assertPaymentIndex(t, pControl, info.PaymentHash)
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentIndex(t, pControl, info.PaymentIdentifier)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, nil,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, nil,
|
||||
)
|
||||
|
||||
// Try to initiate double sending of htlc message with the same
|
||||
// payment hash, should result in error indicating that payment has
|
||||
// already been sent.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != ErrPaymentInFlight {
|
||||
t.Fatalf("payment control wrong behaviour: " +
|
||||
"double sending must trigger ErrPaymentInFlight error")
|
||||
}
|
||||
|
||||
// Record an attempt.
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
|
||||
htlc := &htlcStatus{
|
||||
HTLCAttemptInfo: attempt,
|
||||
}
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
|
||||
// Sends base htlc message which initiate StatusInFlight.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != ErrPaymentInFlight {
|
||||
t.Fatalf("payment control wrong behaviour: " +
|
||||
"double sending must trigger ErrPaymentInFlight error")
|
||||
@ -262,7 +262,7 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
|
||||
|
||||
// After settling, the error should be ErrAlreadyPaid.
|
||||
_, err = pControl.SettleAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@ -270,12 +270,12 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("error shouldn't have been received, got: %v", err)
|
||||
}
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusSucceeded)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusSucceeded)
|
||||
|
||||
htlc.settle = &preimg
|
||||
assertPaymentInfo(t, pControl, info.PaymentHash, info, nil, htlc)
|
||||
assertPaymentInfo(t, pControl, info.PaymentIdentifier, info, nil, htlc)
|
||||
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != ErrAlreadyPaid {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
@ -302,7 +302,7 @@ func TestPaymentControlSuccessesWithoutInFlight(t *testing.T) {
|
||||
|
||||
// Attempt to complete the payment should fail.
|
||||
_, err = pControl.SettleAttempt(
|
||||
info.PaymentHash, 0,
|
||||
info.PaymentIdentifier, 0,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@ -311,7 +311,7 @@ func TestPaymentControlSuccessesWithoutInFlight(t *testing.T) {
|
||||
t.Fatalf("expected ErrPaymentNotInitiated, got %v", err)
|
||||
}
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusUnknown)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusUnknown)
|
||||
}
|
||||
|
||||
// TestPaymentControlFailsWithoutInFlight checks that a strict payment
|
||||
@ -334,12 +334,12 @@ func TestPaymentControlFailsWithoutInFlight(t *testing.T) {
|
||||
}
|
||||
|
||||
// Calling Fail should return an error.
|
||||
_, err = pControl.Fail(info.PaymentHash, FailureReasonNoRoute)
|
||||
_, err = pControl.Fail(info.PaymentIdentifier, FailureReasonNoRoute)
|
||||
if err != ErrPaymentNotInitiated {
|
||||
t.Fatalf("expected ErrPaymentNotInitiated, got %v", err)
|
||||
}
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusUnknown)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusUnknown)
|
||||
}
|
||||
|
||||
// TestPaymentControlDeleteNonInFlight checks that calling DeletePayments only
|
||||
@ -397,11 +397,11 @@ func TestPaymentControlDeleteNonInFligt(t *testing.T) {
|
||||
}
|
||||
|
||||
// Sends base htlc message which initiate StatusInFlight.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
@ -414,7 +414,7 @@ func TestPaymentControlDeleteNonInFligt(t *testing.T) {
|
||||
// Fail the payment attempt.
|
||||
htlcFailure := HTLCFailUnreadable
|
||||
_, err := pControl.FailAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFailure,
|
||||
},
|
||||
@ -425,23 +425,23 @@ func TestPaymentControlDeleteNonInFligt(t *testing.T) {
|
||||
|
||||
// Fail the payment, which should moved it to Failed.
|
||||
failReason := FailureReasonNoRoute
|
||||
_, err = pControl.Fail(info.PaymentHash, failReason)
|
||||
_, err = pControl.Fail(info.PaymentIdentifier, failReason)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail payment hash: %v", err)
|
||||
}
|
||||
|
||||
// Verify the status is indeed Failed.
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusFailed)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusFailed)
|
||||
|
||||
htlc.failure = &htlcFailure
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info,
|
||||
t, pControl, info.PaymentIdentifier, info,
|
||||
&failReason, htlc,
|
||||
)
|
||||
} else if p.success {
|
||||
// Verifies that status was changed to StatusSucceeded.
|
||||
_, err := pControl.SettleAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@ -450,18 +450,18 @@ func TestPaymentControlDeleteNonInFligt(t *testing.T) {
|
||||
t.Fatalf("error shouldn't have been received, got: %v", err)
|
||||
}
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusSucceeded)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusSucceeded)
|
||||
|
||||
htlc.settle = &preimg
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
|
||||
numSuccess++
|
||||
} else {
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
|
||||
numInflight++
|
||||
@ -471,7 +471,7 @@ func TestPaymentControlDeleteNonInFligt(t *testing.T) {
|
||||
// add one.
|
||||
if p.hasDuplicate {
|
||||
appendDuplicatePayment(
|
||||
t, pControl.db, info.PaymentHash,
|
||||
t, pControl.db, info.PaymentIdentifier,
|
||||
uint64(duplicateSeqNr), preimg,
|
||||
)
|
||||
duplicateSeqNr++
|
||||
@ -582,20 +582,20 @@ func TestPaymentControlDeletePayments(t *testing.T) {
|
||||
attemptID++
|
||||
|
||||
// Init the payment.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
|
||||
// Register and fail the first attempt for all three payments.
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
|
||||
htlcFailure := HTLCFailUnreadable
|
||||
_, err = pControl.FailAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFailure,
|
||||
},
|
||||
@ -609,7 +609,7 @@ func TestPaymentControlDeletePayments(t *testing.T) {
|
||||
attempt.AttemptID = attemptID
|
||||
attemptID++
|
||||
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
@ -620,7 +620,7 @@ func TestPaymentControlDeletePayments(t *testing.T) {
|
||||
case 0:
|
||||
htlcFailure := HTLCFailUnreadable
|
||||
_, err = pControl.FailAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFailure,
|
||||
},
|
||||
@ -630,7 +630,7 @@ func TestPaymentControlDeletePayments(t *testing.T) {
|
||||
}
|
||||
|
||||
failReason := FailureReasonNoRoute
|
||||
_, err = pControl.Fail(info.PaymentHash, failReason)
|
||||
_, err = pControl.Fail(info.PaymentIdentifier, failReason)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail payment hash: %v", err)
|
||||
}
|
||||
@ -638,7 +638,7 @@ func TestPaymentControlDeletePayments(t *testing.T) {
|
||||
// Settle the attempt
|
||||
case 1:
|
||||
_, err := pControl.SettleAttempt(
|
||||
info.PaymentHash, attempt.AttemptID,
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@ -807,15 +807,15 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
}
|
||||
|
||||
// Init the payment, moving it to the StatusInFlight state.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
|
||||
assertPaymentIndex(t, pControl, info.PaymentHash)
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentIndex(t, pControl, info.PaymentIdentifier)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, nil,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, nil,
|
||||
)
|
||||
|
||||
// Create three unique attempts we'll use for the test, and
|
||||
@ -834,19 +834,19 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
a.AttemptID = i
|
||||
attempts = append(attempts, &a)
|
||||
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &a)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &a)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
assertPaymentStatus(
|
||||
t, pControl, info.PaymentHash, StatusInFlight,
|
||||
t, pControl, info.PaymentIdentifier, StatusInFlight,
|
||||
)
|
||||
|
||||
htlc := &htlcStatus{
|
||||
HTLCAttemptInfo: &a,
|
||||
}
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
}
|
||||
|
||||
@ -855,7 +855,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
// will be too large.
|
||||
b := *attempt
|
||||
b.AttemptID = 3
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &b)
|
||||
if err != ErrValueExceedsAmt {
|
||||
t.Fatalf("expected ErrValueExceedsAmt, got: %v",
|
||||
err)
|
||||
@ -865,7 +865,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
a := attempts[1]
|
||||
htlcFail := HTLCFailUnreadable
|
||||
_, err = pControl.FailAttempt(
|
||||
info.PaymentHash, a.AttemptID,
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFail,
|
||||
},
|
||||
@ -879,11 +879,11 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
failure: &htlcFail,
|
||||
}
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
|
||||
// Payment should still be in-flight.
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
|
||||
// Depending on the test case, settle or fail the first attempt.
|
||||
a = attempts[0]
|
||||
@ -894,7 +894,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
var firstFailReason *FailureReason
|
||||
if test.settleFirst {
|
||||
_, err := pControl.SettleAttempt(
|
||||
info.PaymentHash, a.AttemptID,
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@ -907,11 +907,11 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
// Assert that the HTLC has had the preimage recorded.
|
||||
htlc.settle = &preimg
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
} else {
|
||||
_, err := pControl.FailAttempt(
|
||||
info.PaymentHash, a.AttemptID,
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFail,
|
||||
},
|
||||
@ -924,13 +924,13 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
// Assert the failure was recorded.
|
||||
htlc.failure = &htlcFail
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info, nil, htlc,
|
||||
t, pControl, info.PaymentIdentifier, info, nil, htlc,
|
||||
)
|
||||
|
||||
// We also record a payment level fail, to move it into
|
||||
// a terminal state.
|
||||
failReason := FailureReasonNoRoute
|
||||
_, err = pControl.Fail(info.PaymentHash, failReason)
|
||||
_, err = pControl.Fail(info.PaymentIdentifier, failReason)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail payment hash: %v", err)
|
||||
}
|
||||
@ -942,18 +942,18 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
|
||||
// The payment should still be considered in-flight, since there
|
||||
// is still an active HTLC.
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
|
||||
// Try to register yet another attempt. This should fail now
|
||||
// that the payment has reached a terminal condition.
|
||||
b = *attempt
|
||||
b.AttemptID = 3
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &b)
|
||||
if err != ErrPaymentTerminal {
|
||||
t.Fatalf("expected ErrPaymentTerminal, got: %v", err)
|
||||
}
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, StatusInFlight)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, StatusInFlight)
|
||||
|
||||
// Settle or fail the remaining attempt based on the testcase.
|
||||
a = attempts[2]
|
||||
@ -963,7 +963,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
if test.settleLast {
|
||||
// Settle the last outstanding attempt.
|
||||
_, err = pControl.SettleAttempt(
|
||||
info.PaymentHash, a.AttemptID,
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@ -975,13 +975,13 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
|
||||
htlc.settle = &preimg
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info,
|
||||
t, pControl, info.PaymentIdentifier, info,
|
||||
firstFailReason, htlc,
|
||||
)
|
||||
} else {
|
||||
// Fail the attempt.
|
||||
_, err := pControl.FailAttempt(
|
||||
info.PaymentHash, a.AttemptID,
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFail,
|
||||
},
|
||||
@ -994,7 +994,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
// Assert the failure was recorded.
|
||||
htlc.failure = &htlcFail
|
||||
assertPaymentInfo(
|
||||
t, pControl, info.PaymentHash, info,
|
||||
t, pControl, info.PaymentIdentifier, info,
|
||||
firstFailReason, htlc,
|
||||
)
|
||||
|
||||
@ -1003,7 +1003,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
// write a terminal failure to the database without
|
||||
// syncing.
|
||||
failReason := FailureReasonPaymentDetails
|
||||
_, err = pControl.Fail(info.PaymentHash, failReason)
|
||||
_, err = pControl.Fail(info.PaymentIdentifier, failReason)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail payment hash: %v", err)
|
||||
}
|
||||
@ -1017,10 +1017,10 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
finalStatus = StatusSucceeded
|
||||
}
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, finalStatus)
|
||||
assertPaymentStatus(t, pControl, info.PaymentIdentifier, finalStatus)
|
||||
|
||||
// Finally assert we cannot register more attempts.
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &b)
|
||||
require.Equal(t, ErrPaymentTerminal, err)
|
||||
}
|
||||
|
||||
@ -1053,7 +1053,7 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
// Init the payment.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
@ -1068,7 +1068,7 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
info.Value, [32]byte{1},
|
||||
)
|
||||
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
@ -1077,7 +1077,7 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
b := *attempt
|
||||
b.AttemptID = 1
|
||||
b.Route.FinalHop().MPP = nil
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &b)
|
||||
if err != ErrMPPayment {
|
||||
t.Fatalf("expected ErrMPPayment, got: %v", err)
|
||||
}
|
||||
@ -1086,7 +1086,7 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
b.Route.FinalHop().MPP = record.NewMPP(
|
||||
info.Value, [32]byte{2},
|
||||
)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &b)
|
||||
if err != ErrMPPPaymentAddrMismatch {
|
||||
t.Fatalf("expected ErrMPPPaymentAddrMismatch, got: %v", err)
|
||||
}
|
||||
@ -1095,7 +1095,7 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
b.Route.FinalHop().MPP = record.NewMPP(
|
||||
info.Value/2, [32]byte{1},
|
||||
)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &b)
|
||||
if err != ErrMPPTotalAmountMismatch {
|
||||
t.Fatalf("expected ErrMPPTotalAmountMismatch, got: %v", err)
|
||||
}
|
||||
@ -1107,13 +1107,13 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
t.Fatalf("unable to generate htlc message: %v", err)
|
||||
}
|
||||
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
|
||||
attempt.Route.FinalHop().MPP = nil
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send htlc message: %v", err)
|
||||
}
|
||||
@ -1125,7 +1125,7 @@ func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
info.Value, [32]byte{1},
|
||||
)
|
||||
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
_, err = pControl.RegisterAttempt(info.PaymentIdentifier, &b)
|
||||
if err != ErrNonMPPayment {
|
||||
t.Fatalf("expected ErrNonMPPayment, got: %v", err)
|
||||
}
|
||||
|
@ -216,8 +216,9 @@ func (ps PaymentStatus) String() string {
|
||||
// PaymentCreationInfo is the information necessary to have ready when
|
||||
// initiating a payment, moving it into state InFlight.
|
||||
type PaymentCreationInfo struct {
|
||||
// PaymentHash is the hash this payment is paying to.
|
||||
PaymentHash lntypes.Hash
|
||||
// PaymentIdentifier is the hash this payment is paying to in case of
|
||||
// non-AMP payments, and the SetID for AMP payments.
|
||||
PaymentIdentifier lntypes.Hash
|
||||
|
||||
// Value is the amount we are paying.
|
||||
Value lnwire.MilliSatoshi
|
||||
@ -856,7 +857,7 @@ func fetchSequenceNumbers(paymentBucket kvdb.RBucket) ([][]byte, error) {
|
||||
func serializePaymentCreationInfo(w io.Writer, c *PaymentCreationInfo) error {
|
||||
var scratch [8]byte
|
||||
|
||||
if _, err := w.Write(c.PaymentHash[:]); err != nil {
|
||||
if _, err := w.Write(c.PaymentIdentifier[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -886,7 +887,7 @@ func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, error) {
|
||||
|
||||
c := &PaymentCreationInfo{}
|
||||
|
||||
if _, err := io.ReadFull(r, c.PaymentHash[:]); err != nil {
|
||||
if _, err := io.ReadFull(r, c.PaymentIdentifier[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,8 @@ func makeFakeInfo() (*PaymentCreationInfo, *HTLCAttemptInfo) {
|
||||
hash := preimg.Hash()
|
||||
|
||||
c := &PaymentCreationInfo{
|
||||
PaymentHash: hash,
|
||||
Value: 1000,
|
||||
PaymentIdentifier: hash,
|
||||
Value: 1000,
|
||||
// Use single second precision to avoid false positive test
|
||||
// failures due to the monotonic time component.
|
||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||
@ -433,7 +433,7 @@ func TestQueryPayments(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create a new payment entry in the database.
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to initialize "+
|
||||
"payment in database: %v", err)
|
||||
@ -442,11 +442,11 @@ func TestQueryPayments(t *testing.T) {
|
||||
// Immediately delete the payment with index 2.
|
||||
if i == 1 {
|
||||
pmt, err := pControl.FetchPayment(
|
||||
info.PaymentHash,
|
||||
info.PaymentIdentifier,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
deletePayment(t, db, info.PaymentHash,
|
||||
deletePayment(t, db, info.PaymentIdentifier,
|
||||
pmt.SequenceNum)
|
||||
}
|
||||
|
||||
@ -456,13 +456,13 @@ func TestQueryPayments(t *testing.T) {
|
||||
// duplicate payments will always be succeeded.
|
||||
if i == (nonDuplicatePayments - 1) {
|
||||
pmt, err := pControl.FetchPayment(
|
||||
info.PaymentHash,
|
||||
info.PaymentIdentifier,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
appendDuplicatePayment(
|
||||
t, pControl.db,
|
||||
info.PaymentHash,
|
||||
info.PaymentIdentifier,
|
||||
pmt.SequenceNum+1,
|
||||
preimg,
|
||||
)
|
||||
@ -529,12 +529,12 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a new payment entry in the database.
|
||||
err = pControl.InitPayment(noDuplicates.PaymentHash, noDuplicates)
|
||||
err = pControl.InitPayment(noDuplicates.PaymentIdentifier, noDuplicates)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Fetch the payment so we can get its sequence nr.
|
||||
noDuplicatesPayment, err := pControl.FetchPayment(
|
||||
noDuplicates.PaymentHash,
|
||||
noDuplicates.PaymentIdentifier,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -543,12 +543,12 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a new payment entry in the database.
|
||||
err = pControl.InitPayment(hasDuplicates.PaymentHash, hasDuplicates)
|
||||
err = pControl.InitPayment(hasDuplicates.PaymentIdentifier, hasDuplicates)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Fetch the payment so we can get its sequence nr.
|
||||
hasDuplicatesPayment, err := pControl.FetchPayment(
|
||||
hasDuplicates.PaymentHash,
|
||||
hasDuplicates.PaymentIdentifier,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -561,10 +561,10 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
||||
|
||||
// Add two duplicates to our second payment.
|
||||
appendDuplicatePayment(
|
||||
t, db, hasDuplicates.PaymentHash, duplicateOneSeqNr, preimg,
|
||||
t, db, hasDuplicates.PaymentIdentifier, duplicateOneSeqNr, preimg,
|
||||
)
|
||||
appendDuplicatePayment(
|
||||
t, db, hasDuplicates.PaymentHash, duplicateTwoSeqNr, preimg,
|
||||
t, db, hasDuplicates.PaymentIdentifier, duplicateTwoSeqNr, preimg,
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
@ -575,37 +575,37 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "lookup payment without duplicates",
|
||||
paymentHash: noDuplicates.PaymentHash,
|
||||
paymentHash: noDuplicates.PaymentIdentifier,
|
||||
sequenceNumber: noDuplicatesPayment.SequenceNum,
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "lookup payment with duplicates",
|
||||
paymentHash: hasDuplicates.PaymentHash,
|
||||
paymentHash: hasDuplicates.PaymentIdentifier,
|
||||
sequenceNumber: hasDuplicatesPayment.SequenceNum,
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "lookup first duplicate",
|
||||
paymentHash: hasDuplicates.PaymentHash,
|
||||
paymentHash: hasDuplicates.PaymentIdentifier,
|
||||
sequenceNumber: duplicateOneSeqNr,
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "lookup second duplicate",
|
||||
paymentHash: hasDuplicates.PaymentHash,
|
||||
paymentHash: hasDuplicates.PaymentIdentifier,
|
||||
sequenceNumber: duplicateTwoSeqNr,
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "lookup non-existent duplicate",
|
||||
paymentHash: hasDuplicates.PaymentHash,
|
||||
paymentHash: hasDuplicates.PaymentIdentifier,
|
||||
sequenceNumber: 999999,
|
||||
expectedErr: ErrDuplicateNotFound,
|
||||
},
|
||||
{
|
||||
name: "lookup duplicate, no duplicates bucket",
|
||||
paymentHash: noDuplicates.PaymentHash,
|
||||
paymentHash: noDuplicates.PaymentIdentifier,
|
||||
sequenceNumber: duplicateTwoSeqNr,
|
||||
expectedErr: ErrNoDuplicateBucket,
|
||||
},
|
||||
|
@ -698,7 +698,11 @@ func (r *RouterBackend) extractIntentFromSendRequest(
|
||||
payIntent.MaxParts = 1
|
||||
}
|
||||
|
||||
copy(payIntent.PaymentHash[:], payReq.PaymentHash[:])
|
||||
err = payIntent.SetPaymentHash(*payReq.PaymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
destKey := payReq.Destination.SerializeCompressed()
|
||||
copy(payIntent.Target[:], destKey)
|
||||
|
||||
@ -737,7 +741,15 @@ func (r *RouterBackend) extractIntentFromSendRequest(
|
||||
payIntent.Amount = reqAmt
|
||||
|
||||
// Payment hash.
|
||||
copy(payIntent.PaymentHash[:], rpcPayReq.PaymentHash)
|
||||
paymentHash, err := lntypes.MakeHash(rpcPayReq.PaymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = payIntent.SetPaymentHash(paymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Parse destination feature bits.
|
||||
features, err := UnmarshalFeatures(rpcPayReq.DestFeatures)
|
||||
@ -1217,7 +1229,7 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
|
||||
htlcs = append(htlcs, htlc)
|
||||
}
|
||||
|
||||
paymentHash := payment.Info.PaymentHash
|
||||
paymentID := payment.Info.PaymentIdentifier
|
||||
creationTimeNS := MarshalTimeNano(payment.Info.CreationTime)
|
||||
|
||||
failureReason, err := marshallPaymentFailureReason(
|
||||
@ -1228,7 +1240,8 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
|
||||
}
|
||||
|
||||
return &lnrpc.Payment{
|
||||
PaymentHash: hex.EncodeToString(paymentHash[:]),
|
||||
// TODO: set this to setID for AMP-payments?
|
||||
PaymentHash: hex.EncodeToString(paymentID[:]),
|
||||
Value: satValue,
|
||||
ValueMsat: msatValue,
|
||||
ValueSat: satValue,
|
||||
|
@ -316,21 +316,21 @@ func (s *Server) SendPaymentV2(req *SendPaymentRequest,
|
||||
if err == channeldb.ErrPaymentInFlight ||
|
||||
err == channeldb.ErrAlreadyPaid {
|
||||
|
||||
log.Debugf("SendPayment async result for hash %x: %v",
|
||||
payment.PaymentHash, err)
|
||||
log.Debugf("SendPayment async result for payment %x: %v",
|
||||
payment.Identifier(), err)
|
||||
|
||||
return status.Error(
|
||||
codes.AlreadyExists, err.Error(),
|
||||
)
|
||||
}
|
||||
|
||||
log.Errorf("SendPayment async error for hash %x: %v",
|
||||
payment.PaymentHash, err)
|
||||
log.Errorf("SendPayment async error for payment %x: %v",
|
||||
payment.Identifier(), err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return s.trackPayment(payment.PaymentHash, stream, req.NoInflightUpdates)
|
||||
return s.trackPayment(payment.Identifier(), stream, req.NoInflightUpdates)
|
||||
}
|
||||
|
||||
// EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it
|
||||
@ -719,14 +719,14 @@ func (s *Server) TrackPaymentV2(request *TrackPaymentRequest,
|
||||
}
|
||||
|
||||
// trackPayment writes payment status updates to the provided stream.
|
||||
func (s *Server) trackPayment(paymentHash lntypes.Hash,
|
||||
func (s *Server) trackPayment(identifier lntypes.Hash,
|
||||
stream Router_TrackPaymentV2Server, noInflightUpdates bool) error {
|
||||
|
||||
router := s.cfg.RouterBackend
|
||||
|
||||
// Subscribe to the outcome of this payment.
|
||||
subscription, err := router.Tower.SubscribePayment(
|
||||
paymentHash,
|
||||
identifier,
|
||||
)
|
||||
switch {
|
||||
case err == channeldb.ErrPaymentNotInitiated:
|
||||
@ -769,7 +769,7 @@ func (s *Server) trackPayment(paymentHash lntypes.Hash,
|
||||
return errServerShuttingDown
|
||||
|
||||
case <-stream.Context().Done():
|
||||
log.Debugf("Payment status stream %v canceled", paymentHash)
|
||||
log.Debugf("Payment status stream %v canceled", identifier)
|
||||
return stream.Context().Err()
|
||||
}
|
||||
}
|
||||
|
@ -36,16 +36,16 @@
|
||||
<time> [ERR] CRTR: Failed sending attempt <number> for payment <hex> to switch: insufficient bandwidth to route htlc
|
||||
<time> [ERR] CRTR: Failed sending attempt <number> for payment <hex> to switch: UnknownNextPeer
|
||||
<time> [ERR] CRTR: out of order block: expecting height=<height>, got height=<height>
|
||||
<time> [ERR] CRTR: Payment with hash <hex> failed: error
|
||||
<time> [ERR] CRTR: Payment with hash <hex> failed: incorrect_payment_details
|
||||
<time> [ERR] CRTR: Payment with hash <hex> failed: insufficient_balance
|
||||
<time> [ERR] CRTR: Payment with hash <hex> failed: no_route
|
||||
<time> [ERR] CRTR: Payment with hash <hex> failed: router shutting down
|
||||
<time> [ERR] CRTR: Payment with hash <hex> failed: timeout
|
||||
<time> [ERR] CRTR: Resuming payment with hash <hex> failed: error.
|
||||
<time> [ERR] CRTR: Resuming payment with hash <hex> failed: incorrect_payment_details.
|
||||
<time> [ERR] CRTR: Resuming payment with hash <hex> failed: no_route.
|
||||
<time> [ERR] CRTR: Resuming payment with hash <hex> failed: router shutting down.
|
||||
<time> [ERR] CRTR: Payment <hex> failed: error
|
||||
<time> [ERR] CRTR: Payment <hex> failed: incorrect_payment_details
|
||||
<time> [ERR] CRTR: Payment <hex> failed: insufficient_balance
|
||||
<time> [ERR] CRTR: Payment <hex> failed: no_route
|
||||
<time> [ERR] CRTR: Payment <hex> failed: router shutting down
|
||||
<time> [ERR] CRTR: Payment <hex> failed: timeout
|
||||
<time> [ERR] CRTR: Resuming payment <hex> failed: error.
|
||||
<time> [ERR] CRTR: Resuming payment <hex> failed: incorrect_payment_details.
|
||||
<time> [ERR] CRTR: Resuming payment <hex> failed: no_route.
|
||||
<time> [ERR] CRTR: Resuming payment <hex> failed: router shutting down.
|
||||
<time> [ERR] CRTR: unable to add channel: edge not found
|
||||
<time> [ERR] CRTR: Unable to retrieve channel by id: edge not found
|
||||
<time> [ERR] DISC: channel announcement proof for short_chan_id=<cid> isn't valid: can't verify first bitcoin signature
|
||||
|
@ -79,26 +79,26 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Subscription should succeed and immediately report the InFlight
|
||||
// status.
|
||||
subscriber1, err := pControl.SubscribePayment(info.PaymentHash)
|
||||
subscriber1, err := pControl.SubscribePayment(info.PaymentIdentifier)
|
||||
if err != nil {
|
||||
t.Fatalf("expected subscribe to succeed, but got: %v", err)
|
||||
}
|
||||
|
||||
// Register an attempt.
|
||||
err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Register a second subscriber after the first attempt has started.
|
||||
subscriber2, err := pControl.SubscribePayment(info.PaymentHash)
|
||||
subscriber2, err := pControl.SubscribePayment(info.PaymentIdentifier)
|
||||
if err != nil {
|
||||
t.Fatalf("expected subscribe to succeed, but got: %v", err)
|
||||
}
|
||||
@ -108,7 +108,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
|
||||
Preimage: preimg,
|
||||
}
|
||||
htlcAttempt, err := pControl.SettleAttempt(
|
||||
info.PaymentHash, attempt.AttemptID, &settleInfo,
|
||||
info.PaymentIdentifier, attempt.AttemptID, &settleInfo,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -118,7 +118,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
// Register a third subscriber after the payment succeeded.
|
||||
subscriber3, err := pControl.SubscribePayment(info.PaymentHash)
|
||||
subscriber3, err := pControl.SubscribePayment(info.PaymentIdentifier)
|
||||
if err != nil {
|
||||
t.Fatalf("expected subscribe to succeed, but got: %v", err)
|
||||
}
|
||||
@ -196,13 +196,13 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = pControl.InitPayment(info.PaymentHash, info)
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Subscription should succeed.
|
||||
subscriber1, err := pControl.SubscribePayment(info.PaymentHash)
|
||||
subscriber1, err := pControl.SubscribePayment(info.PaymentIdentifier)
|
||||
if err != nil {
|
||||
t.Fatalf("expected subscribe to succeed, but got: %v", err)
|
||||
}
|
||||
@ -212,7 +212,7 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
|
||||
// making any attempts at all.
|
||||
if registerAttempt {
|
||||
// Register an attempt.
|
||||
err = pControl.RegisterAttempt(info.PaymentHash, attempt)
|
||||
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -222,7 +222,7 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
|
||||
Reason: channeldb.HTLCFailInternal,
|
||||
}
|
||||
htlcAttempt, err := pControl.FailAttempt(
|
||||
info.PaymentHash, attempt.AttemptID, &failInfo,
|
||||
info.PaymentIdentifier, attempt.AttemptID, &failInfo,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail htlc: %v", err)
|
||||
@ -233,12 +233,12 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
|
||||
}
|
||||
|
||||
// Mark the payment as failed.
|
||||
if err := pControl.Fail(info.PaymentHash, channeldb.FailureReasonTimeout); err != nil {
|
||||
if err := pControl.Fail(info.PaymentIdentifier, channeldb.FailureReasonTimeout); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Register a second subscriber after the payment failed.
|
||||
subscriber2, err := pControl.SubscribePayment(info.PaymentHash)
|
||||
subscriber2, err := pControl.SubscribePayment(info.PaymentIdentifier)
|
||||
if err != nil {
|
||||
t.Fatalf("expected subscribe to succeed, but got: %v", err)
|
||||
}
|
||||
@ -326,10 +326,10 @@ func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.HTLCAttemptInfo,
|
||||
|
||||
rhash := sha256.Sum256(preimage[:])
|
||||
return &channeldb.PaymentCreationInfo{
|
||||
PaymentHash: rhash,
|
||||
Value: testRoute.ReceiverAmt(),
|
||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||
PaymentRequest: []byte("hola"),
|
||||
PaymentIdentifier: rhash,
|
||||
Value: testRoute.ReceiverAmt(),
|
||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||
PaymentRequest: []byte("hola"),
|
||||
},
|
||||
&channeldb.HTLCAttemptInfo{
|
||||
AttemptID: 1,
|
||||
|
@ -152,6 +152,11 @@ func (c *integratedRoutingContext) testPayment(maxParts uint32,
|
||||
MaxParts: maxParts,
|
||||
}
|
||||
|
||||
var paymentHash [32]byte
|
||||
if err := payment.SetPaymentHash(paymentHash); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.maxShardAmt != nil {
|
||||
payment.MaxShardAmt = c.maxShardAmt
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ type paymentLifecycle struct {
|
||||
router *ChannelRouter
|
||||
totalAmount lnwire.MilliSatoshi
|
||||
feeLimit lnwire.MilliSatoshi
|
||||
paymentHash lntypes.Hash
|
||||
identifier lntypes.Hash
|
||||
paySession PaymentSession
|
||||
shardTracker shards.ShardTracker
|
||||
timeoutChan <-chan time.Time
|
||||
@ -86,7 +86,7 @@ func (p *paymentLifecycle) paymentState(payment *channeldb.MPPayment) (
|
||||
func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
||||
shardHandler := &shardHandler{
|
||||
router: p.router,
|
||||
paymentHash: p.paymentHash,
|
||||
identifier: p.identifier,
|
||||
shardTracker: p.shardTracker,
|
||||
shardErrors: make(chan error),
|
||||
quit: make(chan struct{}),
|
||||
@ -101,7 +101,7 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
||||
// up goroutines that'll collect their results and deliver them to the
|
||||
// lifecycle loop below.
|
||||
payment, err := p.router.cfg.Control.FetchPayment(
|
||||
p.paymentHash,
|
||||
p.identifier,
|
||||
)
|
||||
if err != nil {
|
||||
return [32]byte{}, nil, err
|
||||
@ -110,8 +110,8 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
||||
for _, a := range payment.InFlightHTLCs() {
|
||||
a := a
|
||||
|
||||
log.Infof("Resuming payment shard %v for hash %v",
|
||||
a.AttemptID, p.paymentHash)
|
||||
log.Infof("Resuming payment shard %v for payment %v",
|
||||
a.AttemptID, p.identifier)
|
||||
|
||||
shardHandler.collectResultAsync(&a.HTLCAttemptInfo)
|
||||
}
|
||||
@ -131,7 +131,7 @@ lifecycle:
|
||||
// act on the latest available information, whether we are
|
||||
// resuming an existing payment or just sent a new attempt.
|
||||
payment, err := p.router.cfg.Control.FetchPayment(
|
||||
p.paymentHash,
|
||||
p.identifier,
|
||||
)
|
||||
if err != nil {
|
||||
return [32]byte{}, nil, err
|
||||
@ -146,7 +146,7 @@ lifecycle:
|
||||
|
||||
log.Debugf("Payment %v in state terminate=%v, "+
|
||||
"active_shards=%v, rem_value=%v, fee_limit=%v",
|
||||
p.paymentHash, state.terminate, state.numShardsInFlight,
|
||||
p.identifier, state.terminate, state.numShardsInFlight,
|
||||
state.remainingAmt, state.remainingFees)
|
||||
|
||||
switch {
|
||||
@ -193,7 +193,7 @@ lifecycle:
|
||||
// return with an error the moment all active shards
|
||||
// have finished.
|
||||
saveErr := p.router.cfg.Control.Fail(
|
||||
p.paymentHash, channeldb.FailureReasonTimeout,
|
||||
p.identifier, channeldb.FailureReasonTimeout,
|
||||
)
|
||||
if saveErr != nil {
|
||||
return [32]byte{}, nil, saveErr
|
||||
@ -215,7 +215,7 @@ lifecycle:
|
||||
)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to find route for payment %v: %v",
|
||||
p.paymentHash, err)
|
||||
p.identifier, err)
|
||||
|
||||
routeErr, ok := err.(noRouteError)
|
||||
if !ok {
|
||||
@ -229,10 +229,10 @@ lifecycle:
|
||||
failureCode := routeErr.FailureReason()
|
||||
log.Debugf("Marking payment %v permanently "+
|
||||
"failed with no route: %v",
|
||||
p.paymentHash, failureCode)
|
||||
p.identifier, failureCode)
|
||||
|
||||
saveErr := p.router.cfg.Control.Fail(
|
||||
p.paymentHash, failureCode,
|
||||
p.identifier, failureCode,
|
||||
)
|
||||
if saveErr != nil {
|
||||
return [32]byte{}, nil, saveErr
|
||||
@ -261,8 +261,8 @@ lifecycle:
|
||||
// were pathfinding. We know we're in a terminal state here,
|
||||
// so we can continue and wait for our last shards to return.
|
||||
case err == channeldb.ErrPaymentTerminal:
|
||||
log.Infof("Payment: %v in terminal state, abandoning "+
|
||||
"shard", p.paymentHash)
|
||||
log.Infof("Payment %v in terminal state, abandoning "+
|
||||
"shard", p.identifier)
|
||||
|
||||
continue lifecycle
|
||||
|
||||
@ -275,7 +275,7 @@ lifecycle:
|
||||
if outcome.err != nil {
|
||||
log.Warnf("Failed to launch shard %v for "+
|
||||
"payment %v: %v", attempt.AttemptID,
|
||||
p.paymentHash, outcome.err)
|
||||
p.identifier, outcome.err)
|
||||
|
||||
// We must inspect the error to know whether it was
|
||||
// critical or not, to decide whether we should
|
||||
@ -301,7 +301,7 @@ lifecycle:
|
||||
// shardHandler holds what is necessary to send and collect the result of
|
||||
// shards.
|
||||
type shardHandler struct {
|
||||
paymentHash lntypes.Hash
|
||||
identifier lntypes.Hash
|
||||
router *ChannelRouter
|
||||
shardTracker shards.ShardTracker
|
||||
|
||||
@ -398,7 +398,7 @@ func (p *shardHandler) launchShard(rt *route.Route,
|
||||
// of the payment that we attempted to send, such that we can query the
|
||||
// Switch for its whereabouts. The route is needed to handle the result
|
||||
// when it eventually comes back.
|
||||
err = p.router.cfg.Control.RegisterAttempt(p.paymentHash, attempt)
|
||||
err = p.router.cfg.Control.RegisterAttempt(p.identifier, attempt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -450,7 +450,7 @@ func (p *shardHandler) collectResultAsync(attempt *channeldb.HTLCAttemptInfo) {
|
||||
|
||||
log.Errorf("Error collecting result for "+
|
||||
"shard %v for payment %v: %v",
|
||||
attempt.AttemptID, p.paymentHash, err)
|
||||
attempt.AttemptID, p.identifier, err)
|
||||
}
|
||||
|
||||
select {
|
||||
@ -515,7 +515,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
|
||||
// Now ask the switch to return the result of the payment when
|
||||
// available.
|
||||
resultChan, err := p.router.cfg.Payer.GetPaymentResult(
|
||||
attempt.AttemptID, p.paymentHash, errorDecryptor,
|
||||
attempt.AttemptID, p.identifier, errorDecryptor,
|
||||
)
|
||||
switch {
|
||||
|
||||
@ -524,9 +524,9 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
|
||||
// case we can safely send a new payment attempt, and wait for its
|
||||
// result to be available.
|
||||
case err == htlcswitch.ErrPaymentIDNotFound:
|
||||
log.Debugf("Payment ID %v for hash %v not found in "+
|
||||
log.Debugf("Attempt ID %v for payment %v not found in "+
|
||||
"the Switch, retrying.", attempt.AttemptID,
|
||||
p.paymentHash)
|
||||
p.identifier)
|
||||
|
||||
attempt, cErr := p.failAttempt(attempt, err)
|
||||
if cErr != nil {
|
||||
@ -582,7 +582,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
|
||||
|
||||
// We successfully got a payment result back from the switch.
|
||||
log.Debugf("Payment %v succeeded with pid=%v",
|
||||
p.paymentHash, attempt.AttemptID)
|
||||
p.identifier, attempt.AttemptID)
|
||||
|
||||
// Report success to mission control.
|
||||
err = p.router.cfg.MissionControl.ReportPaymentSuccess(
|
||||
@ -596,7 +596,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
|
||||
// In case of success we atomically store settle result to the DB move
|
||||
// the shard to the settled state.
|
||||
htlcAttempt, err := p.router.cfg.Control.SettleAttempt(
|
||||
p.paymentHash, attempt.AttemptID,
|
||||
p.identifier, attempt.AttemptID,
|
||||
&channeldb.HTLCSettleInfo{
|
||||
Preimage: result.Preimage,
|
||||
SettleTime: p.router.cfg.Clock.Now(),
|
||||
@ -696,7 +696,7 @@ func (p *shardHandler) sendPaymentAttempt(
|
||||
htlcAdd *lnwire.UpdateAddHTLC) error {
|
||||
|
||||
log.Tracef("Attempting to send payment %v (pid=%v), "+
|
||||
"using route: %v", p.paymentHash, attempt.AttemptID,
|
||||
"using route: %v", p.identifier, attempt.AttemptID,
|
||||
newLogClosure(func() string {
|
||||
return spew.Sdump(attempt.Route)
|
||||
}),
|
||||
@ -712,12 +712,12 @@ func (p *shardHandler) sendPaymentAttempt(
|
||||
if err != nil {
|
||||
log.Errorf("Failed sending attempt %d for payment "+
|
||||
"%v to switch: %v", attempt.AttemptID,
|
||||
p.paymentHash, err)
|
||||
p.identifier, err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("Payment %v (pid=%v) successfully sent to switch, route: %v",
|
||||
p.paymentHash, attempt.AttemptID, &attempt.Route)
|
||||
p.identifier, attempt.AttemptID, &attempt.Route)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -737,9 +737,9 @@ func (p *shardHandler) handleSendError(attempt *channeldb.HTLCAttemptInfo,
|
||||
}
|
||||
|
||||
log.Infof("Payment %v failed: final_outcome=%v, raw_err=%v",
|
||||
p.paymentHash, *reason, sendErr)
|
||||
p.identifier, *reason, sendErr)
|
||||
|
||||
err := p.router.cfg.Control.Fail(p.paymentHash, *reason)
|
||||
err := p.router.cfg.Control.Fail(p.identifier, *reason)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -752,7 +752,7 @@ func (p *shardHandler) failAttempt(attempt *channeldb.HTLCAttemptInfo,
|
||||
sendError error) (*channeldb.HTLCAttempt, error) {
|
||||
|
||||
log.Warnf("Attempt %v for payment %v failed: %v", attempt.AttemptID,
|
||||
p.paymentHash, sendError)
|
||||
p.identifier, sendError)
|
||||
|
||||
failInfo := marshallError(
|
||||
sendError,
|
||||
@ -767,7 +767,7 @@ func (p *shardHandler) failAttempt(attempt *channeldb.HTLCAttemptInfo,
|
||||
}
|
||||
|
||||
return p.router.cfg.Control.FailAttempt(
|
||||
p.paymentHash, attempt.AttemptID,
|
||||
p.identifier, attempt.AttemptID,
|
||||
failInfo,
|
||||
)
|
||||
}
|
||||
|
@ -815,7 +815,7 @@ func testPaymentLifecycle(t *testing.T, test paymentLifecycleTestCase,
|
||||
Target: testGraph.aliasMap["c"],
|
||||
Amount: paymentAmt,
|
||||
FeeLimit: noFeeLimit,
|
||||
PaymentHash: payHash,
|
||||
paymentHash: &payHash,
|
||||
}
|
||||
|
||||
// Setup our payment session source to block on release of
|
||||
|
@ -171,7 +171,7 @@ func newPaymentSession(p *LightningPayment,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logPrefix := fmt.Sprintf("PaymentSession(%x):", p.PaymentHash)
|
||||
logPrefix := fmt.Sprintf("PaymentSession(%x):", p.Identifier())
|
||||
|
||||
return &paymentSession{
|
||||
additionalEdges: edges,
|
||||
|
@ -23,6 +23,11 @@ func TestRequestRoute(t *testing.T) {
|
||||
FeeLimit: 1000,
|
||||
}
|
||||
|
||||
var paymentHash [32]byte
|
||||
if err := payment.SetPaymentHash(paymentHash); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
session, err := newPaymentSession(
|
||||
payment,
|
||||
func() (map[uint64]lnwire.MilliSatoshi,
|
||||
|
@ -600,7 +600,7 @@ func (r *ChannelRouter) Start() error {
|
||||
}
|
||||
|
||||
for _, payment := range payments {
|
||||
log.Infof("Resuming payment with hash %v", payment.Info.PaymentHash)
|
||||
log.Infof("Resuming payment %v", payment.Info.PaymentIdentifier)
|
||||
r.wg.Add(1)
|
||||
go func(payment *channeldb.MPPayment) {
|
||||
defer r.wg.Done()
|
||||
@ -613,7 +613,7 @@ func (r *ChannelRouter) Start() error {
|
||||
// We check whether the individual attempts
|
||||
// have their HTLC hash set, if not we'll fall
|
||||
// back to the overall payment hash.
|
||||
hash := payment.Info.PaymentHash
|
||||
hash := payment.Info.PaymentIdentifier
|
||||
if a.Hash != nil {
|
||||
hash = *a.Hash
|
||||
}
|
||||
@ -631,30 +631,32 @@ func (r *ChannelRouter) Start() error {
|
||||
// we don't currently persist the root share necessary
|
||||
// to re-derive them.
|
||||
shardTracker := shards.NewSimpleShardTracker(
|
||||
payment.Info.PaymentHash, htlcs,
|
||||
payment.Info.PaymentIdentifier, htlcs,
|
||||
)
|
||||
|
||||
// We create a dummy, empty payment session such that
|
||||
// we won't make another payment attempt when the
|
||||
// result for the in-flight attempt is received.
|
||||
paySession := r.cfg.SessionSource.NewPaymentSessionEmpty()
|
||||
|
||||
// We pass in a zero timeout value, to indicate we
|
||||
// don't need it to timeout. It will stop immediately
|
||||
// after the existing attempt has finished anyway. We
|
||||
// also set a zero fee limit, as no more routes should
|
||||
// be tried.
|
||||
_, _, err := r.sendPayment(
|
||||
payment.Info.Value, 0, payment.Info.PaymentHash,
|
||||
0, paySession, shardTracker,
|
||||
payment.Info.Value, 0,
|
||||
payment.Info.PaymentIdentifier, 0, paySession,
|
||||
shardTracker,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Resuming payment with hash %v "+
|
||||
"failed: %v.", payment.Info.PaymentHash, err)
|
||||
log.Errorf("Resuming payment %v failed: %v.",
|
||||
payment.Info.PaymentIdentifier, err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("Resumed payment with hash %v completed.",
|
||||
payment.Info.PaymentHash)
|
||||
log.Infof("Resumed payment %v completed.",
|
||||
payment.Info.PaymentIdentifier)
|
||||
}(payment)
|
||||
}
|
||||
|
||||
@ -1719,9 +1721,9 @@ type LightningPayment struct {
|
||||
// complete this payment.
|
||||
CltvLimit uint32
|
||||
|
||||
// PaymentHash is the r-hash value to use within the HTLC extended to
|
||||
// the first hop.
|
||||
PaymentHash [32]byte
|
||||
// paymentHash is the r-hash value to use within the HTLC extended to
|
||||
// the first hop. This won't be set for AMP payments.
|
||||
paymentHash *lntypes.Hash
|
||||
|
||||
// amp is an optional field that is set if and only if this is am AMP
|
||||
// payment.
|
||||
@ -1801,6 +1803,20 @@ type AMPOptions struct {
|
||||
RootShare [32]byte
|
||||
}
|
||||
|
||||
// SetPaymentHash sets the given hash as the payment's overall hash. This
|
||||
// should only be used for non-AMP payments.
|
||||
func (l *LightningPayment) SetPaymentHash(hash lntypes.Hash) error {
|
||||
l.paymentHash = &hash
|
||||
return nil
|
||||
}
|
||||
|
||||
// Identifier returns a 32-byte slice that uniquely identifies this single
|
||||
// payment. For non-AMP payments this will be the payment hash, for AMP
|
||||
// payments this will be the used SetID.
|
||||
func (l *LightningPayment) Identifier() [32]byte {
|
||||
return *l.paymentHash
|
||||
}
|
||||
|
||||
// SendPayment attempts to send a payment as described within the passed
|
||||
// LightningPayment. This function is blocking and will return either: when the
|
||||
// payment is successful, or all candidates routes have been attempted and
|
||||
@ -1822,7 +1838,7 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte,
|
||||
// Since this is the first time this payment is being made, we pass nil
|
||||
// for the existing attempt.
|
||||
return r.sendPayment(
|
||||
payment.Amount, payment.FeeLimit, payment.PaymentHash,
|
||||
payment.Amount, payment.FeeLimit, payment.Identifier(),
|
||||
payment.PayAttemptTimeout, paySession, shardTracker,
|
||||
)
|
||||
}
|
||||
@ -1845,12 +1861,12 @@ func (r *ChannelRouter) SendPaymentAsync(payment *LightningPayment) error {
|
||||
spewPayment(payment))
|
||||
|
||||
_, _, err := r.sendPayment(
|
||||
payment.Amount, payment.FeeLimit, payment.PaymentHash,
|
||||
payment.Amount, payment.FeeLimit, payment.Identifier(),
|
||||
payment.PayAttemptTimeout, paySession, shardTracker,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Payment with hash %x failed: %v",
|
||||
payment.PaymentHash, err)
|
||||
log.Errorf("Payment %x failed: %v",
|
||||
payment.Identifier(), err)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -1897,10 +1913,10 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) (
|
||||
//
|
||||
// TODO(roasbeef): store records as part of creation info?
|
||||
info := &channeldb.PaymentCreationInfo{
|
||||
PaymentHash: payment.PaymentHash,
|
||||
Value: payment.Amount,
|
||||
CreationTime: r.cfg.Clock.Now(),
|
||||
PaymentRequest: payment.PaymentRequest,
|
||||
PaymentIdentifier: payment.Identifier(),
|
||||
Value: payment.Amount,
|
||||
CreationTime: r.cfg.Clock.Now(),
|
||||
PaymentRequest: payment.PaymentRequest,
|
||||
}
|
||||
|
||||
// Create a new ShardTracker that we'll use during the life cycle of
|
||||
@ -1919,11 +1935,11 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) (
|
||||
// the same payment hash.
|
||||
default:
|
||||
shardTracker = shards.NewSimpleShardTracker(
|
||||
payment.PaymentHash, nil,
|
||||
payment.Identifier(), nil,
|
||||
)
|
||||
}
|
||||
|
||||
err = r.cfg.Control.InitPayment(payment.PaymentHash, info)
|
||||
err = r.cfg.Control.InitPayment(payment.Identifier(), info)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -1936,7 +1952,7 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) (
|
||||
// information as it is stored in the database. For a successful htlc, this
|
||||
// information will contain the preimage. If an error occurs after the attempt
|
||||
// was initiated, both return values will be non-nil.
|
||||
func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
|
||||
func (r *ChannelRouter) SendToRoute(htlcHash lntypes.Hash, rt *route.Route) (
|
||||
*channeldb.HTLCAttempt, error) {
|
||||
|
||||
// Calculate amount paid to receiver.
|
||||
@ -1950,16 +1966,20 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
|
||||
amt = mpp.TotalMsat()
|
||||
}
|
||||
|
||||
// For non-AMP payments the overall payment identifier will be the same
|
||||
// hash as used for this HTLC.
|
||||
paymentIdentifier := htlcHash
|
||||
|
||||
// Record this payment hash with the ControlTower, ensuring it is not
|
||||
// already in-flight.
|
||||
info := &channeldb.PaymentCreationInfo{
|
||||
PaymentHash: hash,
|
||||
Value: amt,
|
||||
CreationTime: r.cfg.Clock.Now(),
|
||||
PaymentRequest: nil,
|
||||
PaymentIdentifier: paymentIdentifier,
|
||||
Value: amt,
|
||||
CreationTime: r.cfg.Clock.Now(),
|
||||
PaymentRequest: nil,
|
||||
}
|
||||
|
||||
err := r.cfg.Control.InitPayment(hash, info)
|
||||
err := r.cfg.Control.InitPayment(paymentIdentifier, info)
|
||||
switch {
|
||||
// If this is an MPP attempt and the hash is already registered with
|
||||
// the database, we can go on to launch the shard.
|
||||
@ -1970,8 +1990,8 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Tracef("Dispatching SendToRoute for hash %v: %v",
|
||||
hash, newLogClosure(func() string {
|
||||
log.Tracef("Dispatching SendToRoute for HTLC hash %v: %v",
|
||||
htlcHash, newLogClosure(func() string {
|
||||
return spew.Sdump(rt)
|
||||
}),
|
||||
)
|
||||
@ -1981,12 +2001,12 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
|
||||
// a ShardTracker that can generate hashes for AMP payments. Instead we
|
||||
// create a simple tracker that can just return the hash for the single
|
||||
// shard we'll now launch.
|
||||
shardTracker := shards.NewSimpleShardTracker(hash, nil)
|
||||
shardTracker := shards.NewSimpleShardTracker(htlcHash, nil)
|
||||
|
||||
// Launch a shard along the given route.
|
||||
sh := &shardHandler{
|
||||
router: r,
|
||||
paymentHash: hash,
|
||||
identifier: paymentIdentifier,
|
||||
shardTracker: shardTracker,
|
||||
}
|
||||
|
||||
@ -1999,10 +2019,10 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
|
||||
err == sphinx.ErrMaxRoutingInfoSizeExceeded {
|
||||
|
||||
log.Debugf("Invalid route provided for payment %x: %v",
|
||||
hash, err)
|
||||
paymentIdentifier, err)
|
||||
|
||||
controlErr := r.cfg.Control.Fail(
|
||||
hash, channeldb.FailureReasonError,
|
||||
paymentIdentifier, channeldb.FailureReasonError,
|
||||
)
|
||||
if controlErr != nil {
|
||||
return nil, controlErr
|
||||
@ -2050,7 +2070,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
|
||||
reason = &r
|
||||
}
|
||||
|
||||
err = r.cfg.Control.Fail(hash, *reason)
|
||||
err = r.cfg.Control.Fail(paymentIdentifier, *reason)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2075,7 +2095,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
|
||||
// router will call this method for every payment still in-flight according to
|
||||
// the ControlTower.
|
||||
func (r *ChannelRouter) sendPayment(
|
||||
totalAmt, feeLimit lnwire.MilliSatoshi, paymentHash lntypes.Hash,
|
||||
totalAmt, feeLimit lnwire.MilliSatoshi, identifier lntypes.Hash,
|
||||
timeout time.Duration, paySession PaymentSession,
|
||||
shardTracker shards.ShardTracker) ([32]byte, *route.Route, error) {
|
||||
|
||||
@ -2092,7 +2112,7 @@ func (r *ChannelRouter) sendPayment(
|
||||
router: r,
|
||||
totalAmount: totalAmt,
|
||||
feeLimit: feeLimit,
|
||||
paymentHash: paymentHash,
|
||||
identifier: identifier,
|
||||
paySession: paySession,
|
||||
shardTracker: shardTracker,
|
||||
currentHeight: currentHeight,
|
||||
|
@ -275,13 +275,13 @@ func TestSendPaymentRouteFailureFallback(t *testing.T) {
|
||||
|
||||
// Craft a LightningPayment struct that'll send a payment from roasbeef
|
||||
// to luo ji for 1000 satoshis, with a maximum of 1000 satoshis in fees.
|
||||
var payHash [32]byte
|
||||
var payHash lntypes.Hash
|
||||
paymentAmt := lnwire.NewMSatFromSatoshis(1000)
|
||||
payment := LightningPayment{
|
||||
Target: ctx.aliases["sophon"],
|
||||
Amount: paymentAmt,
|
||||
FeeLimit: noFeeLimit,
|
||||
PaymentHash: payHash,
|
||||
paymentHash: &payHash,
|
||||
}
|
||||
|
||||
var preImage [32]byte
|
||||
@ -510,13 +510,13 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
|
||||
|
||||
// Craft a LightningPayment struct that'll send a payment from roasbeef
|
||||
// to luo ji for 100 satoshis.
|
||||
var payHash [32]byte
|
||||
var payHash lntypes.Hash
|
||||
amt := lnwire.NewMSatFromSatoshis(1000)
|
||||
payment := LightningPayment{
|
||||
Target: ctx.aliases["sophon"],
|
||||
Amount: amt,
|
||||
FeeLimit: noFeeLimit,
|
||||
PaymentHash: payHash,
|
||||
paymentHash: &payHash,
|
||||
}
|
||||
|
||||
var preImage [32]byte
|
||||
@ -611,13 +611,13 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) {
|
||||
|
||||
// Craft a LightningPayment struct that'll send a payment from roasbeef
|
||||
// to sophon for 1k satoshis.
|
||||
var payHash [32]byte
|
||||
var payHash lntypes.Hash
|
||||
amt := lnwire.NewMSatFromSatoshis(1000)
|
||||
payment := LightningPayment{
|
||||
Target: ctx.aliases["sophon"],
|
||||
Amount: amt,
|
||||
FeeLimit: noFeeLimit,
|
||||
PaymentHash: payHash,
|
||||
paymentHash: &payHash,
|
||||
}
|
||||
|
||||
var preImage [32]byte
|
||||
@ -720,7 +720,7 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) {
|
||||
// Once again, Roasbeef should route around Goku since they disagree
|
||||
// w.r.t to the block height, and instead go through Pham Nuwen. We
|
||||
// flip a bit in the payment hash to allow resending this payment.
|
||||
payment.PaymentHash[1] ^= 1
|
||||
payment.paymentHash[1] ^= 1
|
||||
paymentPreImage, rt, err = ctx.router.SendPayment(&payment)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payment: %v", err)
|
||||
@ -744,13 +744,13 @@ func TestSendPaymentErrorPathPruning(t *testing.T) {
|
||||
|
||||
// Craft a LightningPayment struct that'll send a payment from roasbeef
|
||||
// to luo ji for 1000 satoshis, with a maximum of 1000 satoshis in fees.
|
||||
var payHash [32]byte
|
||||
var payHash lntypes.Hash
|
||||
paymentAmt := lnwire.NewMSatFromSatoshis(1000)
|
||||
payment := LightningPayment{
|
||||
Target: ctx.aliases["sophon"],
|
||||
Amount: paymentAmt,
|
||||
FeeLimit: noFeeLimit,
|
||||
PaymentHash: payHash,
|
||||
paymentHash: &payHash,
|
||||
}
|
||||
|
||||
var preImage [32]byte
|
||||
@ -887,7 +887,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) {
|
||||
})
|
||||
|
||||
// We flip a bit in the payment hash to allow resending this payment.
|
||||
payment.PaymentHash[1] ^= 1
|
||||
payment.paymentHash[1] ^= 1
|
||||
paymentPreImage, rt, err = ctx.router.SendPayment(&payment)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payment: %v", err)
|
||||
@ -2565,11 +2565,12 @@ func TestUnknownErrorSource(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create a payment to node c.
|
||||
var payHash lntypes.Hash
|
||||
payment := LightningPayment{
|
||||
Target: ctx.aliases["c"],
|
||||
Amount: lnwire.NewMSatFromSatoshis(1000),
|
||||
FeeLimit: noFeeLimit,
|
||||
PaymentHash: lntypes.Hash{},
|
||||
paymentHash: &payHash,
|
||||
}
|
||||
|
||||
// We'll modify the SendToSwitch method so that it simulates hop b as a
|
||||
@ -2616,7 +2617,8 @@ func TestUnknownErrorSource(t *testing.T) {
|
||||
|
||||
// Send off the payment request to the router. We expect the payment to
|
||||
// fail because both routes have been pruned.
|
||||
payment.PaymentHash = lntypes.Hash{1}
|
||||
payHash = lntypes.Hash{1}
|
||||
payment.paymentHash = &payHash
|
||||
_, _, err = ctx.router.SendPayment(&payment)
|
||||
if err == nil {
|
||||
t.Fatalf("expected payment to fail")
|
||||
|
@ -4419,7 +4419,6 @@ func (r *rpcServer) dispatchPaymentIntent(
|
||||
FinalCLTVDelta: payIntent.cltvDelta,
|
||||
FeeLimit: payIntent.feeLimit,
|
||||
CltvLimit: payIntent.cltvLimit,
|
||||
PaymentHash: payIntent.rHash,
|
||||
RouteHints: payIntent.routeHints,
|
||||
OutgoingChannelIDs: payIntent.outgoingChannelIDs,
|
||||
LastHop: payIntent.lastHop,
|
||||
@ -4433,6 +4432,10 @@ func (r *rpcServer) dispatchPaymentIntent(
|
||||
// Users need to use routerrpc for that.
|
||||
MaxParts: 1,
|
||||
}
|
||||
err := payment.SetPaymentHash(payIntent.rHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
preImage, route, routerErr = r.server.chanRouter.SendPayment(
|
||||
payment,
|
||||
|
Loading…
Reference in New Issue
Block a user