Skip to content

Commit 7358c1b

Browse files
authored
Merge pull request #1244 from GeorgeTsagk/strict-forwarding-p2
Strict forwarding pt.2
2 parents 35d8f1c + ffc6e68 commit 7358c1b

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

tapchannel/aux_invoice_manager.go

+7
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ func (s *AuxInvoiceManager) handleInvoiceAccept(_ context.Context,
164164
resp.CancelSet = true
165165
}
166166

167+
return resp, nil
168+
} else if !isAssetInvoice(req.Invoice, s) && !req.Invoice.IsKeysend {
169+
// If we do have custom records, but the invoice does not
170+
// correspond to an asset invoice, we do not settle the invoice.
171+
// Since we requested btc we should be receiving btc.
172+
resp.CancelSet = true
173+
167174
return resp, nil
168175
}
169176

tapchannel/aux_invoice_manager_test.go

+46-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import (
2424
)
2525

2626
const (
27-
// The test channel ID to use across the test cases.
28-
testChanID = 1234
29-
3027
// maxRandomInvoiceValueMSat is the maximum invoice value in mSAT to be
3128
// generated by the property based tests.
3229
maxRandomInvoiceValueMSat = 100_000_000_000
@@ -52,12 +49,20 @@ var (
5249
// The node ID to be used for the RFQ peer.
5350
testNodeID = route.Vertex{1, 2, 3}
5451

52+
// The asset rate value to use across tests.
5553
assetRate = big.NewInt(100_000)
5654

55+
// The asset rate struct based on the assetRate value.
5756
testAssetRate = rfqmath.FixedPoint[rfqmath.BigInt]{
5857
Coefficient: rfqmath.NewBigInt(assetRate),
5958
Scale: 0,
6059
}
60+
61+
// The test RFQ ID to use across tests.
62+
testRfqID = dummyRfqID(31)
63+
64+
// The test RFQ SCID that is derived from testRfqID.
65+
testScid = testRfqID.Scid()
6166
)
6267

6368
// mockRfqManager mocks the interface of the rfq manager required by the aux
@@ -184,6 +189,11 @@ func (m *mockHtlcModifierProperty) HtlcModifier(ctx context.Context,
184189
if r.ExitHtlcAmt != res.AmtPaid {
185190
m.t.Errorf("AmtPaid != ExitHtlcAmt")
186191
}
192+
} else if !isAssetInvoice(r.Invoice, m) {
193+
if !res.CancelSet {
194+
m.t.Errorf("expected cancel set flag")
195+
}
196+
continue
187197
}
188198

189199
htlcBlob, err := r.WireCustomRecords.Serialize()
@@ -293,7 +303,7 @@ func TestAuxInvoiceManager(t *testing.T) {
293303
},
294304
},
295305
buyQuotes: map[rfq.SerialisedScid]rfqmsg.BuyAccept{
296-
testChanID: {
306+
testScid: {
297307
Peer: testNodeID,
298308
},
299309
},
@@ -315,7 +325,7 @@ func TestAuxInvoiceManager(t *testing.T) {
315325
},
316326
},
317327
buyQuotes: map[rfq.SerialisedScid]rfqmsg.BuyAccept{
318-
testChanID: {
328+
testScid: {
319329
Peer: testNodeID,
320330
},
321331
},
@@ -335,7 +345,7 @@ func TestAuxInvoiceManager(t *testing.T) {
335345
dummyAssetID(1),
336346
3,
337347
),
338-
}, fn.Some(dummyRfqID(31)),
348+
}, fn.Some(testRfqID),
339349
),
340350
},
341351
},
@@ -345,7 +355,7 @@ func TestAuxInvoiceManager(t *testing.T) {
345355
},
346356
},
347357
buyQuotes: rfq.BuyAcceptMap{
348-
fn.Ptr(dummyRfqID(31)).Scid(): {
358+
testScid: {
349359
Peer: testNodeID,
350360
AssetRate: rfqmsg.NewAssetRate(
351361
testAssetRate, time.Now(),
@@ -368,7 +378,7 @@ func TestAuxInvoiceManager(t *testing.T) {
368378
dummyAssetID(1),
369379
4,
370380
),
371-
}, fn.Some(dummyRfqID(31)),
381+
}, fn.Some(testRfqID),
372382
),
373383
ExitHtlcAmt: 1234,
374384
},
@@ -379,14 +389,39 @@ func TestAuxInvoiceManager(t *testing.T) {
379389
},
380390
},
381391
buyQuotes: rfq.BuyAcceptMap{
382-
fn.Ptr(dummyRfqID(31)).Scid(): {
392+
testScid: {
383393
Peer: testNodeID,
384394
AssetRate: rfqmsg.NewAssetRate(
385395
testAssetRate, time.Now(),
386396
),
387397
},
388398
},
389399
},
400+
{
401+
name: "btc invoice, custom records",
402+
requests: []lndclient.InvoiceHtlcModifyRequest{
403+
{
404+
Invoice: &lnrpc.Invoice{
405+
ValueMsat: 10_000_000,
406+
PaymentAddr: []byte{1, 1, 1},
407+
},
408+
WireCustomRecords: newWireCustomRecords(
409+
t, []*rfqmsg.AssetBalance{
410+
rfqmsg.NewAssetBalance(
411+
dummyAssetID(1),
412+
4,
413+
),
414+
}, fn.Some(testRfqID),
415+
),
416+
ExitHtlcAmt: 1234,
417+
},
418+
},
419+
responses: []lndclient.InvoiceHtlcModifyResponse{
420+
{
421+
CancelSet: true,
422+
},
423+
},
424+
},
390425
}
391426

392427
for _, testCase := range testCases {
@@ -761,8 +796,8 @@ func testRouteHints() []*lnrpc.RouteHint {
761796
NodeId: route.Vertex{1, 1, 1}.String(),
762797
},
763798
{
764-
ChanId: 1234,
765-
NodeId: route.Vertex{1, 2, 3}.String(),
799+
ChanId: uint64(testScid),
800+
NodeId: testNodeID.String(),
766801
},
767802
},
768803
},

0 commit comments

Comments
 (0)