mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +02:00
invoices: treat replayed HTLCs beforehand.
We make sure that HTLCs which have already been decided upon are resolved before before allowing the external interceptor to potentially cancel them back. This makes the implementation for the external HTLC interceptor more streamlined.
This commit is contained in:
@@ -116,6 +116,7 @@ func testInvoiceHtlcModifierBasic(ht *lntest.HarnessTest) {
|
||||
&invoicesrpc.HtlcModifyResponse{
|
||||
CircuitKey: modifierRequest.ExitHtlcCircuitKey,
|
||||
AmtPaid: &amtPaid,
|
||||
CancelSet: tc.cancelSet,
|
||||
},
|
||||
)
|
||||
require.NoError(ht, err, "failed to send request")
|
||||
@@ -128,7 +129,9 @@ func testInvoiceHtlcModifierBasic(ht *lntest.HarnessTest) {
|
||||
require.Fail(ht, "timeout waiting for payment send")
|
||||
}
|
||||
|
||||
ht.Log("Ensure invoice status is settled")
|
||||
ht.Logf("Ensure invoice status is expected state %v",
|
||||
tc.finalInvoiceState)
|
||||
|
||||
require.Eventually(ht, func() bool {
|
||||
updatedInvoice := carol.RPC.LookupInvoice(
|
||||
tc.invoice.RHash,
|
||||
@@ -141,6 +144,13 @@ func testInvoiceHtlcModifierBasic(ht *lntest.HarnessTest) {
|
||||
tc.invoice.RHash,
|
||||
)
|
||||
|
||||
// If the HTLC modifier canceled the incoming HTLC set, we don't
|
||||
// expect any HTLCs in the invoice.
|
||||
if tc.cancelSet {
|
||||
require.Len(ht, updatedInvoice.Htlcs, 0)
|
||||
return
|
||||
}
|
||||
|
||||
require.Len(ht, updatedInvoice.Htlcs, 1)
|
||||
require.Equal(
|
||||
ht, lntest.CustomRecordsWithUnendorsed(
|
||||
@@ -231,6 +241,10 @@ type acceptorTestCase struct {
|
||||
|
||||
// invoice is the invoice that will be paid.
|
||||
invoice *lnrpc.Invoice
|
||||
|
||||
// cancelSet is a boolean which indicates whether the HTLC modifier
|
||||
// canceled the incoming HTLC set.
|
||||
cancelSet bool
|
||||
}
|
||||
|
||||
// acceptorTestScenario is a helper struct to hold the test context and provides
|
||||
@@ -282,6 +296,12 @@ func (c *acceptorTestScenario) prepareTestCases() []*acceptorTestCase {
|
||||
lnwire.MinCustomRecordsTlvType: {1, 2, 3},
|
||||
},
|
||||
},
|
||||
{
|
||||
invoiceAmountMsat: 9000,
|
||||
sendAmountMsat: 1000,
|
||||
finalInvoiceState: lnrpc.Invoice_OPEN,
|
||||
cancelSet: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, t := range cases {
|
||||
|
Reference in New Issue
Block a user