multi: pass UpdateAddHtlc message custom records to invoice modifier

This commit is contained in:
ffranr authored and Oliver Gugger committed 2024-09-19 09:21:38 +02:00
1 parent 83923c7f33
commit bbae7148aa
11 files changed
+481 -354

No files matched your search

@@ -308,7 +308,7 @@ func (h *htlcIncomingContestResolver) Resolve(
resolution, err := h.Registry.NotifyExitHopHtlc( resolution, err := h.Registry.NotifyExitHopHtlc(
h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight, h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight,
circuitKey, hodlQueue.ChanIn(), payload, circuitKey, hodlQueue.ChanIn(), nil, payload,
) )
if err != nil { if err != nil {
return nil, err return nil, err
+1
View File
@@ -30,6 +30,7 @@ type Registry interface {
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi, NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
expiry uint32, currentHeight int32, expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{}, circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error) payload invoices.Payload) (invoices.HtlcResolution, error)
// HodlUnsubscribeAll unsubscribes from all htlc resolutions. // HodlUnsubscribeAll unsubscribes from all htlc resolutions.
+1
View File
@@ -26,6 +26,7 @@ type mockRegistry struct {
func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash, func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash,
paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32, paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{}, circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error) { payload invoices.Payload) (invoices.HtlcResolution, error) {
r.notifyChan <- notifyExitHopData{ r.notifyChan <- notifyExitHopData{
+1
View File
@@ -33,6 +33,7 @@ type InvoiceDatabase interface {
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi, NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
expiry uint32, currentHeight int32, expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{}, circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error) payload invoices.Payload) (invoices.HtlcResolution, error)
// CancelInvoice attempts to cancel the invoice corresponding to the // CancelInvoice attempts to cancel the invoice corresponding to the
+1 -1
View File
@@ -3846,7 +3846,7 @@ func (l *channelLink) processExitHop(add lnwire.UpdateAddHTLC,
event, err := l.cfg.Registry.NotifyExitHopHtlc( event, err := l.cfg.Registry.NotifyExitHopHtlc(
invoiceHash, add.Amount, add.Expiry, int32(heightNow), invoiceHash, add.Amount, add.Expiry, int32(heightNow),
circuitKey, l.hodlQueue.ChanIn(), payload, circuitKey, l.hodlQueue.ChanIn(), add.CustomRecords, payload,
) )
if err != nil { if err != nil {
return err return err
+3 -2
View File
@@ -1049,11 +1049,12 @@ func (i *mockInvoiceRegistry) SettleHodlInvoice(
func (i *mockInvoiceRegistry) NotifyExitHopHtlc(rhash lntypes.Hash, func (i *mockInvoiceRegistry) NotifyExitHopHtlc(rhash lntypes.Hash,
amt lnwire.MilliSatoshi, expiry uint32, currentHeight int32, amt lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{}, circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error) { payload invoices.Payload) (invoices.HtlcResolution, error) {
event, err := i.registry.NotifyExitHopHtlc( event, err := i.registry.NotifyExitHopHtlc(
rhash, amt, expiry, currentHeight, circuitKey, hodlChan, rhash, amt, expiry, currentHeight, circuitKey,
payload, hodlChan, wireCustomRecords, payload,
) )
if err != nil { if err != nil {
return nil, err return nil, err
+3
View File
@@ -918,6 +918,7 @@ func (i *InvoiceRegistry) processAMP(ctx invoiceUpdateCtx) error {
func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash, func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
amtPaid lnwire.MilliSatoshi, expiry uint32, currentHeight int32, amtPaid lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
circuitKey CircuitKey, hodlChan chan<- interface{}, circuitKey CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload Payload) (HtlcResolution, error) { payload Payload) (HtlcResolution, error) {
// Create the update context containing the relevant details of the // Create the update context containing the relevant details of the
@@ -929,6 +930,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
expiry: expiry, expiry: expiry,
currentHeight: currentHeight, currentHeight: currentHeight,
finalCltvRejectDelta: i.cfg.FinalCltvRejectDelta, finalCltvRejectDelta: i.cfg.FinalCltvRejectDelta,
wireCustomRecords: wireCustomRecords,
customRecords: payload.CustomRecords(), customRecords: payload.CustomRecords(),
mpp: payload.MultiPath(), mpp: payload.MultiPath(),
amp: payload.AMPRecord(), amp: payload.AMPRecord(),
@@ -1051,6 +1053,7 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
// the interceptor's client an opportunity to manipulate the // the interceptor's client an opportunity to manipulate the
// settlement process. // settlement process.
err = i.cfg.HtlcInterceptor.Intercept(HtlcModifyRequest{ err = i.cfg.HtlcInterceptor.Intercept(HtlcModifyRequest{
WireCustomRecords: ctx.wireCustomRecords,
ExitHtlcCircuitKey: ctx.circuitKey, ExitHtlcCircuitKey: ctx.circuitKey,
ExitHtlcAmt: ctx.amtPaid, ExitHtlcAmt: ctx.amtPaid,
ExitHtlcExpiry: ctx.expiry, ExitHtlcExpiry: ctx.expiry,
+56 -43
View File
@@ -245,7 +245,8 @@ func testSettleInvoice(t *testing.T,
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value, testInvoicePaymentHash, testInvoice.Terms.Value,
uint32(testCurrentHeight)+testInvoiceCltvDelta-1, uint32(testCurrentHeight)+testInvoiceCltvDelta-1,
testCurrentHeight, getCircuitKey(10), hodlChan, testPayload, testCurrentHeight, getCircuitKey(10), hodlChan,
nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -261,7 +262,7 @@ func testSettleInvoice(t *testing.T,
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testCurrentHeight, getCircuitKey(0), hodlChan,
testPayload, nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -302,7 +303,8 @@ func testSettleInvoice(t *testing.T,
// behaviour after a restart. // behaviour after a restart.
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload, testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
) )
require.NoError(t, err, "unexpected NotifyExitHopHtlc error") require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
require.NotNil(t, resolution) require.NotNil(t, resolution)
@@ -316,7 +318,8 @@ func testSettleInvoice(t *testing.T,
// paid invoice that may open up a probe vector. // paid invoice that may open up a probe vector.
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid+600, testHtlcExpiry, testInvoicePaymentHash, amtPaid+600, testHtlcExpiry,
testCurrentHeight, getCircuitKey(1), hodlChan, testPayload, testCurrentHeight, getCircuitKey(1), hodlChan,
nil, testPayload,
) )
require.NoError(t, err, "unexpected NotifyExitHopHtlc error") require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
require.NotNil(t, resolution) require.NotNil(t, resolution)
@@ -331,7 +334,8 @@ func testSettleInvoice(t *testing.T,
// would have failed if it were the first payment. // would have failed if it were the first payment.
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid-600, testHtlcExpiry, testInvoicePaymentHash, amtPaid-600, testHtlcExpiry,
testCurrentHeight, getCircuitKey(2), hodlChan, testPayload, testCurrentHeight, getCircuitKey(2), hodlChan,
nil, testPayload,
) )
require.NoError(t, err, "unexpected NotifyExitHopHtlc error") require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
require.NotNil(t, resolution) require.NotNil(t, resolution)
@@ -468,7 +472,8 @@ func testCancelInvoiceImpl(t *testing.T, gc bool,
hodlChan := make(chan interface{}) hodlChan := make(chan interface{})
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoiceAmount, testHtlcExpiry, testInvoicePaymentHash, testInvoiceAmount, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload, testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatal("expected settlement of a canceled invoice to succeed") t.Fatal("expected settlement of a canceled invoice to succeed")
@@ -577,7 +582,8 @@ func testSettleHoldInvoice(t *testing.T,
// should be possible. // should be possible.
resolution, err := registry.NotifyExitHopHtlc( resolution, err := registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload, testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatalf("expected settle to succeed but got %v", err) t.Fatalf("expected settle to succeed but got %v", err)
@@ -589,7 +595,8 @@ func testSettleHoldInvoice(t *testing.T,
// Test idempotency. // Test idempotency.
resolution, err = registry.NotifyExitHopHtlc( resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload, testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatalf("expected settle to succeed but got %v", err) t.Fatalf("expected settle to succeed but got %v", err)
@@ -602,7 +609,8 @@ func testSettleHoldInvoice(t *testing.T,
// is a replay. // is a replay.
resolution, err = registry.NotifyExitHopHtlc( resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight+10, getCircuitKey(0), hodlChan, testPayload, testCurrentHeight+10, getCircuitKey(0), hodlChan,
nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatalf("expected settle to succeed but got %v", err) t.Fatalf("expected settle to succeed but got %v", err)
@@ -615,7 +623,7 @@ func testSettleHoldInvoice(t *testing.T,
// requirement. It should be rejected. // requirement. It should be rejected.
resolution, err = registry.NotifyExitHopHtlc( resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, 1, testCurrentHeight, testInvoicePaymentHash, amtPaid, 1, testCurrentHeight,
getCircuitKey(1), hodlChan, testPayload, getCircuitKey(1), hodlChan, nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatalf("expected settle to succeed but got %v", err) t.Fatalf("expected settle to succeed but got %v", err)
@@ -719,7 +727,8 @@ func testCancelHoldInvoice(t *testing.T,
// should be possible. // should be possible.
resolution, err := registry.NotifyExitHopHtlc( resolution, err := registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload, testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatalf("expected settle to succeed but got %v", err) t.Fatalf("expected settle to succeed but got %v", err)
@@ -741,7 +750,8 @@ func testCancelHoldInvoice(t *testing.T,
// accept height. // accept height.
resolution, err = registry.NotifyExitHopHtlc( resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry, testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight+1, getCircuitKey(0), hodlChan, testPayload, testCurrentHeight+1, getCircuitKey(0), hodlChan,
nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatalf("expected settle to succeed but got %v", err) t.Fatalf("expected settle to succeed but got %v", err)
@@ -770,7 +780,7 @@ func testUnknownInvoice(t *testing.T,
amt := lnwire.MilliSatoshi(100000) amt := lnwire.MilliSatoshi(100000)
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amt, testHtlcExpiry, testCurrentHeight, testInvoicePaymentHash, amt, testHtlcExpiry, testCurrentHeight,
getCircuitKey(0), hodlChan, testPayload, getCircuitKey(0), hodlChan, nil, testPayload,
) )
if err != nil { if err != nil {
t.Fatal("unexpected error") t.Fatal("unexpected error")
@@ -831,7 +841,7 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry, hash, amt, expiry,
testCurrentHeight, getCircuitKey(10), hodlChan, testCurrentHeight, getCircuitKey(10), hodlChan,
invalidKeySendPayload, nil, invalidKeySendPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -852,8 +862,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
} }
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry, hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
testCurrentHeight, getCircuitKey(10), hodlChan, keySendPayload, hodlChan, nil, keySendPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -881,8 +891,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
// Replay the same keysend payment. We expect an identical resolution, // Replay the same keysend payment. We expect an identical resolution,
// but no event should be generated. // but no event should be generated.
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry, hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
testCurrentHeight, getCircuitKey(10), hodlChan, keySendPayload, hodlChan, nil, keySendPayload,
) )
require.Nil(t, err) require.Nil(t, err)
checkSettleResolution(t, resolution, preimage) checkSettleResolution(t, resolution, preimage)
@@ -905,8 +915,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
} }
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
hash2, amt, expiry, hash2, amt, expiry, testCurrentHeight, getCircuitKey(20),
testCurrentHeight, getCircuitKey(20), hodlChan, keySendPayload2, hodlChan, nil, keySendPayload2,
) )
require.Nil(t, err) require.Nil(t, err)
@@ -964,8 +974,8 @@ func testHoldKeysendImpl(t *testing.T, timeoutKeysend bool,
} }
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry, hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
testCurrentHeight, getCircuitKey(10), hodlChan, keysendPayload, hodlChan, nil, keysendPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1047,8 +1057,8 @@ func testMppPayment(t *testing.T,
hodlChan1 := make(chan interface{}, 1) hodlChan1 := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry, testHtlcExpiry, testCurrentHeight, getCircuitKey(10),
testCurrentHeight, getCircuitKey(10), hodlChan1, mppPayload, hodlChan1, nil, mppPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1075,8 +1085,8 @@ func testMppPayment(t *testing.T,
hodlChan2 := make(chan interface{}, 1) hodlChan2 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry, testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
testCurrentHeight, getCircuitKey(11), hodlChan2, mppPayload, hodlChan2, nil, mppPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1089,8 +1099,8 @@ func testMppPayment(t *testing.T,
hodlChan3 := make(chan interface{}, 1) hodlChan3 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry, testHtlcExpiry, testCurrentHeight, getCircuitKey(12),
testCurrentHeight, getCircuitKey(12), hodlChan3, mppPayload, hodlChan3, nil, mppPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1149,7 +1159,7 @@ func testMppPaymentWithOverpayment(t *testing.T,
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry, testCurrentHeight, getCircuitKey(11), testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
hodlChan1, mppPayload, hodlChan1, nil, mppPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1164,7 +1174,7 @@ func testMppPaymentWithOverpayment(t *testing.T,
testInvoicePaymentHash, testInvoicePaymentHash,
testInvoice.Terms.Value/2+overpayment, testHtlcExpiry, testInvoice.Terms.Value/2+overpayment, testHtlcExpiry,
testCurrentHeight, getCircuitKey(12), hodlChan2, testCurrentHeight, getCircuitKey(12), hodlChan2,
mppPayload, nil, mppPayload,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1449,7 +1459,7 @@ func testHeightExpiryWithRegistryImpl(t *testing.T, numParts int, settle bool,
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, htlcAmt, expiry, testInvoicePaymentHash, htlcAmt, expiry,
testCurrentHeight, getCircuitKey(uint64(i)), hodlChan, testCurrentHeight, getCircuitKey(uint64(i)), hodlChan,
payLoad, nil, payLoad,
) )
require.NoError(t, err) require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution") require.Nil(t, resolution, "did not expect direct resolution")
@@ -1551,8 +1561,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
hodlChan1 := make(chan interface{}, 1) hodlChan1 := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry, testHtlcExpiry, testCurrentHeight, getCircuitKey(10),
testCurrentHeight, getCircuitKey(10), hodlChan1, mppPayload, hodlChan1, nil, mppPayload,
) )
require.NoError(t, err) require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution") require.Nil(t, resolution, "did not expect direct resolution")
@@ -1581,7 +1591,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
hodlChan2 := make(chan interface{}, 1) hodlChan2 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry, testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry,
testCurrentHeight, getCircuitKey(11), hodlChan2, mppPayload, testCurrentHeight, getCircuitKey(11), hodlChan2,
nil, mppPayload,
) )
require.NoError(t, err) require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution") require.Nil(t, resolution, "did not expect direct resolution")
@@ -1590,7 +1601,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
hodlChan3 := make(chan interface{}, 1) hodlChan3 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc( resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry, testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry,
testCurrentHeight, getCircuitKey(12), hodlChan3, mppPayload, testCurrentHeight, getCircuitKey(12), hodlChan3,
nil, mppPayload,
) )
require.NoError(t, err) require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution") require.Nil(t, resolution, "did not expect direct resolution")
@@ -1695,7 +1707,8 @@ func testSettleInvoicePaymentAddrRequired(t *testing.T,
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, invoice.Terms.Value, testInvoicePaymentHash, invoice.Terms.Value,
uint32(testCurrentHeight)+testInvoiceCltvDelta-1, uint32(testCurrentHeight)+testInvoiceCltvDelta-1,
testCurrentHeight, getCircuitKey(10), hodlChan, testPayload, testCurrentHeight, getCircuitKey(10), hodlChan,
nil, testPayload,
) )
require.NoError(t, err) require.NoError(t, err)
@@ -1784,9 +1797,9 @@ func testSettleInvoicePaymentAddrRequiredOptionalGrace(t *testing.T,
// no problem as we should allow these existing invoices to be settled. // no problem as we should allow these existing invoices to be settled.
hodlChan := make(chan interface{}, 1) hodlChan := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoiceAmount, testInvoicePaymentHash, testInvoiceAmount, testHtlcExpiry,
testHtlcExpiry, testCurrentHeight, testCurrentHeight, getCircuitKey(10), hodlChan,
getCircuitKey(10), hodlChan, testPayload, nil, testPayload,
) )
require.NoError(t, err) require.NoError(t, err)
@@ -1848,8 +1861,8 @@ func testAMPWithoutMPPPayload(t *testing.T,
hodlChan := make(chan interface{}, 1) hodlChan := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
lntypes.Hash{}, shardAmt, expiry, lntypes.Hash{}, shardAmt, expiry, testCurrentHeight,
testCurrentHeight, getCircuitKey(uint64(10)), hodlChan, getCircuitKey(uint64(10)), hodlChan, nil,
payload, payload,
) )
require.NoError(t, err) require.NoError(t, err)
@@ -2017,8 +2030,8 @@ func testSpontaneousAmpPaymentImpl(
} }
resolution, err := ctx.registry.NotifyExitHopHtlc( resolution, err := ctx.registry.NotifyExitHopHtlc(
child.Hash, shardAmt, expiry, child.Hash, shardAmt, expiry, testCurrentHeight,
testCurrentHeight, getCircuitKey(uint64(i)), hodlChan, getCircuitKey(uint64(i)), hodlChan, nil,
payload, payload,
) )
require.NoError(t, err) require.NoError(t, err)
+6
View File
@@ -547,6 +547,11 @@ type InvoiceHTLC struct {
// the htlc. // the htlc.
CustomRecords record.CustomSet CustomRecords record.CustomSet
// WireCustomRecords contains the custom key/value pairs that were only
// included in p2p wire message of the HTLC and not in the onion
// payload.
WireCustomRecords lnwire.CustomRecords
// AMP encapsulates additional data relevant to AMP HTLCs. This includes // AMP encapsulates additional data relevant to AMP HTLCs. This includes
// the AMP onion record, in addition to the HTLC's payment hash and // the AMP onion record, in addition to the HTLC's payment hash and
// preimage since these are unique to each AMP HTLC, and not the invoice // preimage since these are unique to each AMP HTLC, and not the invoice
@@ -566,6 +571,7 @@ func (h *InvoiceHTLC) Copy() *InvoiceHTLC {
result.CustomRecords[k] = v result.CustomRecords[k] = v
} }
result.WireCustomRecords = h.WireCustomRecords.Copy()
result.AMP = h.AMP.Copy() result.AMP = h.AMP.Copy()
return &result return &result
+35 -13
View File
@@ -21,12 +21,20 @@ type invoiceUpdateCtx struct {
expiry uint32 expiry uint32
currentHeight int32 currentHeight int32
finalCltvRejectDelta int32 finalCltvRejectDelta int32
customRecords record.CustomSet
mpp *record.MPP // wireCustomRecords are the custom records that were included with the
amp *record.AMP // HTLC wire message.
metadata []byte wireCustomRecords lnwire.CustomRecords
pathID *chainhash.Hash
totalAmtMsat lnwire.MilliSatoshi // customRecords is a map of custom records that were included with the
// HTLC onion payload.
customRecords record.CustomSet
mpp *record.MPP
amp *record.AMP
metadata []byte
pathID *chainhash.Hash
totalAmtMsat lnwire.MilliSatoshi
} }
// invoiceRef returns an identifier that can be used to lookup or update the // invoiceRef returns an identifier that can be used to lookup or update the
@@ -95,12 +103,14 @@ func (i invoiceUpdateCtx) settleRes(preimage lntypes.Preimage,
// acceptRes is a helper function which creates an accept resolution with // acceptRes is a helper function which creates an accept resolution with
// the information contained in the invoiceUpdateCtx and the accept resolution // the information contained in the invoiceUpdateCtx and the accept resolution
// result provided. // result provided.
func (i invoiceUpdateCtx) acceptRes(outcome acceptResolutionResult) *htlcAcceptResolution { func (i invoiceUpdateCtx) acceptRes(
outcome acceptResolutionResult) *htlcAcceptResolution {
return newAcceptResolution(i.circuitKey, outcome) return newAcceptResolution(i.circuitKey, outcome)
} }
// updateInvoice is a callback for DB.UpdateInvoice that contains the invoice // updateInvoice is a callback for DB.UpdateInvoice that contains the invoice
// settlement logic. It returns a hltc resolution that indicates what the // settlement logic. It returns a HTLC resolution that indicates what the
// outcome of the update was. // outcome of the update was.
func updateInvoice(ctx *invoiceUpdateCtx, inv *Invoice) ( func updateInvoice(ctx *invoiceUpdateCtx, inv *Invoice) (
*InvoiceUpdateDesc, HtlcResolution, error) { *InvoiceUpdateDesc, HtlcResolution, error) {
@@ -119,7 +129,7 @@ func updateInvoice(ctx *invoiceUpdateCtx, inv *Invoice) (
pre := inv.Terms.PaymentPreimage pre := inv.Terms.PaymentPreimage
// Terms.PaymentPreimage will be nil for AMP invoices. // Terms.PaymentPreimage will be nil for AMP invoices.
// Set it to the HTLC's AMP Preimage instead. // Set it to the HTLCs AMP Preimage instead.
if pre == nil { if pre == nil {
pre = htlc.AMP.Preimage pre = htlc.AMP.Preimage
} }
@@ -180,13 +190,19 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
paymentAddr = ctx.pathID[:] paymentAddr = ctx.pathID[:]
} }
// For storage, we don't really care where the custom records came from.
// So we merge them together and store them in the same field.
customRecords := lnwire.CustomRecords(
ctx.customRecords,
).MergedCopy(ctx.wireCustomRecords)
// Start building the accept descriptor. // Start building the accept descriptor.
acceptDesc := &HtlcAcceptDesc{ acceptDesc := &HtlcAcceptDesc{
Amt: ctx.amtPaid, Amt: ctx.amtPaid,
Expiry: ctx.expiry, Expiry: ctx.expiry,
AcceptHeight: ctx.currentHeight, AcceptHeight: ctx.currentHeight,
MppTotalAmt: totalAmt, MppTotalAmt: totalAmt,
CustomRecords: ctx.customRecords, CustomRecords: record.CustomSet(customRecords),
} }
if ctx.amp != nil { if ctx.amp != nil {
@@ -223,7 +239,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
htlcSet := inv.HTLCSet(setID, HtlcStateAccepted) htlcSet := inv.HTLCSet(setID, HtlcStateAccepted)
// Check whether total amt matches other htlcs in the set. // Check whether total amt matches other HTLCs in the set.
var newSetTotal lnwire.MilliSatoshi var newSetTotal lnwire.MilliSatoshi
for _, htlc := range htlcSet { for _, htlc := range htlcSet {
if totalAmt != htlc.MppTotalAmt { if totalAmt != htlc.MppTotalAmt {
@@ -265,7 +281,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
return &update, ctx.acceptRes(resultPartialAccepted), nil return &update, ctx.acceptRes(resultPartialAccepted), nil
} }
// Check to see if we can settle or this is an hold invoice and // Check to see if we can settle or this is a hold invoice, and
// we need to wait for the preimage. // we need to wait for the preimage.
if inv.HodlInvoice { if inv.HodlInvoice {
update.State = &InvoiceStateUpdateDesc{ update.State = &InvoiceStateUpdateDesc{
@@ -434,13 +450,19 @@ func updateLegacy(ctx *invoiceUpdateCtx,
return nil, ctx.failRes(ResultExpiryTooSoon), nil return nil, ctx.failRes(ResultExpiryTooSoon), nil
} }
// For storage, we don't really care where the custom records came from.
// So we merge them together and store them in the same field.
customRecords := lnwire.CustomRecords(
ctx.customRecords,
).MergedCopy(ctx.wireCustomRecords)
// Record HTLC in the invoice database. // Record HTLC in the invoice database.
newHtlcs := map[CircuitKey]*HtlcAcceptDesc{ newHtlcs := map[CircuitKey]*HtlcAcceptDesc{
ctx.circuitKey: { ctx.circuitKey: {
Amt: ctx.amtPaid, Amt: ctx.amtPaid,
Expiry: ctx.expiry, Expiry: ctx.expiry,
AcceptHeight: ctx.currentHeight, AcceptHeight: ctx.currentHeight,
CustomRecords: ctx.customRecords, CustomRecords: record.CustomSet(customRecords),
}, },
} }
+373 -294
View File
@@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/record"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@@ -37,98 +38,147 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "MPP accept", name: "MPP accept",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
AMP: nil, WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
}, },
invState: ContractAccepted, invState: ContractAccepted,
setID: nil, setID: nil,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
AMP: nil, WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
},
expErr: nil,
},
{
name: "MPP accept, copy custom records",
input: InvoiceHTLC{
Amt: 5000,
MppTotalAmt: 5000,
AcceptHeight: 100,
AcceptTime: testNow,
ResolveTime: time.Time{},
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: record.CustomSet{
0x01: []byte{0x02},
0xffff: []byte{0x04, 0x05, 0x06},
},
WireCustomRecords: lnwire.CustomRecords{
0x010101: []byte{0x02, 0x03},
0xffffff: []byte{0x44, 0x55, 0x66},
},
AMP: nil,
},
invState: ContractAccepted,
setID: nil,
output: InvoiceHTLC{
Amt: 5000,
MppTotalAmt: 5000,
AcceptHeight: 100,
AcceptTime: testNow,
ResolveTime: time.Time{},
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: record.CustomSet{
0x01: []byte{0x02},
0xffff: []byte{0x04, 0x05, 0x06},
},
WireCustomRecords: lnwire.CustomRecords{
0x010101: []byte{0x02, 0x03},
0xffffff: []byte{0x44, 0x55, 0x66},
},
AMP: nil,
}, },
expErr: nil, expErr: nil,
}, },
{ {
name: "MPP settle", name: "MPP settle",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
AMP: nil, WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
}, },
invState: ContractSettled, invState: ContractSettled,
setID: nil, setID: nil,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testNow, ResolveTime: testNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
AMP: nil, WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
}, },
expErr: nil, expErr: nil,
}, },
{ {
name: "MPP cancel", name: "MPP cancel",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
AMP: nil, WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
}, },
invState: ContractCanceled, invState: ContractCanceled,
setID: nil, setID: nil,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testNow, ResolveTime: testNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
AMP: nil, WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
}, },
expErr: nil, expErr: nil,
}, },
{ {
name: "AMP accept missing preimage", name: "AMP accept missing preimage",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -138,14 +188,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractAccepted, invState: ContractAccepted,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -157,14 +208,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "AMP accept invalid preimage", name: "AMP accept invalid preimage",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -174,14 +226,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractAccepted, invState: ContractAccepted,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -193,14 +246,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "AMP accept valid preimage", name: "AMP accept valid preimage",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -210,14 +264,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractAccepted, invState: ContractAccepted,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -229,14 +284,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "AMP accept valid preimage different htlc set", name: "AMP accept valid preimage different htlc set",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -246,14 +302,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractAccepted, invState: ContractAccepted,
setID: &diffSetID, setID: &diffSetID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -265,14 +322,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "AMP settle missing preimage", name: "AMP settle missing preimage",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -282,14 +340,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractSettled, invState: ContractSettled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -301,14 +360,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "AMP settle invalid preimage", name: "AMP settle invalid preimage",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -318,14 +378,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractSettled, invState: ContractSettled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -337,14 +398,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "AMP settle valid preimage", name: "AMP settle valid preimage",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -354,14 +416,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractSettled, invState: ContractSettled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testNow, ResolveTime: testNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -377,14 +440,15 @@ func TestUpdateHTLC(t *testing.T) {
// remain in the accepted state. // 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,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -394,14 +458,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractSettled, invState: ContractSettled,
setID: &diffSetID, setID: &diffSetID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -413,14 +478,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "accept invoice htlc already settled", name: "accept invoice htlc already settled",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -430,14 +496,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractAccepted, invState: ContractAccepted,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -449,14 +516,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "cancel invoice htlc already settled", name: "cancel invoice htlc already settled",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -466,14 +534,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractCanceled, invState: ContractCanceled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -485,14 +554,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "settle invoice htlc already settled", name: "settle invoice htlc already settled",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -502,14 +572,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractSettled, invState: ContractSettled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateSettled, State: HtlcStateSettled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -521,14 +592,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "cancel invoice", name: "cancel invoice",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: time.Time{}, ResolveTime: time.Time{},
Expiry: 40, Expiry: 40,
State: HtlcStateAccepted, State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -538,14 +610,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractCanceled, invState: ContractCanceled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testNow, ResolveTime: testNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -557,14 +630,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "accept invoice htlc already canceled", name: "accept invoice htlc already canceled",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -574,14 +648,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractAccepted, invState: ContractAccepted,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -593,14 +668,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "cancel invoice htlc already canceled", name: "cancel invoice htlc already canceled",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -610,14 +686,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractCanceled, invState: ContractCanceled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -629,14 +706,15 @@ func TestUpdateHTLC(t *testing.T) {
{ {
name: "settle invoice htlc already canceled", name: "settle invoice htlc already canceled",
input: InvoiceHTLC{ input: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,
@@ -646,14 +724,15 @@ func TestUpdateHTLC(t *testing.T) {
invState: ContractSettled, invState: ContractSettled,
setID: &setID, setID: &setID,
output: InvoiceHTLC{ output: InvoiceHTLC{
Amt: 5000, Amt: 5000,
MppTotalAmt: 5000, MppTotalAmt: 5000,
AcceptHeight: 100, AcceptHeight: 100,
AcceptTime: testNow, AcceptTime: testNow,
ResolveTime: testAlreadyNow, ResolveTime: testAlreadyNow,
Expiry: 40, Expiry: 40,
State: HtlcStateCanceled, State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet), CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{ AMP: &InvoiceHtlcAMPData{
Record: *ampRecord, Record: *ampRecord,
Hash: hash, Hash: hash,