channeldb/invoice: map zero-value timestamps to 0
Mainly affects ResolveTime which can be 0 before its settled.
This commit is contained in:
parent
da049ebcf7
commit
7c0d1e0093
@ -1304,8 +1304,8 @@ func serializeHtlcs(w io.Writer, htlcs map[CircuitKey]*InvoiceHTLC) error {
|
|||||||
chanID := key.ChanID.ToUint64()
|
chanID := key.ChanID.ToUint64()
|
||||||
amt := uint64(htlc.Amt)
|
amt := uint64(htlc.Amt)
|
||||||
mppTotalAmt := uint64(htlc.MppTotalAmt)
|
mppTotalAmt := uint64(htlc.MppTotalAmt)
|
||||||
acceptTime := uint64(htlc.AcceptTime.UnixNano())
|
acceptTime := putNanoTime(htlc.AcceptTime)
|
||||||
resolveTime := uint64(htlc.ResolveTime.UnixNano())
|
resolveTime := putNanoTime(htlc.ResolveTime)
|
||||||
state := uint8(htlc.State)
|
state := uint8(htlc.State)
|
||||||
|
|
||||||
var records []tlv.Record
|
var records []tlv.Record
|
||||||
@ -1379,6 +1379,25 @@ func serializeHtlcs(w io.Writer, htlcs map[CircuitKey]*InvoiceHTLC) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// putNanoTime returns the unix nano time for the passed timestamp. A zero-value
|
||||||
|
// timestamp will be mapped to 0, since calling UnixNano in that case is
|
||||||
|
// undefined.
|
||||||
|
func putNanoTime(t time.Time) uint64 {
|
||||||
|
if t.IsZero() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return uint64(t.UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
|
// getNanoTime returns a timestamp for the given number of nano seconds. If zero
|
||||||
|
// is provided, an zero-value time stamp is returned.
|
||||||
|
func getNanoTime(ns uint64) time.Time {
|
||||||
|
if ns == 0 {
|
||||||
|
return time.Time{}
|
||||||
|
}
|
||||||
|
return time.Unix(0, int64(ns))
|
||||||
|
}
|
||||||
|
|
||||||
func fetchInvoice(invoiceNum []byte, invoices kvdb.RBucket) (Invoice, error) {
|
func fetchInvoice(invoiceNum []byte, invoices kvdb.RBucket) (Invoice, error) {
|
||||||
invoiceBytes := invoices.Get(invoiceNum)
|
invoiceBytes := invoices.Get(invoiceNum)
|
||||||
if invoiceBytes == nil {
|
if invoiceBytes == nil {
|
||||||
@ -1564,8 +1583,8 @@ func deserializeHtlcs(r io.Reader) (map[CircuitKey]*InvoiceHTLC, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
key.ChanID = lnwire.NewShortChanIDFromInt(chanID)
|
key.ChanID = lnwire.NewShortChanIDFromInt(chanID)
|
||||||
htlc.AcceptTime = time.Unix(0, int64(acceptTime))
|
htlc.AcceptTime = getNanoTime(acceptTime)
|
||||||
htlc.ResolveTime = time.Unix(0, int64(resolveTime))
|
htlc.ResolveTime = getNanoTime(resolveTime)
|
||||||
htlc.State = HtlcState(state)
|
htlc.State = HtlcState(state)
|
||||||
htlc.Amt = lnwire.MilliSatoshi(amt)
|
htlc.Amt = lnwire.MilliSatoshi(amt)
|
||||||
htlc.MppTotalAmt = lnwire.MilliSatoshi(mppTotalAmt)
|
htlc.MppTotalAmt = lnwire.MilliSatoshi(mppTotalAmt)
|
||||||
|
Loading…
Reference in New Issue
Block a user