Skip to content
Closed
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
44 changes: 34 additions & 10 deletions channeldb/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net"
"time"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
Expand Down Expand Up @@ -182,11 +183,6 @@ func WriteElement(w io.Writer, element interface{}) error {
return err
}

case paymentIndexType:
if err := binary.Write(w, byteOrder, e); err != nil {
return err
}

case lnwire.FundingFlag:
if err := binary.Write(w, byteOrder, e); err != nil {
return err
Expand Down Expand Up @@ -415,11 +411,6 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}

case *paymentIndexType:
if err := binary.Read(r, byteOrder, e); err != nil {
return err
}

case *lnwire.FundingFlag:
if err := binary.Read(r, byteOrder, e); err != nil {
return err
Expand Down Expand Up @@ -466,3 +457,36 @@ func ReadElements(r io.Reader, elements ...interface{}) error {
}
return nil
}

// deserializeTime deserializes time as unix nanoseconds.
func deserializeTime(r io.Reader) (time.Time, error) {
var scratch [8]byte
if _, err := io.ReadFull(r, scratch[:]); err != nil {
return time.Time{}, err
}

// Convert to time.Time. Interpret unix nano time zero as a zero
// time.Time value.
unixNano := byteOrder.Uint64(scratch[:])
if unixNano == 0 {
return time.Time{}, nil
}

return time.Unix(0, int64(unixNano)), nil
}

// serializeTime serializes time as unix nanoseconds.
func serializeTime(w io.Writer, t time.Time) error {
var scratch [8]byte

// Convert to unix nano seconds, but only if time is non-zero. Calling
// UnixNano() on a zero time yields an undefined result.
var unixNano int64
if !t.IsZero() {
unixNano = t.UnixNano()
}

byteOrder.PutUint64(scratch[:], uint64(unixNano))
_, err := w.Write(scratch[:])
return err
}
15 changes: 7 additions & 8 deletions channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ var (
migration: mig.CreateTLB(payAddrIndexBucket),
},
{
// Initialize payment index bucket which will be used
// to index payments by sequence number. This index will
// be used to allow more efficient ListPayments queries.
number: 15,
migration: mig.CreateTLB(paymentsIndexBucket),
// This used to be create payment related top-level
// buckets, however this is now done by the payment
// package.
number: 15,
migration: func(tx kvdb.RwTx) error {
return nil
},
},
{
// Add our existing payments to the index bucket created
Expand Down Expand Up @@ -352,7 +354,6 @@ type DB struct {
dbPath string
clock clock.Clock
dryRun bool
keepFailedPaymentAttempts bool
storeFinalHtlcResolutions bool

// noRevLogAmtData if true, means that commitment transaction amount
Expand Down Expand Up @@ -413,7 +414,6 @@ func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB,
},
clock: opts.clock,
dryRun: opts.dryRun,
keepFailedPaymentAttempts: opts.keepFailedPaymentAttempts,
storeFinalHtlcResolutions: opts.storeFinalHtlcResolutions,
noRevLogAmtData: opts.NoRevLogAmtData,
}
Expand Down Expand Up @@ -452,7 +452,6 @@ var dbTopLevelBuckets = [][]byte{
invoiceBucket,
payAddrIndexBucket,
setIDIndexBucket,
paymentsIndexBucket,
peersBucket,
nodeInfoBucket,
metaBucket,
Expand Down
248 changes: 0 additions & 248 deletions channeldb/duplicate_payments.go

This file was deleted.

4 changes: 2 additions & 2 deletions channeldb/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) (

// Create a paginator which reads from our add index bucket with
// the parameters provided by the invoice query.
paginator := newPaginator(
paginator := NewPaginator(
invoiceAddIndex.ReadCursor(), q.Reversed, q.IndexOffset,
q.NumMaxInvoices,
)
Expand Down Expand Up @@ -603,7 +603,7 @@ func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) (

// Query our paginator using accumulateInvoices to build up a
// set of invoices.
if err := paginator.query(accumulateInvoices); err != nil {
if err := paginator.Query(accumulateInvoices); err != nil {
return err
}

Expand Down
Loading
Loading