channeldb+invoices: add invoice htlcs
This commit adds a set of htlcs to the Invoice struct and serializes/deserializes this set to/from disk. It is a preparation for accurate invoice accounting across restarts of lnd. A migration is added for the invoice htlcs. In addition to these changes, separate final cltv delta and expiry invoice fields are created and populated. Previously it was required to decode this from the stored payment request. The reason to create a combined commit is to prevent multiple migrations.
This commit is contained in:
8 files changed
+633
-4
No files matched your search
@@ -10,6 +10,26 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
var (
|
||||
testCircuitKey = CircuitKey{
|
||||
ChanID: lnwire.ShortChannelID{
|
||||
BlockHeight: 1, TxIndex: 2, TxPosition: 3,
|
||||
},
|
||||
HtlcID: 4,
|
||||
}
|
||||
|
||||
testHtlcs = map[CircuitKey]*InvoiceHTLC{
|
||||
testCircuitKey: {
|
||||
State: HtlcStateCancelled,
|
||||
AcceptTime: time.Unix(1, 0),
|
||||
AcceptHeight: 100,
|
||||
ResolveTime: time.Unix(2, 0),
|
||||
Amt: 5200,
|
||||
Expiry: 150,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
|
||||
var pre [32]byte
|
||||
if _, err := rand.Read(pre[:]); err != nil {
|
||||
@@ -24,6 +44,9 @@ func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
|
||||
PaymentPreimage: pre,
|
||||
Value: value,
|
||||
},
|
||||
Htlcs: testHtlcs,
|
||||
FinalCltvDelta: 50,
|
||||
Expiry: 4000,
|
||||
}
|
||||
i.Memo = []byte("memo")
|
||||
i.Receipt = []byte("receipt")
|
||||
@@ -59,6 +82,7 @@ func TestInvoiceWorkflow(t *testing.T) {
|
||||
// Use single second precision to avoid false positive test
|
||||
// failures due to the monotonic time component.
|
||||
CreationDate: time.Unix(time.Now().Unix(), 0),
|
||||
Htlcs: testHtlcs,
|
||||
}
|
||||
fakeInvoice.Memo = []byte("memo")
|
||||
fakeInvoice.Receipt = []byte("receipt")
|
||||
|
||||
Reference in new issue
Block a user