cnct+htlcswitch+invoices: move invoice parameter check out of link

This commit is the final step in making the link unaware of invoices. It
now purely offers the htlc to the invoice registry and follows
instructions from the invoice registry about how and when to respond to
the htlc.

The change also fixes a bug where upon restart, hodl htlcs were
subjected to the invoice minimum cltv delta requirement again. If the
block height has increased in the mean while, the htlc would be canceled
back.

Furthermore the invoice registry interaction is aligned between link and
contract resolvers.
This commit is contained in:
Joost Jager committed 2019-05-15 14:42:12 +02:00
1 parent e095819385
commit 064e8492de
16 files changed
+533 -265

No files matched your search

+21 -5
View File
@@ -99,7 +99,10 @@ func TestInvoiceWorkflow(t *testing.T) {
// now have the settled bit toggle to true and a non-default
// SettledDate
payAmt := fakeInvoice.Terms.Value * 2
if _, err := db.AcceptOrSettleInvoice(paymentHash, payAmt); err != nil {
_, err = db.AcceptOrSettleInvoice(
paymentHash, payAmt, checkHtlcParameters,
)
if err != nil {
t.Fatalf("unable to settle invoice: %v", err)
}
dbInvoice2, err := db.LookupInvoice(paymentHash)
@@ -261,7 +264,9 @@ func TestInvoiceAddTimeSeries(t *testing.T) {
paymentHash := invoice.Terms.PaymentPreimage.Hash()
_, err := db.AcceptOrSettleInvoice(paymentHash, 0)
_, err := db.AcceptOrSettleInvoice(
paymentHash, 0, checkHtlcParameters,
)
if err != nil {
t.Fatalf("unable to settle invoice: %v", err)
}
@@ -342,7 +347,9 @@ func TestDuplicateSettleInvoice(t *testing.T) {
}
// With the invoice in the DB, we'll now attempt to settle the invoice.
dbInvoice, err := db.AcceptOrSettleInvoice(payHash, amt)
dbInvoice, err := db.AcceptOrSettleInvoice(
payHash, amt, checkHtlcParameters,
)
if err != nil {
t.Fatalf("unable to settle invoice: %v", err)
}
@@ -362,7 +369,9 @@ func TestDuplicateSettleInvoice(t *testing.T) {
// If we try to settle the invoice again, then we should get the very
// same invoice back, but with an error this time.
dbInvoice, err = db.AcceptOrSettleInvoice(payHash, amt)
dbInvoice, err = db.AcceptOrSettleInvoice(
payHash, amt, checkHtlcParameters,
)
if err != ErrInvoiceAlreadySettled {
t.Fatalf("expected ErrInvoiceAlreadySettled")
}
@@ -407,7 +416,10 @@ func TestQueryInvoices(t *testing.T) {
// We'll only settle half of all invoices created.
if i%2 == 0 {
if _, err := db.AcceptOrSettleInvoice(paymentHash, i); err != nil {
_, err := db.AcceptOrSettleInvoice(
paymentHash, i, checkHtlcParameters,
)
if err != nil {
t.Fatalf("unable to settle invoice: %v", err)
}
}
@@ -648,3 +660,7 @@ func TestQueryInvoices(t *testing.T) {
}
}
}
func checkHtlcParameters(invoice *Invoice) error {
return nil
}