Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/coreos/bbolt"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/channeldb/migration12"
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
"github.com/lightningnetwork/lnd/lnwire"
)
Expand Down Expand Up @@ -116,6 +117,12 @@ var (
number: 11,
migration: migration_01_to_11.MigrateInvoices,
},
{
// Migrate to TLV invoice bodies, add payment address
// and features, remove receipt.
number: 12,
migration: migration12.MigrateInvoiceTLV,
},
}

// Big endian is the preferred byte order, due to cursor scans over
Expand Down
18 changes: 11 additions & 7 deletions channeldb/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/lightningnetwork/lnd/lnwire"
)

var (
emptyFeatures = lnwire.NewFeatureVector(nil, lnwire.Features)
)

func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
var pre [32]byte
if _, err := rand.Read(pre[:]); err != nil {
Expand All @@ -21,14 +25,14 @@ func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
Terms: ContractTerm{
Expiry: 4000,
PaymentPreimage: pre,
Value: value,
Features: emptyFeatures,
},
Htlcs: map[CircuitKey]*InvoiceHTLC{},
Expiry: 4000,
Htlcs: map[CircuitKey]*InvoiceHTLC{},
}
i.Memo = []byte("memo")
i.Receipt = []byte("receipt")

// Create a random byte slice of MaxPaymentRequestSize bytes to be used
// as a dummy paymentrequest, and determine if it should be set based
Expand Down Expand Up @@ -64,10 +68,10 @@ func TestInvoiceWorkflow(t *testing.T) {
Htlcs: map[CircuitKey]*InvoiceHTLC{},
}
fakeInvoice.Memo = []byte("memo")
fakeInvoice.Receipt = []byte("receipt")
fakeInvoice.PaymentRequest = []byte("")
copy(fakeInvoice.Terms.PaymentPreimage[:], rev[:])
fakeInvoice.Terms.Value = lnwire.NewMSatFromSatoshis(10000)
fakeInvoice.Terms.Features = emptyFeatures

paymentHash := fakeInvoice.Terms.PaymentPreimage.Hash()

Expand Down Expand Up @@ -110,7 +114,7 @@ func TestInvoiceWorkflow(t *testing.T) {
if err != nil {
t.Fatalf("unable to fetch invoice: %v", err)
}
if dbInvoice2.Terms.State != ContractSettled {
if dbInvoice2.State != ContractSettled {
Comment thread
cfromknecht marked this conversation as resolved.
Outdated
t.Fatalf("invoice should now be settled but isn't")
}
if dbInvoice2.SettleDate.IsZero() {
Expand Down Expand Up @@ -359,7 +363,7 @@ func TestDuplicateSettleInvoice(t *testing.T) {
// We'll update what we expect the settle invoice to be so that our
// comparison below has the correct assumption.
invoice.SettleIndex = 1
invoice.Terms.State = ContractSettled
invoice.State = ContractSettled
invoice.AmtPaid = amt
invoice.SettleDate = dbInvoice.SettleDate
invoice.Htlcs = map[CircuitKey]*InvoiceHTLC{
Expand Down Expand Up @@ -675,7 +679,7 @@ func TestQueryInvoices(t *testing.T) {
// settles the invoice with the given amount.
func getUpdateInvoice(amt lnwire.MilliSatoshi) InvoiceUpdateCallback {
return func(invoice *Invoice) (*InvoiceUpdateDesc, error) {
if invoice.Terms.State == ContractSettled {
if invoice.State == ContractSettled {
return nil, ErrInvoiceAlreadySettled
}

Expand Down
Loading