multi: break invoice depenency on channeldb
Now that we have the new package `lnd/channeldb/models` we can invert the depenency between `channeldb` and `invoices`. - Move all the invoice related types and errors to the `invoices` package. - Ensure that all the packages dealing with invoices use the types and interfaces defined in the `invoices` package. - Implement the InvoiceDB interface (defined in `lnd/invoices`) in channeldb. - Add new mock for InterfaceDB. - `InvoiceRegistery` tests are now in its own subpacakge (they need to import both invoices & channeldb). This is temporary until we can decouple them.
This commit is contained in:
26 files changed
+2839
-2253
No files matched your search
@@ -18,7 +18,7 @@ import (
|
||||
type InvoiceDatabase interface {
|
||||
// LookupInvoice attempts to look up an invoice according to its 32
|
||||
// byte payment hash.
|
||||
LookupInvoice(lntypes.Hash) (channeldb.Invoice, error)
|
||||
LookupInvoice(lntypes.Hash) (invoices.Invoice, error)
|
||||
|
||||
// NotifyExitHopHtlc attempts to mark an invoice as settled. If the
|
||||
// invoice is a debug invoice, then this method is a noop as debug
|
||||
|
||||
+12
-11
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
invpkg "github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
@@ -479,7 +480,7 @@ func TestChannelLinkSingleHopPayment(t *testing.T) {
|
||||
// links was changed.
|
||||
invoice, err := receiver.registry.LookupInvoice(rhash)
|
||||
require.NoError(t, err, "unable to get invoice")
|
||||
if invoice.State != channeldb.ContractSettled {
|
||||
if invoice.State != invpkg.ContractSettled {
|
||||
t.Fatal("alice invoice wasn't settled")
|
||||
}
|
||||
|
||||
@@ -597,7 +598,7 @@ func testChannelLinkMultiHopPayment(t *testing.T,
|
||||
// links were changed.
|
||||
invoice, err := receiver.registry.LookupInvoice(rhash)
|
||||
require.NoError(t, err, "unable to get invoice")
|
||||
if invoice.State != channeldb.ContractSettled {
|
||||
if invoice.State != invpkg.ContractSettled {
|
||||
t.Fatal("carol invoice haven't been settled")
|
||||
}
|
||||
|
||||
@@ -1080,7 +1081,7 @@ func TestUpdateForwardingPolicy(t *testing.T) {
|
||||
// succeeded.
|
||||
invoice, err := n.carolServer.registry.LookupInvoice(payResp)
|
||||
require.NoError(t, err, "unable to get invoice")
|
||||
if invoice.State != channeldb.ContractSettled {
|
||||
if invoice.State != invpkg.ContractSettled {
|
||||
t.Fatal("carol invoice haven't been settled")
|
||||
}
|
||||
|
||||
@@ -1234,7 +1235,7 @@ func TestChannelLinkMultiHopInsufficientPayment(t *testing.T) {
|
||||
// links hasn't been changed.
|
||||
invoice, err := receiver.registry.LookupInvoice(rhash)
|
||||
require.NoError(t, err, "unable to get invoice")
|
||||
if invoice.State == channeldb.ContractSettled {
|
||||
if invoice.State == invpkg.ContractSettled {
|
||||
t.Fatal("carol invoice have been settled")
|
||||
}
|
||||
|
||||
@@ -1412,7 +1413,7 @@ func TestChannelLinkMultiHopUnknownNextHop(t *testing.T) {
|
||||
// links hasn't been changed.
|
||||
invoice, err := receiver.registry.LookupInvoice(rhash)
|
||||
require.NoError(t, err, "unable to get invoice")
|
||||
if invoice.State == channeldb.ContractSettled {
|
||||
if invoice.State == invpkg.ContractSettled {
|
||||
t.Fatal("carol invoice have been settled")
|
||||
}
|
||||
|
||||
@@ -1520,7 +1521,7 @@ func TestChannelLinkMultiHopDecodeError(t *testing.T) {
|
||||
// links hasn't been changed.
|
||||
invoice, err := receiver.registry.LookupInvoice(rhash)
|
||||
require.NoError(t, err, "unable to get invoice")
|
||||
if invoice.State == channeldb.ContractSettled {
|
||||
if invoice.State == invpkg.ContractSettled {
|
||||
t.Fatal("carol invoice have been settled")
|
||||
}
|
||||
|
||||
@@ -3498,7 +3499,7 @@ func TestChannelRetransmission(t *testing.T) {
|
||||
// TODO(andrew.shvv) Will be removed if we move the notification center
|
||||
// to the channel link itself.
|
||||
|
||||
var invoice channeldb.Invoice
|
||||
var invoice invpkg.Invoice
|
||||
for i := 0; i < 20; i++ {
|
||||
select {
|
||||
case <-time.After(time.Millisecond * 200):
|
||||
@@ -3513,7 +3514,7 @@ func TestChannelRetransmission(t *testing.T) {
|
||||
err = errors.Errorf("unable to get invoice: %v", err)
|
||||
continue
|
||||
}
|
||||
if invoice.State != channeldb.ContractSettled {
|
||||
if invoice.State != invpkg.ContractSettled {
|
||||
err = errors.Errorf("alice invoice haven't been settled")
|
||||
continue
|
||||
}
|
||||
@@ -4059,7 +4060,7 @@ func TestChannelLinkAcceptOverpay(t *testing.T) {
|
||||
// accepted the payment and marked it as settled.
|
||||
invoice, err := receiver.registry.LookupInvoice(rhash)
|
||||
require.NoError(t, err, "unable to get invoice")
|
||||
if invoice.State != channeldb.ContractSettled {
|
||||
if invoice.State != invpkg.ContractSettled {
|
||||
t.Fatal("carol invoice haven't been settled")
|
||||
}
|
||||
|
||||
@@ -4383,7 +4384,7 @@ func generateHtlc(t *testing.T, coreLink *channelLink,
|
||||
// generateHtlcAndInvoice generates an invoice and a single hop htlc to send to
|
||||
// the receiver.
|
||||
func generateHtlcAndInvoice(t *testing.T,
|
||||
id uint64) (*lnwire.UpdateAddHTLC, *channeldb.Invoice) {
|
||||
id uint64) (*lnwire.UpdateAddHTLC, *invpkg.Invoice) {
|
||||
|
||||
t.Helper()
|
||||
|
||||
@@ -4778,7 +4779,7 @@ func testChannelLinkBatchPreimageWrite(t *testing.T, disconnect bool) {
|
||||
// We will send 10 HTLCs in total, from Bob to Alice.
|
||||
numHtlcs := 10
|
||||
var htlcs []*lnwire.UpdateAddHTLC
|
||||
var invoices []*channeldb.Invoice
|
||||
var invoices []*invpkg.Invoice
|
||||
for i := 0; i < numHtlcs; i++ {
|
||||
htlc, invoice := generateHtlcAndInvoice(t, uint64(i))
|
||||
htlcs = append(htlcs, htlc)
|
||||
|
||||
+2
-2
@@ -980,7 +980,7 @@ func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
|
||||
}
|
||||
|
||||
func (i *mockInvoiceRegistry) LookupInvoice(rHash lntypes.Hash) (
|
||||
channeldb.Invoice, error) {
|
||||
invoices.Invoice, error) {
|
||||
|
||||
return i.registry.LookupInvoice(rHash)
|
||||
}
|
||||
@@ -1014,7 +1014,7 @@ func (i *mockInvoiceRegistry) CancelInvoice(payHash lntypes.Hash) error {
|
||||
return i.registry.CancelInvoice(payHash)
|
||||
}
|
||||
|
||||
func (i *mockInvoiceRegistry) AddInvoice(invoice channeldb.Invoice,
|
||||
func (i *mockInvoiceRegistry) AddInvoice(invoice invoices.Invoice,
|
||||
paymentHash lntypes.Hash) error {
|
||||
|
||||
_, err := i.registry.AddInvoice(&invoice, paymentHash)
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
@@ -510,7 +511,7 @@ func getChanID(msg lnwire.Message) (lnwire.ChannelID, error) {
|
||||
func generatePaymentWithPreimage(invoiceAmt, htlcAmt lnwire.MilliSatoshi,
|
||||
timelock uint32, blob [lnwire.OnionPacketSize]byte,
|
||||
preimage *lntypes.Preimage, rhash, payAddr [32]byte) (
|
||||
*channeldb.Invoice, *lnwire.UpdateAddHTLC, uint64, error) {
|
||||
*invoices.Invoice, *lnwire.UpdateAddHTLC, uint64, error) {
|
||||
|
||||
// Create the db invoice. Normally the payment requests needs to be set,
|
||||
// because it is decoded in InvoiceRegistry to obtain the cltv expiry.
|
||||
@@ -519,9 +520,9 @@ func generatePaymentWithPreimage(invoiceAmt, htlcAmt lnwire.MilliSatoshi,
|
||||
// don't need to bother here with creating and signing a payment
|
||||
// request.
|
||||
|
||||
invoice := &channeldb.Invoice{
|
||||
invoice := &invoices.Invoice{
|
||||
CreationDate: time.Now(),
|
||||
Terms: channeldb.ContractTerm{
|
||||
Terms: invoices.ContractTerm{
|
||||
FinalCltvDelta: testInvoiceCltvExpiry,
|
||||
Value: invoiceAmt,
|
||||
PaymentPreimage: preimage,
|
||||
@@ -552,7 +553,7 @@ func generatePaymentWithPreimage(invoiceAmt, htlcAmt lnwire.MilliSatoshi,
|
||||
// generatePayment generates the htlc add request by given path blob and
|
||||
// invoice which should be added by destination peer.
|
||||
func generatePayment(invoiceAmt, htlcAmt lnwire.MilliSatoshi, timelock uint32,
|
||||
blob [lnwire.OnionPacketSize]byte) (*channeldb.Invoice,
|
||||
blob [lnwire.OnionPacketSize]byte) (*invoices.Invoice,
|
||||
*lnwire.UpdateAddHTLC, uint64, error) {
|
||||
|
||||
var preimage lntypes.Preimage
|
||||
@@ -753,7 +754,7 @@ func makePayment(sendingPeer, receivingPeer lnpeer.Peer,
|
||||
func preparePayment(sendingPeer, receivingPeer lnpeer.Peer,
|
||||
firstHop lnwire.ShortChannelID, hops []*hop.Payload,
|
||||
invoiceAmt, htlcAmt lnwire.MilliSatoshi,
|
||||
timelock uint32) (*channeldb.Invoice, func() error, error) {
|
||||
timelock uint32) (*invoices.Invoice, func() error, error) {
|
||||
|
||||
sender := sendingPeer.(*mockServer)
|
||||
receiver := receivingPeer.(*mockServer)
|
||||
|
||||
Reference in new issue
Block a user