multi: pass UpdateAddHtlc message custom records to invoice modifier

This commit is contained in:
ffranr 2024-05-08 18:17:05 +01:00 committed by Oliver Gugger
parent 109e27cfb2
commit c1aa44c476
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
11 changed files with 481 additions and 354 deletions

View File

@ -308,7 +308,7 @@ func (h *htlcIncomingContestResolver) Resolve(
resolution, err := h.Registry.NotifyExitHopHtlc(
h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight,
circuitKey, hodlQueue.ChanIn(), payload,
circuitKey, hodlQueue.ChanIn(), nil, payload,
)
if err != nil {
return nil, err

View File

@ -30,6 +30,7 @@ type Registry interface {
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error)
// HodlUnsubscribeAll unsubscribes from all htlc resolutions.

View File

@ -26,6 +26,7 @@ type mockRegistry struct {
func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash,
paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error) {
r.notifyChan <- notifyExitHopData{

View File

@ -33,6 +33,7 @@ type InvoiceDatabase interface {
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error)
// CancelInvoice attempts to cancel the invoice corresponding to the

View File

@ -3845,7 +3845,7 @@ func (l *channelLink) processExitHop(add lnwire.UpdateAddHTLC,
event, err := l.cfg.Registry.NotifyExitHopHtlc(
invoiceHash, add.Amount, add.Expiry, int32(heightNow),
circuitKey, l.hodlQueue.ChanIn(), payload,
circuitKey, l.hodlQueue.ChanIn(), add.CustomRecords, payload,
)
if err != nil {
return err

View File

@ -1049,11 +1049,12 @@ func (i *mockInvoiceRegistry) SettleHodlInvoice(
func (i *mockInvoiceRegistry) NotifyExitHopHtlc(rhash lntypes.Hash,
amt lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error) {
event, err := i.registry.NotifyExitHopHtlc(
rhash, amt, expiry, currentHeight, circuitKey, hodlChan,
payload,
rhash, amt, expiry, currentHeight, circuitKey,
hodlChan, wireCustomRecords, payload,
)
if err != nil {
return nil, err

View File

@ -918,6 +918,7 @@ func (i *InvoiceRegistry) processAMP(ctx invoiceUpdateCtx) error {
func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
amtPaid lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
circuitKey CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload Payload) (HtlcResolution, error) {
// Create the update context containing the relevant details of the
@ -929,6 +930,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
expiry: expiry,
currentHeight: currentHeight,
finalCltvRejectDelta: i.cfg.FinalCltvRejectDelta,
wireCustomRecords: wireCustomRecords,
customRecords: payload.CustomRecords(),
mpp: payload.MultiPath(),
amp: payload.AMPRecord(),
@ -1051,6 +1053,7 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
// the interceptor's client an opportunity to manipulate the
// settlement process.
err = i.cfg.HtlcInterceptor.Intercept(HtlcModifyRequest{
WireCustomRecords: ctx.wireCustomRecords,
ExitHtlcCircuitKey: ctx.circuitKey,
ExitHtlcAmt: ctx.amtPaid,
ExitHtlcExpiry: ctx.expiry,

View File

@ -245,7 +245,8 @@ func testSettleInvoice(t *testing.T,
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value,
uint32(testCurrentHeight)+testInvoiceCltvDelta-1,
testCurrentHeight, getCircuitKey(10), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(10), hodlChan,
nil, testPayload,
)
if err != nil {
t.Fatal(err)
@ -261,7 +262,7 @@ func testSettleInvoice(t *testing.T,
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan,
testPayload,
nil, testPayload,
)
if err != nil {
t.Fatal(err)
@ -302,7 +303,8 @@ func testSettleInvoice(t *testing.T,
// behaviour after a restart.
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
)
require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
require.NotNil(t, resolution)
@ -316,7 +318,8 @@ func testSettleInvoice(t *testing.T,
// paid invoice that may open up a probe vector.
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid+600, testHtlcExpiry,
testCurrentHeight, getCircuitKey(1), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(1), hodlChan,
nil, testPayload,
)
require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
require.NotNil(t, resolution)
@ -331,7 +334,8 @@ func testSettleInvoice(t *testing.T,
// would have failed if it were the first payment.
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid-600, testHtlcExpiry,
testCurrentHeight, getCircuitKey(2), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(2), hodlChan,
nil, testPayload,
)
require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
require.NotNil(t, resolution)
@ -468,7 +472,8 @@ func testCancelInvoiceImpl(t *testing.T, gc bool,
hodlChan := make(chan interface{})
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoiceAmount, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
)
if err != nil {
t.Fatal("expected settlement of a canceled invoice to succeed")
@ -577,7 +582,8 @@ func testSettleHoldInvoice(t *testing.T,
// should be possible.
resolution, err := registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@ -589,7 +595,8 @@ func testSettleHoldInvoice(t *testing.T,
// Test idempotency.
resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@ -602,7 +609,8 @@ func testSettleHoldInvoice(t *testing.T,
// is a replay.
resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight+10, getCircuitKey(0), hodlChan, testPayload,
testCurrentHeight+10, getCircuitKey(0), hodlChan,
nil, testPayload,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@ -615,7 +623,7 @@ func testSettleHoldInvoice(t *testing.T,
// requirement. It should be rejected.
resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, 1, testCurrentHeight,
getCircuitKey(1), hodlChan, testPayload,
getCircuitKey(1), hodlChan, nil, testPayload,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@ -719,7 +727,8 @@ func testCancelHoldInvoice(t *testing.T,
// should be possible.
resolution, err := registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(0), hodlChan,
nil, testPayload,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@ -741,7 +750,8 @@ func testCancelHoldInvoice(t *testing.T,
// accept height.
resolution, err = registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
testCurrentHeight+1, getCircuitKey(0), hodlChan, testPayload,
testCurrentHeight+1, getCircuitKey(0), hodlChan,
nil, testPayload,
)
if err != nil {
t.Fatalf("expected settle to succeed but got %v", err)
@ -770,7 +780,7 @@ func testUnknownInvoice(t *testing.T,
amt := lnwire.MilliSatoshi(100000)
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, amt, testHtlcExpiry, testCurrentHeight,
getCircuitKey(0), hodlChan, testPayload,
getCircuitKey(0), hodlChan, nil, testPayload,
)
if err != nil {
t.Fatal("unexpected error")
@ -831,7 +841,7 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
resolution, err := ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry,
testCurrentHeight, getCircuitKey(10), hodlChan,
invalidKeySendPayload,
nil, invalidKeySendPayload,
)
if err != nil {
t.Fatal(err)
@ -852,8 +862,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
}
resolution, err = ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry,
testCurrentHeight, getCircuitKey(10), hodlChan, keySendPayload,
hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
hodlChan, nil, keySendPayload,
)
if err != nil {
t.Fatal(err)
@ -881,8 +891,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
// Replay the same keysend payment. We expect an identical resolution,
// but no event should be generated.
resolution, err = ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry,
testCurrentHeight, getCircuitKey(10), hodlChan, keySendPayload,
hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
hodlChan, nil, keySendPayload,
)
require.Nil(t, err)
checkSettleResolution(t, resolution, preimage)
@ -905,8 +915,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
}
resolution, err = ctx.registry.NotifyExitHopHtlc(
hash2, amt, expiry,
testCurrentHeight, getCircuitKey(20), hodlChan, keySendPayload2,
hash2, amt, expiry, testCurrentHeight, getCircuitKey(20),
hodlChan, nil, keySendPayload2,
)
require.Nil(t, err)
@ -964,8 +974,8 @@ func testHoldKeysendImpl(t *testing.T, timeoutKeysend bool,
}
resolution, err := ctx.registry.NotifyExitHopHtlc(
hash, amt, expiry,
testCurrentHeight, getCircuitKey(10), hodlChan, keysendPayload,
hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
hodlChan, nil, keysendPayload,
)
if err != nil {
t.Fatal(err)
@ -1047,8 +1057,8 @@ func testMppPayment(t *testing.T,
hodlChan1 := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry,
testCurrentHeight, getCircuitKey(10), hodlChan1, mppPayload,
testHtlcExpiry, testCurrentHeight, getCircuitKey(10),
hodlChan1, nil, mppPayload,
)
if err != nil {
t.Fatal(err)
@ -1075,8 +1085,8 @@ func testMppPayment(t *testing.T,
hodlChan2 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry,
testCurrentHeight, getCircuitKey(11), hodlChan2, mppPayload,
testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
hodlChan2, nil, mppPayload,
)
if err != nil {
t.Fatal(err)
@ -1089,8 +1099,8 @@ func testMppPayment(t *testing.T,
hodlChan3 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry,
testCurrentHeight, getCircuitKey(12), hodlChan3, mppPayload,
testHtlcExpiry, testCurrentHeight, getCircuitKey(12),
hodlChan3, nil, mppPayload,
)
if err != nil {
t.Fatal(err)
@ -1149,7 +1159,7 @@ func testMppPaymentWithOverpayment(t *testing.T,
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
hodlChan1, mppPayload,
hodlChan1, nil, mppPayload,
)
if err != nil {
t.Fatal(err)
@ -1164,7 +1174,7 @@ func testMppPaymentWithOverpayment(t *testing.T,
testInvoicePaymentHash,
testInvoice.Terms.Value/2+overpayment, testHtlcExpiry,
testCurrentHeight, getCircuitKey(12), hodlChan2,
mppPayload,
nil, mppPayload,
)
if err != nil {
t.Fatal(err)
@ -1449,7 +1459,7 @@ func testHeightExpiryWithRegistryImpl(t *testing.T, numParts int, settle bool,
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, htlcAmt, expiry,
testCurrentHeight, getCircuitKey(uint64(i)), hodlChan,
payLoad,
nil, payLoad,
)
require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution")
@ -1551,8 +1561,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
hodlChan1 := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2,
testHtlcExpiry,
testCurrentHeight, getCircuitKey(10), hodlChan1, mppPayload,
testHtlcExpiry, testCurrentHeight, getCircuitKey(10),
hodlChan1, nil, mppPayload,
)
require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution")
@ -1581,7 +1591,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
hodlChan2 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry,
testCurrentHeight, getCircuitKey(11), hodlChan2, mppPayload,
testCurrentHeight, getCircuitKey(11), hodlChan2,
nil, mppPayload,
)
require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution")
@ -1590,7 +1601,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
hodlChan3 := make(chan interface{}, 1)
resolution, err = ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry,
testCurrentHeight, getCircuitKey(12), hodlChan3, mppPayload,
testCurrentHeight, getCircuitKey(12), hodlChan3,
nil, mppPayload,
)
require.NoError(t, err)
require.Nil(t, resolution, "did not expect direct resolution")
@ -1695,7 +1707,8 @@ func testSettleInvoicePaymentAddrRequired(t *testing.T,
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, invoice.Terms.Value,
uint32(testCurrentHeight)+testInvoiceCltvDelta-1,
testCurrentHeight, getCircuitKey(10), hodlChan, testPayload,
testCurrentHeight, getCircuitKey(10), hodlChan,
nil, testPayload,
)
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.
hodlChan := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc(
testInvoicePaymentHash, testInvoiceAmount,
testHtlcExpiry, testCurrentHeight,
getCircuitKey(10), hodlChan, testPayload,
testInvoicePaymentHash, testInvoiceAmount, testHtlcExpiry,
testCurrentHeight, getCircuitKey(10), hodlChan,
nil, testPayload,
)
require.NoError(t, err)
@ -1848,8 +1861,8 @@ func testAMPWithoutMPPPayload(t *testing.T,
hodlChan := make(chan interface{}, 1)
resolution, err := ctx.registry.NotifyExitHopHtlc(
lntypes.Hash{}, shardAmt, expiry,
testCurrentHeight, getCircuitKey(uint64(10)), hodlChan,
lntypes.Hash{}, shardAmt, expiry, testCurrentHeight,
getCircuitKey(uint64(10)), hodlChan, nil,
payload,
)
require.NoError(t, err)
@ -2017,8 +2030,8 @@ func testSpontaneousAmpPaymentImpl(
}
resolution, err := ctx.registry.NotifyExitHopHtlc(
child.Hash, shardAmt, expiry,
testCurrentHeight, getCircuitKey(uint64(i)), hodlChan,
child.Hash, shardAmt, expiry, testCurrentHeight,
getCircuitKey(uint64(i)), hodlChan, nil,
payload,
)
require.NoError(t, err)

View File

@ -547,6 +547,11 @@ type InvoiceHTLC struct {
// the htlc.
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
// 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
@ -566,6 +571,7 @@ func (h *InvoiceHTLC) Copy() *InvoiceHTLC {
result.CustomRecords[k] = v
}
result.WireCustomRecords = h.WireCustomRecords.Copy()
result.AMP = h.AMP.Copy()
return &result

View File

@ -21,7 +21,15 @@ type invoiceUpdateCtx struct {
expiry uint32
currentHeight int32
finalCltvRejectDelta int32
// wireCustomRecords are the custom records that were included with the
// HTLC wire message.
wireCustomRecords lnwire.CustomRecords
// 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
@ -95,12 +103,14 @@ func (i invoiceUpdateCtx) settleRes(preimage lntypes.Preimage,
// acceptRes is a helper function which creates an accept resolution with
// the information contained in the invoiceUpdateCtx and the accept resolution
// result provided.
func (i invoiceUpdateCtx) acceptRes(outcome acceptResolutionResult) *htlcAcceptResolution {
func (i invoiceUpdateCtx) acceptRes(
outcome acceptResolutionResult) *htlcAcceptResolution {
return newAcceptResolution(i.circuitKey, outcome)
}
// 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.
func updateInvoice(ctx *invoiceUpdateCtx, inv *Invoice) (
*InvoiceUpdateDesc, HtlcResolution, error) {
@ -119,7 +129,7 @@ func updateInvoice(ctx *invoiceUpdateCtx, inv *Invoice) (
pre := inv.Terms.PaymentPreimage
// 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 {
pre = htlc.AMP.Preimage
}
@ -180,13 +190,19 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
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.
acceptDesc := &HtlcAcceptDesc{
Amt: ctx.amtPaid,
Expiry: ctx.expiry,
AcceptHeight: ctx.currentHeight,
MppTotalAmt: totalAmt,
CustomRecords: ctx.customRecords,
CustomRecords: record.CustomSet(customRecords),
}
if ctx.amp != nil {
@ -223,7 +239,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
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
for _, htlc := range htlcSet {
if totalAmt != htlc.MppTotalAmt {
@ -265,7 +281,7 @@ func updateMpp(ctx *invoiceUpdateCtx, inv *Invoice) (*InvoiceUpdateDesc,
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.
if inv.HodlInvoice {
update.State = &InvoiceStateUpdateDesc{
@ -434,13 +450,19 @@ func updateLegacy(ctx *invoiceUpdateCtx,
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.
newHtlcs := map[CircuitKey]*HtlcAcceptDesc{
ctx.circuitKey: {
Amt: ctx.amtPaid,
Expiry: ctx.expiry,
AcceptHeight: ctx.currentHeight,
CustomRecords: ctx.customRecords,
CustomRecords: record.CustomSet(customRecords),
},
}

View File

@ -5,6 +5,7 @@ import (
"time"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
"github.com/stretchr/testify/require"
)
@ -45,6 +46,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
},
invState: ContractAccepted,
@ -58,6 +60,49 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
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,
@ -73,6 +118,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
},
invState: ContractSettled,
@ -86,6 +132,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
},
expErr: nil,
@ -101,6 +148,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
},
invState: ContractCanceled,
@ -114,6 +162,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: nil,
},
expErr: nil,
@ -129,6 +178,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -146,6 +196,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -165,6 +216,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -182,6 +234,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -201,6 +254,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -218,6 +272,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -237,6 +292,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -254,6 +310,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -273,6 +330,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -290,6 +348,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -309,6 +368,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -326,6 +386,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -345,6 +406,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -362,6 +424,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -385,6 +448,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -402,6 +466,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -421,6 +486,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -438,6 +504,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -457,6 +524,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -474,6 +542,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -493,6 +562,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -510,6 +580,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateSettled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -529,6 +600,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateAccepted,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -546,6 +618,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -565,6 +638,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -582,6 +656,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -601,6 +676,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -618,6 +694,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -637,6 +714,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,
@ -654,6 +732,7 @@ func TestUpdateHTLC(t *testing.T) {
Expiry: 40,
State: HtlcStateCanceled,
CustomRecords: make(record.CustomSet),
WireCustomRecords: make(lnwire.CustomRecords),
AMP: &InvoiceHtlcAMPData{
Record: *ampRecord,
Hash: hash,