diff --git a/tapchannel/aux_invoice_manager.go b/tapchannel/aux_invoice_manager.go index 51b212c59..2df17ebb5 100644 --- a/tapchannel/aux_invoice_manager.go +++ b/tapchannel/aux_invoice_manager.go @@ -164,6 +164,13 @@ func (s *AuxInvoiceManager) handleInvoiceAccept(_ context.Context, resp.CancelSet = true } + return resp, nil + } else if !isAssetInvoice(req.Invoice, s) && !req.Invoice.IsKeysend { + // If we do have custom records, but the invoice does not + // correspond to an asset invoice, we do not settle the invoice. + // Since we requested btc we should be receiving btc. + resp.CancelSet = true + return resp, nil } diff --git a/tapchannel/aux_invoice_manager_test.go b/tapchannel/aux_invoice_manager_test.go index d40d0b580..a6dadc3a5 100644 --- a/tapchannel/aux_invoice_manager_test.go +++ b/tapchannel/aux_invoice_manager_test.go @@ -24,9 +24,6 @@ import ( ) const ( - // The test channel ID to use across the test cases. - testChanID = 1234 - // maxRandomInvoiceValueMSat is the maximum invoice value in mSAT to be // generated by the property based tests. maxRandomInvoiceValueMSat = 100_000_000_000 @@ -52,12 +49,20 @@ var ( // The node ID to be used for the RFQ peer. testNodeID = route.Vertex{1, 2, 3} + // The asset rate value to use across tests. assetRate = big.NewInt(100_000) + // The asset rate struct based on the assetRate value. testAssetRate = rfqmath.FixedPoint[rfqmath.BigInt]{ Coefficient: rfqmath.NewBigInt(assetRate), Scale: 0, } + + // The test RFQ ID to use across tests. + testRfqID = dummyRfqID(31) + + // The test RFQ SCID that is derived from testRfqID. + testScid = testRfqID.Scid() ) // mockRfqManager mocks the interface of the rfq manager required by the aux @@ -184,6 +189,11 @@ func (m *mockHtlcModifierProperty) HtlcModifier(ctx context.Context, if r.ExitHtlcAmt != res.AmtPaid { m.t.Errorf("AmtPaid != ExitHtlcAmt") } + } else if !isAssetInvoice(r.Invoice, m) { + if !res.CancelSet { + m.t.Errorf("expected cancel set flag") + } + continue } htlcBlob, err := r.WireCustomRecords.Serialize() @@ -293,7 +303,7 @@ func TestAuxInvoiceManager(t *testing.T) { }, }, buyQuotes: map[rfq.SerialisedScid]rfqmsg.BuyAccept{ - testChanID: { + testScid: { Peer: testNodeID, }, }, @@ -315,7 +325,7 @@ func TestAuxInvoiceManager(t *testing.T) { }, }, buyQuotes: map[rfq.SerialisedScid]rfqmsg.BuyAccept{ - testChanID: { + testScid: { Peer: testNodeID, }, }, @@ -335,7 +345,7 @@ func TestAuxInvoiceManager(t *testing.T) { dummyAssetID(1), 3, ), - }, fn.Some(dummyRfqID(31)), + }, fn.Some(testRfqID), ), }, }, @@ -345,7 +355,7 @@ func TestAuxInvoiceManager(t *testing.T) { }, }, buyQuotes: rfq.BuyAcceptMap{ - fn.Ptr(dummyRfqID(31)).Scid(): { + testScid: { Peer: testNodeID, AssetRate: rfqmsg.NewAssetRate( testAssetRate, time.Now(), @@ -368,7 +378,7 @@ func TestAuxInvoiceManager(t *testing.T) { dummyAssetID(1), 4, ), - }, fn.Some(dummyRfqID(31)), + }, fn.Some(testRfqID), ), ExitHtlcAmt: 1234, }, @@ -379,7 +389,7 @@ func TestAuxInvoiceManager(t *testing.T) { }, }, buyQuotes: rfq.BuyAcceptMap{ - fn.Ptr(dummyRfqID(31)).Scid(): { + testScid: { Peer: testNodeID, AssetRate: rfqmsg.NewAssetRate( testAssetRate, time.Now(), @@ -387,6 +397,31 @@ func TestAuxInvoiceManager(t *testing.T) { }, }, }, + { + name: "btc invoice, custom records", + requests: []lndclient.InvoiceHtlcModifyRequest{ + { + Invoice: &lnrpc.Invoice{ + ValueMsat: 10_000_000, + PaymentAddr: []byte{1, 1, 1}, + }, + WireCustomRecords: newWireCustomRecords( + t, []*rfqmsg.AssetBalance{ + rfqmsg.NewAssetBalance( + dummyAssetID(1), + 4, + ), + }, fn.Some(testRfqID), + ), + ExitHtlcAmt: 1234, + }, + }, + responses: []lndclient.InvoiceHtlcModifyResponse{ + { + CancelSet: true, + }, + }, + }, } for _, testCase := range testCases { @@ -761,8 +796,8 @@ func testRouteHints() []*lnrpc.RouteHint { NodeId: route.Vertex{1, 1, 1}.String(), }, { - ChanId: 1234, - NodeId: route.Vertex{1, 2, 3}.String(), + ChanId: uint64(testScid), + NodeId: testNodeID.String(), }, }, },