diff --git a/invoices/invoices_test.go b/invoices/invoices_test.go index 4e30b0ac9..800261355 100644 --- a/invoices/invoices_test.go +++ b/invoices/invoices_test.go @@ -69,7 +69,7 @@ func randInvoice(value lnwire.MilliSatoshi) (*invpkg.Invoice, error) { i := &invpkg.Invoice{ CreationDate: testNow, Terms: invpkg.ContractTerm{ - Expiry: 4000, + Expiry: time.Duration(4000) * time.Second, PaymentPreimage: &pre, PaymentAddr: payAddr, Value: value, diff --git a/invoices/sql_store.go b/invoices/sql_store.go index 21254ddef..4b488715b 100644 --- a/invoices/sql_store.go +++ b/invoices/sql_store.go @@ -233,7 +233,7 @@ func (i *SQLStore) AddInvoice(ctx context.Context, CltvDelta: sqldb.SQLInt32( newInvoice.Terms.FinalCltvDelta, ), - Expiry: int32(newInvoice.Terms.Expiry), + Expiry: int32(newInvoice.Terms.Expiry.Seconds()), // Note: keysend invoices don't have a payment request. PaymentRequest: sqldb.SQLStr(string( newInvoice.PaymentRequest), @@ -1598,6 +1598,8 @@ func unmarshalInvoice(row sqlc.Invoice) (*lntypes.Hash, *Invoice, cltvDelta = row.CltvDelta.Int32 } + expiry := time.Duration(row.Expiry) * time.Second + invoice := &Invoice{ SettleIndex: uint64(settleIndex), SettleDate: settledAt, @@ -1606,7 +1608,7 @@ func unmarshalInvoice(row sqlc.Invoice) (*lntypes.Hash, *Invoice, CreationDate: row.CreatedAt.Local(), Terms: ContractTerm{ FinalCltvDelta: cltvDelta, - Expiry: time.Duration(row.Expiry), + Expiry: expiry, PaymentPreimage: preimage, Value: lnwire.MilliSatoshi(row.AmountMsat), PaymentAddr: paymentAddr, diff --git a/sqldb/sqlc/migrations/000004_invoice_expiry_fix.down.sql b/sqldb/sqlc/migrations/000004_invoice_expiry_fix.down.sql new file mode 100644 index 000000000..5a4ff3ab2 --- /dev/null +++ b/sqldb/sqlc/migrations/000004_invoice_expiry_fix.down.sql @@ -0,0 +1,2 @@ +-- Given that all expiries are changed in this migration we won't be able to +-- roll back to the previous values. diff --git a/sqldb/sqlc/migrations/000004_invoice_expiry_fix.up.sql b/sqldb/sqlc/migrations/000004_invoice_expiry_fix.up.sql new file mode 100644 index 000000000..02311f830 --- /dev/null +++ b/sqldb/sqlc/migrations/000004_invoice_expiry_fix.up.sql @@ -0,0 +1,14 @@ +-- Update the expiry for all records in the invoices table. This is needed as +-- previously we stored raw time.Duration values which are 64 bit integers and +-- are used to express duration in nanoseconds however the intent is to store +-- invoice expiry in seconds. + +-- Update the expiry to 86400 seconds (24 hours) for non-AMP invoices. +UPDATE invoices +SET expiry = 86400 +WHERE is_amp = FALSE; + +-- Update the expiry to 2592000 seconds (30 days) for AMP invoices +UPDATE invoices +SET expiry = 2592000 +WHERE is_amp = TRUE;