Skip to content

Commit 197b291

Browse files
ffranrguggero
authored andcommitted
multi: pass UpdateAddHtlc message custom records to invoice modifier
1 parent c0d2b53 commit 197b291

File tree

12 files changed

+492
-364
lines changed

12 files changed

+492
-364
lines changed

contractcourt/htlc_incoming_contest_resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (h *htlcIncomingContestResolver) Resolve(
308308

309309
resolution, err := h.Registry.NotifyExitHopHtlc(
310310
h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight,
311-
circuitKey, hodlQueue.ChanIn(), payload,
311+
circuitKey, hodlQueue.ChanIn(), nil, payload,
312312
)
313313
if err != nil {
314314
return nil, err

contractcourt/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Registry interface {
3030
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
3131
expiry uint32, currentHeight int32,
3232
circuitKey models.CircuitKey, hodlChan chan<- interface{},
33+
wireCustomRecords lnwire.CustomRecords,
3334
payload invoices.Payload) (invoices.HtlcResolution, error)
3435

3536
// HodlUnsubscribeAll unsubscribes from all htlc resolutions.

contractcourt/mock_registry_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type mockRegistry struct {
2626
func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash,
2727
paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
2828
circuitKey models.CircuitKey, hodlChan chan<- interface{},
29+
wireCustomRecords lnwire.CustomRecords,
2930
payload invoices.Payload) (invoices.HtlcResolution, error) {
3031

3132
r.notifyChan <- notifyExitHopData{

htlcswitch/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type InvoiceDatabase interface {
3232
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
3333
expiry uint32, currentHeight int32,
3434
circuitKey models.CircuitKey, hodlChan chan<- interface{},
35+
wireCustomRecords lnwire.CustomRecords,
3536
payload invoices.Payload) (invoices.HtlcResolution, error)
3637

3738
// CancelInvoice attempts to cancel the invoice corresponding to the

htlcswitch/link.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3584,7 +3584,7 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
35843584

35853585
event, err := l.cfg.Registry.NotifyExitHopHtlc(
35863586
invoiceHash, pd.Amount, pd.Timeout, int32(heightNow),
3587-
circuitKey, l.hodlQueue.ChanIn(), payload,
3587+
circuitKey, l.hodlQueue.ChanIn(), pd.CustomRecords, payload,
35883588
)
35893589
if err != nil {
35903590
return err

htlcswitch/mock.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,12 @@ func (i *mockInvoiceRegistry) SettleHodlInvoice(
10461046
func (i *mockInvoiceRegistry) NotifyExitHopHtlc(rhash lntypes.Hash,
10471047
amt lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
10481048
circuitKey models.CircuitKey, hodlChan chan<- interface{},
1049+
wireCustomRecords lnwire.CustomRecords,
10491050
payload invoices.Payload) (invoices.HtlcResolution, error) {
10501051

10511052
event, err := i.registry.NotifyExitHopHtlc(
1052-
rhash, amt, expiry, currentHeight, circuitKey, hodlChan,
1053-
payload,
1053+
rhash, amt, expiry, currentHeight, circuitKey,
1054+
hodlChan, wireCustomRecords, payload,
10541055
)
10551056
if err != nil {
10561057
return nil, err

invoices/invoiceregistry.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ func (i *InvoiceRegistry) processAMP(ctx invoiceUpdateCtx) error {
892892
func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
893893
amtPaid lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
894894
circuitKey CircuitKey, hodlChan chan<- interface{},
895+
wireCustomRecords lnwire.CustomRecords,
895896
payload Payload) (HtlcResolution, error) {
896897

897898
// Create the update context containing the relevant details of the
@@ -903,6 +904,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
903904
expiry: expiry,
904905
currentHeight: currentHeight,
905906
finalCltvRejectDelta: i.cfg.FinalCltvRejectDelta,
907+
wireCustomRecords: wireCustomRecords,
906908
customRecords: payload.CustomRecords(),
907909
mpp: payload.MultiPath(),
908910
amp: payload.AMPRecord(),
@@ -1007,6 +1009,7 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
10071009
// the interceptor's client an opportunity to manipulate the
10081010
// settlement process.
10091011
clientReq := HtlcModifyRequest{
1012+
WireCustomRecords: ctx.wireCustomRecords,
10101013
ExitHtlcCircuitKey: ctx.circuitKey,
10111014
ExitHtlcAmt: ctx.amtPaid,
10121015
ExitHtlcExpiry: ctx.expiry,

invoices/invoiceregistry_test.go

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ func testSettleInvoice(t *testing.T,
245245
resolution, err := ctx.registry.NotifyExitHopHtlc(
246246
testInvoicePaymentHash, testInvoice.Terms.Value,
247247
uint32(testCurrentHeight)+testInvoiceCltvDelta-1,
248-
testCurrentHeight, getCircuitKey(10), hodlChan, testPayload,
248+
testCurrentHeight, getCircuitKey(10), hodlChan,
249+
nil, testPayload,
249250
)
250251
if err != nil {
251252
t.Fatal(err)
@@ -261,7 +262,7 @@ func testSettleInvoice(t *testing.T,
261262
resolution, err = ctx.registry.NotifyExitHopHtlc(
262263
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
263264
testCurrentHeight, getCircuitKey(0), hodlChan,
264-
testPayload,
265+
nil, testPayload,
265266
)
266267
if err != nil {
267268
t.Fatal(err)
@@ -302,7 +303,8 @@ func testSettleInvoice(t *testing.T,
302303
// behaviour after a restart.
303304
resolution, err = ctx.registry.NotifyExitHopHtlc(
304305
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
305-
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
306+
testCurrentHeight, getCircuitKey(0), hodlChan,
307+
nil, testPayload,
306308
)
307309
require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
308310
require.NotNil(t, resolution)
@@ -316,7 +318,8 @@ func testSettleInvoice(t *testing.T,
316318
// paid invoice that may open up a probe vector.
317319
resolution, err = ctx.registry.NotifyExitHopHtlc(
318320
testInvoicePaymentHash, amtPaid+600, testHtlcExpiry,
319-
testCurrentHeight, getCircuitKey(1), hodlChan, testPayload,
321+
testCurrentHeight, getCircuitKey(1), hodlChan,
322+
nil, testPayload,
320323
)
321324
require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
322325
require.NotNil(t, resolution)
@@ -331,7 +334,8 @@ func testSettleInvoice(t *testing.T,
331334
// would have failed if it were the first payment.
332335
resolution, err = ctx.registry.NotifyExitHopHtlc(
333336
testInvoicePaymentHash, amtPaid-600, testHtlcExpiry,
334-
testCurrentHeight, getCircuitKey(2), hodlChan, testPayload,
337+
testCurrentHeight, getCircuitKey(2), hodlChan,
338+
nil, testPayload,
335339
)
336340
require.NoError(t, err, "unexpected NotifyExitHopHtlc error")
337341
require.NotNil(t, resolution)
@@ -468,7 +472,8 @@ func testCancelInvoiceImpl(t *testing.T, gc bool,
468472
hodlChan := make(chan interface{})
469473
resolution, err := ctx.registry.NotifyExitHopHtlc(
470474
testInvoicePaymentHash, testInvoiceAmount, testHtlcExpiry,
471-
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
475+
testCurrentHeight, getCircuitKey(0), hodlChan,
476+
nil, testPayload,
472477
)
473478
if err != nil {
474479
t.Fatal("expected settlement of a canceled invoice to succeed")
@@ -577,7 +582,8 @@ func testSettleHoldInvoice(t *testing.T,
577582
// should be possible.
578583
resolution, err := registry.NotifyExitHopHtlc(
579584
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
580-
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
585+
testCurrentHeight, getCircuitKey(0), hodlChan,
586+
nil, testPayload,
581587
)
582588
if err != nil {
583589
t.Fatalf("expected settle to succeed but got %v", err)
@@ -589,7 +595,8 @@ func testSettleHoldInvoice(t *testing.T,
589595
// Test idempotency.
590596
resolution, err = registry.NotifyExitHopHtlc(
591597
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
592-
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
598+
testCurrentHeight, getCircuitKey(0), hodlChan,
599+
nil, testPayload,
593600
)
594601
if err != nil {
595602
t.Fatalf("expected settle to succeed but got %v", err)
@@ -602,7 +609,8 @@ func testSettleHoldInvoice(t *testing.T,
602609
// is a replay.
603610
resolution, err = registry.NotifyExitHopHtlc(
604611
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
605-
testCurrentHeight+10, getCircuitKey(0), hodlChan, testPayload,
612+
testCurrentHeight+10, getCircuitKey(0), hodlChan,
613+
nil, testPayload,
606614
)
607615
if err != nil {
608616
t.Fatalf("expected settle to succeed but got %v", err)
@@ -615,7 +623,7 @@ func testSettleHoldInvoice(t *testing.T,
615623
// requirement. It should be rejected.
616624
resolution, err = registry.NotifyExitHopHtlc(
617625
testInvoicePaymentHash, amtPaid, 1, testCurrentHeight,
618-
getCircuitKey(1), hodlChan, testPayload,
626+
getCircuitKey(1), hodlChan, nil, testPayload,
619627
)
620628
if err != nil {
621629
t.Fatalf("expected settle to succeed but got %v", err)
@@ -719,7 +727,8 @@ func testCancelHoldInvoice(t *testing.T,
719727
// should be possible.
720728
resolution, err := registry.NotifyExitHopHtlc(
721729
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
722-
testCurrentHeight, getCircuitKey(0), hodlChan, testPayload,
730+
testCurrentHeight, getCircuitKey(0), hodlChan,
731+
nil, testPayload,
723732
)
724733
if err != nil {
725734
t.Fatalf("expected settle to succeed but got %v", err)
@@ -741,7 +750,8 @@ func testCancelHoldInvoice(t *testing.T,
741750
// accept height.
742751
resolution, err = registry.NotifyExitHopHtlc(
743752
testInvoicePaymentHash, amtPaid, testHtlcExpiry,
744-
testCurrentHeight+1, getCircuitKey(0), hodlChan, testPayload,
753+
testCurrentHeight+1, getCircuitKey(0), hodlChan,
754+
nil, testPayload,
745755
)
746756
if err != nil {
747757
t.Fatalf("expected settle to succeed but got %v", err)
@@ -770,7 +780,7 @@ func testUnknownInvoice(t *testing.T,
770780
amt := lnwire.MilliSatoshi(100000)
771781
resolution, err := ctx.registry.NotifyExitHopHtlc(
772782
testInvoicePaymentHash, amt, testHtlcExpiry, testCurrentHeight,
773-
getCircuitKey(0), hodlChan, testPayload,
783+
getCircuitKey(0), hodlChan, nil, testPayload,
774784
)
775785
if err != nil {
776786
t.Fatal("unexpected error")
@@ -831,7 +841,7 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
831841
resolution, err := ctx.registry.NotifyExitHopHtlc(
832842
hash, amt, expiry,
833843
testCurrentHeight, getCircuitKey(10), hodlChan,
834-
invalidKeySendPayload,
844+
nil, invalidKeySendPayload,
835845
)
836846
if err != nil {
837847
t.Fatal(err)
@@ -852,8 +862,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
852862
}
853863

854864
resolution, err = ctx.registry.NotifyExitHopHtlc(
855-
hash, amt, expiry,
856-
testCurrentHeight, getCircuitKey(10), hodlChan, keySendPayload,
865+
hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
866+
hodlChan, nil, keySendPayload,
857867
)
858868
if err != nil {
859869
t.Fatal(err)
@@ -881,8 +891,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
881891
// Replay the same keysend payment. We expect an identical resolution,
882892
// but no event should be generated.
883893
resolution, err = ctx.registry.NotifyExitHopHtlc(
884-
hash, amt, expiry,
885-
testCurrentHeight, getCircuitKey(10), hodlChan, keySendPayload,
894+
hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
895+
hodlChan, nil, keySendPayload,
886896
)
887897
require.Nil(t, err)
888898
checkSettleResolution(t, resolution, preimage)
@@ -905,8 +915,8 @@ func testKeySendImpl(t *testing.T, keySendEnabled bool,
905915
}
906916

907917
resolution, err = ctx.registry.NotifyExitHopHtlc(
908-
hash2, amt, expiry,
909-
testCurrentHeight, getCircuitKey(20), hodlChan, keySendPayload2,
918+
hash2, amt, expiry, testCurrentHeight, getCircuitKey(20),
919+
hodlChan, nil, keySendPayload2,
910920
)
911921
require.Nil(t, err)
912922

@@ -964,8 +974,8 @@ func testHoldKeysendImpl(t *testing.T, timeoutKeysend bool,
964974
}
965975

966976
resolution, err := ctx.registry.NotifyExitHopHtlc(
967-
hash, amt, expiry,
968-
testCurrentHeight, getCircuitKey(10), hodlChan, keysendPayload,
977+
hash, amt, expiry, testCurrentHeight, getCircuitKey(10),
978+
hodlChan, nil, keysendPayload,
969979
)
970980
if err != nil {
971981
t.Fatal(err)
@@ -1047,8 +1057,8 @@ func testMppPayment(t *testing.T,
10471057
hodlChan1 := make(chan interface{}, 1)
10481058
resolution, err := ctx.registry.NotifyExitHopHtlc(
10491059
testInvoicePaymentHash, testInvoice.Terms.Value/2,
1050-
testHtlcExpiry,
1051-
testCurrentHeight, getCircuitKey(10), hodlChan1, mppPayload,
1060+
testHtlcExpiry, testCurrentHeight, getCircuitKey(10),
1061+
hodlChan1, nil, mppPayload,
10521062
)
10531063
if err != nil {
10541064
t.Fatal(err)
@@ -1075,8 +1085,8 @@ func testMppPayment(t *testing.T,
10751085
hodlChan2 := make(chan interface{}, 1)
10761086
resolution, err = ctx.registry.NotifyExitHopHtlc(
10771087
testInvoicePaymentHash, testInvoice.Terms.Value/2,
1078-
testHtlcExpiry,
1079-
testCurrentHeight, getCircuitKey(11), hodlChan2, mppPayload,
1088+
testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
1089+
hodlChan2, nil, mppPayload,
10801090
)
10811091
if err != nil {
10821092
t.Fatal(err)
@@ -1089,8 +1099,8 @@ func testMppPayment(t *testing.T,
10891099
hodlChan3 := make(chan interface{}, 1)
10901100
resolution, err = ctx.registry.NotifyExitHopHtlc(
10911101
testInvoicePaymentHash, testInvoice.Terms.Value/2,
1092-
testHtlcExpiry,
1093-
testCurrentHeight, getCircuitKey(12), hodlChan3, mppPayload,
1102+
testHtlcExpiry, testCurrentHeight, getCircuitKey(12),
1103+
hodlChan3, nil, mppPayload,
10941104
)
10951105
if err != nil {
10961106
t.Fatal(err)
@@ -1149,7 +1159,7 @@ func testMppPaymentWithOverpayment(t *testing.T,
11491159
resolution, err := ctx.registry.NotifyExitHopHtlc(
11501160
testInvoicePaymentHash, testInvoice.Terms.Value/2,
11511161
testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
1152-
hodlChan1, mppPayload,
1162+
hodlChan1, nil, mppPayload,
11531163
)
11541164
if err != nil {
11551165
t.Fatal(err)
@@ -1164,7 +1174,7 @@ func testMppPaymentWithOverpayment(t *testing.T,
11641174
testInvoicePaymentHash,
11651175
testInvoice.Terms.Value/2+overpayment, testHtlcExpiry,
11661176
testCurrentHeight, getCircuitKey(12), hodlChan2,
1167-
mppPayload,
1177+
nil, mppPayload,
11681178
)
11691179
if err != nil {
11701180
t.Fatal(err)
@@ -1449,7 +1459,7 @@ func testHeightExpiryWithRegistryImpl(t *testing.T, numParts int, settle bool,
14491459
resolution, err := ctx.registry.NotifyExitHopHtlc(
14501460
testInvoicePaymentHash, htlcAmt, expiry,
14511461
testCurrentHeight, getCircuitKey(uint64(i)), hodlChan,
1452-
payLoad,
1462+
nil, payLoad,
14531463
)
14541464
require.NoError(t, err)
14551465
require.Nil(t, resolution, "did not expect direct resolution")
@@ -1551,8 +1561,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
15511561
hodlChan1 := make(chan interface{}, 1)
15521562
resolution, err := ctx.registry.NotifyExitHopHtlc(
15531563
testInvoicePaymentHash, testInvoice.Terms.Value/2,
1554-
testHtlcExpiry,
1555-
testCurrentHeight, getCircuitKey(10), hodlChan1, mppPayload,
1564+
testHtlcExpiry, testCurrentHeight, getCircuitKey(10),
1565+
hodlChan1, nil, mppPayload,
15561566
)
15571567
require.NoError(t, err)
15581568
require.Nil(t, resolution, "did not expect direct resolution")
@@ -1581,7 +1591,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
15811591
hodlChan2 := make(chan interface{}, 1)
15821592
resolution, err = ctx.registry.NotifyExitHopHtlc(
15831593
testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry,
1584-
testCurrentHeight, getCircuitKey(11), hodlChan2, mppPayload,
1594+
testCurrentHeight, getCircuitKey(11), hodlChan2,
1595+
nil, mppPayload,
15851596
)
15861597
require.NoError(t, err)
15871598
require.Nil(t, resolution, "did not expect direct resolution")
@@ -1590,7 +1601,8 @@ func testMultipleSetHeightExpiry(t *testing.T,
15901601
hodlChan3 := make(chan interface{}, 1)
15911602
resolution, err = ctx.registry.NotifyExitHopHtlc(
15921603
testInvoicePaymentHash, testInvoice.Terms.Value/2, expiry,
1593-
testCurrentHeight, getCircuitKey(12), hodlChan3, mppPayload,
1604+
testCurrentHeight, getCircuitKey(12), hodlChan3,
1605+
nil, mppPayload,
15941606
)
15951607
require.NoError(t, err)
15961608
require.Nil(t, resolution, "did not expect direct resolution")
@@ -1695,7 +1707,8 @@ func testSettleInvoicePaymentAddrRequired(t *testing.T,
16951707
resolution, err := ctx.registry.NotifyExitHopHtlc(
16961708
testInvoicePaymentHash, invoice.Terms.Value,
16971709
uint32(testCurrentHeight)+testInvoiceCltvDelta-1,
1698-
testCurrentHeight, getCircuitKey(10), hodlChan, testPayload,
1710+
testCurrentHeight, getCircuitKey(10), hodlChan,
1711+
nil, testPayload,
16991712
)
17001713
require.NoError(t, err)
17011714

@@ -1784,9 +1797,9 @@ func testSettleInvoicePaymentAddrRequiredOptionalGrace(t *testing.T,
17841797
// no problem as we should allow these existing invoices to be settled.
17851798
hodlChan := make(chan interface{}, 1)
17861799
resolution, err := ctx.registry.NotifyExitHopHtlc(
1787-
testInvoicePaymentHash, testInvoiceAmount,
1788-
testHtlcExpiry, testCurrentHeight,
1789-
getCircuitKey(10), hodlChan, testPayload,
1800+
testInvoicePaymentHash, testInvoiceAmount, testHtlcExpiry,
1801+
testCurrentHeight, getCircuitKey(10), hodlChan,
1802+
nil, testPayload,
17901803
)
17911804
require.NoError(t, err)
17921805

@@ -1848,8 +1861,8 @@ func testAMPWithoutMPPPayload(t *testing.T,
18481861

18491862
hodlChan := make(chan interface{}, 1)
18501863
resolution, err := ctx.registry.NotifyExitHopHtlc(
1851-
lntypes.Hash{}, shardAmt, expiry,
1852-
testCurrentHeight, getCircuitKey(uint64(10)), hodlChan,
1864+
lntypes.Hash{}, shardAmt, expiry, testCurrentHeight,
1865+
getCircuitKey(uint64(10)), hodlChan, nil,
18531866
payload,
18541867
)
18551868
require.NoError(t, err)
@@ -2017,8 +2030,8 @@ func testSpontaneousAmpPaymentImpl(
20172030
}
20182031

20192032
resolution, err := ctx.registry.NotifyExitHopHtlc(
2020-
child.Hash, shardAmt, expiry,
2021-
testCurrentHeight, getCircuitKey(uint64(i)), hodlChan,
2033+
child.Hash, shardAmt, expiry, testCurrentHeight,
2034+
getCircuitKey(uint64(i)), hodlChan, nil,
20222035
payload,
20232036
)
20242037
require.NoError(t, err)

0 commit comments

Comments
 (0)