mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-08 14:57:38 +02:00
channeldb: don't cancel other HTLCs w/ diff setID once once is settled
With this change, we allow multiple users to concurrently pay the same AMP invoice with distinct set IDs.
This commit is contained in:
@@ -1669,7 +1669,9 @@ func testUpdateHTLCPreimages(t *testing.T, test updateHTLCPreimageTestCase) {
|
|||||||
// Update the invoice with an accepted HTLC that also accepts the
|
// Update the invoice with an accepted HTLC that also accepts the
|
||||||
// invoice.
|
// invoice.
|
||||||
ref := InvoiceRefByAddr(invoice.Terms.PaymentAddr)
|
ref := InvoiceRefByAddr(invoice.Terms.PaymentAddr)
|
||||||
dbInvoice, err := db.UpdateInvoice(ref, updateAcceptAMPHtlc(0, amt, setID, true))
|
dbInvoice, err := db.UpdateInvoice(
|
||||||
|
ref, updateAcceptAMPHtlc(0, amt, setID, true),
|
||||||
|
)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
htlcPreimages := make(map[CircuitKey]lntypes.Preimage)
|
htlcPreimages := make(map[CircuitKey]lntypes.Preimage)
|
||||||
@@ -2062,6 +2064,10 @@ func TestUpdateHTLC(t *testing.T) {
|
|||||||
expErr: nil,
|
expErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
// With the newer AMP logic, this is now valid, as we
|
||||||
|
// want to be able to accept multiple settle attempts
|
||||||
|
// to a given pay_addr. In this case, the HTLC should
|
||||||
|
// remain in the accepted state.
|
||||||
name: "AMP settle valid preimage different htlc set",
|
name: "AMP settle valid preimage different htlc set",
|
||||||
input: InvoiceHTLC{
|
input: InvoiceHTLC{
|
||||||
Amt: 5000,
|
Amt: 5000,
|
||||||
@@ -2085,9 +2091,9 @@ func TestUpdateHTLC(t *testing.T) {
|
|||||||
MppTotalAmt: 5000,
|
MppTotalAmt: 5000,
|
||||||
AcceptHeight: 100,
|
AcceptHeight: 100,
|
||||||
AcceptTime: testNow,
|
AcceptTime: testNow,
|
||||||
ResolveTime: testNow,
|
ResolveTime: time.Time{},
|
||||||
Expiry: 40,
|
Expiry: 40,
|
||||||
State: HtlcStateCanceled,
|
State: HtlcStateAccepted,
|
||||||
CustomRecords: make(record.CustomSet),
|
CustomRecords: make(record.CustomSet),
|
||||||
AMP: &InvoiceHtlcAMPData{
|
AMP: &InvoiceHtlcAMPData{
|
||||||
Record: *ampRecord,
|
Record: *ampRecord,
|
||||||
|
@@ -2710,13 +2710,12 @@ func updateHtlc(resolveTime time.Time, htlc *InvoiceHTLC,
|
|||||||
}
|
}
|
||||||
|
|
||||||
htlcState = HtlcStateSettled
|
htlcState = HtlcStateSettled
|
||||||
} else {
|
|
||||||
htlcState = HtlcStateCanceled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only persist the changes if the invoice is moving to the
|
// Only persist the changes if the invoice is moving to the
|
||||||
// settled state.
|
// settled state, and we're actually updating the state to
|
||||||
if persist {
|
// settled.
|
||||||
|
if persist && htlcState == HtlcStateSettled {
|
||||||
htlc.State = htlcState
|
htlc.State = htlcState
|
||||||
htlc.ResolveTime = resolveTime
|
htlc.ResolveTime = resolveTime
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user