channeldb: index payments by sequence number
Add an entry to a payments index bucket which maps sequence number to payment hash when we initiate payments. This allows for more efficient paginated queries. We create the top level bucket in its own migration so that we do not need to create it on the fly. When we retry payments and provide them with a new sequence number, we delete the index for their existing payment so that we do not have an index that points to a non-existent payment. If we delete a payment, we also delete its index entry. This prevents us from looking up entries from indexes to payments that do not exist.
This commit is contained in:
10 files changed
+647
-11
No files matched your search
@@ -16,6 +16,7 @@ import (
|
||||
mig "github.com/lightningnetwork/lnd/channeldb/migration"
|
||||
"github.com/lightningnetwork/lnd/channeldb/migration12"
|
||||
"github.com/lightningnetwork/lnd/channeldb/migration13"
|
||||
"github.com/lightningnetwork/lnd/channeldb/migration16"
|
||||
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@@ -144,6 +145,19 @@ var (
|
||||
number: 14,
|
||||
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),
|
||||
},
|
||||
{
|
||||
// Add our existing payments to the index bucket created
|
||||
// in migration 15.
|
||||
number: 16,
|
||||
migration: migration16.MigrateSequenceIndex,
|
||||
},
|
||||
}
|
||||
|
||||
// Big endian is the preferred byte order, due to cursor scans over
|
||||
@@ -257,6 +271,7 @@ var topLevelBuckets = [][]byte{
|
||||
fwdPackagesKey,
|
||||
invoiceBucket,
|
||||
payAddrIndexBucket,
|
||||
paymentsIndexBucket,
|
||||
nodeInfoBucket,
|
||||
nodeBucket,
|
||||
edgeBucket,
|
||||
|
||||
Reference in new issue
Block a user